mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-06 07:43:10 +00:00
Implement various syscalls (#930)
* Bunch of syscalls * Minor * Minor * Minor * Add todo for overflow
This commit is contained in:
parent
2df1439d35
commit
06936c7649
@ -55,12 +55,6 @@ global extcodesize:
|
|||||||
// stack: extcodesize(address), retdest
|
// stack: extcodesize(address), retdest
|
||||||
SWAP1 JUMP
|
SWAP1 JUMP
|
||||||
|
|
||||||
%macro codecopy
|
|
||||||
// stack: dest_offset, offset, size
|
|
||||||
%address
|
|
||||||
%extcodecopy
|
|
||||||
%endmacro
|
|
||||||
|
|
||||||
%macro extcodecopy
|
%macro extcodecopy
|
||||||
// stack: address, dest_offset, offset, size
|
// stack: address, dest_offset, offset, size
|
||||||
%stack (address, dest_offset, offset, size) -> (address, dest_offset, offset, size, %%after)
|
%stack (address, dest_offset, offset, size) -> (address, dest_offset, offset, size, %%after)
|
||||||
|
|||||||
@ -13,32 +13,11 @@ global sys_sgt:
|
|||||||
PANIC
|
PANIC
|
||||||
global sys_sar:
|
global sys_sar:
|
||||||
PANIC
|
PANIC
|
||||||
global sys_origin:
|
|
||||||
PANIC
|
|
||||||
global sys_calldatasize:
|
|
||||||
PANIC
|
|
||||||
global sys_calldatacopy:
|
|
||||||
PANIC
|
|
||||||
global sys_codecopy:
|
|
||||||
PANIC
|
|
||||||
global sys_returndatasize:
|
|
||||||
PANIC
|
|
||||||
global sys_returndatacopy:
|
|
||||||
PANIC
|
|
||||||
global sys_blockhash:
|
global sys_blockhash:
|
||||||
PANIC
|
PANIC
|
||||||
global sys_coinbase:
|
|
||||||
PANIC
|
|
||||||
global sys_timestamp:
|
|
||||||
PANIC
|
|
||||||
global sys_number:
|
|
||||||
PANIC
|
|
||||||
global sys_prevrandao:
|
global sys_prevrandao:
|
||||||
// TODO: What semantics will this have for Edge?
|
// TODO: What semantics will this have for Edge?
|
||||||
PANIC
|
PANIC
|
||||||
global sys_gaslimit:
|
|
||||||
// TODO: Return the block's gas limit.
|
|
||||||
PANIC
|
|
||||||
global sys_chainid:
|
global sys_chainid:
|
||||||
// TODO: Return the block's chain ID instead of the txn's, even though they should match.
|
// TODO: Return the block's chain ID instead of the txn's, even though they should match.
|
||||||
// stack: kexit_info
|
// stack: kexit_info
|
||||||
@ -48,8 +27,6 @@ global sys_chainid:
|
|||||||
// stack: chain_id, kexit_info
|
// stack: chain_id, kexit_info
|
||||||
SWAP1
|
SWAP1
|
||||||
EXIT_KERNEL
|
EXIT_KERNEL
|
||||||
global sys_basefee:
|
|
||||||
PANIC
|
|
||||||
global sys_log0:
|
global sys_log0:
|
||||||
PANIC
|
PANIC
|
||||||
global sys_log1:
|
global sys_log1:
|
||||||
|
|||||||
@ -104,6 +104,97 @@ global sys_msize:
|
|||||||
SWAP1
|
SWAP1
|
||||||
EXIT_KERNEL
|
EXIT_KERNEL
|
||||||
|
|
||||||
|
%macro calldatasize
|
||||||
|
%mload_context_metadata(@CTX_METADATA_CALLDATA_SIZE)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_calldatasize:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%calldatasize
|
||||||
|
// stack: calldatasize, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|
||||||
|
%macro returndatasize
|
||||||
|
%mload_context_metadata(@CTX_METADATA_RETURNDATA_SIZE)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_returndatasize:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%returndatasize
|
||||||
|
// stack: returndatasize, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|
||||||
|
%macro coinbase
|
||||||
|
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_BENEFICIARY)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_coinbase:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%coinbase
|
||||||
|
// stack: coinbase, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|
||||||
|
%macro timestamp
|
||||||
|
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_TIMESTAMP)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_timestamp:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%timestamp
|
||||||
|
// stack: timestamp, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|
||||||
|
%macro blocknumber
|
||||||
|
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_NUMBER)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_number:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%blocknumber
|
||||||
|
// stack: blocknumber, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|
||||||
|
%macro blockgaslimit
|
||||||
|
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_GAS_LIMIT)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_gaslimit:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%blockgaslimit
|
||||||
|
// stack: blockgaslimit, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|
||||||
|
%macro basefee
|
||||||
|
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_BASE_FEE)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_basefee:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%basefee
|
||||||
|
// stack: basefee, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|
||||||
%macro update_mem_words
|
%macro update_mem_words
|
||||||
// stack: num_words, kexit_info
|
// stack: num_words, kexit_info
|
||||||
%mem_words
|
%mem_words
|
||||||
|
|||||||
@ -118,3 +118,32 @@ sys_calldataload_after_mload_packing:
|
|||||||
SWAP1
|
SWAP1
|
||||||
EXIT_KERNEL
|
EXIT_KERNEL
|
||||||
PANIC
|
PANIC
|
||||||
|
|
||||||
|
// Macro for {CALLDATA,CODE,RETURNDATA}COPY (W_copy in Yellow Paper).
|
||||||
|
%macro wcopy(segment)
|
||||||
|
// stack: kexit_info, dest_offset, offset, size
|
||||||
|
DUP4 %num_bytes_to_num_words %mul_const(@GAS_COPY) %add_const(@GAS_VERYLOW) %charge_gas
|
||||||
|
|
||||||
|
%stack (kexit_info, dest_offset, offset, size) -> (dest_offset, size, dest_offset, offset, size, kexit_info)
|
||||||
|
ADD // TODO: check for overflow, see discussion here https://github.com/mir-protocol/plonky2/pull/930/files/a4ea0965d79561c345e2f77836c07949c7e0bc69#r1143630253
|
||||||
|
// stack: expanded_num_bytes, dest_offset, offset, size, kexit_info
|
||||||
|
DUP1 %ensure_reasonable_offset
|
||||||
|
%update_mem_bytes
|
||||||
|
|
||||||
|
GET_CONTEXT
|
||||||
|
%stack (context, dest_offset, offset, size, kexit_info) ->
|
||||||
|
(context, @SEGMENT_MAIN_MEMORY, dest_offset, context, $segment, offset, size, %%after, kexit_info)
|
||||||
|
%jump(memcpy)
|
||||||
|
%%after:
|
||||||
|
// stack: kexit_info
|
||||||
|
EXIT_KERNEL
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_calldatacopy:
|
||||||
|
%wcopy(@SEGMENT_CALLDATA)
|
||||||
|
|
||||||
|
global sys_codecopy:
|
||||||
|
%wcopy(@SEGMENT_CODE)
|
||||||
|
|
||||||
|
global sys_returndatacopy:
|
||||||
|
%wcopy(@SEGMENT_RETURNDATA)
|
||||||
|
|||||||
@ -15,3 +15,16 @@
|
|||||||
%mstore_kernel(@SEGMENT_NORMALIZED_TXN)
|
%mstore_kernel(@SEGMENT_NORMALIZED_TXN)
|
||||||
// stack: (empty)
|
// stack: (empty)
|
||||||
%endmacro
|
%endmacro
|
||||||
|
|
||||||
|
%macro origin
|
||||||
|
%mload_txn_field(@TXN_FIELD_ORIGIN)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
global sys_origin:
|
||||||
|
// stack: kexit_info
|
||||||
|
%charge_gas_const(@GAS_BASE)
|
||||||
|
// stack: kexit_info
|
||||||
|
%origin
|
||||||
|
// stack: origin, kexit_info
|
||||||
|
SWAP1
|
||||||
|
EXIT_KERNEL
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user