Skip to content

Commit

Permalink
Merge pull request #15701 from ethereum/smt-fix-array-of-strings
Browse files Browse the repository at this point in the history
SMTChecker: Fix error when initializing fixed-sized-bytes array
  • Loading branch information
blishko authored Jan 9, 2025
2 parents c6ed825 + 225ccac commit 6355ff6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
7 changes: 4 additions & 3 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Compiler Features:


Bugfixes:
* General: Fix internal compiler error when requesting IR AST outputs for interfaces and abstract contracts.
* 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.
* 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.
* 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.


### 0.8.28 (2024-10-09)
Expand Down
8 changes: 5 additions & 3 deletions libsolidity/formal/SMTEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,11 @@ void SMTEncoder::endVisit(TupleExpression const& _tuple)
{
// Add constraints for the length and values as it is known.
auto symbArray = std::dynamic_pointer_cast<smt::SymbolicArrayVariable>(m_context.expression(_tuple));
solAssert(symbArray, "");

addArrayLiteralAssertions(*symbArray, applyMap(_tuple.components(), [&](auto const& c) { return expr(*c); }));
smtAssert(symbArray, "Inline array must be represented with SymbolicArrayVariable");
auto originalType = symbArray->originalType();
auto arrayType = dynamic_cast<ArrayType const*>(originalType);
smtAssert(arrayType, "Type of inline array must be ArrayType");
addArrayLiteralAssertions(*symbArray, applyMap(_tuple.components(), [&](auto const& c) { return expr(*c, arrayType->baseType()); }));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
contract D {
function test() public pure {
bytes7[2] memory dummyBytes = [bytes7("A"), "B"];
assert(uint56(dummyBytes[0]) == 0x41000000000000);
assert(uint56(dummyBytes[1]) == 0x42000000000000);
assert(uint56(dummyBytes[1]) == 0x41000000000000); // Should fail
}
}
// ====
// SMTEngine: chc
// SMTTargets: assert
// ----
// Warning 6328: (231-280): CHC: Assertion violation happens here.\nCounterexample:\n\ndummyBytes = [0x41000000000000, 0x42000000000000]\n\nTransaction trace:\nD.constructor()\nD.test()
// Info 1391: CHC: 2 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them.

0 comments on commit 6355ff6

Please sign in to comment.