Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consolidations, withdrawals: reject callvalue when calldatasize == 0 #28

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/consolidations/main.eas
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@

.start:
;; Protect the system subroutine by checking if the caller is the system
;; address.
caller ;; [caller]
push20 SYSTEM_ADDR ;; [sysaddr, caller]
eq ;; [sysaddr == caller]
push1 @read_requests ;; [read_lbl, sysaddr == caller]
jumpi ;; []
;; address.
caller ;; [caller]
push20 SYSTEM_ADDR ;; [sysaddr, caller]
eq ;; [sysaddr == caller]
jumpi @read_requests ;; []

;; ---------------------------------------------------------------------------
;; USER SUBROUTINE -----------------------------------------------------------
Expand All @@ -56,6 +55,12 @@
iszero ;; [calldatasize != 0]
jumpi @check_input

;; Reject any callvalue here to prevent lost funds.
callvalue ;; [value]
iszero ;; [value == 0]
iszero ;; [value != 0]
jumpi @revert

;; Load excess requests and return the value.
push SLOT_EXCESS ;; [excess_reqs_slot]
sload ;; [excess_reqs]
Expand Down Expand Up @@ -184,7 +189,7 @@ check_input:
;; with each record being exactly RECORD_SIZE bytes.
;;
;; Consolidation request record:
;;
;;
;; +------+--------+--------+
;; | addr | source | target |
;; +------+--------+--------+
Expand Down Expand Up @@ -280,7 +285,7 @@ accum_loop:
swap3 ;; [addr, src[32:48] ++ tgt[0:16], source[0:32], target[16:32], record_offset, i, ..]
push 12*8 ;; [96, addr, src[32:48] ++ tgt[0:16], source[0:32], target[16:32], record_offset, i, ..]
shl ;; [addr<<96, src[32:48] ++ tgt[0:16], source[0:32], target[16:32], record_offset, i, ..]

;; Store addr at offset = i*RECORD_SIZE.
dup5 ;; [record_offset, addr<<96, src[32:48] ++ tgt[0:16], source[0:32], target[16:32], record_offset, i, ..]
mstore ;; [src[32:48] ++ tgt[0:16], source[0:32], target[16:32], record_offset, i, ..]
Expand Down Expand Up @@ -346,7 +351,7 @@ update_excess:
;; Update the new excess withdrawal requests.
push SLOT_EXCESS ;; [excess_slot, count]
sload ;; [excess, count]

;; Check if excess needs to be reset to 0 for first iteration after
;; activation.
dup1 ;; [excess, excess, count]
Expand All @@ -372,11 +377,11 @@ skip_reset:
add ;; [count+excess, target, count, excess, count]
gt ;; [count+excess > target, count, excess, count]
jumpi @compute_excess ;; [count, excess, count]

;; Zero out excess.
pop ;; [excess, count]
pop ;; [count]
push0
push0
jump @store_excess

compute_excess:
Expand Down
15 changes: 10 additions & 5 deletions src/withdrawals/main.eas
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@
.start:
;; Protect the system subroutine by checking if the caller is the system
;; address.
caller ;; [caller]
push20 SYSTEM_ADDR ;; [sysaddr, caller]
eq ;; [sysaddr == caller]
push1 @read_requests ;; [read_lbl, sysaddr == caller]
jumpi ;; []
caller ;; [caller]
push20 SYSTEM_ADDR ;; [sysaddr, caller]
eq ;; [sysaddr == caller]
jumpi @read_requests ;; []

;; ---------------------------------------------------------------------------
;; USER SUBROUTINE -----------------------------------------------------------
Expand All @@ -66,6 +65,12 @@
iszero ;; [calldatasize != 0]
jumpi @check_input

;; Reject any callvalue here to prevent lost funds.
lightclient marked this conversation as resolved.
Show resolved Hide resolved
callvalue ;; [value]
iszero ;; [value == 0]
iszero ;; [value != 0]
jumpi @revert

;; Load excess withdrawal requests and return the value.
push SLOT_EXCESS ;; [excess_reqs_slot]
sload ;; [excess_reqs]
Expand Down
Loading