@@ -563,9 +563,12 @@ def test_extcodehash_dynamic_account_overwrite(
563563 target_storage [target_storage_slot ] = 1
564564
565565 sender = pre .fund_eoa ()
566- gas_limit = 400_000
567- if fork .is_eip_enabled (8037 ):
568- gas_limit = 1_000_000
566+ # Test does ~10 first-time SSTOREs plus a CREATE2 (NEW_ACCOUNT)
567+ # in the caller. Both terms are 0 pre-EIP-8037 and scale with cpsb
568+ # on Amsterdam, keeping this CPSB-agnostic.
569+ gas_limit = (
570+ 400_000 + fork .gas_costs ().NEW_ACCOUNT + 10 * fork .sstore_state_gas ()
571+ )
569572
570573 tx = Transaction (
571574 sender = sender ,
@@ -1352,19 +1355,22 @@ def test_extcodehash_call_to_selfdestruct(
13521355
13531356 call_succeeds = call_opcode != Op .STATICCALL
13541357
1358+ # SELFDESTRUCT to a nonexistent beneficiary creates a new account
1359+ # whose state gas scales with cpsb on Amsterdam. Forward enough so
1360+ # the inner CALL still completes when NEW_ACCOUNT grows.
1361+ new_account = fork .gas_costs ().NEW_ACCOUNT
1362+ sstore_state = fork .sstore_state_gas ()
13551363 code = Op .SSTORE (
13561364 storage .store_next (int (call_succeeds )),
1357- call_opcode (address = target , gas = 165_000 ),
1365+ call_opcode (address = target , gas = 165_000 + new_account ),
13581366 ) + Op .SSTORE (
13591367 storage .store_next (target_code .keccak256 ()),
13601368 Op .EXTCODEHASH (target ),
13611369 )
13621370
13631371 code_address = pre .deploy_contract (code , storage = storage .canary ())
13641372
1365- gas_limit = 400_000
1366- if fork .is_eip_enabled (8037 ):
1367- gas_limit = 1_000_000
1373+ gas_limit = 400_000 + new_account + 2 * sstore_state
13681374 tx = Transaction (
13691375 sender = pre .fund_eoa (),
13701376 to = code_address ,
@@ -1578,9 +1584,11 @@ def inner_extcode_checks() -> Bytecode:
15781584 )
15791585 outer = pre .deploy_contract (outer_code , storage = outer_storage .canary ())
15801586
1581- gas_limit = 400_000
1582- if fork .is_eip_enabled (8037 ):
1583- gas_limit = 1_000_000
1587+ # Test does ~10 first-time SSTOREs (across inner and outer) plus a
1588+ # CREATE2 (NEW_ACCOUNT). Both terms scale with cpsb on Amsterdam.
1589+ gas_limit = (
1590+ 400_000 + fork .gas_costs ().NEW_ACCOUNT + 10 * fork .sstore_state_gas ()
1591+ )
15841592 tx = Transaction (
15851593 sender = pre .fund_eoa (),
15861594 to = outer ,
@@ -1639,9 +1647,14 @@ def test_extcodehash_subcall_selfdestruct(
16391647 selfdestruct_code = Op .SELFDESTRUCT (beneficiary )
16401648 target_c = pre .deploy_contract (selfdestruct_code )
16411649
1650+ # SELFDESTRUCT to a nonexistent beneficiary creates a new account
1651+ # whose state gas scales with cpsb on Amsterdam.
1652+ new_account = fork .gas_costs ().NEW_ACCOUNT
1653+ sstore_state = fork .sstore_state_gas ()
1654+
16421655 # A: executes C's code in A's context via CALLCODE/DELEGATECALL
16431656 a_code = call_opcode (
1644- gas = 350_000 ,
1657+ gas = 350_000 + new_account ,
16451658 address = target_c ,
16461659 ret_size = 32 ,
16471660 )
@@ -1682,12 +1695,12 @@ def extcode_checks(target: Address | Bytecode) -> Bytecode:
16821695 code += extcode_checks (a_target )
16831696 code += Op .SSTORE (
16841697 storage .store_next (1 ),
1685- Op .CALL (gas = 350_000 , address = a_target ),
1698+ Op .CALL (gas = 350_000 + new_account , address = a_target ),
16861699 )
16871700 code += extcode_checks (a_target )
16881701 code += Op .SSTORE (
16891702 storage .store_next (1 ),
1690- Op .CALL (gas = 350_000 , address = a_target ),
1703+ Op .CALL (gas = 350_000 + new_account , address = a_target ),
16911704 )
16921705
16931706 code_address = pre .deploy_contract (code , storage = storage .canary ())
@@ -1696,9 +1709,8 @@ def extcode_checks(target: Address | Bytecode) -> Bytecode:
16961709 a = compute_create_address (address = code_address , nonce = 1 )
16971710 storage [created_slot ] = a
16981711
1699- gas_limit = 500_000
1700- if fork .is_eip_enabled (8037 ):
1701- gas_limit = 1_000_000
1712+ # Test does up to ~7 first-time SSTOREs plus a CREATE for dynamic A.
1713+ gas_limit = 500_000 + new_account + 7 * sstore_state
17021714 tx = Transaction (
17031715 sender = pre .fund_eoa (),
17041716 to = code_address ,
@@ -1757,6 +1769,12 @@ def test_extcodehash_subcall_create2_oog(
17571769 deploy_code_bytes = bytes (deploy_code )
17581770 initcode = Initcode (deploy_code = deploy_code )
17591771
1772+ # CREATE2 charges NEW_ACCOUNT state gas; the deploy_code's SSTORE
1773+ # also charges first-time SSTORE state gas. Both scale with cpsb
1774+ # on Amsterdam.
1775+ new_account = fork .gas_costs ().NEW_ACCOUNT
1776+ sstore_state = fork .sstore_state_gas ()
1777+
17601778 # Factory: CREATE2, optionally consume all gas to trigger OOG.
17611779 factory_code = Om .MSTORE (initcode , 0 ) + Op .MSTORE (
17621780 0 , Op .CREATE2 (value = 0 , offset = 0 , size = len (initcode ), salt = 0 )
@@ -1777,7 +1795,7 @@ def test_extcodehash_subcall_create2_oog(
17771795 storage .store_next (int (not oog ), "call_result" ),
17781796 call_opcode (
17791797 address = factory ,
1780- gas = 200_000 ,
1798+ gas = 200_000 + new_account + sstore_state ,
17811799 ret_offset = 0 ,
17821800 ret_size = 32 ,
17831801 ),
@@ -1813,9 +1831,8 @@ def test_extcodehash_subcall_create2_oog(
18131831 else :
18141832 post [created ] = Account (nonce = 1 , code = deploy_code )
18151833
1816- gas_limit = 500_000
1817- if fork .is_eip_enabled (8037 ):
1818- gas_limit = 1_000_000
1834+ # Caller does ~5 first-time SSTOREs plus the inner CALL+CREATE2.
1835+ gas_limit = 500_000 + new_account + 5 * sstore_state
18191836 tx = Transaction (
18201837 sender = pre .fund_eoa (),
18211838 to = code_address ,
0 commit comments