Skip to content

Commit

Permalink
4788: reduce indent
Browse files Browse the repository at this point in the history
  • Loading branch information
lightclient committed Oct 28, 2024
1 parent aa33981 commit 14e7ff0
Showing 1 changed file with 81 additions and 81 deletions.
162 changes: 81 additions & 81 deletions src/beacon_root/main.eas
Original file line number Diff line number Diff line change
Expand Up @@ -45,94 +45,94 @@
;; ----------------------------------------------------------------------------

.start:
;; 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() ;; []
;; 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.
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() ;; []
;; 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.
push 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.
push 0 ;; [0, root]
mstore ;; []
;; Write the retrieved root to memory so it can be returned.
push 0 ;; [0, root]
mstore ;; []

;; Return the root.
push 32 ;; [size]
push 0 ;; [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).
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 ;; []
;; 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 ;; []

0 comments on commit 14e7ff0

Please sign in to comment.