diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp index 858dbefb2..c74272434 100644 --- a/libsolidity/codegen/ABIFunctions.cpp +++ b/libsolidity/codegen/ABIFunctions.cpp @@ -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 (, pos) -> updatedPos { updatedPos := (, 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 (, pos) -> updatedPos { diff --git a/libsolidity/codegen/ABIFunctions.h b/libsolidity/codegen/ABIFunctions.h index b90494168..81ddcac00 100644 --- a/libsolidity/codegen/ABIFunctions.h +++ b/libsolidity/codegen/ABIFunctions.h @@ -79,7 +79,7 @@ public: /// If @reversed is true, the order of the variables after 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 is reversed. std::string tupleEncoderPacked( TypePointers const& _givenTypes, - TypePointers const& _targetTypes, + TypePointers _targetTypes, bool _reversed = false );