Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMTChecker: Fix crash in BMC engine regarding state variables #15782

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Compiler Features:

Bugfixes:
* General: Fix internal compiler error when requesting IR AST outputs for interfaces and abstract contracts.
* SMTChecker: Fix SMT logic error when analyzing cross-contract getter call with BMC.
* SMTChecker: Fix SMT logic error when initializing a fixed-sized-bytes array using string literals.
* SMTChecker: Fix SMT logic error when translating invariants involving array store and select operations.
* SMTChecker: Fix wrong encoding of string literals as arguments of ``ecrecover`` precompile.
Expand Down
4 changes: 3 additions & 1 deletion libsolidity/formal/BMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ void BMC::analyze(SourceUnit const& _source, std::map<ASTNode const*, std::set<V
m_context.reset();
m_context.setAssertionAccumulation(true);
m_variableUsage.setFunctionInlining(shouldInlineFunctionCall);
createFreeConstants(sourceDependencies(_source));
auto const& sources = sourceDependencies(_source);
createFreeConstants(sources);
createStateVariables(sources);
m_unprovedAmt = 0;

_source.accept(*this);
Expand Down
8 changes: 8 additions & 0 deletions libsolidity/formal/SMTEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3271,6 +3271,14 @@ void SMTEncoder::createFreeConstants(std::set<SourceUnit const*, ASTNode::Compar
}
}

void SMTEncoder::createStateVariables(std::set<SourceUnit const*, ASTNode::CompareByID> const& _sources)
{
for (auto const& source: _sources)
for (auto const& node: source->nodes())
if (auto contract = dynamic_cast<ContractDefinition const*>(node.get()))
createStateVariables(*contract);
}

smt::SymbolicState& SMTEncoder::state()
{
return m_context.state();
Expand Down
3 changes: 3 additions & 0 deletions libsolidity/formal/SMTEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ class SMTEncoder: public ASTConstVisitor
/// Create symbolic variables for the free constants in all @param _sources.
void createFreeConstants(std::set<SourceUnit const*, ASTNode::CompareByID> const& _sources);

/// Create symbolic variables for all state variables for all contracts in all @param _sources.
void createStateVariables(std::set<SourceUnit const*, ASTNode::CompareByID> const& _sources);

/// @returns a note to be added to warnings.
std::string extraComment();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
contract C {
D internal d;
constructor() {
d = new D();
}
function invokeAndCheck() public {
d.set();
assert(d.n() <= 1);
}
}

contract D {
uint public n;
function set() external {
n = 1;
}
}
// ====
// SMTEngine: bmc
// ----
// Warning 8729: (51-58): Contract deployment is only supported in the trusted mode for external calls with the CHC engine.
// Warning 4661: (112-130): BMC: Assertion violation happens here.
Loading