Skip to content

Commit dd03613

Browse files
committed
SMTChecker: Fix string literal to fixed bytes conversion with user-defined type
1 parent 2536b14 commit dd03613

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Compiler Features:
88

99
Bugfixes:
1010
* SMTChecker: Fix incorrect analysis when only a subset of contracts is selected with `--model-checker-contracts`.
11+
* SMTChecker: Fix internal compiler error when string literal is used to initialize user-defined type based on fixed bytes.
1112

1213

1314
### 0.8.29 (2025-03-12)

libsolidity/formal/SMTEncoder.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,10 @@ void SMTEncoder::visitAddMulMod(FunctionCall const& _funCall)
929929
void SMTEncoder::visitWrapUnwrap(FunctionCall const& _funCall)
930930
{
931931
auto const& args = _funCall.arguments();
932-
solAssert(args.size() == 1, "");
933-
defineExpr(_funCall, expr(*args.front()));
932+
smtAssert(args.size() == 1, "Expected exactly one argument to wrap/unwrap");
933+
auto const& funType = dynamic_cast<FunctionType const&>(*_funCall.expression().annotation().type);
934+
auto const* argType = funType.parameterTypes().front();
935+
defineExpr(_funCall, expr(*args.front(), argType));
934936
}
935937

936938
void SMTEncoder::visitObjectCreation(FunctionCall const& _funCall)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type MyBytes is bytes2;
2+
3+
contract C {
4+
MyBytes b = MyBytes.wrap("ab");
5+
6+
function check() view public {
7+
assert(MyBytes.unwrap(b) == 0); // should fail
8+
assert(MyBytes.unwrap(b) == 0x6162); // should hold
9+
}
10+
}
11+
// ====
12+
// SMTEngine: chc
13+
// ----
14+
// Warning 6328: (118-148): CHC: Assertion violation happens here.\nCounterexample:\n\n\nTransaction trace:\nC.constructor()\nC.check()
15+
// Info 1391: CHC: 1 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them.

0 commit comments

Comments
 (0)