7
7
8
8
import pytest
9
9
10
- from ethereum_test_tools import (
11
- Account ,
12
- Address ,
13
- Environment ,
14
- StateTestFiller ,
15
- TestAddress ,
16
- Transaction ,
17
- )
10
+ from ethereum_test_tools import Account , Address , Alloc , Environment , StateTestFiller , Transaction
18
11
from ethereum_test_tools .vm .opcode import Opcodes as Op
19
12
20
13
from .spec import Spec , ref_spec_1153
26
19
@pytest .mark .valid_from ("Cancun" )
27
20
def test_basic_tload_transaction_begin (
28
21
state_test : StateTestFiller ,
22
+ pre : Alloc ,
29
23
):
30
24
"""
31
25
Ported .json vectors:
@@ -36,38 +30,27 @@ def test_basic_tload_transaction_begin(
36
30
slot_tload_at_transaction_begin_result = 1
37
31
slot_code_worked = 2
38
32
39
- address_to = Address ("A00000000000000000000000000000000000000A" )
40
- pre = {
33
+ address_to = pre .deploy_contract (
34
+ code = Op .JUMPDEST ()
35
+ # 01 test
36
+ + Op .SSTORE (slot_tload_at_transaction_begin_result , Op .TLOAD (0 ))
37
+ + Op .SSTORE (slot_code_worked , 1 ),
38
+ storage = {
39
+ slot_tload_at_transaction_begin_result : 0xFF ,
40
+ },
41
+ )
42
+
43
+ post = {
41
44
address_to : Account (
42
- balance = 1000000000000000000 ,
43
- nonce = 0 ,
44
- code = Op .JUMPDEST ()
45
- # 01 test
46
- + Op .SSTORE (slot_tload_at_transaction_begin_result , Op .TLOAD (0 ))
47
- + Op .SSTORE (slot_code_worked , 1 ),
48
45
storage = {
49
- slot_tload_at_transaction_begin_result : 0xFF ,
50
- },
51
- ),
52
- TestAddress : Account (
53
- balance = 7000000000000000000 ,
54
- nonce = 0 ,
55
- code = "0x" ,
56
- storage = {},
57
- ),
46
+ slot_tload_at_transaction_begin_result : 0x00 ,
47
+ slot_code_worked : 0x01 ,
48
+ }
49
+ )
58
50
}
59
51
60
- post : Dict [Address , Union [Account , object ]] = {}
61
-
62
- post [address_to ] = Account (
63
- storage = {
64
- slot_tload_at_transaction_begin_result : 0x00 ,
65
- slot_code_worked : 0x01 ,
66
- }
67
- )
68
-
69
52
tx = Transaction (
70
- nonce = 0 ,
53
+ sender = pre . fund_eoa ( 7_000_000_000_000_000_000 ) ,
71
54
to = address_to ,
72
55
gas_price = 10 ,
73
56
data = b"" ,
@@ -81,6 +64,7 @@ def test_basic_tload_transaction_begin(
81
64
@pytest .mark .valid_from ("Cancun" )
82
65
def test_basic_tload_works (
83
66
state_test : StateTestFiller ,
67
+ pre : Alloc ,
84
68
):
85
69
"""
86
70
Ported .json vectors:
@@ -94,42 +78,31 @@ def test_basic_tload_works(
94
78
slot_tload_after_tstore_result_second_time = 1
95
79
slot_code_worked = 2
96
80
97
- address_to = Address ("A00000000000000000000000000000000000000A" )
98
- pre = {
81
+ address_to = pre .deploy_contract (
82
+ code = Op .JUMPDEST ()
83
+ # 02 test
84
+ + Op .TSTORE (2 , tstore_value )
85
+ + Op .SSTORE (slot_tload_after_tstore_result , Op .TLOAD (2 ))
86
+ + Op .SSTORE (slot_tload_after_tstore_result_second_time , Op .TLOAD (2 ))
87
+ + Op .SSTORE (slot_code_worked , 1 ),
88
+ storage = {
89
+ slot_tload_after_tstore_result : 0xFF ,
90
+ slot_tload_after_tstore_result_second_time : 0xFF ,
91
+ },
92
+ )
93
+
94
+ post = {
99
95
address_to : Account (
100
- balance = 1000000000000000000 ,
101
- nonce = 0 ,
102
- code = Op .JUMPDEST ()
103
- # 02 test
104
- + Op .TSTORE (2 , tstore_value )
105
- + Op .SSTORE (slot_tload_after_tstore_result , Op .TLOAD (2 ))
106
- + Op .SSTORE (slot_tload_after_tstore_result_second_time , Op .TLOAD (2 ))
107
- + Op .SSTORE (slot_code_worked , 1 ),
108
96
storage = {
109
- slot_tload_after_tstore_result : 0xFF ,
110
- slot_tload_after_tstore_result_second_time : 0xFF ,
111
- },
112
- ),
113
- TestAddress : Account (
114
- balance = 7000000000000000000 ,
115
- nonce = 0 ,
116
- code = "0x" ,
117
- storage = {},
118
- ),
97
+ slot_tload_after_tstore_result : tstore_value ,
98
+ slot_tload_after_tstore_result_second_time : tstore_value ,
99
+ slot_code_worked : 0x01 ,
100
+ }
101
+ )
119
102
}
120
103
121
- post : Dict [Address , Union [Account , object ]] = {}
122
-
123
- post [address_to ] = Account (
124
- storage = {
125
- slot_tload_after_tstore_result : tstore_value ,
126
- slot_tload_after_tstore_result_second_time : tstore_value ,
127
- slot_code_worked : 0x01 ,
128
- }
129
- )
130
-
131
104
tx = Transaction (
132
- nonce = 0 ,
105
+ sender = pre . fund_eoa ( 7_000_000_000_000_000_000 ) ,
133
106
to = address_to ,
134
107
gas_price = 10 ,
135
108
data = b"" ,
@@ -143,6 +116,7 @@ def test_basic_tload_works(
143
116
@pytest .mark .valid_from ("Cancun" )
144
117
def test_basic_tload_other_after_tstore (
145
118
state_test : StateTestFiller ,
119
+ pre : Alloc ,
146
120
):
147
121
"""
148
122
Ported .json vectors:
@@ -155,39 +129,28 @@ def test_basic_tload_other_after_tstore(
155
129
slot_tload_untouched_slot_after_tstore_result = 1
156
130
slot_code_worked = 2
157
131
158
- address_to = Address ("A00000000000000000000000000000000000000A" )
159
- pre = {
132
+ address_to = pre .deploy_contract (
133
+ code = Op .JUMPDEST ()
134
+ # 03 test
135
+ + Op .TSTORE (3 , tstore_value )
136
+ + Op .SSTORE (slot_tload_untouched_slot_after_tstore_result , Op .TLOAD (0 ))
137
+ + Op .SSTORE (slot_code_worked , 1 ),
138
+ storage = {
139
+ slot_tload_untouched_slot_after_tstore_result : 0xFF ,
140
+ },
141
+ )
142
+
143
+ post = {
160
144
address_to : Account (
161
- balance = 1000000000000000000 ,
162
- nonce = 0 ,
163
- code = Op .JUMPDEST ()
164
- # 03 test
165
- + Op .TSTORE (3 , tstore_value )
166
- + Op .SSTORE (slot_tload_untouched_slot_after_tstore_result , Op .TLOAD (0 ))
167
- + Op .SSTORE (slot_code_worked , 1 ),
168
145
storage = {
169
- slot_tload_untouched_slot_after_tstore_result : 0xFF ,
170
- },
171
- ),
172
- TestAddress : Account (
173
- balance = 7000000000000000000 ,
174
- nonce = 0 ,
175
- code = "0x" ,
176
- storage = {},
177
- ),
146
+ slot_tload_untouched_slot_after_tstore_result : 0x00 ,
147
+ slot_code_worked : 0x01 ,
148
+ }
149
+ )
178
150
}
179
151
180
- post : Dict [Address , Union [Account , object ]] = {}
181
-
182
- post [address_to ] = Account (
183
- storage = {
184
- slot_tload_untouched_slot_after_tstore_result : 0x00 ,
185
- slot_code_worked : 0x01 ,
186
- }
187
- )
188
-
189
152
tx = Transaction (
190
- nonce = 0 ,
153
+ sender = pre . fund_eoa ( 7_000_000_000_000_000_000 ) ,
191
154
to = address_to ,
192
155
gas_price = 10 ,
193
156
data = b"" ,
@@ -201,6 +164,7 @@ def test_basic_tload_other_after_tstore(
201
164
@pytest .mark .valid_from ("Cancun" )
202
165
def test_basic_tload_gasprice (
203
166
state_test : StateTestFiller ,
167
+ pre : Alloc ,
204
168
):
205
169
"""
206
170
Ported .json vectors:
@@ -212,8 +176,6 @@ def test_basic_tload_gasprice(
212
176
slot_tload_zero_gas_price_result = 2
213
177
slot_code_worked = 3
214
178
215
- address_to = Address ("A00000000000000000000000000000000000000A" )
216
-
217
179
"""
218
180
N OPNAME GAS_COST TOTAL_GAS REMAINING_GAS STACK
219
181
28-1 MSTORE 2 20748 4958252 2:[4ba82f,0,]
@@ -227,57 +189,46 @@ def test_basic_tload_gasprice(
227
189
"""
228
190
extra_opcode_gas = 11 # mstore(3), push1(3),gas(2),push1(3)
229
191
230
- pre = {
192
+ address_to = pre .deploy_contract (
193
+ code = Op .JUMPDEST ()
194
+ # 16 test
195
+ + Op .TSTORE (16 , 2 )
196
+ + Op .MSTORE (0 , Op .GAS ()) # hot load the memory to make the extra_opcode_gas be 11
197
+ + Op .MSTORE (0 , Op .GAS ())
198
+ + Op .TLOAD (16 )
199
+ + Op .MSTORE (32 , Op .GAS ())
200
+ + Op .SSTORE (slot_tload_nonzero_gas_price_result , Op .SUB (Op .MLOAD (0 ), Op .MLOAD (32 )))
201
+ + Op .SSTORE (
202
+ slot_tload_nonzero_gas_price_result ,
203
+ Op .SUB (Op .SLOAD (slot_tload_nonzero_gas_price_result ), extra_opcode_gas ),
204
+ )
205
+ + Op .MSTORE (0 , Op .GAS ())
206
+ + Op .TLOAD (5 ) # tload slot at 5 is 0
207
+ + Op .MSTORE (32 , Op .GAS ())
208
+ + Op .SSTORE (slot_tload_zero_gas_price_result , Op .SUB (Op .MLOAD (0 ), Op .MLOAD (32 )))
209
+ + Op .SSTORE (
210
+ slot_tload_zero_gas_price_result ,
211
+ Op .SUB (Op .SLOAD (slot_tload_zero_gas_price_result ), extra_opcode_gas ),
212
+ )
213
+ + Op .SSTORE (slot_code_worked , 1 ),
214
+ storage = {
215
+ slot_tload_nonzero_gas_price_result : 0xFF ,
216
+ slot_tload_zero_gas_price_result : 0xFF ,
217
+ },
218
+ )
219
+
220
+ post = {
231
221
address_to : Account (
232
- balance = 1000000000000000000 ,
233
- nonce = 0 ,
234
- code = Op .JUMPDEST ()
235
- # 16 test
236
- + Op .TSTORE (16 , 2 )
237
- + Op .MSTORE (0 , Op .GAS ()) # hot load the memory to make the extra_opcode_gas be 11
238
- + Op .MSTORE (0 , Op .GAS ())
239
- + Op .TLOAD (16 )
240
- + Op .MSTORE (32 , Op .GAS ())
241
- + Op .SSTORE (slot_tload_nonzero_gas_price_result , Op .SUB (Op .MLOAD (0 ), Op .MLOAD (32 )))
242
- + Op .SSTORE (
243
- slot_tload_nonzero_gas_price_result ,
244
- Op .SUB (Op .SLOAD (slot_tload_nonzero_gas_price_result ), extra_opcode_gas ),
245
- )
246
- # from zero slot
247
- + Op .MSTORE (0 , Op .GAS ())
248
- + Op .TLOAD (5 )
249
- + Op .MSTORE (32 , Op .GAS ())
250
- + Op .SSTORE (slot_tload_zero_gas_price_result , Op .SUB (Op .MLOAD (0 ), Op .MLOAD (32 )))
251
- + Op .SSTORE (
252
- slot_tload_zero_gas_price_result ,
253
- Op .SUB (Op .SLOAD (slot_tload_zero_gas_price_result ), extra_opcode_gas ),
254
- )
255
- + Op .SSTORE (slot_code_worked , 1 ),
256
222
storage = {
257
- slot_tload_nonzero_gas_price_result : 0xFF ,
258
- slot_tload_zero_gas_price_result : 0xFF ,
259
- },
260
- ),
261
- TestAddress : Account (
262
- balance = 7000000000000000000 ,
263
- nonce = 0 ,
264
- code = "0x" ,
265
- storage = {},
266
- ),
223
+ slot_tload_nonzero_gas_price_result : Spec .TLOAD_GAS_COST ,
224
+ slot_tload_zero_gas_price_result : Spec .TLOAD_GAS_COST ,
225
+ slot_code_worked : 0x01 ,
226
+ }
227
+ )
267
228
}
268
229
269
- post : Dict [Address , Union [Account , object ]] = {}
270
-
271
- post [address_to ] = Account (
272
- storage = {
273
- slot_tload_nonzero_gas_price_result : Spec .TLOAD_GAS_COST ,
274
- slot_tload_zero_gas_price_result : Spec .TLOAD_GAS_COST ,
275
- slot_code_worked : 0x01 ,
276
- }
277
- )
278
-
279
230
tx = Transaction (
280
- nonce = 0 ,
231
+ sender = pre . fund_eoa ( 7_000_000_000_000_000_000 ) ,
281
232
to = address_to ,
282
233
gas_price = 10 ,
283
234
data = b"" ,
@@ -291,41 +242,29 @@ def test_basic_tload_gasprice(
291
242
@pytest .mark .valid_from ("Cancun" )
292
243
def test_basic_tload_after_store (
293
244
state_test : StateTestFiller ,
245
+ pre : Alloc ,
294
246
):
295
247
"""
296
248
Ported .json vectors:
297
249
298
250
(18_tloadAfterStoreFiller.yml)
299
251
tload from same slot after store returns 0
300
252
"""
301
- address_to = Address ("A00000000000000000000000000000000000000A" )
302
-
303
253
slot_tload_from_sstore_result = 1
304
254
slot_code_worked = 2
305
255
306
- pre = {
307
- address_to : Account (
308
- balance = 1000000000000000000 ,
309
- nonce = 0 ,
310
- code = Op .JUMPDEST ()
311
- # 18 test
312
- + Op .SSTORE (slot_tload_from_sstore_result , 22 )
313
- + Op .SSTORE (slot_tload_from_sstore_result , Op .TLOAD (slot_tload_from_sstore_result ))
314
- + Op .SSTORE (slot_code_worked , 1 ),
315
- storage = {
316
- slot_tload_from_sstore_result : 0xFF ,
317
- },
318
- ),
319
- TestAddress : Account (
320
- balance = 7000000000000000000 ,
321
- nonce = 0 ,
322
- code = "0x" ,
323
- storage = {},
324
- ),
325
- }
256
+ address_to = pre .deploy_contract (
257
+ code = Op .JUMPDEST ()
258
+ # 18 test
259
+ + Op .SSTORE (slot_tload_from_sstore_result , 22 )
260
+ + Op .SSTORE (slot_tload_from_sstore_result , Op .TLOAD (slot_tload_from_sstore_result ))
261
+ + Op .SSTORE (slot_code_worked , 1 ),
262
+ storage = {
263
+ slot_tload_from_sstore_result : 0xFF ,
264
+ },
265
+ )
326
266
327
267
post : Dict [Address , Union [Account , object ]] = {}
328
-
329
268
post [address_to ] = Account (
330
269
storage = {
331
270
slot_tload_from_sstore_result : 0x00 ,
@@ -334,7 +273,7 @@ def test_basic_tload_after_store(
334
273
)
335
274
336
275
tx = Transaction (
337
- nonce = 0 ,
276
+ sender = pre . fund_eoa ( 7_000_000_000_000_000_000 ) ,
338
277
to = address_to ,
339
278
gas_price = 10 ,
340
279
data = b"" ,
0 commit comments