Skip to content

Commit 314b145

Browse files
authored
Merge pull request ethereum#15334 from ethereum/smt-z3-command
SMTChecker: Add setup of z3 to SMTSolverCommand
2 parents add191d + da1bc0b commit 314b145

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

libsolidity/interface/SMTSolverCommand.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,35 @@ void SMTSolverCommand::setCvc5(std::optional<unsigned int> timeoutInMilliseconds
5757
}
5858
}
5959

60+
void SMTSolverCommand::setZ3(std::optional<unsigned int> timeoutInMilliseconds, bool _preprocessing, bool _computeInvariants)
61+
{
62+
constexpr int Z3ResourceLimit = 2000000;
63+
m_arguments.clear();
64+
m_solverCmd = "z3";
65+
m_arguments.emplace_back("-in"); // Read from standard input
66+
m_arguments.emplace_back("-smt2"); // Expect input in SMT-LIB2 format
67+
if (_computeInvariants)
68+
m_arguments.emplace_back("-model"); // Output model automatically after check-sat
69+
if (timeoutInMilliseconds)
70+
m_arguments.emplace_back("-t:" + std::to_string(timeoutInMilliseconds.value()));
71+
else
72+
m_arguments.emplace_back("rlimit=" + std::to_string(Z3ResourceLimit));
73+
74+
// These options have been empirically established to be helpful
75+
m_arguments.emplace_back("rewriter.pull_cheap_ite=true");
76+
m_arguments.emplace_back("fp.spacer.q3.use_qgen=true");
77+
m_arguments.emplace_back("fp.spacer.mbqi=false");
78+
m_arguments.emplace_back("fp.spacer.ground_pobs=false");
79+
80+
// Spacer optimization should be
81+
// - enabled for better solving (default)
82+
// - disable for counterexample generation
83+
std::string preprocessingArg = _preprocessing ? "true" : "false";
84+
m_arguments.emplace_back("fp.xform.slice=" + preprocessingArg);
85+
m_arguments.emplace_back("fp.xform.inline_linear=" + preprocessingArg);
86+
m_arguments.emplace_back("fp.xform.inline_eager=" + preprocessingArg);
87+
}
88+
6089
ReadCallback::Result SMTSolverCommand::solve(std::string const& _kind, std::string const& _query) const
6190
{
6291
try

libsolidity/interface/SMTSolverCommand.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class SMTSolverCommand
3838

3939
void setEldarica(std::optional<unsigned int> timeoutInMilliseconds, bool computeInvariants);
4040
void setCvc5(std::optional<unsigned int> timeoutInMilliseconds);
41+
void setZ3(std::optional<unsigned int> timeoutInMilliseconds, bool _preprocessing, bool _computeInvariants);
4142

4243
private:
4344
/// The name of the solver's binary.

0 commit comments

Comments
 (0)