mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Supply scanner to model checker.
This commit is contained in:
parent
01dc77e5a2
commit
e3525b81d0
@ -22,6 +22,9 @@
|
|||||||
|
|
||||||
#include <libsmtutil/SMTPortfolio.h>
|
#include <libsmtutil/SMTPortfolio.h>
|
||||||
|
|
||||||
|
#include <liblangutil/CharStream.h>
|
||||||
|
#include <liblangutil/CharStreamProvider.h>
|
||||||
|
|
||||||
#ifdef HAVE_Z3_DLOPEN
|
#ifdef HAVE_Z3_DLOPEN
|
||||||
#include <z3_version.h>
|
#include <z3_version.h>
|
||||||
#endif
|
#endif
|
||||||
@ -38,9 +41,10 @@ BMC::BMC(
|
|||||||
map<h256, string> const& _smtlib2Responses,
|
map<h256, string> const& _smtlib2Responses,
|
||||||
ReadCallback::Callback const& _smtCallback,
|
ReadCallback::Callback const& _smtCallback,
|
||||||
smtutil::SMTSolverChoice _enabledSolvers,
|
smtutil::SMTSolverChoice _enabledSolvers,
|
||||||
ModelCheckerSettings const& _settings
|
ModelCheckerSettings const& _settings,
|
||||||
|
CharStreamProvider const& _charStreamProvider
|
||||||
):
|
):
|
||||||
SMTEncoder(_context, _settings),
|
SMTEncoder(_context, _settings, _charStreamProvider),
|
||||||
m_interface(make_unique<smtutil::SMTPortfolio>(_smtlib2Responses, _smtCallback, _enabledSolvers, _settings.timeout)),
|
m_interface(make_unique<smtutil::SMTPortfolio>(_smtlib2Responses, _smtCallback, _enabledSolvers, _settings.timeout)),
|
||||||
m_outerErrorReporter(_errorReporter)
|
m_outerErrorReporter(_errorReporter)
|
||||||
{
|
{
|
||||||
@ -650,7 +654,12 @@ pair<vector<smtutil::Expression>, vector<string>> BMC::modelExpressions()
|
|||||||
if (uf->annotation().type->isValueType())
|
if (uf->annotation().type->isValueType())
|
||||||
{
|
{
|
||||||
expressionsToEvaluate.emplace_back(expr(*uf));
|
expressionsToEvaluate.emplace_back(expr(*uf));
|
||||||
// TODO expressionNames.push_back(uf->location().text());
|
string expressionName;
|
||||||
|
if (uf->location().hasText())
|
||||||
|
expressionName = m_charStreamProvider.charStream(*uf->location().sourceName).text(
|
||||||
|
uf->location()
|
||||||
|
);
|
||||||
|
expressionNames.push_back(move(expressionName));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {expressionsToEvaluate, expressionNames};
|
return {expressionsToEvaluate, expressionNames};
|
||||||
|
@ -63,7 +63,8 @@ public:
|
|||||||
std::map<h256, std::string> const& _smtlib2Responses,
|
std::map<h256, std::string> const& _smtlib2Responses,
|
||||||
ReadCallback::Callback const& _smtCallback,
|
ReadCallback::Callback const& _smtCallback,
|
||||||
smtutil::SMTSolverChoice _enabledSolvers,
|
smtutil::SMTSolverChoice _enabledSolvers,
|
||||||
ModelCheckerSettings const& _settings
|
ModelCheckerSettings const& _settings,
|
||||||
|
langutil::CharStreamProvider const& _charStreamProvider
|
||||||
);
|
);
|
||||||
|
|
||||||
void analyze(SourceUnit const& _sources, std::map<ASTNode const*, std::set<VerificationTargetType>> _solvedTargets);
|
void analyze(SourceUnit const& _sources, std::map<ASTNode const*, std::set<VerificationTargetType>> _solvedTargets);
|
||||||
|
@ -57,9 +57,10 @@ CHC::CHC(
|
|||||||
[[maybe_unused]] map<util::h256, string> const& _smtlib2Responses,
|
[[maybe_unused]] map<util::h256, string> const& _smtlib2Responses,
|
||||||
[[maybe_unused]] ReadCallback::Callback const& _smtCallback,
|
[[maybe_unused]] ReadCallback::Callback const& _smtCallback,
|
||||||
SMTSolverChoice _enabledSolvers,
|
SMTSolverChoice _enabledSolvers,
|
||||||
ModelCheckerSettings const& _settings
|
ModelCheckerSettings const& _settings,
|
||||||
|
CharStreamProvider const& _charStreamProvider
|
||||||
):
|
):
|
||||||
SMTEncoder(_context, _settings),
|
SMTEncoder(_context, _settings, _charStreamProvider),
|
||||||
m_outerErrorReporter(_errorReporter),
|
m_outerErrorReporter(_errorReporter),
|
||||||
m_enabledSolvers(_enabledSolvers)
|
m_enabledSolvers(_enabledSolvers)
|
||||||
{
|
{
|
||||||
@ -1741,7 +1742,7 @@ optional<string> CHC::generateCounterexample(CHCSolverInterface::CexGraph const&
|
|||||||
path.emplace_back("State: " + modelMsg);
|
path.emplace_back("State: " + modelMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
string txCex = summaryPredicate->formatSummaryCall(summaryArgs);
|
string txCex = summaryPredicate->formatSummaryCall(summaryArgs, m_charStreamProvider);
|
||||||
|
|
||||||
list<string> calls;
|
list<string> calls;
|
||||||
auto dfs = [&](unsigned parent, unsigned node, unsigned depth, auto&& _dfs) -> void {
|
auto dfs = [&](unsigned parent, unsigned node, unsigned depth, auto&& _dfs) -> void {
|
||||||
@ -1753,7 +1754,7 @@ optional<string> CHC::generateCounterexample(CHCSolverInterface::CexGraph const&
|
|||||||
if (!pred->isConstructorSummary())
|
if (!pred->isConstructorSummary())
|
||||||
for (unsigned v: callGraph[node])
|
for (unsigned v: callGraph[node])
|
||||||
_dfs(node, v, depth + 1, _dfs);
|
_dfs(node, v, depth + 1, _dfs);
|
||||||
calls.push_front(string(depth * 4, ' ') + pred->formatSummaryCall(nodeArgs(node)));
|
calls.push_front(string(depth * 4, ' ') + pred->formatSummaryCall(nodeArgs(node), m_charStreamProvider));
|
||||||
if (pred->isInternalCall())
|
if (pred->isInternalCall())
|
||||||
calls.front() += " -- internal call";
|
calls.front() += " -- internal call";
|
||||||
else if (pred->isExternalCallTrusted())
|
else if (pred->isExternalCallTrusted())
|
||||||
|
@ -57,7 +57,8 @@ public:
|
|||||||
std::map<util::h256, std::string> const& _smtlib2Responses,
|
std::map<util::h256, std::string> const& _smtlib2Responses,
|
||||||
ReadCallback::Callback const& _smtCallback,
|
ReadCallback::Callback const& _smtCallback,
|
||||||
smtutil::SMTSolverChoice _enabledSolvers,
|
smtutil::SMTSolverChoice _enabledSolvers,
|
||||||
ModelCheckerSettings const& _settings
|
ModelCheckerSettings const& _settings,
|
||||||
|
langutil::CharStreamProvider const& _charStreamProvider
|
||||||
);
|
);
|
||||||
|
|
||||||
void analyze(SourceUnit const& _sources);
|
void analyze(SourceUnit const& _sources);
|
||||||
|
@ -32,6 +32,7 @@ using namespace solidity::frontend;
|
|||||||
|
|
||||||
ModelChecker::ModelChecker(
|
ModelChecker::ModelChecker(
|
||||||
ErrorReporter& _errorReporter,
|
ErrorReporter& _errorReporter,
|
||||||
|
langutil::CharStreamProvider const& _charStreamProvider,
|
||||||
map<h256, string> const& _smtlib2Responses,
|
map<h256, string> const& _smtlib2Responses,
|
||||||
ModelCheckerSettings _settings,
|
ModelCheckerSettings _settings,
|
||||||
ReadCallback::Callback const& _smtCallback,
|
ReadCallback::Callback const& _smtCallback,
|
||||||
@ -40,8 +41,8 @@ ModelChecker::ModelChecker(
|
|||||||
m_errorReporter(_errorReporter),
|
m_errorReporter(_errorReporter),
|
||||||
m_settings(_settings),
|
m_settings(_settings),
|
||||||
m_context(),
|
m_context(),
|
||||||
m_bmc(m_context, _errorReporter, _smtlib2Responses, _smtCallback, _enabledSolvers, m_settings),
|
m_bmc(m_context, _errorReporter, _smtlib2Responses, _smtCallback, _enabledSolvers, m_settings, _charStreamProvider),
|
||||||
m_chc(m_context, _errorReporter, _smtlib2Responses, _smtCallback, _enabledSolvers, m_settings)
|
m_chc(m_context, _errorReporter, _smtlib2Responses, _smtCallback, _enabledSolvers, m_settings, _charStreamProvider)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ public:
|
|||||||
/// should be used, even if all are available. The default choice is to use all.
|
/// should be used, even if all are available. The default choice is to use all.
|
||||||
ModelChecker(
|
ModelChecker(
|
||||||
langutil::ErrorReporter& _errorReporter,
|
langutil::ErrorReporter& _errorReporter,
|
||||||
|
langutil::CharStreamProvider const& _charStreamProvider,
|
||||||
std::map<solidity::util::h256, std::string> const& _smtlib2Responses,
|
std::map<solidity::util::h256, std::string> const& _smtlib2Responses,
|
||||||
ModelCheckerSettings _settings = ModelCheckerSettings{},
|
ModelCheckerSettings _settings = ModelCheckerSettings{},
|
||||||
ReadCallback::Callback const& _smtCallback = ReadCallback::Callback(),
|
ReadCallback::Callback const& _smtCallback = ReadCallback::Callback(),
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#include <libsolidity/formal/SMTEncoder.h>
|
#include <libsolidity/formal/SMTEncoder.h>
|
||||||
|
|
||||||
|
#include <liblangutil/CharStreamProvider.h>
|
||||||
|
#include <liblangutil/CharStream.h>
|
||||||
#include <libsolidity/ast/AST.h>
|
#include <libsolidity/ast/AST.h>
|
||||||
#include <libsolidity/ast/TypeProvider.h>
|
#include <libsolidity/ast/TypeProvider.h>
|
||||||
|
|
||||||
@ -196,13 +198,20 @@ bool Predicate::isInterface() const
|
|||||||
return m_type == PredicateType::Interface;
|
return m_type == PredicateType::Interface;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Predicate::formatSummaryCall(vector<smtutil::Expression> const& _args) const
|
string Predicate::formatSummaryCall(
|
||||||
|
vector<smtutil::Expression> const& _args,
|
||||||
|
langutil::CharStreamProvider const& _charStreamProvider
|
||||||
|
) const
|
||||||
{
|
{
|
||||||
solAssert(isSummary(), "");
|
solAssert(isSummary(), "");
|
||||||
|
|
||||||
//if (auto funCall = programFunctionCall())
|
if (auto funCall = programFunctionCall())
|
||||||
// return funCall->location().text();
|
{
|
||||||
// TODO
|
if (funCall->location().hasText())
|
||||||
|
return string(_charStreamProvider.charStream(*funCall->location().sourceName).text(funCall->location()));
|
||||||
|
else
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
/// The signature of a function summary predicate is: summary(error, this, abiFunctions, cryptoFunctions, txData, preBlockChainState, preStateVars, preInputVars, postBlockchainState, postStateVars, postInputVars, outputVars).
|
/// The signature of a function summary predicate is: summary(error, this, abiFunctions, cryptoFunctions, txData, preBlockChainState, preStateVars, preInputVars, postBlockchainState, postStateVars, postInputVars, outputVars).
|
||||||
/// Here we are interested in preInputVars to format the function call,
|
/// Here we are interested in preInputVars to format the function call,
|
||||||
|
@ -27,6 +27,11 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace solidity::langutil
|
||||||
|
{
|
||||||
|
class CharStreamProvider;
|
||||||
|
}
|
||||||
|
|
||||||
namespace solidity::frontend
|
namespace solidity::frontend
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -142,7 +147,10 @@ public:
|
|||||||
|
|
||||||
/// @returns a formatted string representing a call to this predicate
|
/// @returns a formatted string representing a call to this predicate
|
||||||
/// with _args.
|
/// with _args.
|
||||||
std::string formatSummaryCall(std::vector<smtutil::Expression> const& _args) const;
|
std::string formatSummaryCall(
|
||||||
|
std::vector<smtutil::Expression> const& _args,
|
||||||
|
langutil::CharStreamProvider const& _charStreamProvider
|
||||||
|
) const;
|
||||||
|
|
||||||
/// @returns the values of the state variables from _args at the point
|
/// @returns the values of the state variables from _args at the point
|
||||||
/// where this summary was reached.
|
/// where this summary was reached.
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
#include <libsmtutil/SMTPortfolio.h>
|
#include <libsmtutil/SMTPortfolio.h>
|
||||||
#include <libsmtutil/Helpers.h>
|
#include <libsmtutil/Helpers.h>
|
||||||
|
|
||||||
|
#include <liblangutil/CharStreamProvider.h>
|
||||||
|
|
||||||
#include <range/v3/view.hpp>
|
#include <range/v3/view.hpp>
|
||||||
|
|
||||||
#include <boost/range/adaptors.hpp>
|
#include <boost/range/adaptors.hpp>
|
||||||
@ -45,11 +47,13 @@ using namespace solidity::frontend;
|
|||||||
|
|
||||||
SMTEncoder::SMTEncoder(
|
SMTEncoder::SMTEncoder(
|
||||||
smt::EncodingContext& _context,
|
smt::EncodingContext& _context,
|
||||||
ModelCheckerSettings const& _settings
|
ModelCheckerSettings const& _settings,
|
||||||
|
langutil::CharStreamProvider const& _charStreamProvider
|
||||||
):
|
):
|
||||||
m_errorReporter(m_smtErrors),
|
m_errorReporter(m_smtErrors),
|
||||||
m_context(_context),
|
m_context(_context),
|
||||||
m_settings(_settings)
|
m_settings(_settings),
|
||||||
|
m_charStreamProvider(_charStreamProvider)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ namespace solidity::langutil
|
|||||||
{
|
{
|
||||||
class ErrorReporter;
|
class ErrorReporter;
|
||||||
struct SourceLocation;
|
struct SourceLocation;
|
||||||
|
class CharStreamProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace solidity::frontend
|
namespace solidity::frontend
|
||||||
@ -53,7 +54,8 @@ class SMTEncoder: public ASTConstVisitor
|
|||||||
public:
|
public:
|
||||||
SMTEncoder(
|
SMTEncoder(
|
||||||
smt::EncodingContext& _context,
|
smt::EncodingContext& _context,
|
||||||
ModelCheckerSettings const& _settings
|
ModelCheckerSettings const& _settings,
|
||||||
|
langutil::CharStreamProvider const& _charStreamProvider
|
||||||
);
|
);
|
||||||
|
|
||||||
/// @returns true if engine should proceed with analysis.
|
/// @returns true if engine should proceed with analysis.
|
||||||
@ -469,6 +471,10 @@ protected:
|
|||||||
|
|
||||||
ModelCheckerSettings const& m_settings;
|
ModelCheckerSettings const& m_settings;
|
||||||
|
|
||||||
|
/// Character stream for each source,
|
||||||
|
/// used for retrieving source text of expressions for e.g. counter-examples.
|
||||||
|
langutil::CharStreamProvider const& m_charStreamProvider;
|
||||||
|
|
||||||
smt::SymbolicState& state();
|
smt::SymbolicState& state();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -555,7 +555,7 @@ bool CompilerStack::analyze()
|
|||||||
|
|
||||||
if (noErrors)
|
if (noErrors)
|
||||||
{
|
{
|
||||||
ModelChecker modelChecker(m_errorReporter, m_smtlib2Responses, m_modelCheckerSettings, m_readFile, m_enabledSMTSolvers);
|
ModelChecker modelChecker(m_errorReporter, *this, m_smtlib2Responses, m_modelCheckerSettings, m_readFile, m_enabledSMTSolvers);
|
||||||
auto allSources = applyMap(m_sourceOrder, [](Source const* _source) { return _source->ast; });
|
auto allSources = applyMap(m_sourceOrder, [](Source const* _source) { return _source->ast; });
|
||||||
modelChecker.enableAllEnginesIfPragmaPresent(allSources);
|
modelChecker.enableAllEnginesIfPragmaPresent(allSources);
|
||||||
modelChecker.checkRequestedSourcesAndContracts(allSources);
|
modelChecker.checkRequestedSourcesAndContracts(allSources);
|
||||||
|
Loading…
Reference in New Issue
Block a user