Skip to content

Commit 1d67916

Browse files
authored
Merge pull request #35 from lightclient/fix-audit
all: prague audit fixes
2 parents a1b3f44 + d6233b1 commit 1d67916

File tree

16 files changed

+77
-99
lines changed

16 files changed

+77
-99
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ jobs:
2727
- name: Run Forge build
2828
run: |
2929
forge --version
30-
./build-wrapper build --sizes
30+
forge build --sizes
3131
id: build
3232
- name: Run Forge tests
33-
run: ./build-wrapper test -vvv
33+
run: forge test -vvv
3434
id: test

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
cache/
22
out/
3-
test/*.t.sol

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "lib/forge-std"]
22
path = lib/forge-std
33
url = https://github.com/foundry-rs/forge-std
4+
[submodule "lib/geas-ffi"]
5+
path = lib/geas-ffi
6+
url = https://github.com/lightclient/geas-ffi

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ $ geas src/withdrawals/main.eas
2626

2727
## Testing
2828

29-
The tests can be executed using the `build-wrapper` script with the same arguments as [forge][forge]:
29+
The tests can be executed using [forge][forge]:
3030

3131
```console
32-
$ ./build-wrapper test
32+
$ forge test
3333
[⠒] Compiling...
3434
[⠒] Compiling 1 files with 0.8.14
3535
[⠢] Solc 0.8.14 finished in 976.49ms

build-wrapper

Lines changed: 0 additions & 34 deletions
This file was deleted.

foundry.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[profile.default]
2+
evm_version = 'prague'
23
src = 'src'
34
out = 'out'
5+
ffi = true
46
libs = ['lib']

lib/geas-ffi

Submodule geas-ffi added at d18faf3

src/common/fake_expo.eas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@ swap1 ;; [accum, output, i, numer, denom]
4343
swap4 ;; [denom, output, i, numer, accum]
4444
swap1 ;; [output, denom, i, numer, accum]
4545
div ;; [output / denom, i , numer, accum]
46+
47+
;; clean up stack
48+
swap3 ;; [accum, i, numer, result]
49+
pop ;; [i, numer, result]
50+
pop ;; [numer, result]
51+
pop ;; [result]

src/consolidations/main.eas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ handle_input:
201201
;; reset.
202202
read_requests:
203203
;; Determine the size of the queue by calculating tail - head.
204-
push QUEUE_TAIL ;; [tail_idx_slot, head_idx, head_idx]
204+
push QUEUE_TAIL ;; [tail_idx_slot]
205205
sload ;; [tail_idx]
206206
push QUEUE_HEAD ;; [head_idx_slot, tail_idx]
207207
sload ;; [head_idx, tail_idx]
@@ -369,7 +369,7 @@ update_excess:
369369
iszero ;; [inhibitor != excess, excess, count]
370370
jumpi @skip_reset ;; [excess, count]
371371

372-
;; Drop the excess from storage and use 0.
372+
;; Drop the excess from stack and use 0.
373373
pop ;; [count]
374374
push 0 ;; [reset_excess, count]
375375

src/execution_hash/main.eas

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,9 @@
1414
;; BUFLEN returns the HISTORY_BUFFER_LENGTH as defined in the EIP.
1515
#define BUFLEN 8191
1616

17-
;; SYSADDR is the address which calls the contract to submit a new root.
17+
;; SYSADDR is the address which calls the contract to submit a new block hash.
1818
#define SYSADDR 0xfffffffffffffffffffffffffffffffffffffffe
1919

20-
;; do_revert sets up and then executes a revert(0,0) operation.
21-
#define %do_revert() {
22-
push 0 ;; [0]
23-
push 0 ;; [0, 0]
24-
revert ;; []
25-
}
26-
2720
;; ----------------------------------------------------------------------------
2821
;; MACROS END -----------------------------------------------------------------
2922
;; ----------------------------------------------------------------------------
@@ -37,20 +30,18 @@
3730
jumpi @submit ;; []
3831

3932
;; Fallthrough if addresses don't match -- this means the caller intends
40-
;; to read a root.
33+
;; to read a block hash.
4134

4235
;; Verify input is 32 bytes long.
4336
push 32 ;; [32]
4437
calldatasize ;; [calldatasize, 32]
45-
eq ;; [calldatasize == 32]
38+
sub ;; [calldatasize - 32]
4639

4740
;; Jump to continue if length-check passed, otherwise revert.
48-
jumpi @load ;; []
49-
%do_revert() ;; []
41+
jumpi @throw ;; []
5042

51-
load:
52-
;; Check if input is requesting a block hash greater than current block
53-
;; number.
43+
;; Check if input is requesting a block hash greater than current block number
44+
;; minus 1.
5445
push 0 ;; [0]
5546
calldataload ;; [input]
5647
push 1 ;; [1, input]
@@ -62,13 +53,11 @@ load:
6253

6354
;; Check if the input is requesting a block hash before the earliest available
6455
;; hash currently. Since we've verfied that input <= number - 1, it's safe to
65-
;; check the following:
66-
;; number - 1 - input <= BUFLEN, which also equals: number - input < BUFLEN
67-
dup1 ;; [input, input]
68-
number ;; [number, input, input]
69-
sub ;; [number - input, input]
70-
push BUFLEN+1 ;; [buflen, number - input, input]
71-
lt ;; [buflen < number - input, input]
56+
push BUFLEN ;; [buflen, input]
57+
dup2 ;; [input, buflen, input]
58+
number ;; [number, input, buflen, input]
59+
sub ;; [number - input, buflen, input]
60+
gt ;; [number - input > buflen, input]
7261
jumpi @throw ;; [input]
7362

7463
;; Load the hash.
@@ -86,8 +75,9 @@ load:
8675

8776
throw:
8877
;; Reverts current execution with no return data.
89-
pop
90-
%do_revert()
78+
push 0 ;; [0]
79+
push 0 ;; [0, 0]
80+
revert ;; []
9181

9282
submit:
9383
push 0 ;; [0]

0 commit comments

Comments
 (0)