From 52b96b5a3c71b8e01c985352da863c8308f64f63 Mon Sep 17 00:00:00 2001 From: Maximilian Hubert <64627729+gap-editor@users.noreply.github.com> Date: Sun, 20 Apr 2025 00:43:23 +0200 Subject: [PATCH 1/4] Update ABIFunctions.cpp --- libsolidity/codegen/ABIFunctions.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp index 474848760cef..e558be35957a 100644 --- a/libsolidity/codegen/ABIFunctions.cpp +++ b/libsolidity/codegen/ABIFunctions.cpp @@ -242,7 +242,6 @@ std::string ABIFunctions::tupleDecoder(TypePointers const& _types, bool _fromMem } )"); elementTempl("dynamic", decodingTypes[i]->isDynamicallyEncoded()); - // TODO add test elementTempl("revertString", revertReasonIfDebugFunction("ABI decoding: invalid tuple offset")); elementTempl("load", _fromMemory ? "mload" : "calldataload"); elementTempl("values", boost::algorithm::join(valueNamesLocal, ", ")); From 216f99718eecd646bb96ec196a36b7853ae9533d Mon Sep 17 00:00:00 2001 From: Maximilian Hubert <64627729+gap-editor@users.noreply.github.com> Date: Sun, 20 Apr 2025 00:44:09 +0200 Subject: [PATCH 2/4] Update ABIDecoderTests.cpp --- test/libsolidity/ABIDecoderTests.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/libsolidity/ABIDecoderTests.cpp b/test/libsolidity/ABIDecoderTests.cpp index e8ffcad27eb8..298bbdc34ce9 100644 --- a/test/libsolidity/ABIDecoderTests.cpp +++ b/test/libsolidity/ABIDecoderTests.cpp @@ -426,6 +426,24 @@ BOOST_AUTO_TEST_CASE(complex_struct) ) } +BOOST_AUTO_TEST_CASE(invalid_tuple_offset) +{ + std::string sourceCode = R"( + contract C { + function f((uint a, uint b) calldata x) external pure returns (uint) { + return x.a + x.b; + } + } + )"; + BOTH_ENCODERS( + compileAndRun(sourceCode); + // Creating an invalid call with tuple offset pointing outside the calldata + bytes calldata = encodeArgs(0x20, 0xffff) + bytes(62, 0); // 0xffff is an invalid offset + // This should revert because the tuple offset is invalid + ABI_CHECK(callContractFunctionNoEncoding("f((uint256,uint256))", calldata), encodeArgs()); + ) +} + BOOST_AUTO_TEST_SUITE_END() } // end namespaces From 54d8469bf0265aa4f9afa173eef3f560f314dbd1 Mon Sep 17 00:00:00 2001 From: Maximilian Hubert <64627729+gap-editor@users.noreply.github.com> Date: Sun, 20 Apr 2025 12:22:43 +0200 Subject: [PATCH 3/4] Update ABIDecoderTests.cpp --- test/libsolidity/ABIDecoderTests.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/libsolidity/ABIDecoderTests.cpp b/test/libsolidity/ABIDecoderTests.cpp index 298bbdc34ce9..3065f501a50f 100644 --- a/test/libsolidity/ABIDecoderTests.cpp +++ b/test/libsolidity/ABIDecoderTests.cpp @@ -430,7 +430,8 @@ BOOST_AUTO_TEST_CASE(invalid_tuple_offset) { std::string sourceCode = R"( contract C { - function f((uint a, uint b) calldata x) external pure returns (uint) { + struct S { uint a; uint b; } + function f(S calldata x) external pure returns (uint) { return x.a + x.b; } } From 463e37a35a66f15ce7943b75bfb44a45adbca838 Mon Sep 17 00:00:00 2001 From: Maximilian Hubert <64627729+gap-editor@users.noreply.github.com> Date: Sun, 20 Apr 2025 16:14:08 +0200 Subject: [PATCH 4/4] Update ABIDecoderTests.cpp --- test/libsolidity/ABIDecoderTests.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/libsolidity/ABIDecoderTests.cpp b/test/libsolidity/ABIDecoderTests.cpp index 3065f501a50f..08dfcd529bd4 100644 --- a/test/libsolidity/ABIDecoderTests.cpp +++ b/test/libsolidity/ABIDecoderTests.cpp @@ -430,18 +430,17 @@ BOOST_AUTO_TEST_CASE(invalid_tuple_offset) { std::string sourceCode = R"( contract C { - struct S { uint a; uint b; } - function f(S calldata x) external pure returns (uint) { - return x.a + x.b; + function f(uint[] calldata x) external pure returns (uint) { + return x.length > 0 ? x[0] : 0; } } )"; BOTH_ENCODERS( compileAndRun(sourceCode); - // Creating an invalid call with tuple offset pointing outside the calldata + // Creating an invalid call with array offset pointing outside the calldata bytes calldata = encodeArgs(0x20, 0xffff) + bytes(62, 0); // 0xffff is an invalid offset - // This should revert because the tuple offset is invalid - ABI_CHECK(callContractFunctionNoEncoding("f((uint256,uint256))", calldata), encodeArgs()); + // This should revert because the array offset is invalid + ABI_CHECK(callContractFunctionNoEncoding("f(uint256[])", calldata), encodeArgs()); ) }