Skip to content

Commit

Permalink
Fix (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare authored Sep 26, 2024
1 parent 24bcba9 commit c9caaa1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
11 changes: 5 additions & 6 deletions evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,16 @@ 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
// Checks that the addition of the two top elements of the stack does not overflow modulo 2^32.
%macro check_u32_add
// stack: x, y
%add_or_fault
DUP1
// stack: sum, sum
// stack: sum
PUSH 0xffffffff // 2^32 - 1
LT
// stack: is_overflow, sum
// stack: is_overflow
%jumpi(fault_exception)
// stack: sum
// stack: (empty)
%endmacro

%macro call_depth
Expand Down
15 changes: 8 additions & 7 deletions evm_arithmetization/src/cpu/kernel/asm/memory/syscalls.asm
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,7 @@ calldataload_large_offset:
// stack: kexit_info, dest_offset, offset, size
%wcopy_charge_gas

// 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) ->
%stack (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
Expand All @@ -98,6 +92,13 @@ calldataload_large_offset:
// stack: offset, total_size, kexit_info, dest_offset, offset, size
GT %jumpi(wcopy_large_offset)

// stack: 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
%check_u32_add

// stack: kexit_info, dest_offset, offset, size
GET_CONTEXT
PUSH $segment
Expand Down

0 comments on commit c9caaa1

Please sign in to comment.