Skip to content

Commit e3525b8

Browse files
committed
Supply scanner to model checker.
1 parent 01dc77e commit e3525b8

File tree

11 files changed

+61
-20
lines changed

11 files changed

+61
-20
lines changed

libsolidity/formal/BMC.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
#include <libsmtutil/SMTPortfolio.h>
2424

25+
#include <liblangutil/CharStream.h>
26+
#include <liblangutil/CharStreamProvider.h>
27+
2528
#ifdef HAVE_Z3_DLOPEN
2629
#include <z3_version.h>
2730
#endif
@@ -38,9 +41,10 @@ BMC::BMC(
3841
map<h256, string> const& _smtlib2Responses,
3942
ReadCallback::Callback const& _smtCallback,
4043
smtutil::SMTSolverChoice _enabledSolvers,
41-
ModelCheckerSettings const& _settings
44+
ModelCheckerSettings const& _settings,
45+
CharStreamProvider const& _charStreamProvider
4246
):
43-
SMTEncoder(_context, _settings),
47+
SMTEncoder(_context, _settings, _charStreamProvider),
4448
m_interface(make_unique<smtutil::SMTPortfolio>(_smtlib2Responses, _smtCallback, _enabledSolvers, _settings.timeout)),
4549
m_outerErrorReporter(_errorReporter)
4650
{
@@ -650,7 +654,12 @@ pair<vector<smtutil::Expression>, vector<string>> BMC::modelExpressions()
650654
if (uf->annotation().type->isValueType())
651655
{
652656
expressionsToEvaluate.emplace_back(expr(*uf));
653-
// TODO expressionNames.push_back(uf->location().text());
657+
string expressionName;
658+
if (uf->location().hasText())
659+
expressionName = m_charStreamProvider.charStream(*uf->location().sourceName).text(
660+
uf->location()
661+
);
662+
expressionNames.push_back(move(expressionName));
654663
}
655664

656665
return {expressionsToEvaluate, expressionNames};

libsolidity/formal/BMC.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class BMC: public SMTEncoder
6363
std::map<h256, std::string> const& _smtlib2Responses,
6464
ReadCallback::Callback const& _smtCallback,
6565
smtutil::SMTSolverChoice _enabledSolvers,
66-
ModelCheckerSettings const& _settings
66+
ModelCheckerSettings const& _settings,
67+
langutil::CharStreamProvider const& _charStreamProvider
6768
);
6869

6970
void analyze(SourceUnit const& _sources, std::map<ASTNode const*, std::set<VerificationTargetType>> _solvedTargets);

libsolidity/formal/CHC.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ CHC::CHC(
5757
[[maybe_unused]] map<util::h256, string> const& _smtlib2Responses,
5858
[[maybe_unused]] ReadCallback::Callback const& _smtCallback,
5959
SMTSolverChoice _enabledSolvers,
60-
ModelCheckerSettings const& _settings
60+
ModelCheckerSettings const& _settings,
61+
CharStreamProvider const& _charStreamProvider
6162
):
62-
SMTEncoder(_context, _settings),
63+
SMTEncoder(_context, _settings, _charStreamProvider),
6364
m_outerErrorReporter(_errorReporter),
6465
m_enabledSolvers(_enabledSolvers)
6566
{
@@ -1741,7 +1742,7 @@ optional<string> CHC::generateCounterexample(CHCSolverInterface::CexGraph const&
17411742
path.emplace_back("State: " + modelMsg);
17421743
}
17431744

1744-
string txCex = summaryPredicate->formatSummaryCall(summaryArgs);
1745+
string txCex = summaryPredicate->formatSummaryCall(summaryArgs, m_charStreamProvider);
17451746

17461747
list<string> calls;
17471748
auto dfs = [&](unsigned parent, unsigned node, unsigned depth, auto&& _dfs) -> void {
@@ -1753,7 +1754,7 @@ optional<string> CHC::generateCounterexample(CHCSolverInterface::CexGraph const&
17531754
if (!pred->isConstructorSummary())
17541755
for (unsigned v: callGraph[node])
17551756
_dfs(node, v, depth + 1, _dfs);
1756-
calls.push_front(string(depth * 4, ' ') + pred->formatSummaryCall(nodeArgs(node)));
1757+
calls.push_front(string(depth * 4, ' ') + pred->formatSummaryCall(nodeArgs(node), m_charStreamProvider));
17571758
if (pred->isInternalCall())
17581759
calls.front() += " -- internal call";
17591760
else if (pred->isExternalCallTrusted())

libsolidity/formal/CHC.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class CHC: public SMTEncoder
5757
std::map<util::h256, std::string> const& _smtlib2Responses,
5858
ReadCallback::Callback const& _smtCallback,
5959
smtutil::SMTSolverChoice _enabledSolvers,
60-
ModelCheckerSettings const& _settings
60+
ModelCheckerSettings const& _settings,
61+
langutil::CharStreamProvider const& _charStreamProvider
6162
);
6263

6364
void analyze(SourceUnit const& _sources);

libsolidity/formal/ModelChecker.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ using namespace solidity::frontend;
3232

3333
ModelChecker::ModelChecker(
3434
ErrorReporter& _errorReporter,
35+
langutil::CharStreamProvider const& _charStreamProvider,
3536
map<h256, string> const& _smtlib2Responses,
3637
ModelCheckerSettings _settings,
3738
ReadCallback::Callback const& _smtCallback,
@@ -40,8 +41,8 @@ ModelChecker::ModelChecker(
4041
m_errorReporter(_errorReporter),
4142
m_settings(_settings),
4243
m_context(),
43-
m_bmc(m_context, _errorReporter, _smtlib2Responses, _smtCallback, _enabledSolvers, m_settings),
44-
m_chc(m_context, _errorReporter, _smtlib2Responses, _smtCallback, _enabledSolvers, m_settings)
44+
m_bmc(m_context, _errorReporter, _smtlib2Responses, _smtCallback, _enabledSolvers, m_settings, _charStreamProvider),
45+
m_chc(m_context, _errorReporter, _smtlib2Responses, _smtCallback, _enabledSolvers, m_settings, _charStreamProvider)
4546
{
4647
}
4748

libsolidity/formal/ModelChecker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class ModelChecker
4949
/// should be used, even if all are available. The default choice is to use all.
5050
ModelChecker(
5151
langutil::ErrorReporter& _errorReporter,
52+
langutil::CharStreamProvider const& _charStreamProvider,
5253
std::map<solidity::util::h256, std::string> const& _smtlib2Responses,
5354
ModelCheckerSettings _settings = ModelCheckerSettings{},
5455
ReadCallback::Callback const& _smtCallback = ReadCallback::Callback(),

libsolidity/formal/Predicate.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include <libsolidity/formal/SMTEncoder.h>
2222

23+
#include <liblangutil/CharStreamProvider.h>
24+
#include <liblangutil/CharStream.h>
2325
#include <libsolidity/ast/AST.h>
2426
#include <libsolidity/ast/TypeProvider.h>
2527

@@ -196,13 +198,20 @@ bool Predicate::isInterface() const
196198
return m_type == PredicateType::Interface;
197199
}
198200

199-
string Predicate::formatSummaryCall(vector<smtutil::Expression> const& _args) const
201+
string Predicate::formatSummaryCall(
202+
vector<smtutil::Expression> const& _args,
203+
langutil::CharStreamProvider const& _charStreamProvider
204+
) const
200205
{
201206
solAssert(isSummary(), "");
202207

203-
//if (auto funCall = programFunctionCall())
204-
// return funCall->location().text();
205-
// TODO
208+
if (auto funCall = programFunctionCall())
209+
{
210+
if (funCall->location().hasText())
211+
return string(_charStreamProvider.charStream(*funCall->location().sourceName).text(funCall->location()));
212+
else
213+
return {};
214+
}
206215

207216
/// The signature of a function summary predicate is: summary(error, this, abiFunctions, cryptoFunctions, txData, preBlockChainState, preStateVars, preInputVars, postBlockchainState, postStateVars, postInputVars, outputVars).
208217
/// Here we are interested in preInputVars to format the function call,

libsolidity/formal/Predicate.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
#include <optional>
2828
#include <vector>
2929

30+
namespace solidity::langutil
31+
{
32+
class CharStreamProvider;
33+
}
34+
3035
namespace solidity::frontend
3136
{
3237

@@ -142,7 +147,10 @@ class Predicate
142147

143148
/// @returns a formatted string representing a call to this predicate
144149
/// with _args.
145-
std::string formatSummaryCall(std::vector<smtutil::Expression> const& _args) const;
150+
std::string formatSummaryCall(
151+
std::vector<smtutil::Expression> const& _args,
152+
langutil::CharStreamProvider const& _charStreamProvider
153+
) const;
146154

147155
/// @returns the values of the state variables from _args at the point
148156
/// where this summary was reached.

libsolidity/formal/SMTEncoder.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <libsmtutil/SMTPortfolio.h>
3131
#include <libsmtutil/Helpers.h>
3232

33+
#include <liblangutil/CharStreamProvider.h>
34+
3335
#include <range/v3/view.hpp>
3436

3537
#include <boost/range/adaptors.hpp>
@@ -45,11 +47,13 @@ using namespace solidity::frontend;
4547

4648
SMTEncoder::SMTEncoder(
4749
smt::EncodingContext& _context,
48-
ModelCheckerSettings const& _settings
50+
ModelCheckerSettings const& _settings,
51+
langutil::CharStreamProvider const& _charStreamProvider
4952
):
5053
m_errorReporter(m_smtErrors),
5154
m_context(_context),
52-
m_settings(_settings)
55+
m_settings(_settings),
56+
m_charStreamProvider(_charStreamProvider)
5357
{
5458
}
5559

libsolidity/formal/SMTEncoder.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace solidity::langutil
4343
{
4444
class ErrorReporter;
4545
struct SourceLocation;
46+
class CharStreamProvider;
4647
}
4748

4849
namespace solidity::frontend
@@ -53,7 +54,8 @@ class SMTEncoder: public ASTConstVisitor
5354
public:
5455
SMTEncoder(
5556
smt::EncodingContext& _context,
56-
ModelCheckerSettings const& _settings
57+
ModelCheckerSettings const& _settings,
58+
langutil::CharStreamProvider const& _charStreamProvider
5759
);
5860

5961
/// @returns true if engine should proceed with analysis.
@@ -469,6 +471,10 @@ class SMTEncoder: public ASTConstVisitor
469471

470472
ModelCheckerSettings const& m_settings;
471473

474+
/// Character stream for each source,
475+
/// used for retrieving source text of expressions for e.g. counter-examples.
476+
langutil::CharStreamProvider const& m_charStreamProvider;
477+
472478
smt::SymbolicState& state();
473479
};
474480

0 commit comments

Comments
 (0)