|
1 | | -;; ▗▄▄▄▖▄▄▄▄ ▄▄▄▄ ▄ ▗▞▀▜▌ ▄▄▄ |
2 | | -;; ▐▌ █ █ █ ▝▚▄▟▌▀▄▄ ▄▄▄▄ |
3 | | -;; ▐▌█▀▀▀ ▀▀▀█ █ ▄▄▄▀ █ █ █ |
4 | | -;; ▐▌█▄▄▄ ▄▄▄█ █ █ █ |
| 1 | +;; ▗▄▄▄▖▄▄▄▄ ▄▄▄▄ ▄ ▗▞▀▜▌ ▄▄▄ |
| 2 | +;; ▐▌ █ █ █ ▝▚▄▟▌▀▄▄ ▄▄▄▄ |
| 3 | +;; ▐▌█▀▀▀ ▀▀▀█ █ ▄▄▄▀ █ █ █ |
| 4 | +;; ▐▌█▄▄▄ ▄▄▄█ █ █ █ |
5 | 5 |
|
6 | 6 | ;; This is an implementation of EIP-7251 style contract handling EL triggerred |
7 | 7 | ;; consolidations. It leverages on the fee mechanism and the queue design of the |
|
50 | 50 | ;; -------------------------------------------------------------------------- |
51 | 51 | ;; USER SUBROUTINE ---------------------------------------------------------- |
52 | 52 | ;; -------------------------------------------------------------------------- |
53 | | - ;; |
54 | | - ;; Record new request ~~ |
55 | | - ;; This is the default code path. It will attempt to record a user's request |
56 | | - ;; so long as they pay the required fee. |
57 | | - |
58 | | - ;; If calldatasize == 0, return the current excess requests. |
59 | | - calldatasize ;; [calldatasize] |
60 | | - iszero ;; [calldatasize == 0] |
61 | | - jumpi @read_excess |
62 | | - |
63 | | - ;; Input data has the following layout: |
64 | | - ;; |
65 | | - ;; +--------+--------+ |
66 | | - ;; | source | target | |
67 | | - ;; +--------+--------+ |
68 | | - ;; 48 48 |
69 | | - |
70 | | - ;; Verify the input is exactly INPUT_SIZE bytes. |
71 | | - calldatasize ;; [calldatasize] |
72 | | - push INPUT_SIZE ;; [INPUT_SIZE, calldatasize] |
73 | | - eq ;; [INPUT_SIZE == calldatasize] |
74 | | - iszero ;; [INPUT_SIZE != calldatasize] |
75 | | - jumpi @revert ;; [] |
76 | 53 |
|
77 | 54 | ;; Compute the fee using fake expo and the current excess requests. |
78 | 55 | push FEE_UPDATE_FRACTION |
|
88 | 65 | push MIN_FEE ;; [min_fee, excess, update_fraction] |
89 | 66 | #include "../common/fake_expo.eas" |
90 | 67 |
|
| 68 | + ;; If calldatasize matches the expected input size, go to adding the request. |
| 69 | + calldatasize ;; [calldatasize, req_fee] |
| 70 | + push INPUT_SIZE ;; [INPUT_SIZE, calldatasize, req_fee] |
| 71 | + eq ;; [INPUT_SIZE == calldatasize, req_fee] |
| 72 | + jumpi @handle_input ;; [req_fee] |
| 73 | + |
| 74 | + ;; Otherwise calldatasize must be zero. |
| 75 | + calldatasize ;; [calldatasize, req_fee] |
| 76 | + jumpi @revert ;; [req_fee] |
| 77 | + |
| 78 | + ;; This is the read path, where we return the current excess. |
| 79 | + ;; Reject any callvalue here to prevent lost funds. |
| 80 | + callvalue ;; [value, req_fee] |
| 81 | + jumpi @revert ;; [req_fee] |
| 82 | + |
| 83 | + ;; Return req_fee. |
| 84 | + push 0 ;; [0, req_fee] |
| 85 | + mstore ;; [] |
| 86 | + push 32 ;; [32] |
| 87 | + push 0 ;; [0, 32] |
| 88 | + return ;; [] |
| 89 | + |
| 90 | +handle_input: |
| 91 | + ;; This is the write path. We expect the computed fee on the stack. |
| 92 | + ;; Input data has the following layout: |
| 93 | + ;; |
| 94 | + ;; +--------+--------+ |
| 95 | + ;; | source | target | |
| 96 | + ;; +--------+--------+ |
| 97 | + ;; 48 48 |
| 98 | + |
91 | 99 | ;; Determine if the fee provided is enough to cover the request fee. |
92 | 100 | callvalue ;; [callvalue, req_fee] |
93 | 101 | lt ;; [callvalue < req_fee] |
|
167 | 175 |
|
168 | 176 | stop |
169 | 177 |
|
170 | | -read_excess: |
171 | | - ;; This is the read path, where we return the current excess. |
172 | | - ;; Reject any callvalue here to prevent lost funds. |
173 | | - callvalue ;; [value] |
174 | | - iszero ;; [value == 0] |
175 | | - iszero ;; [value != 0] |
176 | | - jumpi @revert |
177 | | - |
178 | | - ;; Load excess requests and return the value. |
179 | | - push SLOT_EXCESS ;; [excess_reqs_slot] |
180 | | - sload ;; [excess_reqs] |
181 | | - push 0 ;; [0, excess_reqs] |
182 | | - mstore ;; [] |
183 | | - push 32 ;; [32] |
184 | | - push 0 ;; [0, 32] |
185 | | - return ;; [] |
186 | | - |
187 | 178 | ;; ---------------------------------------------------------------------------- |
188 | 179 | ;; SYSTEM SUBROUTINE ---------------------------------------------------------- |
189 | 180 | ;; ---------------------------------------------------------------------------- |
|
0 commit comments