mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 16:23:12 +00:00
Merge pull request #1013 from topos-network/overflow-check
Address overflow-related TODOs in ASM code.
This commit is contained in:
commit
b159c9e791
@ -106,7 +106,7 @@ global sys_extcodecopy:
|
|||||||
%charge_gas
|
%charge_gas
|
||||||
|
|
||||||
%stack (kexit_info, address, dest_offset, offset, size) -> (dest_offset, size, kexit_info, address, dest_offset, offset, size)
|
%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
|
// stack: expanded_num_bytes, kexit_info, address, dest_offset, offset, size
|
||||||
DUP1 %ensure_reasonable_offset
|
DUP1 %ensure_reasonable_offset
|
||||||
%update_mem_bytes
|
%update_mem_bytes
|
||||||
|
|||||||
@ -401,7 +401,7 @@ global after_call_instruction:
|
|||||||
%macro checked_mem_expansion
|
%macro checked_mem_expansion
|
||||||
// stack: size, offset, kexit_info
|
// stack: size, offset, kexit_info
|
||||||
DUP1 ISZERO %jumpi(%%zero)
|
DUP1 ISZERO %jumpi(%%zero)
|
||||||
ADD // TODO: check for overflow
|
%add_or_fault
|
||||||
// stack: expanded_num_bytes, kexit_info
|
// stack: expanded_num_bytes, kexit_info
|
||||||
DUP1 %ensure_reasonable_offset
|
DUP1 %ensure_reasonable_offset
|
||||||
%update_mem_bytes
|
%update_mem_bytes
|
||||||
|
|||||||
@ -14,7 +14,7 @@ global sys_stop:
|
|||||||
global sys_return:
|
global sys_return:
|
||||||
// stack: kexit_info, offset, size
|
// stack: kexit_info, offset, size
|
||||||
%stack (kexit_info, offset, size) -> (offset, size, 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
|
DUP1 %ensure_reasonable_offset
|
||||||
%update_mem_bytes
|
%update_mem_bytes
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ sys_selfdestruct_same_addr:
|
|||||||
global sys_revert:
|
global sys_revert:
|
||||||
// stack: kexit_info, offset, size
|
// stack: kexit_info, offset, size
|
||||||
%stack (kexit_info, offset, size) -> (offset, size, 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
|
DUP1 %ensure_reasonable_offset
|
||||||
%update_mem_bytes
|
%update_mem_bytes
|
||||||
|
|
||||||
|
|||||||
@ -312,3 +312,16 @@ global sys_basefee:
|
|||||||
%mload_context_metadata(@CTX_METADATA_STATIC)
|
%mload_context_metadata(@CTX_METADATA_STATIC)
|
||||||
%jumpi(fault_exception)
|
%jumpi(fault_exception)
|
||||||
%endmacro
|
%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
|
||||||
|
|||||||
@ -131,7 +131,7 @@ sys_calldataload_after_mload_packing:
|
|||||||
DUP5 %num_bytes_to_num_words %mul_const(@GAS_COPY) ADD %charge_gas
|
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)
|
%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
|
// stack: expanded_num_bytes, kexit_info, dest_offset, offset, size, kexit_info
|
||||||
DUP1 %ensure_reasonable_offset
|
DUP1 %ensure_reasonable_offset
|
||||||
%update_mem_bytes
|
%update_mem_bytes
|
||||||
|
|||||||
@ -11,7 +11,7 @@ global sys_keccak256:
|
|||||||
// stack: kexit_info, offset, len
|
// stack: kexit_info, offset, len
|
||||||
|
|
||||||
%stack (kexit_info, offset, len) -> (offset, len, 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
|
DUP1 %ensure_reasonable_offset
|
||||||
%update_mem_bytes
|
%update_mem_bytes
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user