Skip to content

Commit 9c46de3

Browse files
committed
chore(test): cleanup / review for 8037 byte value updates
1 parent 81bc8e6 commit 9c46de3

13 files changed

Lines changed: 104 additions & 61 deletions

File tree

tests/amsterdam/eip7708_eth_transfer_logs/test_burn_logs.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def test_selfdestruct_to_self_same_tx(
8383
state_test: StateTestFiller,
8484
env: Environment,
8585
pre: Alloc,
86+
fork: Fork,
8687
sender: EOA,
8788
contract_balance: int,
8889
create_opcode: Op,
@@ -125,7 +126,9 @@ def test_selfdestruct_to_self_same_tx(
125126
sender=sender,
126127
to=factory,
127128
value=contract_balance,
128-
gas_limit=300_000,
129+
# Same-tx CREATE+SELFDESTRUCT charges NEW_ACCOUNT state gas
130+
# under EIP-8037 (0 otherwise).
131+
gas_limit=200_000 + fork.gas_costs().NEW_ACCOUNT,
129132
expected_receipt=TransactionReceipt(logs=expected_logs),
130133
)
131134

@@ -144,6 +147,7 @@ def test_selfdestruct_to_different_address_same_tx(
144147
state_test: StateTestFiller,
145148
env: Environment,
146149
pre: Alloc,
150+
fork: Fork,
147151
sender: EOA,
148152
contract_balance: int,
149153
create_opcode: Op,
@@ -189,7 +193,9 @@ def test_selfdestruct_to_different_address_same_tx(
189193
sender=sender,
190194
to=factory,
191195
value=contract_balance,
192-
gas_limit=300_000,
196+
# Same-tx CREATE+SELFDESTRUCT charges NEW_ACCOUNT state gas
197+
# under EIP-8037 (0 otherwise).
198+
gas_limit=200_000 + fork.gas_costs().NEW_ACCOUNT,
193199
expected_receipt=TransactionReceipt(logs=expected_logs),
194200
)
195201

@@ -222,6 +228,7 @@ def test_selfdestruct_same_tx_via_call(
222228
state_test: StateTestFiller,
223229
env: Environment,
224230
pre: Alloc,
231+
fork: Fork,
225232
sender: EOA,
226233
to_self: bool,
227234
call_twice: bool,
@@ -303,7 +310,9 @@ def test_selfdestruct_same_tx_via_call(
303310
sender=sender,
304311
to=factory,
305312
value=0,
306-
gas_limit=300_000,
313+
# CREATE-then-CALL with same-tx SELFDESTRUCT charges
314+
# NEW_ACCOUNT state gas under EIP-8037 (0 otherwise).
315+
gas_limit=200_000 + fork.gas_costs().NEW_ACCOUNT,
307316
expected_receipt=TransactionReceipt(logs=expected_logs),
308317
)
309318

tests/amsterdam/eip7708_eth_transfer_logs/test_fork_transition.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,14 @@ def test_burn_log_at_fork_transition(
119119
beneficiary: Account(balance=contract_balance * 3),
120120
}
121121

122-
# Same-tx CREATE+SELFDESTRUCT charges NEW_ACCOUNT state gas; the
123-
# pre-transition block has plenty of headroom. `fork` is a
124-
# TransitionFork here, so resolve to the post-transition fork
125-
# (timestamp 15_001) where the larger NEW_ACCOUNT applies.
126-
post_fork = fork.fork_at(timestamp=15_001)
122+
# `fork` is a TransitionFork here; resolve to the post-transition
123+
# fork (where the larger NEW_ACCOUNT applies) so the gas budget
124+
# covers the same-tx CREATE+SELFDESTRUCT on the post-transition
125+
# block. The pre-transition block has plenty of headroom.
126+
pre_transition_timestamp = 14_999
127+
transition_timestamp = 15_000
128+
post_transition_timestamp = 15_001
129+
post_fork = fork.fork_at(timestamp=post_transition_timestamp)
127130
gas_limit = 200_000 + post_fork.gas_costs().NEW_ACCOUNT
128131
blocks = [
129132
Block(
@@ -137,7 +140,13 @@ def test_burn_log_at_fork_transition(
137140
)
138141
],
139142
)
140-
for i, ts in enumerate([14_999, 15_000, 15_001])
143+
for i, ts in enumerate(
144+
[
145+
pre_transition_timestamp,
146+
transition_timestamp,
147+
post_transition_timestamp,
148+
]
149+
)
141150
]
142151

143152
blockchain_test(pre=pre, blocks=blocks, post=post)

tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_cross_index.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
BlockchainTestFiller,
2323
Bytecode,
2424
Fork,
25+
Header,
2526
Op,
2627
Transaction,
2728
)
@@ -275,9 +276,17 @@ def test_bal_noop_write_filtering(
275276
}
276277
)
277278

279+
# Header `gas_used = max(regular, state)` for the single tx; the
280+
# SSTORE metadata pins each transition so `regular_cost`/`state_cost`
281+
# return the actual fork-priced amount.
282+
expected_regular = intrinsic_cost + test_code.regular_cost(fork)
283+
expected_state = test_code.state_cost(fork)
278284
block = Block(
279285
txs=[tx],
280286
expected_block_access_list=expected_block_access_list,
287+
header_verify=Header(
288+
gas_used=max(expected_regular, expected_state),
289+
),
281290
)
282291

283292
blockchain_test(

tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,12 +2465,18 @@ def test_create_collision_burned_gas_counted_in_block_regular(
24652465

24662466
# CPSB-agnostic baseline: block_state_gas is zero for this tx, so
24672467
# header.gas_used equals the regular-gas total. The forwarded
2468-
# create_message_gas is `(gas_limit - NEW_ACCOUNT) * 63 // 64`,
2469-
# plus a CPSB-independent constant covering intrinsic + factory
2470-
# opcodes. A mutation that drops the burned create_message_gas
2471-
# from regular accounting would reduce this value.
2468+
# create_message_gas is `(gas_limit - NEW_ACCOUNT) * 63 // 64`
2469+
# (the regular gas the inner frame burns on collision); the
2470+
# remaining cpsb-independent term captures intrinsic + factory
2471+
# frame regular gas + the parts of CREATE not absorbed by the
2472+
# 63/64 forwarding split. A mutation that drops the burned
2473+
# create_message_gas from regular accounting would reduce this
2474+
# value.
24722475
new_account = fork.gas_costs().NEW_ACCOUNT
2473-
baseline_gas_used = (gas_limit - new_account) * 63 // 64 + 472
2476+
cpsb_independent_overhead = 472
2477+
baseline_gas_used = (
2478+
gas_limit - new_account
2479+
) * 63 // 64 + cpsb_independent_overhead
24742480

24752481
blockchain_test(
24762482
pre=pre,

tests/cancun/eip4788_beacon_root/test_beacon_root_contract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ def test_multi_block_beacon_root_timestamp_calls(
451451
all_timestamps: List[int] = []
452452

453453
sender = pre.fund_eoa()
454+
intrinsic_calc = fork.transaction_intrinsic_cost_calculator()
454455

455456
for timestamp, beacon_root, _i in zip(
456457
timestamps,
@@ -509,7 +510,6 @@ def test_multi_block_beacon_root_timestamp_calls(
509510
post[current_call_account_address] = Account(
510511
storage=current_call_account_expected_storage,
511512
)
512-
intrinsic_calc = fork.transaction_intrinsic_cost_calculator()
513513
# Bytecode's regular+state cost + N forwarded call_gas envelopes
514514
# (one per `t` in all_timestamps) + EIP-1706 stipend slack.
515515
block_gas_limit = (

tests/cancun/eip4844_blobs/test_blobhash_opcode_contexts.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,10 @@ def test_blobhash_opcode_contexts(
313313
case _:
314314
raise Exception(f"Unknown test case {test_case}")
315315

316-
# The 500k figure pre-dates EIP-8037 and was empirically chosen to cover
317-
# all branches of this test (simple SSTOREs through to CREATE/CREATE2
318-
# initcode + deploy). Under EIP-8037 each branch's per-blob SSTOREs add a
319-
# `sstore_state_gas()` of state work; bump by that per blob so the budget
320-
# remains a precise envelope rather than a rough magic number.
316+
# Budget covers all branches (simple SSTOREs, CREATE / CREATE2
317+
# initcode + deploy) plus per-blob SSTOREs whose state cost
318+
# scales with cpsb under EIP-8037 (`sstore_state_gas()` is 0
319+
# otherwise).
321320
gas_limit = 500_000 + max_blobs_per_tx * fork.sstore_state_gas()
322321
state_test(
323322
pre=pre,

tests/common/precompile_fixtures.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,9 @@ def tx_gas_limit(fork: Fork, input_data: bytes, precompile_gas: int) -> int:
183183
fork.transaction_intrinsic_cost_calculator()
184184
)
185185
memory_expansion_gas_calculator = fork.memory_expansion_gas_calculator()
186-
# `call_contract_code` performs up to 3 SSTOREs (succeeds-flag,
187-
# output-length, output-hash) per call. Pre-EIP-8037 each SSTORE
188-
# fits comfortably in the 100_000 budget; under EIP-8037 each
189-
# SSTORE additionally consumes `fork.sstore_state_gas()` of state
190-
# gas, so size the budget against the actual per-fork cost.
186+
# `call_contract_code` performs up to 3 SSTOREs per call
187+
# (succeeds-flag, output-length, output-hash); under EIP-8037
188+
# each adds `sstore_state_gas()` of state work (0 otherwise).
191189
extra_gas = 100_000 + 3 * fork.sstore_state_gas()
192190
return (
193191
extra_gas

tests/constantinople/eip145_bitwise_shift/test_shift_combinations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ def test_combinations(
8585
+ Op.STOP,
8686
)
8787

88-
# Osaka (EIP-7825) caps tx gas at 16,777,216. Amsterdam (EIP-8037)
89-
# lifts the cap and increases SSTORE state gas, needing 25M for
90-
# 401 cold zero-to-nonzero SSTOREs (cpsb=1530).
88+
# Osaka (EIP-7825) caps tx gas at 16,777,216; Amsterdam
89+
# (EIP-8037) lifts that cap and lets state gas fund the test's
90+
# ~400 SSTOREs from the reservoir.
9191
# TODO: auto gas limit will remove this
9292
gas_limit = 16_000_000
9393
if fork.is_eip_enabled(8037):

tests/frontier/create/test_create_one_byte.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Transaction,
1818
compute_create_address,
1919
)
20-
from execution_testing.forks import London, Osaka
20+
from execution_testing.forks import London
2121

2222

2323
@pytest.mark.ported_from(
@@ -101,14 +101,16 @@ def test_create_one_byte(
101101
expect_post[opcode] = created_accounts[opcode]
102102
expect_post[256] = 1
103103

104-
# Osaka (EIP-7825) caps transaction gas limit at 16,777,216.
105-
# Amsterdam (EIP-8037) adds state gas via the reservoir on top of
106-
# the cap. NEW_ACCOUNT and sstore_state_gas are 0 pre-EIP-8037 and
107-
# scale with cpsb on Amsterdam, keeping this CPSB-agnostic.
104+
# Osaka (EIP-7825) caps transaction gas at
105+
# `fork.transaction_gas_limit_cap()`. Amsterdam (EIP-8037) adds
106+
# state gas via the reservoir on top of the cap (256 CREATEs and
107+
# 257 first-time SSTOREs in this test). Pre-Osaka there's no cap.
108+
gas_cap = fork.transaction_gas_limit_cap()
108109
if fork.is_eip_enabled(8037):
109-
gas_limit = 16_000_000 + 256 * new_account + 257 * sstore_state
110-
elif fork >= Osaka:
111-
gas_limit = 16_000_000
110+
assert gas_cap is not None
111+
gas_limit = gas_cap + 256 * new_account + 257 * sstore_state
112+
elif gas_cap is not None:
113+
gas_limit = gas_cap
112114
else:
113115
gas_limit = 50_000_000
114116

tests/prague/eip7002_el_triggerable_withdrawals/helpers.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,15 @@ def transactions(self, fork: Fork | None = None) -> List[Transaction]:
209209
gas_limit = self.tx_gas_limit
210210
if fork is not None and fork.is_eip_enabled(8037):
211211
# Per request the system contract writes 3 entry slots
212-
# (source, pubkey, amount); it also bumps a queue tail/count
213-
# slot once per call. Cover `3*N + 2` SSTOREs (one tail
214-
# slot + one slack slot) of state-set work; the term is 0
215-
# pre-EIP-8037 and scales with cpsb on Amsterdam, keeping
216-
# this CPSB-agnostic.
217-
gas_limit += (len(self.requests) * 3 + 2) * fork.sstore_state_gas()
212+
# (source, pubkey, amount); plus a queue-tail bump and
213+
# one slot of headroom per tx.
214+
sstores_per_request = 3
215+
queue_tail_and_slack_sstores = 2
216+
sstores = (
217+
len(self.requests) * sstores_per_request
218+
+ queue_tail_and_slack_sstores
219+
)
220+
gas_limit += sstores * fork.sstore_state_gas()
218221
return [
219222
Transaction(
220223
gas_limit=gas_limit,

0 commit comments

Comments
 (0)