mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #10181 from ethereum/smt_user_timeout
[SMTChecker] User timeout option
This commit is contained in:
@@ -34,10 +34,11 @@ BMC::BMC(
|
||||
ErrorReporter& _errorReporter,
|
||||
map<h256, string> const& _smtlib2Responses,
|
||||
ReadCallback::Callback const& _smtCallback,
|
||||
smtutil::SMTSolverChoice _enabledSolvers
|
||||
smtutil::SMTSolverChoice _enabledSolvers,
|
||||
optional<unsigned> _timeout
|
||||
):
|
||||
SMTEncoder(_context),
|
||||
m_interface(make_unique<smtutil::SMTPortfolio>(_smtlib2Responses, _smtCallback, _enabledSolvers)),
|
||||
m_interface(make_unique<smtutil::SMTPortfolio>(_smtlib2Responses, _smtCallback, _enabledSolvers, _timeout)),
|
||||
m_outerErrorReporter(_errorReporter)
|
||||
{
|
||||
#if defined (HAVE_Z3) || defined (HAVE_CVC4)
|
||||
|
||||
@@ -61,7 +61,8 @@ public:
|
||||
langutil::ErrorReporter& _errorReporter,
|
||||
std::map<h256, std::string> const& _smtlib2Responses,
|
||||
ReadCallback::Callback const& _smtCallback,
|
||||
smtutil::SMTSolverChoice _enabledSolvers
|
||||
smtutil::SMTSolverChoice _enabledSolvers,
|
||||
std::optional<unsigned> timeout
|
||||
);
|
||||
|
||||
void analyze(SourceUnit const& _sources, std::map<ASTNode const*, std::set<VerificationTarget::Type>> _solvedTargets);
|
||||
|
||||
@@ -49,18 +49,20 @@ CHC::CHC(
|
||||
ErrorReporter& _errorReporter,
|
||||
[[maybe_unused]] map<util::h256, string> const& _smtlib2Responses,
|
||||
[[maybe_unused]] ReadCallback::Callback const& _smtCallback,
|
||||
SMTSolverChoice _enabledSolvers
|
||||
SMTSolverChoice _enabledSolvers,
|
||||
optional<unsigned> _timeout
|
||||
):
|
||||
SMTEncoder(_context),
|
||||
m_outerErrorReporter(_errorReporter),
|
||||
m_enabledSolvers(_enabledSolvers)
|
||||
m_enabledSolvers(_enabledSolvers),
|
||||
m_queryTimeout(_timeout)
|
||||
{
|
||||
bool usesZ3 = _enabledSolvers.z3;
|
||||
#ifndef HAVE_Z3
|
||||
usesZ3 = false;
|
||||
#endif
|
||||
if (!usesZ3)
|
||||
m_interface = make_unique<CHCSmtLib2Interface>(_smtlib2Responses, _smtCallback);
|
||||
m_interface = make_unique<CHCSmtLib2Interface>(_smtlib2Responses, _smtCallback, m_queryTimeout);
|
||||
}
|
||||
|
||||
void CHC::analyze(SourceUnit const& _source)
|
||||
@@ -699,7 +701,7 @@ void CHC::resetSourceAnalysis()
|
||||
if (usesZ3)
|
||||
{
|
||||
/// z3::fixedpoint does not have a reset mechanism, so we need to create another.
|
||||
m_interface.reset(new Z3CHCInterface());
|
||||
m_interface.reset(new Z3CHCInterface(m_queryTimeout));
|
||||
auto z3Interface = dynamic_cast<Z3CHCInterface const*>(m_interface.get());
|
||||
solAssert(z3Interface, "");
|
||||
m_context.setSolver(z3Interface->z3Interface());
|
||||
|
||||
@@ -55,7 +55,8 @@ public:
|
||||
langutil::ErrorReporter& _errorReporter,
|
||||
std::map<util::h256, std::string> const& _smtlib2Responses,
|
||||
ReadCallback::Callback const& _smtCallback,
|
||||
smtutil::SMTSolverChoice _enabledSolvers
|
||||
smtutil::SMTSolverChoice _enabledSolvers,
|
||||
std::optional<unsigned> timeout
|
||||
);
|
||||
|
||||
void analyze(SourceUnit const& _sources);
|
||||
@@ -330,6 +331,9 @@ private:
|
||||
|
||||
/// SMT solvers that are chosen at runtime.
|
||||
smtutil::SMTSolverChoice m_enabledSolvers;
|
||||
|
||||
/// SMT query timeout in seconds.
|
||||
std::optional<unsigned> m_queryTimeout;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -27,14 +27,14 @@ using namespace solidity::frontend;
|
||||
ModelChecker::ModelChecker(
|
||||
ErrorReporter& _errorReporter,
|
||||
map<h256, string> const& _smtlib2Responses,
|
||||
ModelCheckerEngine _engine,
|
||||
ModelCheckerSettings _settings,
|
||||
ReadCallback::Callback const& _smtCallback,
|
||||
smtutil::SMTSolverChoice _enabledSolvers
|
||||
):
|
||||
m_engine(_engine),
|
||||
m_settings(_settings),
|
||||
m_context(),
|
||||
m_bmc(m_context, _errorReporter, _smtlib2Responses, _smtCallback, _enabledSolvers),
|
||||
m_chc(m_context, _errorReporter, _smtlib2Responses, _smtCallback, _enabledSolvers)
|
||||
m_bmc(m_context, _errorReporter, _smtlib2Responses, _smtCallback, _enabledSolvers, _settings.timeout),
|
||||
m_chc(m_context, _errorReporter, _smtlib2Responses, _smtCallback, _enabledSolvers, _settings.timeout)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -43,14 +43,14 @@ void ModelChecker::analyze(SourceUnit const& _source)
|
||||
if (!_source.annotation().experimentalFeatures.count(ExperimentalFeature::SMTChecker))
|
||||
return;
|
||||
|
||||
if (m_engine.chc)
|
||||
if (m_settings.engine.chc)
|
||||
m_chc.analyze(_source);
|
||||
|
||||
auto solvedTargets = m_chc.safeTargets();
|
||||
for (auto const& target: m_chc.unsafeTargets())
|
||||
solvedTargets[target.first] += target.second;
|
||||
|
||||
if (m_engine.bmc)
|
||||
if (m_settings.engine.bmc)
|
||||
m_bmc.analyze(_source, solvedTargets);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,12 @@ struct ModelCheckerEngine
|
||||
}
|
||||
};
|
||||
|
||||
struct ModelCheckerSettings
|
||||
{
|
||||
ModelCheckerEngine engine = ModelCheckerEngine::All();
|
||||
std::optional<unsigned> timeout;
|
||||
};
|
||||
|
||||
class ModelChecker
|
||||
{
|
||||
public:
|
||||
@@ -79,7 +85,7 @@ public:
|
||||
ModelChecker(
|
||||
langutil::ErrorReporter& _errorReporter,
|
||||
std::map<solidity::util::h256, std::string> const& _smtlib2Responses,
|
||||
ModelCheckerEngine _engine = ModelCheckerEngine::All(),
|
||||
ModelCheckerSettings _settings = ModelCheckerSettings{},
|
||||
ReadCallback::Callback const& _smtCallback = ReadCallback::Callback(),
|
||||
smtutil::SMTSolverChoice _enabledSolvers = smtutil::SMTSolverChoice::All()
|
||||
);
|
||||
@@ -95,7 +101,7 @@ public:
|
||||
static smtutil::SMTSolverChoice availableSolvers();
|
||||
|
||||
private:
|
||||
ModelCheckerEngine m_engine;
|
||||
ModelCheckerSettings m_settings;
|
||||
|
||||
/// Stores the context of the encoding.
|
||||
smt::EncodingContext m_context;
|
||||
|
||||
Reference in New Issue
Block a user