Merge pull request #1013 from topos-network/overflow-check

Address overflow-related TODOs in ASM code.
This commit is contained in:
Daniel Lubarov 2023-05-02 10:22:53 -07:00 committed by GitHub
commit b159c9e791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 6 deletions

View File

@ -106,7 +106,7 @@ global sys_extcodecopy:
%charge_gas
%stack (kexit_info, address, dest_offset, offset, size) -> (dest_offset, size, kexit_info, address, dest_offset, offset, size)
ADD // TODO: check for overflow, see discussion here https://github.com/mir-protocol/plonky2/pull/930/files/a4ea0965d79561c345e2f77836c07949c7e0bc69#r1143630253
%add_or_fault
// stack: expanded_num_bytes, kexit_info, address, dest_offset, offset, size
DUP1 %ensure_reasonable_offset
%update_mem_bytes

View File

@ -401,7 +401,7 @@ global after_call_instruction:
%macro checked_mem_expansion
// stack: size, offset, kexit_info
DUP1 ISZERO %jumpi(%%zero)
ADD // TODO: check for overflow
%add_or_fault
// stack: expanded_num_bytes, kexit_info
DUP1 %ensure_reasonable_offset
%update_mem_bytes

View File

@ -14,7 +14,7 @@ global sys_stop:
global sys_return:
// stack: kexit_info, offset, size
%stack (kexit_info, offset, size) -> (offset, size, kexit_info, offset, size)
ADD // TODO: Check for overflow?
%add_or_fault
DUP1 %ensure_reasonable_offset
%update_mem_bytes
@ -109,7 +109,7 @@ sys_selfdestruct_same_addr:
global sys_revert:
// stack: kexit_info, offset, size
%stack (kexit_info, offset, size) -> (offset, size, kexit_info, offset, size)
ADD // TODO: Check for overflow?
%add_or_fault
DUP1 %ensure_reasonable_offset
%update_mem_bytes

View File

@ -312,3 +312,16 @@ global sys_basefee:
%mload_context_metadata(@CTX_METADATA_STATIC)
%jumpi(fault_exception)
%endmacro
// Adds the two top elements of the stack, and faults in case of overflow.
%macro add_or_fault
// stack: x, y
DUP2 ADD
// stack: sum, y
DUP1 SWAP2
// stack: y, sum, sum
GT
// stack: is_overflow, sum
%jumpi(fault_exception)
// stack: sum
%endmacro

View File

@ -131,7 +131,7 @@ sys_calldataload_after_mload_packing:
DUP5 %num_bytes_to_num_words %mul_const(@GAS_COPY) ADD %charge_gas
%stack (kexit_info, dest_offset, offset, size) -> (dest_offset, size, kexit_info, dest_offset, offset, size)
ADD // TODO: check for overflow, see discussion here https://github.com/mir-protocol/plonky2/pull/930/files/a4ea0965d79561c345e2f77836c07949c7e0bc69#r1143630253
%add_or_fault
// stack: expanded_num_bytes, kexit_info, dest_offset, offset, size, kexit_info
DUP1 %ensure_reasonable_offset
%update_mem_bytes

View File

@ -11,7 +11,7 @@ global sys_keccak256:
// stack: kexit_info, offset, len
%stack (kexit_info, offset, len) -> (offset, len, kexit_info, offset, len)
ADD // TODO: need to check for overflow?
%add_or_fault
DUP1 %ensure_reasonable_offset
%update_mem_bytes