Merge pull request #10816 from ethereum/fixEmptyPacked

Fix empty packed encoder.
This commit is contained in:
chriseth 2021-01-19 16:01:12 +01:00 committed by GitHub
commit 66dac95b88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 101 additions and 82 deletions

View File

@ -146,8 +146,6 @@ string ABIFunctions::tupleEncoderPacked(
functionName += "_reversed";
return createFunction(functionName, [&]() {
solAssert(!_givenTypes.empty(), "");
// Note that the values are in reverse due to the difference in calling semantics.
Whiskers templ(R"(
function <functionName>(pos <valueParams>) -> end {

View File

@ -4983,6 +4983,8 @@ BOOST_AUTO_TEST_CASE(abi_encodePacked)
)";
for (auto v2: {false, true})
{
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
string prefix = "pragma abicoder " + string(v2 ? "v2" : "v1") + ";\n";
compileAndRun(prefix + sourceCode, 0, "C");
ABI_CHECK(callContractFunction("f0()"), encodeArgs(0x20, 0));
@ -4992,6 +4994,7 @@ BOOST_AUTO_TEST_CASE(abi_encodePacked)
ABI_CHECK(callContractFunction("f4()"), encodeArgs(0x20, 2 + 26 + 26 + 2, "\x07\x01" "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" "\x12\x01"));
ABI_CHECK(callContractFunction("f_literal()"), encodeArgs(0x20, 5, "\x01" "abc" "\x02"));
ABI_CHECK(callContractFunction("f_calldata()"), encodeArgs(0x20, 6, "\x01" "\xa5\xbf\xa1\xee" "\x02"));
)
}
}
@ -5058,6 +5061,8 @@ BOOST_AUTO_TEST_CASE(abi_encodePacked_from_storage)
)";
for (auto v2: {false, true})
{
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
string prefix = "pragma abicoder " + string(v2 ? "v2" : "v1") + ";\n";
compileAndRun(prefix + sourceCode, 0, "C");
bytes payload = encodeArgs(0xfffff1, 0, 0xfffff2, 0, 0, 0xfffff3, 0, 0, 0xfffff4);
@ -5078,6 +5083,7 @@ BOOST_AUTO_TEST_CASE(abi_encodePacked_from_storage)
ABI_CHECK(callContractFunction("ld()"), encodeArgs(0x20, 5 * 32 + 2, "\x01" + asString(encodeArgs(payload)) + "\x02"));
ABI_CHECK(callContractFunction("bytes_short()"), encodeArgs(0x20, 6, "\x01" "abcd\x02"));
ABI_CHECK(callContractFunction("bytes_long()"), encodeArgs(0x20, 42, "\x01" "0123456789012345678901234567890123456789\x02"));
)
}
}
@ -5129,6 +5135,8 @@ BOOST_AUTO_TEST_CASE(abi_encodePacked_from_memory)
)";
for (auto v2: {false, true})
{
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
string prefix = "pragma abicoder " + string(v2 ? "v2" : "v1") + ";\n";
compileAndRun(prefix + sourceCode, 0, "C");
bytes payload = encodeArgs(0xfffff1, 0, 0xfffff2, 0, 0, 0xfffff3, 0, 0, 0xfffff4);
@ -5147,6 +5155,7 @@ BOOST_AUTO_TEST_CASE(abi_encodePacked_from_memory)
);
ABI_CHECK(callContractFunction("lf()"), encodeArgs(0x20, 5 * 32 + 2, "\x01" + asString(encodeArgs(payload)) + "\x02"));
ABI_CHECK(callContractFunction("ld()"), encodeArgs(0x20, 5 * 32 + 2, "\x01" + asString(encodeArgs(payload)) + "\x02"));
)
}
}
@ -5173,6 +5182,8 @@ BOOST_AUTO_TEST_CASE(abi_encodePacked_functionPtr)
)";
for (auto v2: {false, true})
{
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
string prefix = "pragma abicoder " + string(v2 ? "v2" : "v1") + ";\n";
compileAndRun(prefix + sourceCode, 0, "C");
string directEncoding = asString(fromHex("08" "1112131400000000000011121314000000000087" "26121ff0" "02"));
@ -5180,6 +5191,7 @@ BOOST_AUTO_TEST_CASE(abi_encodePacked_functionPtr)
string arrayEncoding = asString(fromHex("08" "1112131400000000000011121314000000000087" "26121ff0" "0000000000000000" "02"));
ABI_CHECK(callContractFunction("testFixedArray()"), encodeArgs(0x20, arrayEncoding.size(), arrayEncoding));
ABI_CHECK(callContractFunction("testDynamicArray()"), encodeArgs(0x20, arrayEncoding.size(), arrayEncoding));
)
}
}
@ -5213,6 +5225,8 @@ BOOST_AUTO_TEST_CASE(abi_encodePackedV2_structs)
}
}
)";
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
compileAndRun(sourceCode, 0, "C");
bytes structEnc = encodeArgs(int(0x12), u256(-7), int(2), int(3), u256(-7), u256(-8));
ABI_CHECK(callContractFunction("testStorage()"), encodeArgs());
@ -5223,6 +5237,7 @@ BOOST_AUTO_TEST_CASE(abi_encodePackedV2_structs)
BOOST_REQUIRE_EQUAL(numLogTopics(0), 2);
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("E((uint8,int16,uint8[2],int16[]))")));
BOOST_CHECK_EQUAL(logTopic(0, 1), util::keccak256(asString(structEnc)));
)
}
BOOST_AUTO_TEST_CASE(abi_encodePackedV2_nestedArray)
@ -5246,12 +5261,15 @@ BOOST_AUTO_TEST_CASE(abi_encodePackedV2_nestedArray)
}
}
)";
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
compileAndRun(sourceCode, 0, "C");
bytes structEnc = encodeArgs(1, 2, 3, 0, 0, 0, 0, 4);
ABI_CHECK(callContractFunction("testNestedArrays()"), encodeArgs());
BOOST_REQUIRE_EQUAL(numLogTopics(0), 2);
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("E((uint8,int16)[2][][3])")));
BOOST_CHECK_EQUAL(logTopic(0, 1), util::keccak256(asString(structEnc)));
)
}
BOOST_AUTO_TEST_CASE(abi_encodePackedV2_arrayOfStrings)
@ -5274,6 +5292,8 @@ BOOST_AUTO_TEST_CASE(abi_encodePackedV2_arrayOfStrings)
}
}
)";
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
compileAndRun(sourceCode, 0, "C");
bytes arrayEncoding = encodeArgs("abc", "0123456789012345678901234567890123456789");
ABI_CHECK(callContractFunction("testStorage()"), encodeArgs());
@ -5284,6 +5304,7 @@ BOOST_AUTO_TEST_CASE(abi_encodePackedV2_arrayOfStrings)
BOOST_REQUIRE_EQUAL(numLogTopics(0), 2);
BOOST_CHECK_EQUAL(logTopic(0, 0), util::keccak256(string("E(string[])")));
BOOST_CHECK_EQUAL(logTopic(0, 1), util::keccak256(asString(arrayEncoding)));
)
}
BOOST_AUTO_TEST_CASE(event_signature_in_library)