Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure proper offset + size bounds in wcopy #445

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,19 @@ zero_hash:
// stack: sum
%endmacro

// Adds the two top elements of the stack, and faults in case of overflow modulo 2^32.
%macro add_u32_or_fault
// stack: x, y
%add_or_fault
DUP1
// stack: sum, sum
PUSH 0xffffffff // 2^32 - 1
LT
// stack: is_overflow, sum
%jumpi(fault_exception)
// stack: sum
%endmacro

%macro call_depth
%mload_global_metadata(@GLOBAL_METADATA_CALL_STACK_DEPTH)
%endmacro
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@ calldataload_large_offset:
// stack: kexit_info, dest_offset, offset, size
%wcopy_charge_gas

%stack (kexit_info, dest_offset, offset, size) -> (dest_offset, size, kexit_info, dest_offset, offset, size)
// Ensure that `offset + size` won't overflow the reserved 32-bit limb
// of the `virtual` component of the source memory address.
DUP4 DUP4
// stack: offset, size, kexit_info, dest_offset, offset, size
%add_u32_or_fault

%stack (offset_plus_size, kexit_info, dest_offset, offset, size) ->
(dest_offset, size, kexit_info, dest_offset, offset, size)
%add_or_fault
// stack: expanded_num_bytes, kexit_info, dest_offset, offset, size, kexit_info
DUP1 %ensure_reasonable_offset
Expand Down
Loading