summaryrefslogtreecommitdiff
path: root/src/smt/smt_engine_check_proof.cpp
blob: c86ec7a891acf8777e074248d6d8846ebeed4c8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*********************                                                        */
/*! \file smt_engine_check_proof.cpp
 ** \verbatim
 ** Top contributors (to current version):
 **   Morgan Deters, Mark Laws, Guy Katz
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2018 by the authors listed in the file AUTHORS
 ** in the top-level source directory) and their institutional affiliations.
 ** All rights reserved.  See the file COPYING in the top-level source
 ** directory for licensing information.\endverbatim
 **
 ** \brief [[ Add one-line brief description here ]]
 **
 ** [[ Add lengthier description here ]]
 ** \todo document this file
 **/

#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
#include <io.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#include <cstdlib>
#include <cstring>
#include <fstream>
#include <string>

#include "base/configuration_private.h"
#include "base/cvc4_assert.h"
#include "base/output.h"
#include "smt/smt_engine.h"
#include "util/proof.h"
#include "util/statistics_registry.h"

#if (IS_LFSC_BUILD && IS_PROOFS_BUILD)
#include "lfscc.h"
#endif

using namespace CVC4;
using namespace std;

namespace CVC4 {

namespace proof {
  extern const char *const plf_signatures;
}/* CVC4::proof namespace */

namespace smt {

class UnlinkProofFile {
  string d_filename;
public:
  UnlinkProofFile(const char* filename) : d_filename(filename) {}
  ~UnlinkProofFile() { unlink(d_filename.c_str()); }
};/* class UnlinkProofFile */

}/* CVC4::smt namespace */

}/* CVC4 namespace */

void SmtEngine::checkProof() {

#if (IS_LFSC_BUILD && IS_PROOFS_BUILD)

  Chat() << "generating proof..." << endl;

  const Proof& pf = getProof();

  Chat() << "checking proof..." << endl;

  std::string logicString = d_logic.getLogicString();

  if (!(
        // Pure logics
        logicString == "QF_UF" ||
        logicString == "QF_AX" ||
        logicString == "QF_BV" ||
        // Non-pure logics
        logicString == "QF_AUF" ||
        logicString == "QF_UFBV" ||
        logicString == "QF_ABV" ||
        logicString == "QF_AUFBV"
        )) {
    // This logic is not yet supported
    Notice() << "Notice: no proof-checking for " << logicString << " proofs yet" << endl;
    return;
  }

  char *pfFile = tempnam(NULL, "cvc4_");
  if (!pfFile) {
    Notice() << "Error: couldn't get path from tempnam() during proof checking" << endl;
    return;
  }
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
  int fd = _open(pfFile,
                 _O_CREAT | _O_EXCL | _O_SHORT_LIVED | _O_RDWR,
                 _S_IREAD | _S_IWRITE);
#else
  mode_t openmode = S_IRUSR | S_IWUSR;
  int fd = open(pfFile, O_CREAT | O_EXCL | O_RDWR, openmode);
#endif
  if (fd == -1) {
    free(pfFile);
    Notice() << "Error: failed to open temporary file during proof checking" << endl;
    return;
  }

  // ensure this temp file is removed after
  smt::UnlinkProofFile unlinker(pfFile);

  ofstream pfStream(pfFile);
  pfStream << proof::plf_signatures << endl;
  pf.toStream(pfStream);
  pfStream.close();
  lfscc_init();
  lfscc_check_file(pfFile, false, false, false, false, false, false, false);
  // FIXME: we should actually call lfscc_cleanup here, but lfscc_cleanup
  // segfaults on regress0/bv/core/bitvec7.smt
  //lfscc_cleanup();
  free(pfFile);
  close(fd);

#else /* (IS_LFSC_BUILD && IS_PROOFS_BUILD) */
  Unreachable("This version of CVC4 was built without proof support; cannot check proofs.");
#endif /* (IS_LFSC_BUILD && IS_PROOFS_BUILD) */
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback