Skip to content

Commit 5d10cac

Browse files
committed
chore(tests): fix modexp conftest for tx gas limit cap.
1 parent bce61c1 commit 5d10cac

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

tests/osaka/eip7883_modexp_gas_increase/conftest.py

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,38 @@ def call_contract_post_storage() -> Storage:
4040

4141

4242
@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:
4470
"""
4571
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.
4773
"""
48-
return True
74+
return not exceeds_tx_gas_cap
4975

5076

5177
@pytest.fixture
@@ -111,7 +137,7 @@ def gas_measure_contract(
111137
Op.CALLDATACOPY(dest_offset=0, offset=0, size=Op.CALLDATASIZE)
112138
+ Op.SSTORE(call_contract_post_storage.store_next(call_succeeds), call_result_measurement)
113139
+ 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),
115141
Op.RETURNDATASIZE(),
116142
)
117143
)
@@ -174,28 +200,12 @@ def tx(
174200

175201

176202
@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:
180204
"""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-
194205
tx_gas_limit_cap = fork.transaction_gas_limit_cap()
195-
196206
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
199209

200210

201211
@pytest.fixture

0 commit comments

Comments
 (0)