Skip to content

Commit a6475db

Browse files
committed
chore(test): cleanup / review for 8037 byte value updates
1 parent 1c7d28e commit a6475db

19 files changed

Lines changed: 162 additions & 68 deletions

File tree

packages/testing/src/execution_testing/forks/forks/eips/amsterdam/eip_8037.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ def _calculate_sstore_state_gas(
310310
Calculate updated SSTORE state gas cost.
311311
"""
312312
del gas_costs
313+
STATE_BYTES_PER_STORAGE_SET = 64 # noqa: N806
313314
metadata = opcode.metadata
314315
cpsb = cls.cost_per_state_byte()
315316

@@ -324,7 +325,7 @@ def _calculate_sstore_state_gas(
324325
and current_value != new_value
325326
and original_value == 0
326327
):
327-
return 64 * cpsb
328+
return STATE_BYTES_PER_STORAGE_SET * cpsb
328329
return 0
329330

330331
@classmethod
@@ -373,6 +374,7 @@ def _calculate_sstore_state_refund(
373374
to zero within the transaction; otherwise return 0.
374375
"""
375376
del gas_costs
377+
STATE_BYTES_PER_STORAGE_SET = 64 # noqa: N806
376378
metadata = opcode.metadata
377379
cpsb = cls.cost_per_state_byte()
378380

@@ -384,7 +386,7 @@ def _calculate_sstore_state_refund(
384386
if current_value != new_value:
385387
if original_value == new_value:
386388
if original_value == 0:
387-
return 64 * cpsb
389+
return STATE_BYTES_PER_STORAGE_SET * cpsb
388390
return 0
389391

390392
@classmethod
@@ -400,6 +402,8 @@ def _calculate_selfdestruct_state_refund(
400402
Code deposit: len(code) × cost_per_state_byte
401403
"""
402404
del gas_costs
405+
STATE_BYTES_PER_NEW_ACCOUNT = 120 # noqa: N806
406+
STATE_BYTES_PER_STORAGE_SET = 64 # noqa: N806
403407
metadata = opcode.metadata
404408
cpsb = cls.cost_per_state_byte()
405409

@@ -412,9 +416,11 @@ def _calculate_selfdestruct_state_refund(
412416
]
413417
state_refund = 0
414418
if self_destructed_account:
415-
state_refund = 120 * cpsb
419+
state_refund = STATE_BYTES_PER_NEW_ACCOUNT * cpsb
416420
state_refund += (
417-
64 * cpsb * self_destructed_account_storage_slot_count
421+
STATE_BYTES_PER_STORAGE_SET
422+
* cpsb
423+
* self_destructed_account_storage_slot_count
418424
)
419425
state_refund += cpsb * self_destructed_account_code_deposit
420426
return state_refund

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
@@ -2466,12 +2466,18 @@ def test_create_collision_burned_gas_counted_in_block_regular(
24662466

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

24762482
blockchain_test(
24772483
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

0 commit comments

Comments
 (0)