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 parsing of array select and store expressions #15705

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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 initializing a fixed-sized-bytes array using string literals.
* SMTChecker: Fix SMT logic error when translating invariants involving array store and select operations.
* Standard JSON Interface: Fix ``generatedSources`` and ``sourceMap`` being generated internally even when not requested.
* Yul: Fix internal compiler error when a code generation error should be reported instead.

Expand Down
10 changes: 10 additions & 0 deletions libsmtutil/CHCSmtLib2Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,16 @@ smtutil::Expression CHCSmtLib2Interface::ScopedParser::toSMTUtilExpression(SMTLi
auto accessor = maybeTupleAccessor.value();
return smtutil::Expression("dt_accessor_" + accessor.first, std::move(arguments), accessor.second);
}
if (op == "select")
{
smtSolverInteractionRequire(arguments.size() == 2, "Select has two arguments: array and index");
return smtutil::Expression::select(arguments[0], arguments[1]);
}
if (op == "store")
{
smtSolverInteractionRequire(arguments.size() == 3, "Store has three arguments: array, index and element");
return smtutil::Expression::store(arguments[0], arguments[1], arguments[2]);
}
else
{
std::set<std::string> boolOperators{"and", "or", "not", "=", "<", ">", "<=", ">=", "=>"};
Expand Down
23 changes: 23 additions & 0 deletions test/libsolidity/smtCheckerTests/invariants/array_access_2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
contract C {
constructor() {
int8 v;
(v *= v);
}
}

contract D {
bool[2] internal a;

function f() internal {
do {} while(!(a[1]));
}
}
// ====
// SMTEngine: chc
// SMTIgnoreInv: no
// SMTSolvers: z3
// SMTTargets: overflow
// ----
// Warning 2018: (102-155): Function state mutability can be restricted to view
// Info 1391: CHC: 1 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them.
// Info 1180: Contract invariant(s) for :D:\n(true || true)\nReentrancy property(ies) for :C:\n((<errorCode> = 0) && (x!5 = x!4))\nReentrancy property(ies) for :D:\n((<errorCode> = 0) && (x!6 = x!4) && (a' = a))\n<errorCode> = 0 -> no errors\n<errorCode> = 1 -> Overflow at v *= v\n
Loading