diff --git a/src/beacon_root/main.eas b/src/beacon_root/main.eas index 32063e6..74d5886 100644 --- a/src/beacon_root/main.eas +++ b/src/beacon_root/main.eas @@ -35,9 +35,9 @@ ;; do_revert sets up and then executes a revert(0,0) operation. #define %do_revert() { - push0 ;; [0] - push0 ;; [0, 0] - revert ;; [] + push 0 ;; [0] + push 0 ;; [0, 0] + revert ;; [] } ;; ---------------------------------------------------------------------------- @@ -45,94 +45,94 @@ ;; ---------------------------------------------------------------------------- .start: - ;; Protect the submit routine by verifying the caller is equal to - ;; sysaddr(). - caller ;; [caller] - push20 SYSADDR ;; [sysaddr, caller] - eq ;; [sysaddr == caller] - push1 @submit ;; [submit_lbl, sysaddr == caller] - jumpi ;; [] - - ;; Fallthrough if addresses don't match -- this means the caller intends - ;; to read a root. - - ;; Check if calldata is equal to 32 bytes. - push1 32 ;; [32] - calldatasize ;; [calldatasize, 32] - eq ;; [calldatasize == 32] - - ;; Jump to continue if length-check passed, otherwise revert. - push1 @loadtime ;; [loadtime_lbl, calldatasize == 32] - jumpi ;; [] - %do_revert() ;; [] + ;; Protect the submit routine by verifying the caller is equal to + ;; sysaddr(). + caller ;; [caller] + push SYSADDR ;; [sysaddr, caller] + eq ;; [sysaddr == caller] + push @submit ;; [submit_lbl, sysaddr == caller] + jumpi ;; [] + + ;; Fallthrough if addresses don't match -- this means the caller intends + ;; to read a root. + + ;; Check if calldata is equal to 32 bytes. + push 32 ;; [32] + calldatasize ;; [calldatasize, 32] + eq ;; [calldatasize == 32] + + ;; Jump to continue if length-check passed, otherwise revert. + push @loadtime ;; [loadtime_lbl, calldatasize == 32] + jumpi ;; [] + %do_revert() ;; [] loadtime: - ;; Load input timestamp. - push0 ;; [0] - calldataload ;; [input_timestamp] - dup1 ;; [input_timestamp, input_timestamp] - - ;; Verify input timestamp is non-zero. - iszero ;; [input_timestamp == 0, input_timestamp] - push1 @throw ;; [throw_lbl, input_timestamp == 0, input_timestamp] - jumpi ;; [input_timestamp] - - ;; Compute the timestamp index and load from storage. - push3 BUFLEN ;; [buflen, input_timestamp] - dup2 ;; [input_timestamp, buflen, input_timestamp] - mod ;; [time_index, input_timestamp] - swap1 ;; [input_timestamp, time_index] - dup2 ;; [time_index, input_timestamp, time_index] - sload ;; [stored_timestamp, input_timestamp, time_index] - - ;; Verify stored timestamp matches input timestamp. It's possible these - ;; don't match if the slot has been overwritten by the ring buffer or if - ;; the timestamp input wasn't a valid previous timestamp. - eq ;; [stored_timestamp == input_timestamp, time_index] - push1 @loadroot ;; [loadroot_lbl, input == timestamp, time_index] - jumpi ;; [time_index] - %do_revert() ;; [] + ;; Load input timestamp. + push 0 ;; [0] + calldataload ;; [input_timestamp] + dup1 ;; [input_timestamp, input_timestamp] + + ;; Verify input timestamp is non-zero. + iszero ;; [input_timestamp == 0, input_timestamp] + push @throw ;; [throw_lbl, input_timestamp == 0, input_timestamp] + jumpi ;; [input_timestamp] + + ;; Compute the timestamp index and load from storage. + push BUFLEN ;; [buflen, input_timestamp] + dup2 ;; [input_timestamp, buflen, input_timestamp] + mod ;; [time_index, input_timestamp] + swap1 ;; [input_timestamp, time_index] + dup2 ;; [time_index, input_timestamp, time_index] + sload ;; [stored_timestamp, input_timestamp, time_index] + + ;; Verify stored timestamp matches input timestamp. It's possible these + ;; don't match if the slot has been overwritten by the ring buffer or if + ;; the timestamp input wasn't a valid previous timestamp. + eq ;; [stored_timestamp == input_timestamp, time_index] + push @loadroot ;; [loadroot_lbl, input == timestamp, time_index] + jumpi ;; [time_index] + %do_revert() ;; [] loadroot: - ;; Extend index to get root index. - push3 BUFLEN ;; [buflen, time_index] - add ;; [root_index] - sload ;; [root] + ;; Extend index to get root index. + push BUFLEN ;; [buflen, time_index] + add ;; [root_index] + sload ;; [root] - ;; Write the retrieved root to memory so it can be returned. - push0 ;; [0, root] - mstore ;; [] + ;; Write the retrieved root to memory so it can be returned. + push 0 ;; [0, root] + mstore ;; [] - ;; Return the root. - push1 32 ;; [size] - push0 ;; [offset, size] - return ;; [] + ;; Return the root. + push 32 ;; [size] + push 0 ;; [offset, size] + return ;; [] throw: - ;; Reverts current execution with no return data. - %do_revert() + ;; Reverts current execution with no return data. + %do_revert() submit: - ;; Calculate the index the timestamp should be stored at, e.g. - ;; time_index = (time % buflen). - push3 BUFLEN ;; [buflen] - timestamp ;; [time, buflen] - mod ;; [time % buflen] - - ;; Write timestamp into storage slot at time_index. - timestamp ;; [time, time_index] - dup2 ;; [time_index, time, time_index] - sstore ;; [time_index] - - ;; Get root from calldata and write into root_index. No validation is - ;; done on the input root. Becuase the routine is protected by a caller - ;; check against sysaddr(), it's okay to assume the value is correctly - ;; given. - push0 ;; [0, time_index] - calldataload ;; [root, time_index] - swap1 ;; [time_index, root] - push3 BUFLEN ;; [buflen, time_index, root] - add ;; [root_index, root] - sstore ;; [] - - stop ;; [] + ;; Calculate the index the timestamp should be stored at, e.g. + ;; time_index = (time % buflen). + push BUFLEN ;; [buflen] + timestamp ;; [time, buflen] + mod ;; [time % buflen] + + ;; Write timestamp into storage slot at time_index. + timestamp ;; [time, time_index] + dup2 ;; [time_index, time, time_index] + sstore ;; [time_index] + + ;; Get root from calldata and write into root_index. No validation is + ;; done on the input root. Becuase the routine is protected by a caller + ;; check against sysaddr(), it's okay to assume the value is correctly + ;; given. + push 0 ;; [0, time_index] + calldataload ;; [root, time_index] + swap1 ;; [time_index, root] + push BUFLEN ;; [buflen, time_index, root] + add ;; [root_index, root] + sstore ;; [] + + stop ;; [] diff --git a/src/common/fake_expo.eas b/src/common/fake_expo.eas index 4588083..b78e360 100644 --- a/src/common/fake_expo.eas +++ b/src/common/fake_expo.eas @@ -3,14 +3,14 @@ dup3 ;; [denom, factor, numer, denom] mul ;; [accum, numer, denom] -push1 1 ;; [i, accum, numer, denom] +push 1 ;; [i, accum, numer, denom] swap1 ;; [accum, i, numer, denom] -push0 ;; [output, accum, i, numer, denom] +push 0 ;; [output, accum, i, numer, denom] loop: ;; while accum > 0 -push0 ;; [0, output, accum, i, numer, denom] +push 0 ;; [0, output, accum, i, numer, denom] dup3 ;; [accum, 0, output, accum, i, numer, denom] gt ;; [accum > 0, output, accum, i, numer, denom] iszero ;; [!(accum > 0), output, accum, i, numer, denom] @@ -32,7 +32,7 @@ swap1 ;; [accum*numer, i*denom, output, i, numer, denom] div ;; [accum, output, i, numer, denom] swap2 ;; [i, output, accum, numer, denom] -push1 1 ;; [1, i, output, accum, numer, denom] +push 1 ;; [1, i, output, accum, numer, denom] add ;; [i, output, accum, numer, denom] swap2 ;; [accum, output, i, numer, denom] swap1 ;; [output, accum, i, numer, denom] diff --git a/src/consolidations/main.eas b/src/consolidations/main.eas index 2945e59..27e58c3 100644 --- a/src/consolidations/main.eas +++ b/src/consolidations/main.eas @@ -1,14 +1,19 @@ +;; ▗▄▄▄▖▄▄▄▄ ▄▄▄▄ ▄ ▗▞▀▜▌ ▄▄▄ +;; ▐▌ █ █ █ ▝▚▄▟▌▀▄▄ ▄▄▄▄ +;; ▐▌█▀▀▀ ▀▀▀█ █ ▄▄▄▀ █ █ █ +;; ▐▌█▄▄▄ ▄▄▄█ █ █ █ + ;; This is an implementation of EIP-7251 style contract handling EL triggerred -;; consolidations. It leverages on the fee mechanism and the queue design of -;; the original EIP-7002 smart contract implementation. Therefore, the subroutines +;; consolidations. It leverages on the fee mechanism and the queue design of the +;; original EIP-7002 smart contract implementation. Therefore, the subroutines ;; logic of the original smart contract remains. ;; -;; The difference from the EIP-7002 smart contract is in input data, the size -;; of the queue item, target and max block parameters. +;; The difference from the EIP-7002 smart contract is in input data, the size of +;; the queue item, target and max block parameters. -;; ----------------------------------------------------------------------------- -;; CONSTANTS ------------------------------------------------------------------- -;; ----------------------------------------------------------------------------- +;; ---------------------------------------------------------------------------- +;; CONSTANTS ------------------------------------------------------------------ +;; ---------------------------------------------------------------------------- #define SYSTEM_ADDR 0xfffffffffffffffffffffffffffffffffffffffe @@ -18,7 +23,7 @@ #define QUEUE_HEAD 2 #define QUEUE_TAIL 3 #define QUEUE_OFFSET 4 -#define SLOTS_PER_ITEM 4 ;; (address, source[0:32], source[32:48] ++ target[0:16], target[16::48]) + #define MIN_FEE 1 #define TARGET_PER_BLOCK 1 @@ -28,22 +33,23 @@ #define INPUT_SIZE 96 ;; the size of (source ++ target) #define RECORD_SIZE 116 ;; the size of (address ++ source ++ target) +#define SLOTS_PER_ITEM 4 ;; (addr, src[0:32], src[32:48]+tgt[0:16], tgt[16:48]) -;; ----------------------------------------------------------------------------- -;; PROGRAM START --------------------------------------------------------------- -;; ----------------------------------------------------------------------------- +;; ---------------------------------------------------------------------------- +;; PROGRAM START -------------------------------------------------------------- +;; ---------------------------------------------------------------------------- .start: ;; Protect the system subroutine by checking if the caller is the system ;; address. caller ;; [caller] - push20 SYSTEM_ADDR ;; [sysaddr, caller] + push SYSTEM_ADDR ;; [sysaddr, caller] eq ;; [sysaddr == caller] jumpi @read_requests ;; [] - ;; --------------------------------------------------------------------------- - ;; USER SUBROUTINE ----------------------------------------------------------- - ;; --------------------------------------------------------------------------- + ;; -------------------------------------------------------------------------- + ;; USER SUBROUTINE ---------------------------------------------------------- + ;; -------------------------------------------------------------------------- ;; ;; Record new request ~~ ;; This is the default code path. It will attempt to record a user's request @@ -63,7 +69,7 @@ ;; Verify the input is exactly INPUT_SIZE bytes. calldatasize ;; [calldatasize] - push1 INPUT_SIZE ;; [INPUT_SIZE, calldatasize] + push INPUT_SIZE ;; [INPUT_SIZE, calldatasize] eq ;; [INPUT_SIZE == calldatasize] iszero ;; [INPUT_SIZE != calldatasize] jumpi @revert ;; [] @@ -90,7 +96,7 @@ ;; The request can pay, increment request count. push SLOT_COUNT sload ;; [req_count] - push1 1 ;; [1, req_count] + push 1 ;; [1, req_count] add ;; [req_count+1] push SLOT_COUNT sstore ;; [] @@ -99,8 +105,8 @@ push QUEUE_TAIL ;; [tail_idx_slot] sload ;; [tail_idx] dup1 ;; [tail_idx, tail_idx] - push1 SLOTS_PER_ITEM ;; [SLOTS_PER_ITEM, tail_idx, tail_idx] - mul ;; [SLOTS_PER_ITEM*tail_idx, tail_idx] + push SLOTS_PER_ITEM ;; [slots, tail_idx, tail_idx] + mul ;; [slots*tail_idx, tail_idx] push QUEUE_OFFSET add ;; [slot, tail_idx] @@ -109,29 +115,29 @@ dup2 ;; [slot, caller, slot, ..] sstore ;; [slot, ..] - push1 1 ;; [1, slot, ..] + push 1 ;; [1, slot, ..] add ;; [slot, ..] ;; Store source[0:32] to queue. - push0 ;; [0, slot, ..] + push 0 ;; [0, slot, ..] calldataload ;; [source[0:32], slot, ..] dup2 ;; [slot, source[0:32], slot, ..] sstore ;; [slot, ..] - push1 1 ;; [1, slot, ..] + push 1 ;; [1, slot, ..] add ;; [slot, ..] ;; Store source[32:48] ++ target[0:16] to queue. - push1 32 ;; [32, slot, ..] + push 32 ;; [32, slot, ..] calldataload ;; [source[32:48] ++ target[0:16], slot, ..] dup2 ;; [slot, source[32:48] ++ target[0:16], slot, ..] sstore ;; [slot, ..] - push1 1 ;; [1, slot, ..] + push 1 ;; [1, slot, ..] add ;; [slot, ..] ;; Store target[16:48] to queue. - push1 64 ;; [64, slot, ..] + push 64 ;; [64, slot, ..] calldataload ;; [target[16:48], slot, ..] swap1 ;; [slot, target[16:48], ..] sstore ;; [..] @@ -139,22 +145,22 @@ ;; Assemble log data. caller ;; [caller, ..] - push1 96 ;; [96, caller, ..] + push 96 ;; [96, caller, ..] shl ;; [caller, ..] - push0 ;; [0, caller, ..] + push 0 ;; [0, caller, ..] mstore ;; [..] - push1 INPUT_SIZE ;; [size, ..] - push0 ;; [ost, size, ..] - push1 20 ;; [dest, ost, size, ..] + push INPUT_SIZE ;; [size, ..] + push 0 ;; [ost, size, ..] + push 20 ;; [dest, ost, size, ..] calldatacopy ;; [..] ;; Log record. - push1 RECORD_SIZE ;; [size, ..] - push0 ;; [idx, size, ..] + push RECORD_SIZE ;; [size, ..] + push 0 ;; [idx, size, ..] log0 ;; [..] ;; Increment queue tail over last and write to storage. - push1 1 ;; [1, tail_idx] + push 1 ;; [1, tail_idx] add ;; [tail_idx+1] push QUEUE_TAIL ;; [tail_idx_slot] sstore ;; [] @@ -172,21 +178,21 @@ read_excess: ;; Load excess requests and return the value. push SLOT_EXCESS ;; [excess_reqs_slot] sload ;; [excess_reqs] - push0 ;; [0, excess_reqs] + push 0 ;; [0, excess_reqs] mstore ;; [] push 32 ;; [32] push 0 ;; [0, 32] return ;; [] -;; ----------------------------------------------------------------------------- -;; SYSTEM SUBROUTINE ----------------------------------------------------------- -;; ----------------------------------------------------------------------------- +;; ---------------------------------------------------------------------------- +;; SYSTEM SUBROUTINE ---------------------------------------------------------- +;; ---------------------------------------------------------------------------- ;; -;; Pop request from queue, update fee accumulator ~~ -;; This is the logic executed by the protocol each block. It reads as many -;; requests as available from the queue, until the max request per -;; block is reached. The requests are returned as a contiguous array of bytes -;; with each record being exactly RECORD_SIZE bytes. +;; Pop request from queue, update fee accumulator ~~ This is the logic executed +;; by the protocol each block. It reads as many requests as available from the +;; queue, until the max request per block is reached. The requests are returned +;; as a contiguous array of bytes with each record being exactly RECORD_SIZE +;; bytes. ;; ;; Consolidation request record: ;; @@ -195,13 +201,13 @@ read_excess: ;; +------+--------+--------+ ;; 20 48 48 ;; -;; Because the requests are stored across SLOTS_PER_ITEM storage slots, there is some -;; shuffling to align the data. +;; Because the requests are stored across SLOTS_PER_ITEM storage slots, there is +;; some shuffling to align the data. ;; -;; After reading the requests, they are removed from the queue by -;; modifying the queue's head index. The excess requests accumulator is updated -;; so that the new cost of submitting a request is reflected. Finally, the -;; request count is reset. +;; After reading the requests, they are removed from the queue by modifying the +;; queue's head index. The excess requests accumulator is updated so that the +;; new cost of submitting a request is reflected. Finally, the request count is +;; reset. read_requests: ;; Determine the size of the queue by calculating tail - head. push QUEUE_TAIL ;; [tail_idx_slot, head_idx, head_idx] @@ -225,7 +231,7 @@ read_requests: push MAX_PER_BLOCK ;; [count, head_idx, tail_idx] begin_loop: - push0 ;; [i, count, head_idx, tail_idx] + push 0 ;; [i, count, head_idx, tail_idx] accum_loop: ;; This loop will read each request and byte bang it into a RECORD_SIZE byte chunk. @@ -272,9 +278,8 @@ accum_loop: sload ;; [target[16:32], src[32:48] ++ tgt[0:16], source[0:32], addr, i, ..] ;; Write values to memory flat and contiguously. This require combining the - ;; four storage elements + ;; four storage elements so there is no padding: ;; (addr, source[0:32], source[32:48] ++ target[0:16], target[16:48]) - ;; so there is no padding. ;; Compute offset = i*RECORD_SIZE. @@ -317,8 +322,8 @@ accum_loop: jump @accum_loop ;; [i, count, head_idx, tail_idx] update_head: - ;; All requests have been read, update queue by adding the count read. - ;; to the current head index. + ;; All requests have been read, update queue by adding the count read. to the + ;; current head index. swap2 ;; [head_idx, count, count, tail_idx] add ;; [new_head_idx, count, tail_idx] @@ -340,11 +345,11 @@ reset_queue: swap1 ;; [new_head_idx, count] pop ;; [count] - push0 ;; [0, count] + push 0 ;; [0, count] push QUEUE_HEAD ;; [head_slot, 0, count] sstore ;; [count] - push0 ;; [0, count] + push 0 ;; [0, count] push QUEUE_TAIL ;; [tail_slot, 0, count] sstore ;; [count] @@ -363,7 +368,7 @@ update_excess: ;; Drop the excess from storage and use 0. pop ;; [count] - push0 ;; [reset_excess, count] + push 0 ;; [reset_excess, count] skip_reset: push SLOT_COUNT ;; [count_slot, excess, count] @@ -382,8 +387,8 @@ skip_reset: ;; Zero out excess. pop ;; [excess, count] pop ;; [count] - push0 - jump @store_excess + push 0 ;; [0, count] + jump @store_excess ;; [0, count] compute_excess: add ;; [count+excess, count] @@ -396,18 +401,18 @@ store_excess: sstore ;; [count] ;; Reset request count. - push0 ;; [0, count] + push 0 ;; [0, count] push SLOT_COUNT ;; [count_slot, 0, count] sstore ;; [count] ;; Return the requests. push RECORD_SIZE ;; [record_size, count] mul ;; [size] - push0 ;; [0, size] + push 0 ;; [0, size] return ;; [] ;; Revert subroutine. revert: - push0 - push0 + push 0 + push 0 revert diff --git a/src/execution_hash/main.eas b/src/execution_hash/main.eas index 73ec511..863d6e2 100644 --- a/src/execution_hash/main.eas +++ b/src/execution_hash/main.eas @@ -4,8 +4,8 @@ ;; ;; This is an implementation of EIP-2935's predeploy contract. ;; -;; The contract implements a ring buffer to create bounded execution block -;; hash lookup. +;; The contract implements a ring buffer to create bounded execution block hash +;; lookup. ;; ---------------------------------------------------------------------------- ;; MACROS --------------------------------------------------------------------- @@ -19,8 +19,8 @@ ;; do_revert sets up and then executes a revert(0,0) operation. #define %do_revert() { - push0 ;; [0] - push0 ;; [0, 0] + push 0 ;; [0] + push 0 ;; [0, 0] revert ;; [] } @@ -32,7 +32,7 @@ ;; Protect the submit routine by verifying the caller is equal to ;; sysaddr(). caller ;; [caller] - push20 SYSADDR ;; [sysaddr, caller] + push SYSADDR ;; [sysaddr, caller] eq ;; [sysaddr == caller] jumpi @submit ;; [] @@ -40,13 +40,13 @@ ;; to read a root. ;; Verify input is 32 bytes long. - push1 32 ;; [32] + push 32 ;; [32] calldatasize ;; [calldatasize, 32] eq ;; [calldatasize == 32] ;; Jump to continue if length-check passed, otherwise revert. - jumpi @load ;; [] - %do_revert() ;; [] + jumpi @load ;; [] + %do_revert() ;; [] load: ;; Check if input is requesting a block hash greater than current block diff --git a/src/withdrawals/main.eas b/src/withdrawals/main.eas index 234b49c..6099e97 100644 --- a/src/withdrawals/main.eas +++ b/src/withdrawals/main.eas @@ -38,22 +38,23 @@ #define INPUT_SIZE 56 ;; the size of (pubkey ++ amount) #define RECORD_SIZE 76 ;; the size of (address ++ pubkey ++ amount) +#define SLOTS_PER_ITEM 3 ;; (address, pubkey[0:32], pubkey[32:48] ++ amount) -;; ----------------------------------------------------------------------------- -;; PROGRAM START --------------------------------------------------------------- -;; ----------------------------------------------------------------------------- +;; ---------------------------------------------------------------------------- +;; PROGRAM START -------------------------------------------------------------- +;; ---------------------------------------------------------------------------- .start: ;; Protect the system subroutine by checking if the caller is the system ;; address. caller ;; [caller] - push20 SYSTEM_ADDR ;; [sysaddr, caller] + push SYSTEM_ADDR ;; [sysaddr, caller] eq ;; [sysaddr == caller] jumpi @read_requests ;; [] - ;; --------------------------------------------------------------------------- - ;; USER SUBROUTINE ----------------------------------------------------------- - ;; --------------------------------------------------------------------------- + ;; -------------------------------------------------------------------------- + ;; USER SUBROUTINE ---------------------------------------------------------- + ;; -------------------------------------------------------------------------- ;; ;; Record new withdrawal request ~~ ;; This is the default code path. It will attempt to record a user's request @@ -73,7 +74,7 @@ ;; Verify the input is exactly 56 bytes. calldatasize ;; [calldatasize] - push1 INPUT_SIZE ;; [INPUT_SIZE, calldatasize] + push INPUT_SIZE ;; [INPUT_SIZE, calldatasize] eq ;; [INPUT_SIZE == calldatasize] iszero ;; [INPUT_SIZE != calldatasize] jumpi @revert ;; [] @@ -100,7 +101,7 @@ ;; The request can pay, increment withdrawal request count. push SLOT_COUNT sload ;; [req_count] - push1 1 ;; [1, req_count] + push 1 ;; [1, req_count] add ;; [req_count+1] push SLOT_COUNT ;; [slot, req_count+1] sstore ;; [] @@ -109,8 +110,8 @@ push QUEUE_TAIL ;; [tail_idx_slot] sload ;; [tail_idx] dup1 ;; [tail_idx, tail_idx] - push1 3 ;; [3, tail_idx, tail_idx] - mul ;; [3*tail_idx, tail_idx] + push SLOTS_PER_ITEM ;; [slots, tail_idx, tail_idx] + mul ;; [slots*tail_idx, tail_idx] push QUEUE_OFFSET ;; [ost, 3*tail_idx, tail_idx] add ;; [slot, tail_idx] @@ -119,42 +120,42 @@ dup2 ;; [slot, caller, slot, ..] sstore ;; [slot, ..] - push1 1 ;; [1, slot, ..] + push 1 ;; [1, slot, ..] add ;; [slot, ..] ;; Store pk[0:32] to queue. - push0 ;; [0, slot, ..] + push 0 ;; [0, slot, ..] calldataload ;; [pk[0:32], slot, ..] dup2 ;; [slot, pk[0:32], slot, ..] sstore ;; [slot, ..] - push1 1 ;; [1, slot, ..] + push 1 ;; [1, slot, ..] add ;; [slot, ..] ;; Store pk2_am to queue. - push1 32 ;; [32, slot, ..] + push 32 ;; [32, slot, ..] calldataload ;; [pk2_am, slot, ..] swap1 ;; [slot, pk2_am, ..] sstore ;; [..] ;; Assemble log data. caller ;; [caller, ..] - push1 96 ;; [96, caller, ..] + push 96 ;; [96, caller, ..] shl ;; [caller, ..] - push0 ;; [0, caller, ..] + push 0 ;; [0, caller, ..] mstore ;; [..] - push1 INPUT_SIZE ;; [size, ..] - push0 ;; [ost, size, ..] - push1 20 ;; [dest, ost, size, ..] + push INPUT_SIZE ;; [size, ..] + push 0 ;; [ost, size, ..] + push 20 ;; [dest, ost, size, ..] calldatacopy ;; [..] ;; Log record. - push1 RECORD_SIZE ;; [size, ..] - push0 ;; [idx, size, ..] + push RECORD_SIZE ;; [size, ..] + push 0 ;; [idx, size, ..] log0 ;; [..] ;; Increment queue tail over last and write to storage. - push1 1 ;; [1, tail_idx] + push 1 ;; [1, tail_idx] add ;; [tail_idx+1] push QUEUE_TAIL ;; [tail_idx_slot] sstore ;; [] @@ -172,15 +173,15 @@ read_excess: ;; Load excess withdrawal requests and return the value. push SLOT_EXCESS ;; [excess_reqs_slot] sload ;; [excess_reqs] - push0 ;; [0, excess_reqs] + push 0 ;; [0, excess_reqs] mstore ;; [] push 32 ;; [32] push 0 ;; [0, 32] return ;; [] -;; ----------------------------------------------------------------------------- -;; SYSTEM SUBROUTINE ----------------------------------------------------------- -;; ----------------------------------------------------------------------------- +;; ---------------------------------------------------------------------------- +;; SYSTEM SUBROUTINE ---------------------------------------------------------- +;; ---------------------------------------------------------------------------- ;; ;; Pop withdrawal request from queue, update fee accumulator ~~ ;; This is the logic executed by the protocol each block. It reads as many @@ -225,7 +226,7 @@ read_requests: push MAX_PER_BLOCK ;; [count, head_idx, tail_idx] begin_loop: - push0 ;; [i, count, head_idx, tail_idx] + push 0 ;; [i, count, head_idx, tail_idx] accum_loop: ;; This loop will read each request and byte bang it into a 76 byte chunk. @@ -339,8 +340,8 @@ accum_loop: jump @accum_loop ;; [i, count, head_idx, tail_idx] update_head: - ;; All requests have been read, update queue by adding the count read. - ;; to the current head index. + ;; All requests have been read, update queue by adding the count read to the + ;; current head index. swap2 ;; [head_idx, count, count, tail_idx] add ;; [new_head_idx, count, tail_idx] @@ -362,11 +363,11 @@ reset_queue: swap1 ;; [new_head_idx, count] pop ;; [count] - push0 ;; [0, count] + push 0 ;; [0, count] push QUEUE_HEAD ;; [head_slot, 0, count] sstore ;; [count] - push0 ;; [0, count] + push 0 ;; [0, count] push QUEUE_TAIL ;; [tail_slot, 0, count] sstore ;; [count] @@ -385,7 +386,7 @@ update_excess: ;; Drop the excess from storage and use 0. pop ;; [count, count] - push0 ;; [reset_excess, count] + push 0 ;; [reset_excess, count] skip_reset: push SLOT_COUNT ;; [count_slot, excess, count] @@ -404,8 +405,8 @@ skip_reset: ;; Zero out excess. pop ;; [excess, count] pop ;; [count] - push0 - jump @store_excess + push 0 ;; [0, count] + jump @store_excess ;; [0, count] compute_excess: add ;; [count+excess, count] @@ -418,25 +419,25 @@ store_excess: sstore ;; [count] ;; Reset withdrawal request count. - push0 ;; [0, count] + push 0 ;; [0, count] push SLOT_COUNT ;; [count_slot, 0, count] sstore ;; [count] ;; Return the withdrawal requests. push RECORD_SIZE ;; [record_size, count] mul ;; [size] - push0 ;; [0, size] + push 0 ;; [0, size] return ;; [] ;; Revert subroutine. revert: - push0 - push0 + push 0 + push 0 revert -;; ----------------------------------------------------------------------------- -;; MACROS ---------------------------------------------------------------------- -;; ----------------------------------------------------------------------------- +;; ---------------------------------------------------------------------------- +;; MACROS --------------------------------------------------------------------- +;; ---------------------------------------------------------------------------- ;; This defines a mask for accessing the top 16 bytes of a number. #define pk2_mask 0xffffffffffffffffffffffffffffffff00000000000000000000000000000000