Skip to content

Commit

Permalink
Merge pull request #15749 from ethereum/smt-fix-crypto-with-string
Browse files Browse the repository at this point in the history
SMTChecker: Fix encoding of arguments of cryptographic functions
  • Loading branch information
cameel authored Jan 22, 2025
2 parents a28b2b1 + 1682f7f commit d5d4558
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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.
* SMTChecker: Fix wrong encoding of string literals as arguments of ``ecrecover`` precompile.
* 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: 5 additions & 5 deletions libsolidity/formal/SMTEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ void SMTEncoder::visitCryptoFunction(FunctionCall const& _funCall)
{
auto const& funType = dynamic_cast<FunctionType const&>(*_funCall.expression().annotation().type);
auto kind = funType.kind();
auto arg0 = expr(*_funCall.arguments().at(0));
auto arg0 = expr(*_funCall.arguments().at(0), TypeProvider::bytesStorage());
std::optional<smtutil::Expression> result;
if (kind == FunctionType::Kind::KECCAK256)
result = smtutil::Expression::select(state().cryptoFunction("keccak256"), arg0);
Expand All @@ -862,10 +862,10 @@ void SMTEncoder::visitCryptoFunction(FunctionCall const& _funCall)
else if (kind == FunctionType::Kind::ECRecover)
{
auto e = state().cryptoFunction("ecrecover");
auto arg0 = expr(*_funCall.arguments().at(0));
auto arg1 = expr(*_funCall.arguments().at(1));
auto arg2 = expr(*_funCall.arguments().at(2));
auto arg3 = expr(*_funCall.arguments().at(3));
auto arg0 = expr(*_funCall.arguments().at(0), TypeProvider::fixedBytes(32));
auto arg1 = expr(*_funCall.arguments().at(1), TypeProvider::uint(8));
auto arg2 = expr(*_funCall.arguments().at(2), TypeProvider::fixedBytes(32));
auto arg3 = expr(*_funCall.arguments().at(3), TypeProvider::fixedBytes(32));
auto inputSort = dynamic_cast<smtutil::ArraySort&>(*e.sort).domain;
auto ecrecoverInput = smtutil::Expression::tuple_constructor(
smtutil::Expression(std::make_shared<smtutil::SortSort>(inputSort), ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@ contract C {
assert(k1 == k2);
}

function c2() public pure {
function c2() public pure {
bytes32 s1 = sha256("10");
bytes32 s2 = sha256("10");
assert(s1 == s2);
}

function c3() public pure {
function c3() public pure {
bytes32 r1 = ripemd160("100");
bytes32 r2 = ripemd160("100");
assert(r1 == r2);
}

function c4() public pure {
address e1 = ecrecover("a", 1, hex"bb", unicode"c");
address e2 = ecrecover("a", 1, hex"bb", unicode"c");
assert(e1 == e2);
}
}
// ====
// SMTEngine: chc
// ----
// Info 1391: CHC: 3 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them.
// Info 1391: CHC: 4 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them.

0 comments on commit d5d4558

Please sign in to comment.