Skip to content

Commit 567b42e

Browse files
committed
Format fixes
1 parent 1bad10b commit 567b42e

File tree

1 file changed

+98
-154
lines changed

1 file changed

+98
-154
lines changed

fillers/eips/eip3855.py

Lines changed: 98 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,32 @@ def test_push0(fork):
2424
"""
2525
env = Environment()
2626

27-
pre = {
28-
TestAddress: Account(balance=1000000000000000000000),
29-
}
30-
27+
pre = {TestAddress: Account(balance=1000000000000000000000)}
3128
post = {}
3229

33-
code_address = to_address(0x100)
30+
addr_1 = to_address(0x100)
31+
addr_2 = to_address(0x200)
3432

35-
# Entry point for all test cases this address
33+
# Entry point for all test cases is the same address
3634
tx = Transaction(
37-
to=code_address,
35+
to=addr_1,
3836
gas_limit=100000,
3937
)
4038

4139
"""
4240
Test case 1: Simple PUSH0 as key to SSTORE
4341
"""
44-
pre[code_address] = Account(
45-
code=bytes(
46-
[
47-
0x60, # PUSH1
48-
0x01,
49-
0x5F, # PUSH0
50-
0x55, # SSTORE
51-
]
52-
),
42+
code = bytes(
43+
[
44+
0x60, # PUSH1
45+
0x01,
46+
0x5F, # PUSH0
47+
0x55, # SSTORE
48+
]
5349
)
5450

55-
post[code_address] = Account(
56-
storage={
57-
0x00: 0x01,
58-
}
59-
)
51+
pre[addr_1] = Account(code=code)
52+
post[addr_1] = Account(storage={0x00: 0x01})
6053

6154
yield StateTest(
6255
env=env, pre=pre, post=post, txs=[tx], name="push0_key_sstore"
@@ -66,57 +59,39 @@ def test_push0(fork):
6659
Test case 2: Fill stack with PUSH0, then OR all values and save using
6760
SSTORE
6861
"""
69-
pre[code_address] = Account(
70-
code=bytes(
71-
[
72-
0x5F, # PUSH0
73-
]
74-
* 1024
75-
)
76-
+ bytes(
77-
[
78-
0x17, # OR
79-
]
80-
* 1023
81-
)
82-
+ bytes(
83-
[
84-
0x60, # PUSH1
85-
0x01,
86-
0x90, # SWAP1
87-
0x55, # SSTORE
88-
]
89-
),
90-
)
91-
92-
post[code_address] = Account(
93-
storage={
94-
0x00: 0x01,
95-
}
62+
code = bytes([0x5F] * 1024) # PUSH0
63+
code += bytes([0x17] * 1023) # OR
64+
code += bytes(
65+
[
66+
0x60, # PUSH1
67+
0x01,
68+
0x90, # SWAP1
69+
0x55, # SSTORE
70+
]
9671
)
9772

73+
pre[addr_1] = Account(code=code)
74+
post[addr_1] = Account(storage={0x00: 0x01})
75+
9876
yield StateTest(
9977
env=env, pre=pre, post=post, txs=[tx], name="push0_fill_stack"
10078
)
10179

10280
"""
10381
Test case 3: Stack overflow by using PUSH0 1025 times
10482
"""
105-
pre[code_address] = Account(
106-
code=Yul("{ sstore(0, 1) }")
107-
+ bytes(
108-
[
109-
0x5F, # PUSH0
110-
]
111-
* 1025 # Stack overflow
112-
),
83+
code = bytes(
84+
[
85+
0x60, # PUSH1
86+
0x01,
87+
0x5F, # PUSH0
88+
0x55, # SSTORE
89+
]
11390
)
91+
code += bytes([0x5F] * 1025) # PUSH0, stack overflow
11492

115-
post[code_address] = Account(
116-
storage={
117-
0x00: 0x00,
118-
}
119-
)
93+
pre[addr_1] = Account(code=code)
94+
post[addr_1] = Account(storage={0x00: 0x00})
12095

12196
yield StateTest(
12297
env=env, pre=pre, post=post, txs=[tx], name="push0_stack_overflow"
@@ -125,129 +100,98 @@ def test_push0(fork):
125100
"""
126101
Test case 4: Update already existing storage value
127102
"""
128-
pre[code_address] = Account(
129-
code=bytes(
130-
[
131-
0x60, # PUSH1
132-
0x02,
133-
0x5F, # PUSH0
134-
0x55, # SSTORE
135-
0x5F, # PUSH0
136-
0x60, # PUSH1
137-
0x01,
138-
0x55, # SSTORE
139-
]
140-
),
141-
storage={
142-
0x00: 0x0A,
143-
0x01: 0x0A,
144-
},
145-
)
146-
147-
post[code_address] = Account(
148-
storage={
149-
0x00: 0x02,
150-
0x01: 0x00,
151-
}
103+
code = bytes(
104+
[
105+
0x60, # PUSH1
106+
0x02,
107+
0x5F, # PUSH0
108+
0x55, # SSTORE
109+
0x5F, # PUSH0
110+
0x60, # PUSH1
111+
0x01,
112+
0x55, # SSTORE
113+
]
152114
)
153115

116+
pre[addr_1] = Account(code=code, storage={0x00: 0x0A, 0x01: 0x0A})
117+
post[addr_1] = Account(storage={0x00: 0x02, 0x01: 0x00})
118+
154119
yield StateTest(
155120
env=env, pre=pre, post=post, txs=[tx], name="push0_storage_overwrite"
156121
)
157122

158123
"""
159124
Test case 5: PUSH0 during staticcall
160125
"""
161-
162-
pre[code_address] = Account(
163-
code=Yul(
164-
"""
165-
{
166-
sstore(0, staticcall(100000, 0x200, 0, 0, 0, 0))
167-
sstore(0, 1)
168-
returndatacopy(0x1f, 0, 1)
169-
sstore(1, mload(0))
170-
}
171-
"""
172-
)
173-
)
174-
pre[to_address(0x200)] = Account(
175-
code=bytes(
176-
[
177-
0x60, # PUSH1
178-
0xFF,
179-
0x5F, # PUSH0
180-
0x53, # MSTORE8
181-
0x60, # PUSH1
182-
0x01,
183-
0x60, # PUSH1
184-
0x00,
185-
0xF3, # RETURN
186-
]
187-
),
188-
)
189-
post[code_address] = Account(
190-
storage={
191-
0x00: 0x01,
192-
0x01: 0xFF,
126+
code_1 = Yul(
127+
"""
128+
{
129+
sstore(0, staticcall(100000, 0x200, 0, 0, 0, 0))
130+
sstore(0, 1)
131+
returndatacopy(0x1f, 0, 1)
132+
sstore(1, mload(0))
193133
}
194-
)
134+
"""
135+
)
136+
code_2 = bytes(
137+
[
138+
0x60, # PUSH1
139+
0xFF,
140+
0x5F, # PUSH0
141+
0x53, # MSTORE8
142+
0x60, # PUSH1
143+
0x01,
144+
0x60, # PUSH1
145+
0x00,
146+
0xF3, # RETURN
147+
]
148+
)
149+
150+
pre[addr_1] = Account(code=code_1)
151+
pre[addr_2] = Account(code=code_2)
152+
post[addr_1] = Account(storage={0x00: 0x01, 0x01: 0xFF})
195153

196154
yield StateTest(
197155
env=env, pre=pre, post=post, txs=[tx], name="push0_during_staticcall"
198156
)
199157

200-
del pre[to_address(0x200)]
158+
del pre[addr_2]
201159

202160
"""
203161
Test case 6: Jump to a JUMPDEST next to a PUSH0, must succeed.
204162
"""
205-
pre[code_address] = Account(
206-
code=bytes(
207-
[
208-
0x60, # PUSH1
209-
0x04,
210-
0x56, # JUMP
211-
0x5F, # PUSH0
212-
0x5B, # JUMPDEST
213-
0x60, # PUSH1
214-
0x01,
215-
0x5F, # PUSH0
216-
0x55, # SSTORE
217-
0x00, # STOP
218-
]
219-
),
220-
)
221-
222-
post[code_address] = Account(
223-
storage={
224-
0x00: 0x01,
225-
}
163+
code = bytes(
164+
[
165+
0x60, # PUSH1
166+
0x04,
167+
0x56, # JUMP
168+
0x5F, # PUSH0
169+
0x5B, # JUMPDEST
170+
0x60, # PUSH1
171+
0x01,
172+
0x5F, # PUSH0
173+
0x55, # SSTORE
174+
0x00, # STOP
175+
]
226176
)
227177

178+
pre[addr_1] = Account(code=code)
179+
post[addr_1] = Account(storage={0x00: 0x01})
180+
228181
yield StateTest(
229182
env=env, pre=pre, post=post, txs=[tx], name="push0_before_jumpdest"
230183
)
231184

232185
"""
233186
Test case 7: PUSH0 gas cost
234187
"""
235-
pre[code_address] = Account(
236-
code=CodeGasMeasure(
237-
code=bytes(
238-
[
239-
0x5F, # PUSH0
240-
]
241-
),
242-
extra_stack_items=1,
243-
),
188+
code = CodeGasMeasure(
189+
code=bytes([0x5F]), # PUSH0
190+
extra_stack_items=1,
244191
)
245192

246-
post[code_address] = Account(
247-
storage={
248-
0x00: 0x02,
249-
}
250-
)
193+
pre[addr_1] = Account(code=code)
194+
post[addr_1] = Account(storage={0x00: 0x02})
251195

252196
yield StateTest(
253197
env=env, pre=pre, post=post, txs=[tx], name="push0_gas_cost"

0 commit comments

Comments
 (0)