14
14
Alloc ,
15
15
AuthorizationTuple ,
16
16
Bytes ,
17
- Hash ,
18
17
StateTestFiller ,
19
18
Transaction ,
20
- add_kzg_version ,
19
+ TransactionReceipt ,
21
20
)
22
21
from ethereum_test_tools import Opcodes as Op
23
22
24
- from ...cancun .eip4844_blobs .spec import Spec as EIP_4844_Spec
25
23
from .helpers import DataTestType
26
24
from .spec import ref_spec_7623
27
25
@@ -39,7 +37,7 @@ def data_test_type() -> DataTestType:
39
37
40
38
41
39
@pytest .fixture
42
- def authorization_existing_authority () -> bool :
40
+ def authorization_refund () -> bool :
43
41
"""
44
42
Force the authority of the authorization tuple to be an existing authority in order
45
43
to produce a refund.
@@ -68,27 +66,31 @@ def to(
68
66
"""Return a contract that when executed results in refunds due to storage clearing."""
69
67
return pre .deploy_contract (Op .SSTORE (0 , 0 ) + Op .STOP , storage = {0 : 1 })
70
68
69
+ @pytest .fixture
70
+ def refund (self , fork : Fork , ty : int ) -> int :
71
+ """Return the refund gas of the transaction."""
72
+ gas_costs = fork .gas_costs ()
73
+ refund = gas_costs .R_STORAGE_CLEAR
74
+ if ty == 4 :
75
+ refund += gas_costs .R_AUTHORIZATION_EXISTING_AUTHORITY
76
+ return refund
77
+
71
78
@pytest .mark .parametrize (
72
- "ty,protected,blob_versioned_hashes, authorization_list" ,
79
+ "ty,protected,authorization_list" ,
73
80
[
74
- pytest .param (0 , False , None , None , id = "type_0_unprotected" ),
75
- pytest .param (0 , True , None , None , id = "type_0_protected" ),
76
- pytest .param (1 , True , None , None , id = "type_1" ),
77
- pytest .param (2 , True , None , None , id = "type_2" ),
81
+ pytest .param (0 , False , None , id = "type_0_unprotected" ),
82
+ pytest .param (0 , True , None , id = "type_0_protected" ),
83
+ pytest .param (1 , True , None , id = "type_1" ),
84
+ pytest .param (2 , True , None , id = "type_2" ),
78
85
pytest .param (
79
86
3 ,
80
87
True ,
81
- add_kzg_version (
82
- [Hash (1 )],
83
- EIP_4844_Spec .BLOB_COMMITMENT_VERSION_KZG ,
84
- ),
85
88
None ,
86
89
id = "type_3" ,
87
90
),
88
91
pytest .param (
89
92
4 ,
90
93
True ,
91
- None ,
92
94
[Address (1 )],
93
95
id = "type_4_with_authorization_refund" ,
94
96
),
@@ -109,13 +111,16 @@ def test_gas_refunds_from_data_floor(
109
111
state_test : StateTestFiller ,
110
112
pre : Alloc ,
111
113
tx : Transaction ,
114
+ tx_floor_data_cost : int ,
115
+ refund : int ,
112
116
) -> None :
113
117
"""
114
118
Test gas refunds deducted from the data floor.
115
119
116
120
I.e. the used gas by the intrinsic gas cost plus the execution cost is less than the data
117
121
floor, hence data floor is used, and then the gas refunds are applied to the data floor.
118
122
"""
123
+ tx .expected_receipt = TransactionReceipt (gas_used = tx_floor_data_cost - refund )
119
124
state_test (
120
125
pre = pre ,
121
126
post = {
@@ -143,27 +148,36 @@ def to(
143
148
"""Return a contract that consumes all gas when executed by calling an invalid opcode."""
144
149
return pre .deploy_contract (Op .INVALID )
145
150
151
+ @pytest .fixture
152
+ def refund (
153
+ self ,
154
+ fork : Fork ,
155
+ ty : int ,
156
+ authorization_refund : bool ,
157
+ ) -> int :
158
+ """Return the refund gas of the transaction."""
159
+ gas_costs = fork .gas_costs ()
160
+ refund = 0
161
+ if ty == 4 and authorization_refund :
162
+ refund += gas_costs .R_AUTHORIZATION_EXISTING_AUTHORITY
163
+ return refund
164
+
146
165
@pytest .mark .parametrize (
147
- "ty,protected,blob_versioned_hashes, authorization_list" ,
166
+ "ty,protected,authorization_list" ,
148
167
[
149
- pytest .param (0 , False , None , None , id = "type_0_unprotected" ),
150
- pytest .param (0 , True , None , None , id = "type_0_protected" ),
151
- pytest .param (1 , True , None , None , id = "type_1" ),
152
- pytest .param (2 , True , None , None , id = "type_2" ),
168
+ pytest .param (0 , False , None , id = "type_0_unprotected" ),
169
+ pytest .param (0 , True , None , id = "type_0_protected" ),
170
+ pytest .param (1 , True , None , id = "type_1" ),
171
+ pytest .param (2 , True , None , id = "type_2" ),
153
172
pytest .param (
154
173
3 ,
155
174
True ,
156
- add_kzg_version (
157
- [Hash (1 )],
158
- EIP_4844_Spec .BLOB_COMMITMENT_VERSION_KZG ,
159
- ),
160
175
None ,
161
176
id = "type_3" ,
162
177
),
163
178
pytest .param (
164
179
4 ,
165
180
True ,
166
- None ,
167
181
[Address (1 )],
168
182
id = "type_4_with_authorization_refund" ,
169
183
),
@@ -184,8 +198,10 @@ def test_full_gas_consumption(
184
198
state_test : StateTestFiller ,
185
199
pre : Alloc ,
186
200
tx : Transaction ,
201
+ refund : int ,
187
202
) -> None :
188
203
"""Test executing a transaction that fully consumes its execution gas allocation."""
204
+ tx .expected_receipt = TransactionReceipt (gas_used = tx .gas_limit - refund )
189
205
state_test (
190
206
pre = pre ,
191
207
post = {},
@@ -201,6 +217,20 @@ def contract_creating_tx(self) -> bool:
201
217
"""Use a constant in order to avoid circular fixture dependencies."""
202
218
return False
203
219
220
+ @pytest .fixture
221
+ def refund (
222
+ self ,
223
+ fork : Fork ,
224
+ ty : int ,
225
+ authorization_refund : bool ,
226
+ ) -> int :
227
+ """Return the refund gas of the transaction."""
228
+ gas_costs = fork .gas_costs ()
229
+ refund = 0
230
+ if ty == 4 and authorization_refund :
231
+ refund += gas_costs .R_AUTHORIZATION_EXISTING_AUTHORITY
232
+ return refund
233
+
204
234
@pytest .fixture
205
235
def to (
206
236
self ,
@@ -209,19 +239,14 @@ def to(
209
239
tx_data : Bytes ,
210
240
access_list : List [AccessList ] | None ,
211
241
authorization_list : List [AuthorizationTuple ] | None ,
242
+ tx_floor_data_cost : int ,
212
243
) -> Address | None :
213
244
"""
214
245
Return a contract that consumes almost all the gas before reaching the
215
246
floor data cost.
216
247
"""
217
248
intrinsic_gas_cost_calculator = fork .transaction_intrinsic_cost_calculator ()
218
- data_floor = intrinsic_gas_cost_calculator (
219
- calldata = tx_data ,
220
- contract_creation = False ,
221
- access_list = access_list ,
222
- authorization_list_or_count = authorization_list ,
223
- )
224
- execution_gas = data_floor - intrinsic_gas_cost_calculator (
249
+ execution_gas = tx_floor_data_cost - intrinsic_gas_cost_calculator (
225
250
calldata = tx_data ,
226
251
contract_creation = False ,
227
252
access_list = access_list ,
@@ -233,35 +258,29 @@ def to(
233
258
return pre .deploy_contract ((Op .JUMPDEST * (execution_gas - 1 )) + Op .STOP )
234
259
235
260
@pytest .mark .parametrize (
236
- "ty,protected,blob_versioned_hashes, authorization_list,authorization_existing_authority " ,
261
+ "ty,protected,authorization_list,authorization_refund " ,
237
262
[
238
- pytest .param (0 , False , None , None , False , id = "type_0_unprotected" ),
239
- pytest .param (0 , True , None , None , False , id = "type_0_protected" ),
240
- pytest .param (1 , True , None , None , False , id = "type_1" ),
241
- pytest .param (2 , True , None , None , False , id = "type_2" ),
263
+ pytest .param (0 , False , None , False , id = "type_0_unprotected" ),
264
+ pytest .param (0 , True , None , False , id = "type_0_protected" ),
265
+ pytest .param (1 , True , None , False , id = "type_1" ),
266
+ pytest .param (2 , True , None , False , id = "type_2" ),
242
267
pytest .param (
243
268
3 ,
244
269
True ,
245
- add_kzg_version (
246
- [Hash (1 )],
247
- EIP_4844_Spec .BLOB_COMMITMENT_VERSION_KZG ,
248
- ),
249
270
None ,
250
271
False ,
251
272
id = "type_3" ,
252
273
),
253
274
pytest .param (
254
275
4 ,
255
276
True ,
256
- None ,
257
277
[Address (1 )],
258
278
False ,
259
279
id = "type_4" ,
260
280
),
261
281
pytest .param (
262
282
4 ,
263
283
True ,
264
- None ,
265
284
[Address (1 )],
266
285
True ,
267
286
id = "type_4_with_authorization_refund" ,
@@ -282,8 +301,11 @@ def test_gas_consumption_below_data_floor(
282
301
state_test : StateTestFiller ,
283
302
pre : Alloc ,
284
303
tx : Transaction ,
304
+ tx_floor_data_cost : int ,
305
+ refund : int ,
285
306
) -> None :
286
307
"""Test executing a transaction that almost consumes the floor data cost."""
308
+ tx .expected_receipt = TransactionReceipt (gas_used = tx_floor_data_cost - refund )
287
309
state_test (
288
310
pre = pre ,
289
311
post = {},
0 commit comments