Skip to content

Commit ae95b1b

Browse files
marioevzspencer-tb
andauthored
fix(tests): EIP-7825: Pre-Osaka tests consuming tx gas above cap (#1928)
* fix(tests): EIP-7825: Pre-Osaka tests consuming more than the tx gas limit cap * fix(tests): EIP-7825: Pre-Osaka BLS tests consuming more than the tx gas limit cap * fix: tox * docs: changelog * chore(tests): make blake2 use dynamic tx limit. * chore(tests): update slow deposit tests. * chore(tests): tstore run until out of gas test. --------- Co-authored-by: spencer-tb <[email protected]>
1 parent ebfd451 commit ae95b1b

File tree

11 files changed

+403
-162
lines changed

11 files changed

+403
-162
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Users can select any of the artifacts depending on their testing needs for their
135135
-[EIP-7939](https://eips.ethereum.org/EIPS/eip-7939) Add count leading zeros (CLZ) opcode tests for Osaka ([#1733](https://github.com/ethereum/execution-spec-tests/pull/1733)).
136136
-[EIP-7918](https://eips.ethereum.org/EIPS/eip-7918): Blob base fee bounded by execution cost test cases (initial), includes some adjustments to [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844) tests ([#1685](https://github.com/ethereum/execution-spec-tests/pull/1685)). Update the blob_base_cost ([#1915](https://github.com/ethereum/EIPs/pull/1915)).
137137
-[EIP-7934](https://eips.ethereum.org/EIPS/eip-7934): Add additional test cases for block RLP max limit with all typed transactions and for a log-creating transactions ([#1890](https://github.com/ethereum/execution-spec-tests/pull/1890)).
138+
-[EIP-7825](https://eips.ethereum.org/EIPS/eip-7825): Pre-Osaka tests have been updated to either (1) dynamically adapt to the transaction gas limit cap, or (2) reduce overall gas consumption to fit the new limit ([#1928](https://github.com/ethereum/EIPs/pull/1928)).
138139

139140
## [v4.5.0](https://github.com/ethereum/execution-spec-tests/releases/tag/v4.5.0) - 2025-05-14
140141

tests/cancun/eip1153_tstore/test_tstorage.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,25 +262,27 @@ class LoopRunUntilOutOfGasCases(PytestParameterEnum):
262262
}
263263

264264

265+
def max_tx_gas_limit(fork):
266+
"""Return the maximum transaction gas limit for the given fork."""
267+
tx_limit = fork.transaction_gas_limit_cap()
268+
return [tx_limit if tx_limit is not None else Environment().gas_limit]
269+
270+
265271
@LoopRunUntilOutOfGasCases.parametrize()
266272
@pytest.mark.slow()
273+
@pytest.mark.parametrize_by_fork("tx_gas_limit", max_tx_gas_limit)
267274
def test_run_until_out_of_gas(
268275
state_test: StateTestFiller,
269276
pre: Alloc,
277+
tx_gas_limit: int,
270278
repeat_bytecode: Bytecode,
271279
bytecode_repeat_times: int,
272280
):
273281
"""Use TSTORE over and over to different keys until we run out of gas."""
274-
env = Environment()
275-
276282
bytecode = Op.JUMPDEST + repeat_bytecode * bytecode_repeat_times + Op.JUMP(Op.PUSH0)
277283
code_address = pre.deploy_contract(code=bytecode)
278-
tx = Transaction(
279-
sender=pre.fund_eoa(),
280-
to=code_address,
281-
gas_limit=env.gas_limit,
282-
)
284+
tx = Transaction(sender=pre.fund_eoa(), to=code_address, gas_limit=tx_gas_limit)
283285
post = {
284286
code_address: Account(code=bytecode, storage={}),
285287
}
286-
state_test(env=env, pre=pre, tx=tx, post=post)
288+
state_test(pre=pre, tx=tx, post=post)

tests/cancun/eip6780_selfdestruct/test_selfdestruct_revert.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Transaction,
1919
compute_create_address,
2020
)
21-
from ethereum_test_tools.vm.opcode import Opcodes as Op
21+
from ethereum_test_tools import Opcodes as Op
2222

2323
REFERENCE_SPEC_GIT_PATH = "EIPS/eip-6780.md"
2424
REFERENCE_SPEC_VERSION = "1b6a0e94cc47e859b9866e570391cf37dc55059a"
@@ -414,7 +414,7 @@ def test_selfdestruct_created_in_same_tx_with_revert( # noqa SC200
414414
data=entry_code,
415415
sender=sender,
416416
to=None,
417-
gas_limit=20_000_000,
417+
gas_limit=500_000,
418418
)
419419

420420
state_test(env=env, pre=pre, post=post, tx=tx)
@@ -507,7 +507,7 @@ def test_selfdestruct_not_created_in_same_tx_with_revert(
507507
data=entry_code,
508508
sender=sender,
509509
to=None,
510-
gas_limit=20_000_000,
510+
gas_limit=500_000,
511511
)
512512

513513
state_test(env=env, pre=pre, post=post, tx=tx)

tests/istanbul/eip1344_chainid/test_chainid.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@
1515
@pytest.mark.valid_from("Istanbul")
1616
def test_chainid(state_test: StateTestFiller, pre: Alloc):
1717
"""Test CHAINID opcode."""
18-
env = Environment(
19-
fee_recipient="0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
20-
difficulty=0x20000,
21-
gas_limit=10000000000,
22-
number=1,
23-
timestamp=1000,
24-
)
18+
env = Environment()
2519

2620
contract_address = pre.deploy_contract(Op.SSTORE(1, Op.CHAINID) + Op.STOP)
2721
sender = pre.fund_eoa()
@@ -30,8 +24,7 @@ def test_chainid(state_test: StateTestFiller, pre: Alloc):
3024
ty=0x0,
3125
chain_id=0x01,
3226
to=contract_address,
33-
gas_limit=100000000,
34-
gas_price=10,
27+
gas_limit=100_000,
3528
sender=sender,
3629
)
3730

tests/istanbul/eip152_blake2/test_blake2.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
Test cases for [EIP-152: BLAKE2b compression precompile](https://eips.ethereum.org/EIPS/eip-152).
44
"""
55

6+
from typing import List
7+
68
import pytest
79

10+
from ethereum_test_forks import Fork
811
from ethereum_test_tools import (
912
Account,
1013
Alloc,
@@ -546,9 +549,22 @@ def test_blake2b_invalid_gas(
546549
state_test(env=env, pre=pre, post=post, tx=tx)
547550

548551

552+
def max_tx_gas_limit(fork: Fork) -> int:
553+
"""Maximum gas limit for a transaction (fork agnostic)."""
554+
tx_limit = fork.transaction_gas_limit_cap()
555+
if tx_limit is not None:
556+
return tx_limit
557+
return Environment().gas_limit
558+
559+
560+
def tx_gas_limits(fork: Fork) -> List[int]:
561+
"""List of tx gas limits."""
562+
return [max_tx_gas_limit(fork), 90_000, 110_000, 200_000]
563+
564+
549565
@pytest.mark.valid_from("Istanbul")
550566
@pytest.mark.parametrize("call_opcode", [Op.CALL, Op.CALLCODE])
551-
@pytest.mark.parametrize("gas_limit", [Environment().gas_limit, 90_000, 110_000, 200_000])
567+
@pytest.mark.parametrize_by_fork("gas_limit", tx_gas_limits)
552568
@pytest.mark.parametrize(
553569
["data", "output"],
554570
[
@@ -658,6 +674,7 @@ def test_blake2b_gas_limit(
658674

659675
@pytest.mark.valid_from("Istanbul")
660676
@pytest.mark.parametrize("call_opcode", [Op.CALL, Op.CALLCODE])
677+
@pytest.mark.parametrize_by_fork("gas_limit", lambda fork: [max_tx_gas_limit(fork)])
661678
@pytest.mark.parametrize(
662679
["data", "output"],
663680
[
@@ -742,13 +759,12 @@ def test_blake2b_large_gas_limit(
742759
state_test: StateTestFiller,
743760
pre: Alloc,
744761
call_opcode: Op,
762+
gas_limit: int,
745763
blake2b_contract_bytecode: Bytecode,
746764
data: Blake2bInput | str | bytes,
747765
output: ExpectedOutput,
748766
):
749767
"""Test BLAKE2b precompile with large gas limit."""
750-
env = Environment()
751-
752768
account = pre.deploy_contract(blake2b_contract_bytecode, storage={0: 0xDEADBEEF})
753769
sender = pre.fund_eoa()
754770

@@ -761,7 +777,7 @@ def test_blake2b_large_gas_limit(
761777
ty=0x0,
762778
to=account,
763779
data=data,
764-
gas_limit=env.gas_limit,
780+
gas_limit=gas_limit,
765781
protected=True,
766782
sender=sender,
767783
value=0,
@@ -776,4 +792,4 @@ def test_blake2b_large_gas_limit(
776792
}
777793
)
778794
}
779-
state_test(env=env, pre=pre, post=post, tx=tx)
795+
state_test(pre=pre, post=post, tx=tx)

tests/prague/eip2537_bls_12_381_precompiles/test_bls12_pairing.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ def test_valid_multi_inf(
154154
memory_expansion_gas_calculator = fork.memory_expansion_gas_calculator()
155155
extra_gas = 100_000
156156

157-
environment_gas_limit = Environment().gas_limit
157+
tx_gas_limit_cap = fork.transaction_gas_limit_cap()
158+
max_gas_limit = Environment().gas_limit if tx_gas_limit_cap is None else tx_gas_limit_cap
158159

159160
inf_data = Spec.INF_G1 + Spec.INF_G2
160161
input_data = inf_data
@@ -167,7 +168,7 @@ def test_valid_multi_inf(
167168
+ memory_expansion_gas_calculator(new_bytes=len(input_data + inf_data))
168169
+ precompile_gas
169170
)
170-
if new_tx_gas_limit > environment_gas_limit:
171+
if new_tx_gas_limit > max_gas_limit:
171172
break
172173
tx_gas_limit = new_tx_gas_limit
173174
input_data += inf_data
@@ -303,7 +304,8 @@ def test_invalid_multi_inf(
303304
memory_expansion_gas_calculator = fork.memory_expansion_gas_calculator()
304305
extra_gas = 100_000
305306

306-
environment_gas_limit = Environment().gas_limit
307+
tx_gas_limit_cap = fork.transaction_gas_limit_cap()
308+
max_gas_limit = Environment().gas_limit if tx_gas_limit_cap is None else tx_gas_limit_cap
307309

308310
inf_data = Spec.INF_G1 + Spec.INF_G2
309311
input_data = PointG1(Spec.P, 0) + Spec.INF_G2
@@ -316,7 +318,7 @@ def test_invalid_multi_inf(
316318
+ memory_expansion_gas_calculator(new_bytes=len(input_data + inf_data))
317319
+ precompile_gas
318320
)
319-
if new_tx_gas_limit > environment_gas_limit:
321+
if new_tx_gas_limit > max_gas_limit:
320322
break
321323
tx_gas_limit = new_tx_gas_limit
322324
input_data = inf_data + input_data

0 commit comments

Comments
 (0)