Skip to content
This repository was archived by the owner on Aug 20, 2024. It is now read-only.

Commit bea9744

Browse files
authored
Merge pull request #19 from lightclient/change-buflen
all: modify buflen to smaller prime number
2 parents 97bc6c1 + 95ebef9 commit bea9744

File tree

3 files changed

+78
-71
lines changed

3 files changed

+78
-71
lines changed

README.md

+74-67
Original file line numberDiff line numberDiff line change
@@ -20,82 +20,89 @@ To assemble `src/main.etk` you will need to invoke `eas`:
2020

2121
```console
2222
$ eas src/main.etk
23-
3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762016da0810690815414603c575f5ffd5b62016da001545f5260205ff35b5f5ffd5b62016da042064281555f359062016da0015500
23+
3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500
2424
```
2525

2626
It's also possible to remove the `etk` preproccessing by doing a roundtrip --
2727
first assembling the program, then disassembling the program:
2828

2929
```console
3030
$ disease --code 0x$(eas src/main.etk)
31-
0: caller
32-
1: push20 0xfffffffffffffffffffffffffffffffffffffffe
33-
16: eq
34-
17: push1 0x4d
35-
19: jumpi
36-
37-
1a: push1 0x20
38-
1c: calldatasize
39-
1d: eq
40-
1e: push1 0x24
41-
20: jumpi
42-
43-
21: push0
44-
22: push0
45-
23: revert
46-
47-
24: jumpdest
48-
25: push0
49-
26: calldataload
50-
27: dup1
51-
28: iszero
52-
29: push1 0x49
53-
2b: jumpi
54-
55-
2c: push3 0x016da0
56-
30: dup2
57-
31: mod
58-
32: swap1
59-
33: dup2
60-
34: sload
61-
35: eq
62-
36: push1 0x3c
63-
38: jumpi
64-
65-
39: push0
66-
3a: push0
67-
3b: revert
68-
69-
3c: jumpdest
70-
3d: push3 0x016da0
71-
41: add
72-
42: sload
31+
0: push1 0x61
32+
2: dup1
33+
3: push1 0x09
34+
5: push0
35+
6: codecopy
36+
7: push0
37+
8: return
38+
39+
9: caller
40+
a: push20 0xfffffffffffffffffffffffffffffffffffffffe
41+
1f: eq
42+
20: push1 0x4d
43+
22: jumpi
44+
45+
23: push1 0x20
46+
25: calldatasize
47+
26: eq
48+
27: push1 0x24
49+
29: jumpi
50+
51+
2a: push0
52+
2b: push0
53+
2c: revert
54+
55+
2d: jumpdest
56+
2e: push0
57+
2f: calldataload
58+
30: dup1
59+
31: iszero
60+
32: push1 0x49
61+
34: jumpi
62+
63+
35: push3 0x001fff
64+
39: dup2
65+
3a: mod
66+
3b: swap1
67+
3c: dup2
68+
3d: sload
69+
3e: eq
70+
3f: push1 0x3c
71+
41: jumpi
72+
73+
42: push0
7374
43: push0
74-
44: mstore
75-
45: push1 0x20
76-
47: push0
77-
48: return
78-
79-
49: jumpdest
80-
4a: push0
81-
4b: push0
82-
4c: revert
83-
84-
4d: jumpdest
85-
4e: push3 0x016da0
86-
52: timestamp
87-
53: mod
88-
54: timestamp
89-
55: dup2
90-
56: sstore
91-
57: push0
92-
58: calldataload
93-
59: swap1
94-
5a: push3 0x016da0
95-
5e: add
75+
44: revert
76+
77+
45: jumpdest
78+
46: push3 0x001fff
79+
4a: add
80+
4b: sload
81+
4c: push0
82+
4d: mstore
83+
4e: push1 0x20
84+
50: push0
85+
51: return
86+
87+
52: jumpdest
88+
53: push0
89+
54: push0
90+
55: revert
91+
92+
56: jumpdest
93+
57: push3 0x001fff
94+
5b: timestamp
95+
5c: mod
96+
5d: timestamp
97+
5e: dup2
9698
5f: sstore
97-
60: stop
98-
99+
60: push0
100+
61: calldataload
101+
62: swap1
102+
63: push3 0x001fff
103+
67: add
104+
68: sstore
105+
69: stop
99106
```
100107

101108
### Control-flow Graph

src/main.etk

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# buflen returns the HISTORY_BUFFER_LENGTH as defined in the EIP.
3131
%def buflen()
32-
93600
32+
8191
3333
%end
3434

3535
# sysaddr is the address which calls the contract to submit a new root.

test/Contract.t.sol.in

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import "../src/Contract.sol";
66

77
address constant addr = 0x000000000000000000000000000000000000000b;
88
address constant sysaddr = 0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE;
9-
uint256 constant buflen = 93600;
9+
uint256 constant buflen = 8191;
1010
bytes32 constant root = hex"88e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6";
1111

1212
function timestamp() view returns (bytes32) {
@@ -142,7 +142,7 @@ contract ContractTest is Test {
142142
uint256 start = block.timestamp;
143143

144144
// Saturate storage with fake roots.
145-
for (uint256 i = 0; i < buflen / 12; i += 1) {
145+
for (uint256 i = 0; i < buflen; i += 1) {
146146
bytes32 pbbr = bytes32(i*1337);
147147
vm.prank(sysaddr);
148148
(bool ret, bytes memory data) = unit.call(bytes.concat(pbbr));
@@ -152,7 +152,7 @@ contract ContractTest is Test {
152152
}
153153

154154
// Attempt to read all values in same block context.
155-
for (uint256 i = 0; i < buflen / 12; i += 1) {
155+
for (uint256 i = 0; i < buflen; i += 1) {
156156
bytes32 time = bytes32(uint256(start+i*12));
157157
(bool ret, bytes memory got) = unit.call(bytes.concat(time));
158158
assertTrue(ret);

0 commit comments

Comments
 (0)