Merge pull request #10733 from ethereum/fixEncodingLibrary

Determine encoding type earlier.
This commit is contained in:
chriseth 2021-01-11 15:27:09 +01:00 committed by GitHub
commit dfcba3bbd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 6 deletions

View File

@ -37,7 +37,7 @@ using namespace solidity::frontend;
string ABIFunctions::tupleEncoder(
TypePointers const& _givenTypes,
TypePointers const& _targetTypes,
TypePointers _targetTypes,
bool _encodeAsLibraryTypes,
bool _reversed
)
@ -49,6 +49,13 @@ string ABIFunctions::tupleEncoder(
options.padded = true;
options.dynamicInplace = false;
for (Type const*& t: _targetTypes)
{
solAssert(t, "");
t = t->fullEncodingType(options.encodeAsLibraryTypes, true, !options.padded);
solAssert(t, "");
}
string functionName = string("abi_encode_tuple_");
for (auto const& t: _givenTypes)
functionName += t->identifier() + "_";
@ -111,7 +118,7 @@ string ABIFunctions::tupleEncoder(
string ABIFunctions::tupleEncoderPacked(
TypePointers const& _givenTypes,
TypePointers const& _targetTypes,
TypePointers _targetTypes,
bool _reversed
)
{
@ -121,6 +128,13 @@ string ABIFunctions::tupleEncoderPacked(
options.padded = false;
options.dynamicInplace = true;
for (Type const*& t: _targetTypes)
{
solAssert(t, "");
t = t->fullEncodingType(options.encodeAsLibraryTypes, true, !options.padded);
solAssert(t, "");
}
string functionName = string("abi_encode_tuple_packed_");
for (auto const& t: _givenTypes)
functionName += t->identifier() + "_";
@ -392,7 +406,9 @@ string ABIFunctions::abiEncodeAndReturnUpdatedPosFunction(
return createFunction(functionName, [&]() {
string values = suffixedVariableNameList("value", 0, numVariablesForType(_givenType, _options));
string encoder = abiEncodingFunction(_givenType, _targetType, _options);
if (_targetType.isDynamicallyEncoded())
Type const* targetEncoding = _targetType.fullEncodingType(_options.encodeAsLibraryTypes, true, false);
solAssert(targetEncoding, "");
if (targetEncoding->isDynamicallyEncoded())
return Whiskers(R"(
function <functionName>(<values>, pos) -> updatedPos {
updatedPos := <encode>(<values>, pos)
@ -404,7 +420,7 @@ string ABIFunctions::abiEncodeAndReturnUpdatedPosFunction(
.render();
else
{
unsigned encodedSize = _targetType.calldataEncodedSize(_options.padded);
unsigned encodedSize = targetEncoding->calldataEncodedSize(_options.padded);
solAssert(encodedSize != 0, "Invalid encoded size.");
return Whiskers(R"(
function <functionName>(<values>, pos) -> updatedPos {

View File

@ -79,7 +79,7 @@ public:
/// If @reversed is true, the order of the variables after <headStart> is reversed.
std::string tupleEncoder(
TypePointers const& _givenTypes,
TypePointers const& _targetTypes,
TypePointers _targetTypes,
bool _encodeAsLibraryTypes = false,
bool _reversed = false
);
@ -106,7 +106,7 @@ public:
/// If @reversed is true, the order of the variables after <headStart> is reversed.
std::string tupleEncoderPacked(
TypePointers const& _givenTypes,
TypePointers const& _targetTypes,
TypePointers _targetTypes,
bool _reversed = false
);

View File

@ -21,6 +21,8 @@ contract C {
return (r[2], s.x, a, b, c, d);
}
}
// ====
// compileViaYul: also
// ----
// library: L
// f() -> 8, 7, 1, 2, 7, 12

View File

@ -12,6 +12,8 @@ contract C {
return L.f(x);
}
}
// ====
// compileViaYul: also
// ----
// library: L
// g(uint256): 4 -> 16

View File

@ -16,6 +16,8 @@ contract test {
L.set(table, k, v);
}
}
// ====
// compileViaYul: also
// ----
// library: L
// get(address): 0 -> 0

View File

@ -19,6 +19,7 @@ contract test {
}
}
// ====
// compileViaYul: also
// EVMVersion: >=byzantium
// ----
// library: L