mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Improve abi decoding functions for arrays.
This commit is contained in:
parent
0fa24c786b
commit
d1c0b428fc
@ -1170,6 +1170,7 @@ string ABIFunctions::abiDecodingFunctionArrayAvailableLength(ArrayType const& _t
|
|||||||
solAssert(_type.dataStoredIn(DataLocation::Memory), "");
|
solAssert(_type.dataStoredIn(DataLocation::Memory), "");
|
||||||
if (_type.isByteArray())
|
if (_type.isByteArray())
|
||||||
return abiDecodingFunctionByteArrayAvailableLength(_type, _fromMemory);
|
return abiDecodingFunctionByteArrayAvailableLength(_type, _fromMemory);
|
||||||
|
solAssert(_type.calldataStride() > 0, "");
|
||||||
|
|
||||||
string functionName =
|
string functionName =
|
||||||
"abi_decode_available_length_" +
|
"abi_decode_available_length_" +
|
||||||
@ -1186,11 +1187,11 @@ string ABIFunctions::abiDecodingFunctionArrayAvailableLength(ArrayType const& _t
|
|||||||
mstore(array, length)
|
mstore(array, length)
|
||||||
dst := add(array, 0x20)
|
dst := add(array, 0x20)
|
||||||
</dynamic>
|
</dynamic>
|
||||||
let src := offset
|
let srcEnd := add(offset, mul(length, <stride>))
|
||||||
if gt(add(src, mul(length, <stride>)), end) {
|
if gt(srcEnd, end) {
|
||||||
<revertInvalidStride>()
|
<revertInvalidStride>()
|
||||||
}
|
}
|
||||||
for { let i := 0 } lt(i, length) { i := add(i, 1) }
|
for { let src := offset } lt(src, srcEnd) { src := add(src, <stride>) }
|
||||||
{
|
{
|
||||||
<?dynamicBase>
|
<?dynamicBase>
|
||||||
let innerOffset := <load>(src)
|
let innerOffset := <load>(src)
|
||||||
@ -1201,7 +1202,6 @@ string ABIFunctions::abiDecodingFunctionArrayAvailableLength(ArrayType const& _t
|
|||||||
</dynamicBase>
|
</dynamicBase>
|
||||||
mstore(dst, <decodingFun>(elementPos, end))
|
mstore(dst, <decodingFun>(elementPos, end))
|
||||||
dst := add(dst, 0x20)
|
dst := add(dst, 0x20)
|
||||||
src := add(src, <stride>)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
|
@ -43,17 +43,16 @@ object "C_59" {
|
|||||||
let dst_1 := dst
|
let dst_1 := dst
|
||||||
mstore(dst, _4)
|
mstore(dst, _4)
|
||||||
dst := add(dst, _2)
|
dst := add(dst, _2)
|
||||||
|
let srcEnd := add(add(offset, _5), 36)
|
||||||
|
if gt(srcEnd, calldatasize()) { revert(_1, _1) }
|
||||||
let src := add(offset, 36)
|
let src := add(offset, 36)
|
||||||
if gt(add(add(offset, _5), 36), calldatasize()) { revert(_1, _1) }
|
for { } lt(src, srcEnd) { src := add(src, _2) }
|
||||||
let i := _1
|
|
||||||
for { } lt(i, _4) { i := add(i, 1) }
|
|
||||||
{
|
{
|
||||||
if slt(sub(calldatasize(), src), _2) { revert(_1, _1) }
|
if slt(sub(calldatasize(), src), _2) { revert(_1, _1) }
|
||||||
let value := allocate_memory_1236()
|
let value := allocate_memory_1174()
|
||||||
mstore(value, calldataload(src))
|
mstore(value, calldataload(src))
|
||||||
mstore(dst, value)
|
mstore(dst, value)
|
||||||
dst := add(dst, _2)
|
dst := add(dst, _2)
|
||||||
src := add(src, _2)
|
|
||||||
}
|
}
|
||||||
let ret, ret_1 := fun_sumArray(dst_1)
|
let ret, ret_1 := fun_sumArray(dst_1)
|
||||||
let memPos := mload(64)
|
let memPos := mload(64)
|
||||||
@ -68,7 +67,7 @@ object "C_59" {
|
|||||||
mstore(4, 0x41)
|
mstore(4, 0x41)
|
||||||
revert(0, 0x24)
|
revert(0, 0x24)
|
||||||
}
|
}
|
||||||
function allocate_memory_1236() -> memPtr
|
function allocate_memory_1174() -> memPtr
|
||||||
{
|
{
|
||||||
memPtr := mload(64)
|
memPtr := mload(64)
|
||||||
let newFreePtr := add(memPtr, 32)
|
let newFreePtr := add(memPtr, 32)
|
||||||
|
@ -252,18 +252,17 @@ object "C_15" {
|
|||||||
mstore(array, length)
|
mstore(array, length)
|
||||||
dst := add(array, 0x20)
|
dst := add(array, 0x20)
|
||||||
|
|
||||||
let src := offset
|
let srcEnd := add(offset, mul(length, 0x20))
|
||||||
if gt(add(src, mul(length, 0x20)), end) {
|
if gt(srcEnd, end) {
|
||||||
revert_error_81385d8c0b31fffe14be1da910c8bd3a80be4cfa248e04f42ec0faea3132a8ef()
|
revert_error_81385d8c0b31fffe14be1da910c8bd3a80be4cfa248e04f42ec0faea3132a8ef()
|
||||||
}
|
}
|
||||||
for { let i := 0 } lt(i, length) { i := add(i, 1) }
|
for { let src := offset } lt(src, srcEnd) { src := add(src, 0x20) }
|
||||||
{
|
{
|
||||||
|
|
||||||
let elementPos := src
|
let elementPos := src
|
||||||
|
|
||||||
mstore(dst, abi_decode_t_uint256(elementPos, end))
|
mstore(dst, abi_decode_t_uint256(elementPos, end))
|
||||||
dst := add(dst, 0x20)
|
dst := add(dst, 0x20)
|
||||||
src := add(src, 0x20)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,11 +281,11 @@ object "C_15" {
|
|||||||
mstore(array, length)
|
mstore(array, length)
|
||||||
dst := add(array, 0x20)
|
dst := add(array, 0x20)
|
||||||
|
|
||||||
let src := offset
|
let srcEnd := add(offset, mul(length, 0x20))
|
||||||
if gt(add(src, mul(length, 0x20)), end) {
|
if gt(srcEnd, end) {
|
||||||
revert_error_81385d8c0b31fffe14be1da910c8bd3a80be4cfa248e04f42ec0faea3132a8ef()
|
revert_error_81385d8c0b31fffe14be1da910c8bd3a80be4cfa248e04f42ec0faea3132a8ef()
|
||||||
}
|
}
|
||||||
for { let i := 0 } lt(i, length) { i := add(i, 1) }
|
for { let src := offset } lt(src, srcEnd) { src := add(src, 0x20) }
|
||||||
{
|
{
|
||||||
|
|
||||||
let innerOffset := calldataload(src)
|
let innerOffset := calldataload(src)
|
||||||
@ -295,7 +294,6 @@ object "C_15" {
|
|||||||
|
|
||||||
mstore(dst, abi_decode_t_array$_t_uint256_$dyn_memory_ptr(elementPos, end))
|
mstore(dst, abi_decode_t_array$_t_uint256_$dyn_memory_ptr(elementPos, end))
|
||||||
dst := add(dst, 0x20)
|
dst := add(dst, 0x20)
|
||||||
src := add(src, 0x20)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
{"contracts":{"a.sol":{"A":{"evm":{"bytecode":{"functionDebugData":{}},"deployedBytecode":{"functionDebugData":{"@f_19":{"entryPoint":96,"id":19,"parameterSlots":1,"returnSlots":1},"abi_decode_available_length_t_array$_t_uint256_$dyn_memory_ptr":{"entryPoint":439,"id":null,"parameterSlots":3,"returnSlots":1},"abi_decode_t_array$_t_uint256_$dyn_memory_ptr":{"entryPoint":551,"id":null,"parameterSlots":2,"returnSlots":1},"abi_decode_t_uint256":{"entryPoint":418,"id":null,"parameterSlots":2,"returnSlots":1},"abi_decode_tuple_t_array$_t_uint256_$dyn_memory_ptr":{"entryPoint":597,"id":null,"parameterSlots":2,"returnSlots":1},"abi_encode_t_uint256_to_t_uint256_fromStack":{"entryPoint":670,"id":null,"parameterSlots":2,"returnSlots":0},"abi_encode_tuple_t_uint256__to_t_uint256__fromStack_reversed":{"entryPoint":685,"id":null,"parameterSlots":2,"returnSlots":1},"allocate_memory":{"entryPoint":309,"id":null,"parameterSlots":1,"returnSlots":1},"allocate_unbounded":{"entryPoint":171,"id":null,"parameterSlots":0,"returnSlots":1},"array_allocation_size_t_array$_t_uint256_$dyn_memory_ptr":{"entryPoint":336,"id":null,"parameterSlots":1,"returnSlots":1},"checked_add_t_uint256":{"entryPoint":806,"id":null,"parameterSlots":2,"returnSlots":1},"cleanup_t_uint256":{"entryPoint":385,"id":null,"parameterSlots":1,"returnSlots":1},"finalize_allocation":{"entryPoint":260,"id":null,"parameterSlots":2,"returnSlots":0},"panic_error_0x11":{"entryPoint":759,"id":null,"parameterSlots":0,"returnSlots":0},"panic_error_0x32":{"entryPoint":712,"id":null,"parameterSlots":0,"returnSlots":0},"panic_error_0x41":{"entryPoint":213,"id":null,"parameterSlots":0,"returnSlots":0},"revert_error_1b9f4a0a5773e33b91aa01db23bf8c55fce1411167c872835e7fa00a4f17d46d":{"entryPoint":191,"id":null,"parameterSlots":0,"returnSlots":0},"revert_error_81385d8c0b31fffe14be1da910c8bd3a80be4cfa248e04f42ec0faea3132a8ef":{"entryPoint":380,"id":null,"parameterSlots":0,"returnSlots":0},"revert_error_c1322bf8034eace5e0b5c7295db60986aa89aae5e0ea0873e4689e076861a5db":{"entryPoint":186,"id":null,"parameterSlots":0,"returnSlots":0},"revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b":{"entryPoint":181,"id":null,"parameterSlots":0,"returnSlots":0},"round_up_to_mul_of_32":{"entryPoint":196,"id":null,"parameterSlots":1,"returnSlots":1},"validator_revert_t_uint256":{"entryPoint":395,"id":null,"parameterSlots":1,"returnSlots":0}}}}}}},"sources":{"a.sol":{"id":0}}}
|
{"contracts":{"a.sol":{"A":{"evm":{"bytecode":{"functionDebugData":{}},"deployedBytecode":{"functionDebugData":{"@f_19":{"entryPoint":96,"id":19,"parameterSlots":1,"returnSlots":1},"abi_decode_available_length_t_array$_t_uint256_$dyn_memory_ptr":{"entryPoint":439,"id":null,"parameterSlots":3,"returnSlots":1},"abi_decode_t_array$_t_uint256_$dyn_memory_ptr":{"entryPoint":544,"id":null,"parameterSlots":2,"returnSlots":1},"abi_decode_t_uint256":{"entryPoint":418,"id":null,"parameterSlots":2,"returnSlots":1},"abi_decode_tuple_t_array$_t_uint256_$dyn_memory_ptr":{"entryPoint":590,"id":null,"parameterSlots":2,"returnSlots":1},"abi_encode_t_uint256_to_t_uint256_fromStack":{"entryPoint":663,"id":null,"parameterSlots":2,"returnSlots":0},"abi_encode_tuple_t_uint256__to_t_uint256__fromStack_reversed":{"entryPoint":678,"id":null,"parameterSlots":2,"returnSlots":1},"allocate_memory":{"entryPoint":309,"id":null,"parameterSlots":1,"returnSlots":1},"allocate_unbounded":{"entryPoint":171,"id":null,"parameterSlots":0,"returnSlots":1},"array_allocation_size_t_array$_t_uint256_$dyn_memory_ptr":{"entryPoint":336,"id":null,"parameterSlots":1,"returnSlots":1},"checked_add_t_uint256":{"entryPoint":799,"id":null,"parameterSlots":2,"returnSlots":1},"cleanup_t_uint256":{"entryPoint":385,"id":null,"parameterSlots":1,"returnSlots":1},"finalize_allocation":{"entryPoint":260,"id":null,"parameterSlots":2,"returnSlots":0},"panic_error_0x11":{"entryPoint":752,"id":null,"parameterSlots":0,"returnSlots":0},"panic_error_0x32":{"entryPoint":705,"id":null,"parameterSlots":0,"returnSlots":0},"panic_error_0x41":{"entryPoint":213,"id":null,"parameterSlots":0,"returnSlots":0},"revert_error_1b9f4a0a5773e33b91aa01db23bf8c55fce1411167c872835e7fa00a4f17d46d":{"entryPoint":191,"id":null,"parameterSlots":0,"returnSlots":0},"revert_error_81385d8c0b31fffe14be1da910c8bd3a80be4cfa248e04f42ec0faea3132a8ef":{"entryPoint":380,"id":null,"parameterSlots":0,"returnSlots":0},"revert_error_c1322bf8034eace5e0b5c7295db60986aa89aae5e0ea0873e4689e076861a5db":{"entryPoint":186,"id":null,"parameterSlots":0,"returnSlots":0},"revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b":{"entryPoint":181,"id":null,"parameterSlots":0,"returnSlots":0},"round_up_to_mul_of_32":{"entryPoint":196,"id":null,"parameterSlots":1,"returnSlots":1},"validator_revert_t_uint256":{"entryPoint":395,"id":null,"parameterSlots":1,"returnSlots":0}}}}}}},"sources":{"a.sol":{"id":0}}}
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -14,9 +14,9 @@ contract C {
|
|||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// creation:
|
// creation:
|
||||||
// codeDepositCost: 1259800
|
// codeDepositCost: 1243000
|
||||||
// executionCost: 1308
|
// executionCost: 1295
|
||||||
// totalCost: 1261108
|
// totalCost: 1244295
|
||||||
// external:
|
// external:
|
||||||
// a(): 2430
|
// a(): 2430
|
||||||
// b(uint256): infinite
|
// b(uint256): infinite
|
||||||
|
@ -17,9 +17,9 @@ contract C {
|
|||||||
// optimize-yul: true
|
// optimize-yul: true
|
||||||
// ----
|
// ----
|
||||||
// creation:
|
// creation:
|
||||||
// codeDepositCost: 680600
|
// codeDepositCost: 660800
|
||||||
// executionCost: 715
|
// executionCost: 696
|
||||||
// totalCost: 681315
|
// totalCost: 661496
|
||||||
// external:
|
// external:
|
||||||
// a(): 2285
|
// a(): 2285
|
||||||
// b(uint256): 4652
|
// b(uint256): 4652
|
||||||
|
@ -24,6 +24,6 @@ contract C {
|
|||||||
// compileViaYul: also
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// f() -> 0x20, 0x8, 0x40, 0x3, 0x9, 0xa, 0xb
|
// f() -> 0x20, 0x8, 0x40, 0x3, 0x9, 0xa, 0xb
|
||||||
// gas irOptimized: 203556
|
// gas irOptimized: 203522
|
||||||
// gas legacy: 206126
|
// gas legacy: 206084
|
||||||
// gas legacyOptimized: 203105
|
// gas legacyOptimized: 203068
|
||||||
|
@ -32,6 +32,6 @@ contract C is B {
|
|||||||
// compileViaYul: also
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// test() -> 77
|
// test() -> 77
|
||||||
// gas irOptimized: 121752
|
// gas irOptimized: 121699
|
||||||
// gas legacy: 155249
|
// gas legacy: 155221
|
||||||
// gas legacyOptimized: 111743
|
// gas legacyOptimized: 111678
|
||||||
|
@ -21,6 +21,6 @@ contract C {
|
|||||||
// f(uint256[][1]): 32, 32, 0 -> true
|
// f(uint256[][1]): 32, 32, 0 -> true
|
||||||
// f(uint256[][1]): 32, 32, 1, 42 -> true
|
// f(uint256[][1]): 32, 32, 1, 42 -> true
|
||||||
// f(uint256[][1]): 32, 32, 8, 421, 422, 423, 424, 425, 426, 427, 428 -> true
|
// f(uint256[][1]): 32, 32, 8, 421, 422, 423, 424, 425, 426, 427, 428 -> true
|
||||||
// gas irOptimized: 177719
|
// gas irOptimized: 177581
|
||||||
// gas legacy: 141900
|
// gas legacy: 141900
|
||||||
// gas legacyOptimized: 121788
|
// gas legacyOptimized: 121788
|
||||||
|
@ -14,9 +14,9 @@ contract Test {
|
|||||||
// compileViaYul: also
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// set(uint24[3][]): 0x20, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12 -> 0x06
|
// set(uint24[3][]): 0x20, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12 -> 0x06
|
||||||
// gas irOptimized: 189567
|
// gas irOptimized: 189239
|
||||||
// gas legacy: 211485
|
// gas legacy: 211149
|
||||||
// gas legacyOptimized: 206394
|
// gas legacyOptimized: 206054
|
||||||
// data(uint256,uint256): 0x02, 0x02 -> 0x09
|
// data(uint256,uint256): 0x02, 0x02 -> 0x09
|
||||||
// data(uint256,uint256): 0x05, 0x01 -> 0x11
|
// data(uint256,uint256): 0x05, 0x01 -> 0x11
|
||||||
// data(uint256,uint256): 0x06, 0x00 -> FAILURE
|
// data(uint256,uint256): 0x06, 0x00 -> FAILURE
|
||||||
|
@ -12,9 +12,9 @@ contract Test {
|
|||||||
// compileViaYul: also
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// set(uint24[]): 0x20, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 -> 18
|
// set(uint24[]): 0x20, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 -> 18
|
||||||
// gas irOptimized: 100066
|
// gas irOptimized: 99873
|
||||||
// gas legacy: 103815
|
// gas legacy: 103563
|
||||||
// gas legacyOptimized: 101614
|
// gas legacyOptimized: 101397
|
||||||
// data(uint256): 7 -> 8
|
// data(uint256): 7 -> 8
|
||||||
// data(uint256): 15 -> 16
|
// data(uint256): 15 -> 16
|
||||||
// data(uint256): 18 -> FAILURE
|
// data(uint256): 18 -> FAILURE
|
||||||
|
@ -21,6 +21,6 @@ contract B {
|
|||||||
// compileViaYul: also
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// f() -> 2, 3, 4, 5, 6, 1000, 1001, 1002, 1003, 1004
|
// f() -> 2, 3, 4, 5, 6, 1000, 1001, 1002, 1003, 1004
|
||||||
// gas irOptimized: 121038
|
// gas irOptimized: 120848
|
||||||
// gas legacy: 235339
|
// gas legacy: 235199
|
||||||
// gas legacyOptimized: 133299
|
// gas legacyOptimized: 133119
|
||||||
|
@ -45,6 +45,6 @@ contract C {
|
|||||||
// compileViaYul: also
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// test() -> 5, 6, 7
|
// test() -> 5, 6, 7
|
||||||
// gas irOptimized: 299965
|
// gas irOptimized: 297690
|
||||||
// gas legacy: 463662
|
// gas legacy: 462080
|
||||||
// gas legacyOptimized: 296513
|
// gas legacyOptimized: 294938
|
||||||
|
@ -26,6 +26,6 @@ contract Creator {
|
|||||||
// compileViaYul: also
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// f(uint256,address[]): 7, 0x40, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 -> 7, 8
|
// f(uint256,address[]): 7, 0x40, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 -> 7, 8
|
||||||
// gas irOptimized: 459815
|
// gas irOptimized: 458295
|
||||||
// gas legacy: 592626
|
// gas legacy: 590939
|
||||||
// gas legacyOptimized: 450224
|
// gas legacyOptimized: 448582
|
||||||
|
@ -25,6 +25,6 @@ contract B {
|
|||||||
// compileViaYul: also
|
// compileViaYul: also
|
||||||
// ----
|
// ----
|
||||||
// g() -> 42
|
// g() -> 42
|
||||||
// gas irOptimized: 110833
|
// gas irOptimized: 105784
|
||||||
// gas legacy: 186609
|
// gas legacy: 185181
|
||||||
// gas legacyOptimized: 116151
|
// gas legacyOptimized: 114726
|
||||||
|
@ -55,9 +55,9 @@ contract C {
|
|||||||
// gas legacy: 125037
|
// gas legacy: 125037
|
||||||
// gas legacyOptimized: 122605
|
// gas legacyOptimized: 122605
|
||||||
// test_g() -> true
|
// test_g() -> true
|
||||||
// gas irOptimized: 95969
|
// gas irOptimized: 95908
|
||||||
// gas legacy: 100656
|
// gas legacy: 100586
|
||||||
// gas legacyOptimized: 96057
|
// gas legacyOptimized: 95996
|
||||||
// addresses(uint256): 0 -> 0x18
|
// addresses(uint256): 0 -> 0x18
|
||||||
// addresses(uint256): 1 -> 0x19
|
// addresses(uint256): 1 -> 0x19
|
||||||
// addresses(uint256): 3 -> 0x1b
|
// addresses(uint256): 3 -> 0x1b
|
||||||
|
Loading…
Reference in New Issue
Block a user