From ed6a657ee188e30dceb1da16960ce2ebd92bf6e8 Mon Sep 17 00:00:00 2001 From: Robin Salen <30937548+Nashtare@users.noreply.github.com> Date: Thu, 25 Jul 2024 08:55:48 -0400 Subject: [PATCH] Add overflow check in codecopy (#444) --- evm_arithmetization/src/cpu/kernel/asm/memory/syscalls.asm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/evm_arithmetization/src/cpu/kernel/asm/memory/syscalls.asm b/evm_arithmetization/src/cpu/kernel/asm/memory/syscalls.asm index de04c111e..e3f43a9e1 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/memory/syscalls.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/memory/syscalls.asm @@ -316,12 +316,12 @@ mcopy_empty: PUSH $segment SWAP1 // stack: total_size, segment, src_ctx, kexit_info, dest_offset, offset, size - DUP1 DUP8 DUP8 ADD + DUP1 DUP8 DUP8 %add_or_fault // stack: offset + size, total_size, total_size, segment, src_ctx, kexit_info, dest_offset, offset, size LT %jumpi(codecopy_within_bounds) // stack: total_size, segment, src_ctx, kexit_info, dest_offset, offset, size - DUP7 DUP7 ADD + DUP7 DUP7 ADD // We already checked for overflow. // stack: offset + size, total_size, segment, src_ctx, kexit_info, dest_offset, offset, size SUB // extra_size = offset + size - total_size // stack: extra_size, segment, src_ctx, kexit_info, dest_offset, offset, size @@ -329,7 +329,7 @@ mcopy_empty: // stack: copy_size = size - extra_size, extra_size, segment, src_ctx, kexit_info, dest_offset, offset, size // Compute the new dest_offset after actual copies, at which we will start padding with zeroes. - DUP1 DUP7 ADD + DUP1 DUP7 ADD // We already checked for overflow. // stack: new_dest_offset, copy_size, extra_size, segment, src_ctx, kexit_info, dest_offset, offset, size GET_CONTEXT