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;; ----------------------------------------------------------------------------
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.
8675
8776throw:
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
9282submit:
9383 push 0 ;; [0]
0 commit comments