diff --git a/Changelog.md b/Changelog.md index 148b67c98..4fceab86f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,8 @@ ### 0.8.16 (unreleased) +Important Bugfixes: + * Code Generation: Fix data corruption that affected ABI-encoding of calldata values represented by tuples: structs at any nesting level; argument lists of external functions, events and errors; return value lists of external functions. The 32 leading bytes of the first dynamically-encoded value in the tuple would get zeroed when the last component contained a statically-encoded array. + Language Features: @@ -10,6 +13,7 @@ Compiler Features: * Yul Optimizer: Add rule to convert `mod(add(X, Y), A)` into `addmod(X, Y, A)`, if `A` is a power of two. * Code Generator: More efficient code for checked addition and subtraction. + Bugfixes: * Commandline Interface: Disallow the following options outside of the compiler mode: ``--via-ir``,``--metadata-literal``, ``--metadata-hash``, ``--model-checker-show-unproved``, ``--model-checker-div-mod-no-slacks``, ``--model-checker-engine``, ``--model-checker-invariants``, ``--model-checker-solvers``, ``--model-checker-timeout``, ``--model-checker-contracts``, ``--model-checker-targets``. * Type Checker: Fix null dereference in `abi.encodeCall` type checking of free function. diff --git a/docs/bugs.json b/docs/bugs.json index b7108fac1..bdea0a7c2 100644 --- a/docs/bugs.json +++ b/docs/bugs.json @@ -1,4 +1,16 @@ [ + { + "uid": "SOL-2022-6", + "name": "AbiReencodingHeadOverflowWithStaticArrayCleanup", + "summary": "ABI-encoding a tuple with a statically-sized calldata array in the last component would corrupt 32 leading bytes of its first dynamically encoded component.", + "description": "When ABI-encoding a statically-sized calldata array, the compiler always pads the data area to a multiple of 32-bytes and ensures that the padding bytes are zeroed. In some cases, this cleanup used to be performed by always writing exactly 32 bytes, regardless of how many needed to be zeroed. This was done with the assumption that the data that would eventually occupy the area past the end of the array had not yet been written, because the encoder processes tuple components in the order they were given. While this assumption is mostly true, there is an important corner case: dynamically encoded tuple components are stored separately from the statically-sized ones in an area called the *tail* of the encoding and the tail immediately follows the *head*, which is where the statically-sized components are placed. The aforementioned cleanup, if performed for the last component of the head would cross into the tail and overwrite up to 32 bytes of the first component stored there with zeros. The only array type for which the cleanup could actually result in an overwrite were arrays with ``uint256`` or ``bytes32`` as the base element type and in this case the size of the corrupted area was always exactly 32 bytes. The problem affected tuples at any nesting level. This included also structs, which are encoded as tuples in the ABI. Note also that lists of parameters and return values of functions, events and errors are encoded as tuples.", + "introduced": "0.5.8", + "fixed": "0.8.16", + "severity": "medium", + "conditions": { + "ABIEncoderV2": true + } + }, { "uid": "SOL-2022-5", "name": "DirtyBytesArrayToStorage", diff --git a/docs/bugs_by_version.json b/docs/bugs_by_version.json index c11f32e19..9c1b7ad74 100644 --- a/docs/bugs_by_version.json +++ b/docs/bugs_by_version.json @@ -1083,6 +1083,7 @@ }, "0.5.10": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "ABIDecodeTwoDimensionalArrayMemory", @@ -1100,6 +1101,7 @@ }, "0.5.11": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "ABIDecodeTwoDimensionalArrayMemory", @@ -1116,6 +1118,7 @@ }, "0.5.12": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "ABIDecodeTwoDimensionalArrayMemory", @@ -1132,6 +1135,7 @@ }, "0.5.13": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "ABIDecodeTwoDimensionalArrayMemory", @@ -1148,6 +1152,7 @@ }, "0.5.14": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "ABIDecodeTwoDimensionalArrayMemory", @@ -1166,6 +1171,7 @@ }, "0.5.15": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "ABIDecodeTwoDimensionalArrayMemory", @@ -1183,6 +1189,7 @@ }, "0.5.16": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "ABIDecodeTwoDimensionalArrayMemory", @@ -1199,6 +1206,7 @@ }, "0.5.17": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "ABIDecodeTwoDimensionalArrayMemory", @@ -1338,6 +1346,7 @@ }, "0.5.8": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "ABIDecodeTwoDimensionalArrayMemory", @@ -1358,6 +1367,7 @@ }, "0.5.9": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "ABIDecodeTwoDimensionalArrayMemory", @@ -1377,6 +1387,7 @@ }, "0.6.0": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "ABIDecodeTwoDimensionalArrayMemory", @@ -1394,6 +1405,7 @@ }, "0.6.1": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "ABIDecodeTwoDimensionalArrayMemory", @@ -1410,6 +1422,7 @@ }, "0.6.10": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1423,6 +1436,7 @@ }, "0.6.11": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1436,6 +1450,7 @@ }, "0.6.12": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1449,6 +1464,7 @@ }, "0.6.2": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "ABIDecodeTwoDimensionalArrayMemory", @@ -1465,6 +1481,7 @@ }, "0.6.3": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "ABIDecodeTwoDimensionalArrayMemory", @@ -1481,6 +1498,7 @@ }, "0.6.4": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "ABIDecodeTwoDimensionalArrayMemory", @@ -1497,6 +1515,7 @@ }, "0.6.5": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "SignedImmutables", @@ -1513,6 +1532,7 @@ }, "0.6.6": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "SignedImmutables", @@ -1528,6 +1548,7 @@ }, "0.6.7": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "SignedImmutables", @@ -1543,6 +1564,7 @@ }, "0.6.8": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "NestedCallataArrayAbiReencodingSizeValidation", "SignedImmutables", @@ -1555,6 +1577,7 @@ }, "0.6.9": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1569,6 +1592,7 @@ }, "0.7.0": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1582,6 +1606,7 @@ }, "0.7.1": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1596,6 +1621,7 @@ }, "0.7.2": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1609,6 +1635,7 @@ }, "0.7.3": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1621,6 +1648,7 @@ }, "0.7.4": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1632,6 +1660,7 @@ }, "0.7.5": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1643,6 +1672,7 @@ }, "0.7.6": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1654,6 +1684,7 @@ }, "0.8.0": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1665,6 +1696,7 @@ }, "0.8.1": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1676,6 +1708,7 @@ }, "0.8.10": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation" @@ -1684,6 +1717,7 @@ }, "0.8.11": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1693,6 +1727,7 @@ }, "0.8.12": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1702,6 +1737,7 @@ }, "0.8.13": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "InlineAssemblyMemorySideEffects", "DataLocationChangeInInternalOverride", @@ -1711,17 +1747,21 @@ }, "0.8.14": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "InlineAssemblyMemorySideEffects" ], "released": "2022-05-17" }, "0.8.15": { - "bugs": [], + "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup" + ], "released": "2022-06-15" }, "0.8.2": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1733,6 +1773,7 @@ }, "0.8.3": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1743,6 +1784,7 @@ }, "0.8.4": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1752,6 +1794,7 @@ }, "0.8.5": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1761,6 +1804,7 @@ }, "0.8.6": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1770,6 +1814,7 @@ }, "0.8.7": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1779,6 +1824,7 @@ }, "0.8.8": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation", @@ -1789,6 +1835,7 @@ }, "0.8.9": { "bugs": [ + "AbiReencodingHeadOverflowWithStaticArrayCleanup", "DirtyBytesArrayToStorage", "DataLocationChangeInInternalOverride", "NestedCallataArrayAbiReencodingSizeValidation" diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp index e83f940f5..c92525f21 100644 --- a/libsolidity/codegen/ABIFunctions.cpp +++ b/libsolidity/codegen/ABIFunctions.cpp @@ -468,7 +468,8 @@ string ABIFunctions::abiEncodingFunctionCalldataArrayWithoutCleanup( _to.identifier() + _options.toFunctionNameSuffix(); return createFunction(functionName, [&]() { - bool needsPadding = _options.padded && fromArrayType.isByteArrayOrString(); + bool bytesOrString = fromArrayType.isByteArrayOrString(); + bool needsPadding = _options.padded && bytesOrString; if (fromArrayType.isDynamicallySized()) { Whiskers templ(R"( @@ -498,7 +499,7 @@ string ABIFunctions::abiEncodingFunctionCalldataArrayWithoutCleanup( ); templ("readableTypeNameFrom", _from.toString(true)); templ("readableTypeNameTo", _to.toString(true)); - templ("copyFun", m_utils.copyToMemoryFunction(true)); + templ("copyFun", m_utils.copyToMemoryFunction(true, /*cleanup*/bytesOrString)); templ("lengthPadded", needsPadding ? m_utils.roundUpFunction() + "(length)" : "length"); return templ.render(); } @@ -514,7 +515,7 @@ string ABIFunctions::abiEncodingFunctionCalldataArrayWithoutCleanup( templ("functionName", functionName); templ("readableTypeNameFrom", _from.toString(true)); templ("readableTypeNameTo", _to.toString(true)); - templ("copyFun", m_utils.copyToMemoryFunction(true)); + templ("copyFun", m_utils.copyToMemoryFunction(true, /*cleanup*/bytesOrString)); templ("byteLength", toCompactHexWithPrefix(fromArrayType.length() * fromArrayType.calldataStride())); return templ.render(); } @@ -662,7 +663,7 @@ string ABIFunctions::abiEncodingFunctionMemoryByteArray( templ("functionName", functionName); templ("lengthFun", m_utils.arrayLengthFunction(_from)); templ("storeLength", arrayStoreLengthForEncodingFunction(_to, _options)); - templ("copyFun", m_utils.copyToMemoryFunction(false)); + templ("copyFun", m_utils.copyToMemoryFunction(false, /*cleanup*/true)); templ("lengthPadded", _options.padded ? m_utils.roundUpFunction() + "(length)" : "length"); return templ.render(); }); @@ -1296,7 +1297,7 @@ string ABIFunctions::abiDecodingFunctionByteArrayAvailableLength(ArrayType const templ("functionName", functionName); templ("allocate", m_utils.allocationFunction()); templ("allocationSize", m_utils.arrayAllocationSizeFunction(_type)); - templ("copyToMemFun", m_utils.copyToMemoryFunction(!_fromMemory)); + templ("copyToMemFun", m_utils.copyToMemoryFunction(!_fromMemory, /*cleanup*/true)); return templ.render(); }); } diff --git a/libsolidity/codegen/ABIFunctions.h b/libsolidity/codegen/ABIFunctions.h index 07088aa3b..b7f7f8ae5 100644 --- a/libsolidity/codegen/ABIFunctions.h +++ b/libsolidity/codegen/ABIFunctions.h @@ -243,7 +243,7 @@ private: std::string abiDecodingFunctionArray(ArrayType const& _type, bool _fromMemory); /// Part of @a abiDecodingFunction for calldata array types. std::string abiDecodingFunctionCalldataArray(ArrayType const& _type); - /// Part of @a abiDecodingFunctionArrayWithAvailableLength + /// Part of @a abiDecodingFunctionArrayAvailableLength std::string abiDecodingFunctionByteArrayAvailableLength(ArrayType const& _type, bool _fromMemory); /// Part of @a abiDecodingFunction for calldata struct types. std::string abiDecodingFunctionCalldataStruct(StructType const& _type); diff --git a/libsolidity/codegen/YulUtilFunctions.cpp b/libsolidity/codegen/YulUtilFunctions.cpp index ee77a476f..b24cf4f90 100644 --- a/libsolidity/codegen/YulUtilFunctions.cpp +++ b/libsolidity/codegen/YulUtilFunctions.cpp @@ -80,20 +80,25 @@ string YulUtilFunctions::splitExternalFunctionIdFunction() }); } -string YulUtilFunctions::copyToMemoryFunction(bool _fromCalldata) +string YulUtilFunctions::copyToMemoryFunction(bool _fromCalldata, bool _cleanup) { - string functionName = "copy_" + string(_fromCalldata ? "calldata" : "memory") + "_to_memory"; + string functionName = + "copy_"s + + (_fromCalldata ? "calldata"s : "memory"s) + + "_to_memory"s + + (_cleanup ? "_with_cleanup"s : ""s); + return m_functionCollector.createFunction(functionName, [&]() { if (_fromCalldata) { return Whiskers(R"( function (src, dst, length) { calldatacopy(dst, src, length) - // clear end - mstore(add(dst, length), 0) + mstore(add(dst, length), 0) } )") ("functionName", functionName) + ("cleanup", _cleanup) .render(); } else @@ -105,14 +110,11 @@ string YulUtilFunctions::copyToMemoryFunction(bool _fromCalldata) { mstore(add(dst, i), mload(add(src, i))) } - if gt(i, length) - { - // clear end - mstore(add(dst, length), 0) - } + mstore(add(dst, length), 0) } )") ("functionName", functionName) + ("cleanup", _cleanup) .render(); } }); diff --git a/libsolidity/codegen/YulUtilFunctions.h b/libsolidity/codegen/YulUtilFunctions.h index aff9c2406..7d736df5b 100644 --- a/libsolidity/codegen/YulUtilFunctions.h +++ b/libsolidity/codegen/YulUtilFunctions.h @@ -73,8 +73,9 @@ public: /// @returns a function that copies raw bytes of dynamic length from calldata /// or memory to memory. - /// Pads with zeros and might write more than exactly length. - std::string copyToMemoryFunction(bool _fromCalldata); + /// @params _cleanup If true, pads with zeros up to the 32 byte boundary after the specified length + /// signature: (src, dst, length) -> + std::string copyToMemoryFunction(bool _fromCalldata, bool _cleanup); /// @returns the name of a function that copies a string literal to memory /// and returns a pointer to the memory area containing the string literal. diff --git a/test/cmdlineTests/debug_info_in_yul_snippet_escaping/output b/test/cmdlineTests/debug_info_in_yul_snippet_escaping/output index 626731c13..9fb9a2dbc 100644 --- a/test/cmdlineTests/debug_info_in_yul_snippet_escaping/output +++ b/test/cmdlineTests/debug_info_in_yul_snippet_escaping/output @@ -179,17 +179,13 @@ object "D_27" { updated_pos := add(pos, 0x20) } - function copy_memory_to_memory(src, dst, length) { + function copy_memory_to_memory_with_cleanup(src, dst, length) { let i := 0 for { } lt(i, length) { i := add(i, 32) } { mstore(add(dst, i), mload(add(src, i))) } - if gt(i, length) - { - // clear end - mstore(add(dst, length), 0) - } + mstore(add(dst, length), 0) } function round_up_to_mul_of_32(value) -> result { @@ -199,7 +195,7 @@ object "D_27" { function abi_encode_t_string_memory_ptr_to_t_string_memory_ptr_fromStack(value, pos) -> end { let length := array_length_t_string_memory_ptr(value) pos := array_storeLengthForEncoding_t_string_memory_ptr_fromStack(pos, length) - copy_memory_to_memory(add(value, 0x20), pos, length) + copy_memory_to_memory_with_cleanup(add(value, 0x20), pos, length) end := add(pos, round_up_to_mul_of_32(length)) } @@ -496,10 +492,7 @@ object "D_27" { { mstore(add(add(memPos, i), _2), mload(add(add(memPtr_1, i), _7))) } - if gt(i, length) - { - mstore(add(add(memPos, length), _2), _3) - } + mstore(add(add(memPos, length), _2), _3) return(memPos, add(sub(add(memPos, and(add(length, 31), not(31))), memPos), _2)) } } diff --git a/test/cmdlineTests/name_simplifier/output b/test/cmdlineTests/name_simplifier/output index 0e100122f..170e58ffb 100644 --- a/test/cmdlineTests/name_simplifier/output +++ b/test/cmdlineTests/name_simplifier/output @@ -114,10 +114,7 @@ object "C_59" { { mstore(add(add(memPos, i), _12), mload(add(add(memPtr_1, i), _4))) } - if gt(i, length) - { - mstore(add(add(memPos, length), _12), _3) - } + mstore(add(add(memPos, length), _12), _3) return(memPos, add(sub(add(memPos, and(add(length, 31), _9)), memPos), _12)) } } diff --git a/test/cmdlineTests/viair_subobject_optimization/output b/test/cmdlineTests/viair_subobject_optimization/output index 0cdfc6b8b..4d5aa7f70 100644 --- a/test/cmdlineTests/viair_subobject_optimization/output +++ b/test/cmdlineTests/viair_subobject_optimization/output @@ -132,17 +132,18 @@ sub_0: assembly { /* "viair_subobject_optimization/input.sol":745:765 type(C).creationCode */ dataSize(sub_0) /* "viair_subobject_optimization/input.sol":669:772 contract D {... */ + swap2 not(0x1f) swap1 dup2 0x3f - dup3 + dup6 add and - dup5 + dup2 add swap3 - dup5 + dup2 dup5 lt 0xffffffffffffffff @@ -151,61 +152,61 @@ sub_0: assembly { or tag_9 jumpi - swap3 + swap1 swap2 - dup5 0x40 swap4 dup5 mstore /* "viair_subobject_optimization/input.sol":745:765 type(C).creationCode */ - dup3 - dup2 - mstore - 0x20 - swap3 - dataOffset(sub_0) dup5 dup4 + mstore + 0x20 + swap5 + dataOffset(sub_0) + dup7 + dup6 add codecopy /* "viair_subobject_optimization/input.sol":669:772 contract D {... */ dup4 mload swap5 - dup4 - dup7 - swap5 dup6 - mstore - dup3 - mload swap3 - dup4 + dup2 + dup5 + mstore + dup5 + mload + swap2 dup3 - dup8 + dup2 + dup7 add mstore - dup3 - swap2 + dup2 + swap6 tag_11: - dup5 dup4 + dup8 lt tag_12 jumpi pop pop - swap1 + dup4 + swap5 + pop + dup6 dup3 0x1f - swap4 - swap3 - gt - tag_14 - jumpi - tag_15: - pop + swap5 + swap6 + add + add + mstore add and dup2 @@ -214,35 +215,26 @@ sub_0: assembly { add swap1 return - tag_14: - dup6 - dup3 - dup7 - add - add - mstore - dup7 - jump(tag_15) tag_12: + dup7 dup2 - dup4 add - dup2 + dup3 add mload dup10 - dup5 + dup9 add dup10 add mstore - dup9 - swap7 - pop - swap2 - dup3 + swap6 + dup2 add - swap2 + swap6 + dup9 + swap6 + pop jump(tag_11) tag_9: shl(0xe0, 0x4e487b71) diff --git a/test/cmdlineTests/yul_string_format_ascii/output.json b/test/cmdlineTests/yul_string_format_ascii/output.json index 3ff8779ff..4bc66584c 100644 --- a/test/cmdlineTests/yul_string_format_ascii/output.json +++ b/test/cmdlineTests/yul_string_format_ascii/output.json @@ -88,17 +88,13 @@ object \"C_11\" { updated_pos := add(pos, 0x20) } - function copy_memory_to_memory(src, dst, length) { + function copy_memory_to_memory_with_cleanup(src, dst, length) { let i := 0 for { } lt(i, length) { i := add(i, 32) } { mstore(add(dst, i), mload(add(src, i))) } - if gt(i, length) - { - // clear end - mstore(add(dst, length), 0) - } + mstore(add(dst, length), 0) } function round_up_to_mul_of_32(value) -> result { @@ -108,7 +104,7 @@ object \"C_11\" { function abi_encode_t_string_memory_ptr_to_t_string_memory_ptr_fromStack(value, pos) -> end { let length := array_length_t_string_memory_ptr(value) pos := array_storeLengthForEncoding_t_string_memory_ptr_fromStack(pos, length) - copy_memory_to_memory(add(value, 0x20), pos, length) + copy_memory_to_memory_with_cleanup(add(value, 0x20), pos, length) end := add(pos, round_up_to_mul_of_32(length)) } diff --git a/test/cmdlineTests/yul_string_format_ascii_long/output.json b/test/cmdlineTests/yul_string_format_ascii_long/output.json index e019e5c2f..68f033773 100644 --- a/test/cmdlineTests/yul_string_format_ascii_long/output.json +++ b/test/cmdlineTests/yul_string_format_ascii_long/output.json @@ -88,17 +88,13 @@ object \"C_11\" { updated_pos := add(pos, 0x20) } - function copy_memory_to_memory(src, dst, length) { + function copy_memory_to_memory_with_cleanup(src, dst, length) { let i := 0 for { } lt(i, length) { i := add(i, 32) } { mstore(add(dst, i), mload(add(src, i))) } - if gt(i, length) - { - // clear end - mstore(add(dst, length), 0) - } + mstore(add(dst, length), 0) } function round_up_to_mul_of_32(value) -> result { @@ -108,7 +104,7 @@ object \"C_11\" { function abi_encode_t_string_memory_ptr_to_t_string_memory_ptr_fromStack(value, pos) -> end { let length := array_length_t_string_memory_ptr(value) pos := array_storeLengthForEncoding_t_string_memory_ptr_fromStack(pos, length) - copy_memory_to_memory(add(value, 0x20), pos, length) + copy_memory_to_memory_with_cleanup(add(value, 0x20), pos, length) end := add(pos, round_up_to_mul_of_32(length)) } diff --git a/test/libsolidity/gasTests/abiv2.sol b/test/libsolidity/gasTests/abiv2.sol index 2dbe334b3..da433a9e5 100644 --- a/test/libsolidity/gasTests/abiv2.sol +++ b/test/libsolidity/gasTests/abiv2.sol @@ -14,9 +14,9 @@ contract C { } // ---- // creation: -// codeDepositCost: 1243000 -// executionCost: 1295 -// totalCost: 1244295 +// codeDepositCost: 1241200 +// executionCost: 1288 +// totalCost: 1242488 // external: // a(): 2430 // b(uint256): infinite diff --git a/test/libsolidity/gasTests/abiv2_optimised.sol b/test/libsolidity/gasTests/abiv2_optimised.sol index ca344afd0..26e2104f2 100644 --- a/test/libsolidity/gasTests/abiv2_optimised.sol +++ b/test/libsolidity/gasTests/abiv2_optimised.sol @@ -17,9 +17,9 @@ contract C { // optimize-yul: true // ---- // creation: -// codeDepositCost: 660800 -// executionCost: 696 -// totalCost: 661496 +// codeDepositCost: 659000 +// executionCost: 689 +// totalCost: 659689 // external: // a(): 2285 // b(uint256): 4652 diff --git a/test/libsolidity/semanticTests/abiEncoderV1/abi_encode_calldata_slice.sol b/test/libsolidity/semanticTests/abiEncoderV1/abi_encode_calldata_slice.sol index d1fe673a2..069c32370 100644 --- a/test/libsolidity/semanticTests/abiEncoderV1/abi_encode_calldata_slice.sol +++ b/test/libsolidity/semanticTests/abiEncoderV1/abi_encode_calldata_slice.sol @@ -59,10 +59,10 @@ contract C { // EVMVersion: >homestead // ---- // test_bytes() -> -// gas irOptimized: 367365 -// gas legacy: 416585 -// gas legacyOptimized: 322043 +// gas irOptimized: 362445 +// gas legacy: 414569 +// gas legacyOptimized: 319271 // test_uint256() -> -// gas irOptimized: 515982 -// gas legacy: 583100 -// gas legacyOptimized: 444161 +// gas irOptimized: 511910 +// gas legacy: 581876 +// gas legacyOptimized: 442757 diff --git a/test/libsolidity/semanticTests/abiEncoderV1/calldata_bytes_bytes32_arrays.sol b/test/libsolidity/semanticTests/abiEncoderV1/calldata_bytes_bytes32_arrays.sol new file mode 100644 index 000000000..18a4ee1a9 --- /dev/null +++ b/test/libsolidity/semanticTests/abiEncoderV1/calldata_bytes_bytes32_arrays.sol @@ -0,0 +1,14 @@ +pragma abicoder v1; + +contract C { + function f(bool a, bytes calldata b, bytes32[2] calldata c) + public + returns (bool, bytes calldata, bytes32[2] calldata) + { + return (a, b, c); + } +} +// ==== +// compileViaYul: false +// ---- +// f(bool,bytes,bytes32[2]): true, 0x80, "a", "b", 4, "abcd" -> true, 0x80, "a", "b", 4, "abcd" diff --git a/test/libsolidity/semanticTests/abiEncoderV1/memory_dynamic_array_and_calldata_bytes.sol b/test/libsolidity/semanticTests/abiEncoderV1/memory_dynamic_array_and_calldata_bytes.sol new file mode 100644 index 000000000..3b2b90c6c --- /dev/null +++ b/test/libsolidity/semanticTests/abiEncoderV1/memory_dynamic_array_and_calldata_bytes.sol @@ -0,0 +1,17 @@ +pragma abicoder v1; + +contract C { + function f(uint256[] memory a, bytes calldata b) public returns (bytes memory) { + return abi.encode(a, b); + } + + function g(uint256[] memory a, bytes calldata b) external returns (bytes memory) { + return f(a, b); + } +} + +// ==== +// EVMVersion: >homestead +// ---- +// f(uint256[],bytes): 0x40, 0x80, 1, 0xFF, 6, "123456" -> 0x20, 0xc0, 0x40, 0x80, 1, 0xff, 6, "123456" +// g(uint256[],bytes): 0x40, 0x80, 1, 0xffff, 8, "12345678" -> 0x20, 0xc0, 0x40, 0x80, 1, 0xffff, 8, "12345678" diff --git a/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_calldata_slice.sol b/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_calldata_slice.sol index 592595df3..7ebac64ea 100644 --- a/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_calldata_slice.sol +++ b/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_calldata_slice.sol @@ -60,10 +60,10 @@ contract C { // EVMVersion: >homestead // ---- // test_bytes() -> -// gas irOptimized: 367365 -// gas legacy: 416585 -// gas legacyOptimized: 322043 +// gas irOptimized: 362445 +// gas legacy: 414569 +// gas legacyOptimized: 319271 // test_uint256() -> -// gas irOptimized: 515982 -// gas legacy: 583100 -// gas legacyOptimized: 444161 +// gas irOptimized: 511910 +// gas legacy: 581876 +// gas legacyOptimized: 442757 diff --git a/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_v2.sol b/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_v2.sol index 5a1c2aebf..58b38a9c3 100644 --- a/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_v2.sol +++ b/test/libsolidity/semanticTests/abiEncoderV2/abi_encode_v2.sol @@ -51,6 +51,6 @@ contract C { // f2() -> 0x20, 0xa0, 0x1, 0x60, 0x2, 0x3, "abc" // f3() -> 0x20, 0xa0, 0x1, 0x60, 0x2, 0x3, "abc" // f4() -> 0x20, 0x160, 0x1, 0x80, 0xc0, 0x2, 0x3, "abc", 0x7, 0x40, 0x2, 0x2, 0x3 -// gas irOptimized: 112820 -// gas legacy: 114900 -// gas legacyOptimized: 112606 +// gas irOptimized: 112646 +// gas legacy: 114866 +// gas legacyOptimized: 112586 diff --git a/test/libsolidity/semanticTests/abiEncoderV2/abi_encoder_v2_head_overflow_with_static_array_cleanup_bug.sol b/test/libsolidity/semanticTests/abiEncoderV2/abi_encoder_v2_head_overflow_with_static_array_cleanup_bug.sol new file mode 100644 index 000000000..9e5d57552 --- /dev/null +++ b/test/libsolidity/semanticTests/abiEncoderV2/abi_encoder_v2_head_overflow_with_static_array_cleanup_bug.sol @@ -0,0 +1,17 @@ +pragma abicoder v2; + +struct T { + bytes x; + uint[3] y; +} + +contract E { + function f(bool a, T calldata b, bytes32[2] calldata c) + public + returns (bool, T calldata, bytes32[2] calldata) + { + return (a, b, c); + } +} +// ---- +// f(bool,(bytes,uint256[3]),bytes32[2]): 1, 0x80, "a", "b", 0x80, 11, 12, 13, 4, "abcd" -> 1, 0x80, "a", "b", 0x80, 11, 12, 13, 4, "abcd" diff --git a/test/libsolidity/semanticTests/abiEncoderV2/calldata_array.sol b/test/libsolidity/semanticTests/abiEncoderV2/calldata_array.sol index 3e3dcc274..689bb9810 100644 --- a/test/libsolidity/semanticTests/abiEncoderV2/calldata_array.sol +++ b/test/libsolidity/semanticTests/abiEncoderV2/calldata_array.sol @@ -20,6 +20,6 @@ contract C { // f(uint256[][1]): 32, 32, 0 -> true // f(uint256[][1]): 32, 32, 1, 42 -> true // f(uint256[][1]): 32, 32, 8, 421, 422, 423, 424, 425, 426, 427, 428 -> true -// gas irOptimized: 128098 -// gas legacy: 140672 -// gas legacyOptimized: 119588 +// gas irOptimized: 127347 +// gas legacy: 140553 +// gas legacyOptimized: 119450 diff --git a/test/libsolidity/semanticTests/abiEncoderV2/calldata_array_dynamic_static_in_library.sol b/test/libsolidity/semanticTests/abiEncoderV2/calldata_array_dynamic_static_in_library.sol new file mode 100644 index 000000000..b15a203f2 --- /dev/null +++ b/test/libsolidity/semanticTests/abiEncoderV2/calldata_array_dynamic_static_in_library.sol @@ -0,0 +1,17 @@ +library L { + // This case used to be affected by the buggy cleanup due to ABIEncoderV2HeadOverflowWithStaticArrayCleanup bug. + function g(uint[] memory a, uint[1] calldata b) public returns (uint[] memory, uint[1] calldata) { + return (a, b); + } +} + +contract C { + function f(uint[] memory a, uint[1] calldata b) public returns (uint[] memory, uint[1] memory) { + return L.g(a, b); + } +} +// ==== +// EVMVersion: >homestead +// ---- +// library: L +// f(uint256[],uint256[1]): 0x40, 0xff, 1, 0xffff -> 0x40, 0xff, 0x01, 0xffff diff --git a/test/libsolidity/semanticTests/abiEncoderV2/cleanup/reencoded_calldata_string.sol b/test/libsolidity/semanticTests/abiEncoderV2/cleanup/reencoded_calldata_string.sol new file mode 100644 index 000000000..1cf129529 --- /dev/null +++ b/test/libsolidity/semanticTests/abiEncoderV2/cleanup/reencoded_calldata_string.sol @@ -0,0 +1,27 @@ +contract C { + function f(string calldata x) external returns (bytes memory r) { + uint mptr; + assembly { + // dirty memory + mptr := mload(0x40) + for { let i := mptr } lt(i, add(mptr, 0x0100)) { i := add(i, 32) } + { + mstore(i, sub(0, 1)) + } + } + r = abi.encode(x); + assembly { + // assert that we dirtied the memory that was encoded to + if iszero(eq(mptr, r)) { + revert(0, 0) + } + } + } + function test() external returns (bytes memory) { + return this.f("abc"); + } +} +// ==== +// EVMVersion: >homestead +// ---- +// test() -> 0x20, 0x60, 0x20, 3, "abc" diff --git a/test/libsolidity/semanticTests/abiEncoderV2/memory_dynamic_array_and_calldata_bytes.sol b/test/libsolidity/semanticTests/abiEncoderV2/memory_dynamic_array_and_calldata_bytes.sol new file mode 100644 index 000000000..07d035080 --- /dev/null +++ b/test/libsolidity/semanticTests/abiEncoderV2/memory_dynamic_array_and_calldata_bytes.sol @@ -0,0 +1,13 @@ +contract C { + function f(uint256[] memory a, bytes calldata b) public returns (bytes memory) { + return abi.encode(a, b); + } + + function g(uint256[] memory a, bytes calldata b) external returns (bytes memory) { + return f(a, b); + } +} + +// ---- +// f(uint256[],bytes): 0x40, 0x80, 1, 0xFF, 6, "123456" -> 0x20, 0xc0, 0x40, 0x80, 1, 0xff, 6, "123456" +// g(uint256[],bytes): 0x40, 0x80, 1, 0xffff, 8, "12345678" -> 0x20, 0xc0, 0x40, 0x80, 1, 0xffff, 8, "12345678" diff --git a/test/libsolidity/semanticTests/abiEncoderV2/memory_dynamic_array_and_calldata_static_array.sol b/test/libsolidity/semanticTests/abiEncoderV2/memory_dynamic_array_and_calldata_static_array.sol new file mode 100644 index 000000000..a8f4f5554 --- /dev/null +++ b/test/libsolidity/semanticTests/abiEncoderV2/memory_dynamic_array_and_calldata_static_array.sol @@ -0,0 +1,18 @@ +contract C { + function f(uint256[] memory a, uint256[1] calldata b) public returns (bytes memory) { + return abi.encode(a, b); + } + + function g(uint256[] memory a, uint256[1] calldata b) external returns (bytes memory) { + return f(a, b); + } + + function h(uint256[] memory a, uint256[1] calldata b) external returns (uint256[] memory, uint256[1] calldata) { + return (a, b); + } +} + +// ---- +// f(uint256[],uint256[1]): 0x40, 0xff, 1, 0xffff -> 0x20, 0x80, 0x40, 0xff, 1, 0xffff +// g(uint256[],uint256[1]): 0x40, 0xff, 1, 0xffff -> 0x20, 0x80, 0x40, 0xff, 1, 0xffff +// h(uint256[],uint256[1]): 0x40, 0xff, 1, 0xffff -> 0x40, 0xff, 1, 0xffff diff --git a/test/libsolidity/semanticTests/abiEncoderV2/storage_array_encoding.sol b/test/libsolidity/semanticTests/abiEncoderV2/storage_array_encoding.sol index 0ef6d88eb..5f71fc7e2 100644 --- a/test/libsolidity/semanticTests/abiEncoderV2/storage_array_encoding.sol +++ b/test/libsolidity/semanticTests/abiEncoderV2/storage_array_encoding.sol @@ -18,10 +18,10 @@ contract C { // EVMVersion: >homestead // ---- // h(uint256[2][]): 0x20, 3, 123, 124, 223, 224, 323, 324 -> 32, 256, 0x20, 3, 123, 124, 223, 224, 323, 324 -// gas irOptimized: 180768 -// gas legacy: 184929 -// gas legacyOptimized: 181504 +// gas irOptimized: 180726 +// gas legacy: 184921 +// gas legacyOptimized: 181506 // i(uint256[2][2]): 123, 124, 223, 224 -> 32, 128, 123, 124, 223, 224 -// gas irOptimized: 112471 -// gas legacy: 115468 -// gas legacyOptimized: 112988 +// gas irOptimized: 112453 +// gas legacy: 115460 +// gas legacyOptimized: 112990 diff --git a/test/libsolidity/semanticTests/abiencodedecode/abi_decode_simple_storage.sol b/test/libsolidity/semanticTests/abiencodedecode/abi_decode_simple_storage.sol index e877e627b..15ba6f7de 100644 --- a/test/libsolidity/semanticTests/abiencodedecode/abi_decode_simple_storage.sol +++ b/test/libsolidity/semanticTests/abiencodedecode/abi_decode_simple_storage.sol @@ -9,6 +9,6 @@ contract C { // ---- // f(bytes): 0x20, 0x80, 0x21, 0x40, 0x7, "abcdefg" -> 0x21, 0x40, 0x7, "abcdefg" -// gas irOptimized: 135787 -// gas legacy: 137377 -// gas legacyOptimized: 136125 +// gas irOptimized: 135699 +// gas legacy: 137325 +// gas legacyOptimized: 136059 diff --git a/test/libsolidity/semanticTests/array/copying/bytes_storage_to_storage.sol b/test/libsolidity/semanticTests/array/copying/bytes_storage_to_storage.sol index 0f0b4083f..ae17b76b1 100644 --- a/test/libsolidity/semanticTests/array/copying/bytes_storage_to_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/bytes_storage_to_storage.sol @@ -17,25 +17,25 @@ contract c { // ---- // f(uint256): 0 -> 0x20, 0x00 // f(uint256): 31 -> 0x20, 0x1f, 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e00 -// gas irOptimized: 108395 -// gas legacy: 124322 -// gas legacyOptimized: 119141 +// gas irOptimized: 109413 +// gas legacy: 124296 +// gas legacyOptimized: 119119 // f(uint256): 32 -> 0x20, 0x20, 1780731860627700044960722568376592200742329637303199754547598369979440671 -// gas irOptimized: 117480 -// gas legacy: 135259 -// gas legacyOptimized: 130089 +// gas irOptimized: 118565 +// gas legacy: 135251 +// gas legacyOptimized: 130091 // f(uint256): 33 -> 0x20, 33, 1780731860627700044960722568376592200742329637303199754547598369979440671, 0x2000000000000000000000000000000000000000000000000000000000000000 -// gas irOptimized: 124117 -// gas legacy: 142861 -// gas legacyOptimized: 137030 +// gas irOptimized: 125184 +// gas legacy: 142835 +// gas legacyOptimized: 137008 // f(uint256): 63 -> 0x20, 0x3f, 1780731860627700044960722568376592200742329637303199754547598369979440671, 14532552714582660066924456880521368950258152170031413196862950297402215316992 -// gas irOptimized: 126467 -// gas legacy: 160901 -// gas legacyOptimized: 150960 +// gas irOptimized: 128584 +// gas legacy: 160875 +// gas legacyOptimized: 150938 // f(uint256): 12 -> 0x20, 0x0c, 0x0102030405060708090a0b0000000000000000000000000000000000000000 // gas legacy: 59345 // gas legacyOptimized: 57279 // f(uint256): 129 -> 0x20, 0x81, 1780731860627700044960722568376592200742329637303199754547598369979440671, 0x202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f, 29063324697304692433803953038474361308315562010425523193971352996434451193439, 0x606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f, -57896044618658097711785492504343953926634992332820282019728792003956564819968 -// gas irOptimized: 353326 -// gas legacy: 421700 -// gas legacyOptimized: 402999 +// gas irOptimized: 357699 +// gas legacy: 421674 +// gas legacyOptimized: 402977 diff --git a/test/libsolidity/semanticTests/array/copying/copy_byte_array_in_struct_to_storage.sol b/test/libsolidity/semanticTests/array/copying/copy_byte_array_in_struct_to_storage.sol index 2a3e2044f..2b3cad19f 100644 --- a/test/libsolidity/semanticTests/array/copying/copy_byte_array_in_struct_to_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/copy_byte_array_in_struct_to_storage.sol @@ -35,12 +35,12 @@ contract C { } // ---- // f() -> 0x40, 0x80, 6, 0x6162636465660000000000000000000000000000000000000000000000000000, 0x49, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738390000000000000000000000000000000000000000000000 -// gas irOptimized: 179880 -// gas legacy: 181099 -// gas legacyOptimized: 180073 +// gas irOptimized: 179766 +// gas legacy: 181047 +// gas legacyOptimized: 180029 // g() -> 0x40, 0xc0, 0x49, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738390000000000000000000000000000000000000000000000, 0x11, 0x3132333435363738393233343536373839000000000000000000000000000000 -// gas irOptimized: 107211 -// gas legacy: 110253 -// gas legacyOptimized: 107397 +// gas irOptimized: 107097 +// gas legacy: 110201 +// gas legacyOptimized: 107353 // h() -> 0x40, 0x60, 0x00, 0x00 // storageEmpty -> 1 diff --git a/test/libsolidity/semanticTests/array/copying/function_type_array_to_storage.sol b/test/libsolidity/semanticTests/array/copying/function_type_array_to_storage.sol index 347f2f2ee..17c97d200 100644 --- a/test/libsolidity/semanticTests/array/copying/function_type_array_to_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/function_type_array_to_storage.sol @@ -46,11 +46,11 @@ contract C { } // ---- // test() -> 0x20, 0x14, "[a called][b called]" -// gas irOptimized: 116724 -// gas legacy: 119056 -// gas legacyOptimized: 117043 +// gas irOptimized: 116688 +// gas legacy: 119030 +// gas legacyOptimized: 117021 // test2() -> 0x20, 0x14, "[b called][a called]" // test3() -> 0x20, 0x14, "[b called][a called]" -// gas irOptimized: 103304 -// gas legacy: 102840 -// gas legacyOptimized: 101728 +// gas irOptimized: 103268 +// gas legacy: 102814 +// gas legacyOptimized: 101706 diff --git a/test/libsolidity/semanticTests/array/copying/storage_memory_nested_bytes.sol b/test/libsolidity/semanticTests/array/copying/storage_memory_nested_bytes.sol index 349bfd935..550e74a6f 100644 --- a/test/libsolidity/semanticTests/array/copying/storage_memory_nested_bytes.sol +++ b/test/libsolidity/semanticTests/array/copying/storage_memory_nested_bytes.sol @@ -11,6 +11,6 @@ contract C { } // ---- // f() -> 0x20, 0x02, 0x40, 0x80, 3, 0x6162630000000000000000000000000000000000000000000000000000000000, 0x99, 44048183304486788312148433451363384677562265908331949128489393215789685032262, 32241931068525137014058842823026578386641954854143559838526554899205067598957, 49951309422467613961193228765530489307475214998374779756599339590522149884499, 0x54555658595a6162636465666768696a6b6c6d6e6f707172737475767778797a, 0x4142434445464748494a4b4c4d4e4f5051525354555658595a00000000000000 -// gas irOptimized: 202952 -// gas legacy: 204912 -// gas legacyOptimized: 203437 +// gas irOptimized: 202808 +// gas legacy: 204860 +// gas legacyOptimized: 203385 diff --git a/test/libsolidity/semanticTests/array/pop/byte_array_pop_copy_long.sol b/test/libsolidity/semanticTests/array/pop/byte_array_pop_copy_long.sol index 743a848d9..931069dee 100644 --- a/test/libsolidity/semanticTests/array/pop/byte_array_pop_copy_long.sol +++ b/test/libsolidity/semanticTests/array/pop/byte_array_pop_copy_long.sol @@ -10,6 +10,6 @@ contract c { // ---- // test() -> 0x20, 29, 0x0303030303030303030303030303030303030303030303030303030303000000 -// gas irOptimized: 109341 -// gas legacy: 126728 -// gas legacyOptimized: 123444 +// gas irOptimized: 109310 +// gas legacy: 126702 +// gas legacyOptimized: 123422 diff --git a/test/libsolidity/semanticTests/array/pop/byte_array_pop_masking_long.sol b/test/libsolidity/semanticTests/array/pop/byte_array_pop_masking_long.sol index 0be102f17..9f3884dae 100644 --- a/test/libsolidity/semanticTests/array/pop/byte_array_pop_masking_long.sol +++ b/test/libsolidity/semanticTests/array/pop/byte_array_pop_masking_long.sol @@ -10,6 +10,6 @@ contract c { // ---- // test() -> 0x20, 33, 0x303030303030303030303030303030303030303030303030303030303030303, 0x0300000000000000000000000000000000000000000000000000000000000000 -// gas irOptimized: 108146 -// gas legacy: 125610 -// gas legacyOptimized: 122582 +// gas irOptimized: 108115 +// gas legacy: 125584 +// gas legacyOptimized: 122560 diff --git a/test/libsolidity/semanticTests/byte_array_to_storage_cleanup.sol b/test/libsolidity/semanticTests/byte_array_to_storage_cleanup.sol index f275590e4..745b8ee12 100644 --- a/test/libsolidity/semanticTests/byte_array_to_storage_cleanup.sol +++ b/test/libsolidity/semanticTests/byte_array_to_storage_cleanup.sol @@ -28,9 +28,9 @@ contract C { // compileViaYul: also // ---- // constructor() -> -// gas irOptimized: 521983 -// gas legacy: 731840 -// gas legacyOptimized: 494859 +// gas irOptimized: 518935 +// gas legacy: 729908 +// gas legacyOptimized: 493347 // h() -> 0x20, 0x40, 0x00, 0 // ~ emit ev(uint256[],uint256): 0x40, 0x21, 0x02, 0x00, 0x00 // g() -> 0x20, 0x40, 0, 0x00 diff --git a/test/libsolidity/semanticTests/constructor/bytes_in_constructors_packer.sol b/test/libsolidity/semanticTests/constructor/bytes_in_constructors_packer.sol index 5c57963b2..4e3f92c81 100644 --- a/test/libsolidity/semanticTests/constructor/bytes_in_constructors_packer.sol +++ b/test/libsolidity/semanticTests/constructor/bytes_in_constructors_packer.sol @@ -24,6 +24,6 @@ contract Creator { } // ---- // f(uint256,bytes): 7, 0x40, 78, "abcdefghijklmnopqrstuvwxyzabcdef", "ghijklmnopqrstuvwxyzabcdefghijkl", "mnopqrstuvwxyz" -> 7, "h" -// gas irOptimized: 282398 -// gas legacy: 429047 -// gas legacyOptimized: 297958 +// gas irOptimized: 279069 +// gas legacy: 427192 +// gas legacyOptimized: 296504 diff --git a/test/libsolidity/semanticTests/constructor/bytes_in_constructors_unpacker.sol b/test/libsolidity/semanticTests/constructor/bytes_in_constructors_unpacker.sol index 867a85a12..905114aba 100644 --- a/test/libsolidity/semanticTests/constructor/bytes_in_constructors_unpacker.sol +++ b/test/libsolidity/semanticTests/constructor/bytes_in_constructors_unpacker.sol @@ -8,8 +8,8 @@ contract Test { } // ---- // constructor(): 7, 0x40, 78, "abcdefghijklmnopqrstuvwxyzabcdef", "ghijklmnopqrstuvwxyzabcdefghijkl", "mnopqrstuvwxyz" -> -// gas irOptimized: 273340 -// gas legacy: 317746 -// gas legacyOptimized: 262368 +// gas irOptimized: 270118 +// gas legacy: 315616 +// gas legacyOptimized: 260686 // m_x() -> 7 // m_s() -> 0x20, 78, "abcdefghijklmnopqrstuvwxyzabcdef", "ghijklmnopqrstuvwxyzabcdefghijkl", "mnopqrstuvwxyz" diff --git a/test/libsolidity/semanticTests/errors/error_static_calldata_uint_array_and_dynamic_array.sol b/test/libsolidity/semanticTests/errors/error_static_calldata_uint_array_and_dynamic_array.sol new file mode 100644 index 000000000..bfda3b126 --- /dev/null +++ b/test/libsolidity/semanticTests/errors/error_static_calldata_uint_array_and_dynamic_array.sol @@ -0,0 +1,10 @@ +contract C { + error E(uint[], uint[1]); + + // This case used to be affected by the buggy cleanup due to ABIEncoderV2HeadOverflowWithStaticArrayCleanup bug. + function f(uint[] memory a, uint[1] calldata b) public { + revert E(a, b); + } +} +// ---- +// f(uint256[],uint256[1]): 0x40, 0xff, 1, 0xffff -> FAILURE, hex"f42f106d", 0x40, 0xff, 1, 0xffff diff --git a/test/libsolidity/semanticTests/events/event_static_calldata_uint_array_and_dynamic_array.sol b/test/libsolidity/semanticTests/events/event_static_calldata_uint_array_and_dynamic_array.sol new file mode 100644 index 000000000..a72ad938c --- /dev/null +++ b/test/libsolidity/semanticTests/events/event_static_calldata_uint_array_and_dynamic_array.sol @@ -0,0 +1,11 @@ +contract C { + event E(uint[], uint[1]); + + // This case used to be affected by the buggy cleanup due to ABIEncoderV2HeadOverflowWithStaticArrayCleanup bug. + function f(uint[] memory a, uint[1] calldata b) public { + emit E(a, b); + } +} +// ---- +// f(uint256[],uint256[1]): 0x40, 0xff, 1, 0xffff -> +// ~ emit E(uint256[],uint256[1]): 0x40, 0xff, 0x01, 0xffff diff --git a/test/libsolidity/semanticTests/externalContracts/FixedFeeRegistrar.sol b/test/libsolidity/semanticTests/externalContracts/FixedFeeRegistrar.sol index 10096c03b..b56ec7801 100644 --- a/test/libsolidity/semanticTests/externalContracts/FixedFeeRegistrar.sol +++ b/test/libsolidity/semanticTests/externalContracts/FixedFeeRegistrar.sol @@ -74,9 +74,9 @@ contract FixedFeeRegistrar is Registrar { } // ---- // constructor() -// gas irOptimized: 414897 -// gas legacy: 935817 -// gas legacyOptimized: 489951 +// gas irOptimized: 411435 +// gas legacy: 933867 +// gas legacyOptimized: 487352 // reserve(string), 69 ether: 0x20, 3, "abc" -> // ~ emit Changed(string): #0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45 // gas irOptimized: 45967 diff --git a/test/libsolidity/semanticTests/externalContracts/base64.sol b/test/libsolidity/semanticTests/externalContracts/base64.sol index c0cf34627..84ece36be 100644 --- a/test/libsolidity/semanticTests/externalContracts/base64.sol +++ b/test/libsolidity/semanticTests/externalContracts/base64.sol @@ -33,9 +33,9 @@ contract test { // EVMVersion: >=constantinople // ---- // constructor() -// gas irOptimized: 444190 -// gas legacy: 757857 -// gas legacyOptimized: 539866 +// gas irOptimized: 441142 +// gas legacy: 755907 +// gas legacyOptimized: 538354 // encode_inline_asm(bytes): 0x20, 0 -> 0x20, 0 // encode_inline_asm(bytes): 0x20, 1, "f" -> 0x20, 4, "Zg==" // encode_inline_asm(bytes): 0x20, 2, "fo" -> 0x20, 4, "Zm8=" diff --git a/test/libsolidity/semanticTests/externalContracts/deposit_contract.sol b/test/libsolidity/semanticTests/externalContracts/deposit_contract.sol index 61a1f6bd6..7b5418ed1 100644 --- a/test/libsolidity/semanticTests/externalContracts/deposit_contract.sol +++ b/test/libsolidity/semanticTests/externalContracts/deposit_contract.sol @@ -176,35 +176,35 @@ contract DepositContract is IDepositContract, ERC165 { } // ---- // constructor() -// gas irOptimized: 1432633 -// gas legacy: 2427722 -// gas legacyOptimized: 1773892 +// gas irOptimized: 1428137 +// gas legacy: 2425301 +// gas legacyOptimized: 1770477 // supportsInterface(bytes4): 0x0 -> 0 // supportsInterface(bytes4): 0xffffffff00000000000000000000000000000000000000000000000000000000 -> false # defined to be false by ERC-165 # // supportsInterface(bytes4): 0x01ffc9a700000000000000000000000000000000000000000000000000000000 -> true # ERC-165 id # // supportsInterface(bytes4): 0x8564090700000000000000000000000000000000000000000000000000000000 -> true # the deposit interface id # // get_deposit_root() -> 0xd70a234731285c6804c2a4f56711ddb8c82c99740f207854891028af34e27e5e -// gas irOptimized: 116284 -// gas legacy: 150273 -// gas legacyOptimized: 122510 +// gas irOptimized: 114626 +// gas legacy: 149888 +// gas legacyOptimized: 121887 // get_deposit_count() -> 0x20, 8, 0 # TODO: check balance and logs after each deposit # // deposit(bytes,bytes,bytes,bytes32), 32 ether: 0 -> FAILURE # Empty input # // get_deposit_root() -> 0xd70a234731285c6804c2a4f56711ddb8c82c99740f207854891028af34e27e5e -// gas irOptimized: 116284 -// gas legacy: 150273 -// gas legacyOptimized: 122510 +// gas irOptimized: 114626 +// gas legacy: 149888 +// gas legacyOptimized: 121887 // get_deposit_count() -> 0x20, 8, 0 // deposit(bytes,bytes,bytes,bytes32), 1 ether: 0x80, 0xe0, 0x120, 0xaa4a8d0b7d9077248630f1a4701ae9764e42271d7f22b7838778411857fd349e, 0x30, 0x933ad9491b62059dd065b560d256d8957a8c402cc6e8d8ee7290ae11e8f73292, 0x67a8811c397529dac52ae1342ba58c9500000000000000000000000000000000, 0x20, 0x00f50428677c60f997aadeab24aabf7fceaef491c96a52b463ae91f95611cf71, 0x60, 0xa29d01cc8c6296a8150e515b5995390ef841dc18948aa3e79be6d7c1851b4cbb, 0x5d6ff49fa70b9c782399506a22a85193151b9b691245cebafd2063012443c132, 0x4b6c36debaedefb7b2d71b0503ffdc00150aaffd42e63358238ec888901738b8 -> # txhash: 0x7085c586686d666e8bb6e9477a0f0b09565b2060a11f1c4209d3a52295033832 # // ~ emit DepositEvent(bytes,bytes,bytes,bytes,bytes): 0xa0, 0x0100, 0x0140, 0x0180, 0x0200, 0x30, 0x933ad9491b62059dd065b560d256d8957a8c402cc6e8d8ee7290ae11e8f73292, 0x67a8811c397529dac52ae1342ba58c9500000000000000000000000000000000, 0x20, 0xf50428677c60f997aadeab24aabf7fceaef491c96a52b463ae91f95611cf71, 0x08, 0xca9a3b00000000000000000000000000000000000000000000000000000000, 0x60, 0xa29d01cc8c6296a8150e515b5995390ef841dc18948aa3e79be6d7c1851b4cbb, 0x5d6ff49fa70b9c782399506a22a85193151b9b691245cebafd2063012443c132, 0x4b6c36debaedefb7b2d71b0503ffdc00150aaffd42e63358238ec888901738b8, 0x08, 0x00 // get_deposit_root() -> 0x2089653123d9c721215120b6db6738ba273bbc5228ac093b1f983badcdc8a438 -// gas irOptimized: 116269 -// gas legacy: 150283 -// gas legacyOptimized: 122523 +// gas irOptimized: 114611 +// gas legacy: 149898 +// gas legacyOptimized: 121900 // get_deposit_count() -> 0x20, 8, 0x0100000000000000000000000000000000000000000000000000000000000000 // deposit(bytes,bytes,bytes,bytes32), 32 ether: 0x80, 0xe0, 0x120, 0xdbd986dc85ceb382708cf90a3500f500f0a393c5ece76963ac3ed72eccd2c301, 0x30, 0xb2ce0f79f90e7b3a113ca5783c65756f96c4b4673c2b5c1eb4efc22280259441, 0x06d601211e8866dc5b50dc48a244dd7c00000000000000000000000000000000, 0x20, 0x00344b6c73f71b11c56aba0d01b7d8ad83559f209d0a4101a515f6ad54c89771, 0x60, 0x945caaf82d18e78c033927d51f452ebcd76524497b91d7a11219cb3db6a1d369, 0x7595fc095ce489e46b2ef129591f2f6d079be4faaf345a02c5eb133c072e7c56, 0x0c6c3617eee66b4b878165c502357d49485326bc6b31bc96873f308c8f19c09d -> # txhash: 0x404d8e109822ce448e68f45216c12cb051b784d068fbe98317ab8e50c58304ac # // ~ emit DepositEvent(bytes,bytes,bytes,bytes,bytes): 0xa0, 0x0100, 0x0140, 0x0180, 0x0200, 0x30, 0xb2ce0f79f90e7b3a113ca5783c65756f96c4b4673c2b5c1eb4efc22280259441, 0x06d601211e8866dc5b50dc48a244dd7c00000000000000000000000000000000, 0x20, 0x344b6c73f71b11c56aba0d01b7d8ad83559f209d0a4101a515f6ad54c89771, 0x08, 0x40597307000000000000000000000000000000000000000000000000000000, 0x60, 0x945caaf82d18e78c033927d51f452ebcd76524497b91d7a11219cb3db6a1d369, 0x7595fc095ce489e46b2ef129591f2f6d079be4faaf345a02c5eb133c072e7c56, 0x0c6c3617eee66b4b878165c502357d49485326bc6b31bc96873f308c8f19c09d, 0x08, 0x0100000000000000000000000000000000000000000000000000000000000000 // get_deposit_root() -> 0x40255975859377d912c53aa853245ebd939bdd2b33a28e084babdcc1ed8238ee -// gas irOptimized: 116269 -// gas legacy: 150283 -// gas legacyOptimized: 122523 +// gas irOptimized: 114611 +// gas legacy: 149898 +// gas legacyOptimized: 121900 // get_deposit_count() -> 0x20, 8, 0x0200000000000000000000000000000000000000000000000000000000000000 diff --git a/test/libsolidity/semanticTests/externalContracts/strings.sol b/test/libsolidity/semanticTests/externalContracts/strings.sol index c604ff142..edbf82a29 100644 --- a/test/libsolidity/semanticTests/externalContracts/strings.sol +++ b/test/libsolidity/semanticTests/externalContracts/strings.sol @@ -49,9 +49,9 @@ contract test { } // ---- // constructor() -// gas irOptimized: 678980 -// gas legacy: 1103242 -// gas legacyOptimized: 745184 +// gas irOptimized: 675980 +// gas legacy: 1101298 +// gas legacyOptimized: 743666 // toSlice(string): 0x20, 11, "hello world" -> 11, 0xa0 // gas irOptimized: 22660 // gas legacy: 23190 diff --git a/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting.sol b/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting.sol index 558ce1c5b..d0c3c4d80 100644 --- a/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting.sol +++ b/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting.sol @@ -23,9 +23,9 @@ contract C { // ---- // constructor(), 1 ether -> -// gas irOptimized: 270449 -// gas legacy: 456680 -// gas legacyOptimized: 302975 +// gas irOptimized: 266135 +// gas legacy: 454729 +// gas legacyOptimized: 301679 // f(uint256): 0 -> FAILURE // f(uint256): 1 -> FAILURE // f(uint256): 2 -> FAILURE diff --git a/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting_debugstrings.sol b/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting_debugstrings.sol index 4af6f97f6..9cc2846ac 100644 --- a/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting_debugstrings.sol +++ b/test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting_debugstrings.sol @@ -26,9 +26,9 @@ contract C { // revertStrings: debug // ---- // constructor(), 1 ether -> -// gas irOptimized: 428444 -// gas legacy: 825625 -// gas legacyOptimized: 508492 +// gas irOptimized: 424088 +// gas legacy: 823681 +// gas legacyOptimized: 505900 // f(uint256): 0 -> FAILURE, hex"08c379a0", 0x20, 37, "Target contract does not contain", " code" // f(uint256): 1 -> FAILURE, hex"08c379a0", 0x20, 37, "Target contract does not contain", " code" // f(uint256): 2 -> FAILURE, hex"08c379a0", 0x20, 37, "Target contract does not contain", " code" diff --git a/test/libsolidity/semanticTests/various/address_code.sol b/test/libsolidity/semanticTests/various/address_code.sol index c44fd410a..8dcdd13e7 100644 --- a/test/libsolidity/semanticTests/various/address_code.sol +++ b/test/libsolidity/semanticTests/various/address_code.sol @@ -16,9 +16,9 @@ contract C { // compileToEwasm: also // ---- // constructor() -> -// gas irOptimized: 177507 -// gas legacy: 249207 -// gas legacyOptimized: 157489 +// gas irOptimized: 175791 +// gas legacy: 247263 +// gas legacyOptimized: 155977 // initCode() -> 0x20, 0 // f() -> true // g() -> 0 diff --git a/test/libsolidity/semanticTests/various/skip_dynamic_types_for_structs.sol b/test/libsolidity/semanticTests/various/skip_dynamic_types_for_structs.sol index 0edb0e04e..cd34a419d 100644 --- a/test/libsolidity/semanticTests/various/skip_dynamic_types_for_structs.sol +++ b/test/libsolidity/semanticTests/various/skip_dynamic_types_for_structs.sol @@ -20,6 +20,6 @@ contract C { // ---- // g() -> 2, 6 -// gas irOptimized: 178637 -// gas legacy: 180945 -// gas legacyOptimized: 179460 +// gas irOptimized: 178549 +// gas legacy: 180893 +// gas legacyOptimized: 179394 diff --git a/test/libsolidity/syntaxTests/bytecode_too_large.sol b/test/libsolidity/syntaxTests/bytecode_too_large.sol index e76c801a1..1b4d02ecb 100644 --- a/test/libsolidity/syntaxTests/bytecode_too_large.sol +++ b/test/libsolidity/syntaxTests/bytecode_too_large.sol @@ -9,4 +9,4 @@ contract test { // ==== // EVMVersion: >byzantium // ---- -// Warning 5574: (21-27154): Contract code size is 27199 bytes and exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable on Mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries. +// Warning 5574: (21-27154): Contract code size is 27192 bytes and exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable on Mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries. diff --git a/test/libsolidity/syntaxTests/bytecode_too_large_byzantium.sol b/test/libsolidity/syntaxTests/bytecode_too_large_byzantium.sol index cdd83602f..4f3239c22 100644 --- a/test/libsolidity/syntaxTests/bytecode_too_large_byzantium.sol +++ b/test/libsolidity/syntaxTests/bytecode_too_large_byzantium.sol @@ -7,4 +7,4 @@ contract test { // ==== // EVMVersion: =byzantium // ---- -// Warning 5574: (0-27133): Contract code size is 27227 bytes and exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable on Mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries. +// Warning 5574: (0-27133): Contract code size is 27220 bytes and exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable on Mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries.