@@ -40,12 +40,38 @@ def call_contract_post_storage() -> Storage:
40
40
41
41
42
42
@pytest .fixture
43
- def call_succeeds () -> bool :
43
+ def total_tx_gas_needed (
44
+ fork : Fork , modexp_expected : bytes , modexp_input : ModExpInput , precompile_gas : int
45
+ ) -> int :
46
+ """Calculate total tx gas needed for the transaction."""
47
+ intrinsic_gas_cost_calculator = fork .transaction_intrinsic_cost_calculator ()
48
+ memory_expansion_gas_calculator = fork .memory_expansion_gas_calculator ()
49
+ sstore_gas = fork .gas_costs ().G_STORAGE_SET * (len (modexp_expected ) // 32 )
50
+ extra_gas = 100_000
51
+
52
+ return (
53
+ extra_gas
54
+ + intrinsic_gas_cost_calculator (calldata = bytes (modexp_input ))
55
+ + memory_expansion_gas_calculator (new_bytes = len (bytes (modexp_input )))
56
+ + precompile_gas
57
+ + sstore_gas
58
+ )
59
+
60
+
61
+ @pytest .fixture
62
+ def exceeds_tx_gas_cap (total_tx_gas_needed : int , fork : Fork ) -> bool :
63
+ """Determine if total gas requirements exceed transaction gas cap."""
64
+ tx_gas_limit_cap = fork .transaction_gas_limit_cap ()
65
+ return tx_gas_limit_cap is not None and total_tx_gas_needed > tx_gas_limit_cap
66
+
67
+
68
+ @pytest .fixture
69
+ def call_succeeds (exceeds_tx_gas_cap : bool ) -> bool :
44
70
"""
45
71
By default, depending on the expected output, we can deduce if the call is expected to succeed
46
- or fail.
72
+ or fail. Under EIP-7825, transactions requiring more gas than the cap should fail.
47
73
"""
48
- return True
74
+ return not exceeds_tx_gas_cap
49
75
50
76
51
77
@pytest .fixture
@@ -111,7 +137,7 @@ def gas_measure_contract(
111
137
Op .CALLDATACOPY (dest_offset = 0 , offset = 0 , size = Op .CALLDATASIZE )
112
138
+ Op .SSTORE (call_contract_post_storage .store_next (call_succeeds ), call_result_measurement )
113
139
+ Op .SSTORE (
114
- call_contract_post_storage .store_next (len (modexp_expected )),
140
+ call_contract_post_storage .store_next (len (modexp_expected ) if call_succeeds else 0 ),
115
141
Op .RETURNDATASIZE (),
116
142
)
117
143
)
@@ -174,28 +200,12 @@ def tx(
174
200
175
201
176
202
@pytest .fixture
177
- def tx_gas_limit (
178
- fork : Fork , modexp_expected : bytes , modexp_input : ModExpInput , precompile_gas : int
179
- ) -> int :
203
+ def tx_gas_limit (total_tx_gas_needed : int , fork : Fork ) -> int :
180
204
"""Transaction gas limit used for the test (Can be overridden in the test)."""
181
- intrinsic_gas_cost_calculator = fork .transaction_intrinsic_cost_calculator ()
182
- memory_expansion_gas_calculator = fork .memory_expansion_gas_calculator ()
183
- sstore_gas = fork .gas_costs ().G_STORAGE_SET * (len (modexp_expected ) // 32 )
184
- extra_gas = 100_000
185
-
186
- total_gas = (
187
- extra_gas
188
- + intrinsic_gas_cost_calculator (calldata = bytes (modexp_input ))
189
- + memory_expansion_gas_calculator (new_bytes = len (bytes (modexp_input )))
190
- + precompile_gas
191
- + sstore_gas
192
- )
193
-
194
205
tx_gas_limit_cap = fork .transaction_gas_limit_cap ()
195
-
196
206
if tx_gas_limit_cap is not None :
197
- return min (tx_gas_limit_cap , total_gas )
198
- return total_gas
207
+ return min (tx_gas_limit_cap , total_tx_gas_needed )
208
+ return total_tx_gas_needed
199
209
200
210
201
211
@pytest .fixture
0 commit comments