Address overflow-related TODOs in ASM code, using a macro add_or_fault. This is related to a4ea0965d7

This commit is contained in:
Linda Guiga 2023-04-13 18:49:18 +08:00 committed by Robin Salen
parent 40515dc66a
commit 1f39c555a9
No known key found for this signature in database
GPG Key ID: F98FD38F65687358
6 changed files with 18 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,15 @@ global sys_basefee:
%mload_context_metadata(@CTX_METADATA_STATIC)
%jumpi(fault_exception)
%endmacro
%macro add_or_fault
// stack: offset, size, kexit_info, offset, size
DUP1
%ensure_reasonable_offset
// stack: offset, size, kexit_info, offset, size
DUP2
// stack: size, offset, size, kexit_info, offset, size
%ensure_reasonable_offset
// stack: offset, size, kexit_info, offset, size
ADD
%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