mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix wrong cleanup when copying from calldata to memory
Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
This commit is contained in:
committed by
Daniel Kirchner
co-authored by
Kamil Śliwak
parent
5b0f4a724a
commit
22c7cd22b9
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user