Skip to content

Commit 225ccac

Browse files
committed
SMTChecker: Fix error when initializing fixed-sized-bytes array
When encoding initialization of an array of fixed-sized bytes, we need to make sure the elements of the inlined array have the right SMT sort. Because of implict conversion from string literals to fixed-sized bytes, we need to pass the information about the desired type when encoding the individual elements.
1 parent c91c204 commit 225ccac

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

Changelog.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ Compiler Features:
99

1010

1111
Bugfixes:
12-
* General: Fix internal compiler error when requesting IR AST outputs for interfaces and abstract contracts.
13-
* Standard JSON Interface: Fix ``generatedSources`` and ``sourceMap`` being generated internally even when not requested.
14-
* Yul: Fix internal compiler error when a code generation error should be reported instead.
12+
* General: Fix internal compiler error when requesting IR AST outputs for interfaces and abstract contracts.
13+
* SMTChecker: Fix SMT logic error when initializing a fixed-sized-bytes array using string literals.
14+
* Standard JSON Interface: Fix ``generatedSources`` and ``sourceMap`` being generated internally even when not requested.
15+
* Yul: Fix internal compiler error when a code generation error should be reported instead.
1516

1617

1718
### 0.8.28 (2024-10-09)

libsolidity/formal/SMTEncoder.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,11 @@ void SMTEncoder::endVisit(TupleExpression const& _tuple)
428428
{
429429
// Add constraints for the length and values as it is known.
430430
auto symbArray = std::dynamic_pointer_cast<smt::SymbolicArrayVariable>(m_context.expression(_tuple));
431-
solAssert(symbArray, "");
432-
433-
addArrayLiteralAssertions(*symbArray, applyMap(_tuple.components(), [&](auto const& c) { return expr(*c); }));
431+
smtAssert(symbArray, "Inline array must be represented with SymbolicArrayVariable");
432+
auto originalType = symbArray->originalType();
433+
auto arrayType = dynamic_cast<ArrayType const*>(originalType);
434+
smtAssert(arrayType, "Type of inline array must be ArrayType");
435+
addArrayLiteralAssertions(*symbArray, applyMap(_tuple.components(), [&](auto const& c) { return expr(*c, arrayType->baseType()); }));
434436
}
435437
else
436438
{
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
contract D {
2+
function test() public pure {
3+
bytes7[2] memory dummyBytes = [bytes7("A"), "B"];
4+
assert(uint56(dummyBytes[0]) == 0x41000000000000);
5+
assert(uint56(dummyBytes[1]) == 0x42000000000000);
6+
assert(uint56(dummyBytes[1]) == 0x41000000000000); // Should fail
7+
}
8+
}
9+
// ====
10+
// SMTEngine: chc
11+
// SMTTargets: assert
12+
// ----
13+
// Warning 6328: (231-280): CHC: Assertion violation happens here.\nCounterexample:\n\ndummyBytes = [0x41000000000000, 0x42000000000000]\n\nTransaction trace:\nD.constructor()\nD.test()
14+
// Info 1391: CHC: 2 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them.

0 commit comments

Comments
 (0)