Skip to content

Commit

Permalink
Fix SMT logic error when assigning to an array of contracts or functi…
Browse files Browse the repository at this point in the history
…ons (#15322)
  • Loading branch information
pgebal committed Aug 9, 2024
1 parent f99c239 commit 55a5fd9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Bugfixes:
* SMTChecker: Fix error that reports invalid number of verified checks for BMC and CHC engines.
* SMTChecker: Fix formatting of unary minus expressions in invariants.
* SMTChecker: Fix internal compiler error when reporting proved targets for BMC engine.
* SMTChecker: Fix SMT logic error when assigning to an array of contracts or functions.
* TypeChecker: Fix segfault when assigning nested tuple to tuple.
* Yul AST: Fix ``nativeSrc`` attributes in optimized IR AST referring to locations in unoptimized IR.
* Yul IR Code Generation: Deterministic order of Yul subobjects.
Expand Down
8 changes: 8 additions & 0 deletions libsolidity/formal/SymbolicTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ SortPointer smtSort(frontend::Type const& _type)
// in the tuple's name.
if (auto tupleSort = std::dynamic_pointer_cast<TupleSort>(array->range))
tupleName = tupleSort->name;
else if (isContract(*baseType))
// use a common sort for contracts so inheriting contracts do not cause conflicting SMT types
// solc handles types mismtach
tupleName = "contract";
else if (isFunction(*baseType))
// use a common sort for functions so pure and view modifier do not cause conflicting SMT types
// solc handles types mismtach
tupleName = "function";
else if (
baseType->category() == frontend::Type::Category::Integer ||
baseType->category() == frontend::Type::Category::FixedPoint
Expand Down
17 changes: 17 additions & 0 deletions test/libsolidity/smtCheckerTests/types/array_of_contracts.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
contract A {}

contract B is A {}

contract C {
A[10] a;
B[10] b;

function f() public returns(address) {
a = b;
return address(a[0]);
}
}
// ====
// SMTEngine: all
// ----
// Info 1391: CHC: 1 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them.
16 changes: 16 additions & 0 deletions test/libsolidity/smtCheckerTests/types/array_of_functions.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
contract C {
function() external returns(uint)[1] a;

function b() external pure returns(uint) {
return 1;
}

function test() public returns(uint) {
a = [this.b];
return a[0]();
}
}
// ====
// SMTEngine: all
// ----
// Info 1391: CHC: 1 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them.

0 comments on commit 55a5fd9

Please sign in to comment.