Fix wrong cleanup when copying from calldata to memory

Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
This commit is contained in:
Marenz
2022-08-08 13:07:16 +02:00
committed by Daniel Kirchner
co-authored by Kamil Śliwak
parent 5b0f4a724a
commit 22c7cd22b9
48 changed files with 396 additions and 211 deletions
@@ -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))
}