Skip to content

Commit 669092c

Browse files
authored
Merge pull request #15782 from ethereum/smt-bmc-getters
SMTChecker: Fix crash in BMC engine regarding state variables
2 parents ee297e4 + 5734266 commit 669092c

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Compiler Features:
1111

1212
Bugfixes:
1313
* General: Fix internal compiler error when requesting IR AST outputs for interfaces and abstract contracts.
14+
* SMTChecker: Fix SMT logic error when analyzing cross-contract getter call with BMC.
1415
* SMTChecker: Fix SMT logic error when initializing a fixed-sized-bytes array using string literals.
1516
* SMTChecker: Fix SMT logic error when translating invariants involving array store and select operations.
1617
* SMTChecker: Fix wrong encoding of string literals as arguments of ``ecrecover`` precompile.

libsolidity/formal/BMC.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ void BMC::analyze(SourceUnit const& _source, std::map<ASTNode const*, std::set<V
9393
m_context.reset();
9494
m_context.setAssertionAccumulation(true);
9595
m_variableUsage.setFunctionInlining(shouldInlineFunctionCall);
96-
createFreeConstants(sourceDependencies(_source));
96+
auto const& sources = sourceDependencies(_source);
97+
createFreeConstants(sources);
98+
createStateVariables(sources);
9799
m_unprovedAmt = 0;
98100

99101
_source.accept(*this);

libsolidity/formal/SMTEncoder.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -3271,6 +3271,14 @@ void SMTEncoder::createFreeConstants(std::set<SourceUnit const*, ASTNode::Compar
32713271
}
32723272
}
32733273

3274+
void SMTEncoder::createStateVariables(std::set<SourceUnit const*, ASTNode::CompareByID> const& _sources)
3275+
{
3276+
for (auto const& source: _sources)
3277+
for (auto const& node: source->nodes())
3278+
if (auto contract = dynamic_cast<ContractDefinition const*>(node.get()))
3279+
createStateVariables(*contract);
3280+
}
3281+
32743282
smt::SymbolicState& SMTEncoder::state()
32753283
{
32763284
return m_context.state();

libsolidity/formal/SMTEncoder.h

+3
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ class SMTEncoder: public ASTConstVisitor
439439
/// Create symbolic variables for the free constants in all @param _sources.
440440
void createFreeConstants(std::set<SourceUnit const*, ASTNode::CompareByID> const& _sources);
441441

442+
/// Create symbolic variables for all state variables for all contracts in all @param _sources.
443+
void createStateVariables(std::set<SourceUnit const*, ASTNode::CompareByID> const& _sources);
444+
442445
/// @returns a note to be added to warnings.
443446
std::string extraComment();
444447

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
contract C {
2+
D internal d;
3+
constructor() {
4+
d = new D();
5+
}
6+
function invokeAndCheck() public {
7+
d.set();
8+
assert(d.n() <= 1);
9+
}
10+
}
11+
12+
contract D {
13+
uint public n;
14+
function set() external {
15+
n = 1;
16+
}
17+
}
18+
// ====
19+
// SMTEngine: bmc
20+
// ----
21+
// Warning 8729: (51-58): Contract deployment is only supported in the trusted mode for external calls with the CHC engine.
22+
// Warning 4661: (112-130): BMC: Assertion violation happens here.

0 commit comments

Comments
 (0)