@@ -1844,15 +1844,16 @@ def test_create_code_deposit_oog_refunds_state_gas(
18441844 ],
18451845)
18461846@pytest .mark .valid_from ("EIP8037" )
1847- def test_failed_create_tx_state_gas_dominates (
1847+ def test_failed_create_tx_refunds_intrinsic_new_account (
18481848 blockchain_test : BlockchainTestFiller ,
18491849 pre : Alloc ,
18501850 fork : Fork ,
18511851 init_code : Bytecode ,
18521852) -> None :
18531853 """
1854- Verify the header gas is set by intrinsic state gas when a
1855- creation tx fails with a tight regular budget.
1854+ Verify the NEW_ACCOUNT × CPSB portion of intrinsic_state_gas is
1855+ refunded on creation-tx revert/halt, so block state-gas excludes
1856+ it and header gas_used reflects only the regular component.
18561857 """
18571858 intrinsic_calc = fork .transaction_intrinsic_cost_calculator ()
18581859 create_state_gas = fork .create_state_gas (code_size = 0 )
@@ -1863,9 +1864,12 @@ def test_failed_create_tx_state_gas_dominates(
18631864 intrinsic_regular = intrinsic_total - create_state_gas
18641865 gas_limit = intrinsic_total + 1000
18651866
1866- assert intrinsic_regular + 1000 < create_state_gas , (
1867- "tight gas budget must keep block_regular below create_state_gas"
1868- )
1867+ if init_code == Op .INVALID :
1868+ regular_consumed = gas_limit - intrinsic_total
1869+ else :
1870+ regular_consumed = init_code .regular_cost (fork )
1871+
1872+ expected_gas_used = intrinsic_regular + regular_consumed
18691873
18701874 tx = Transaction (
18711875 to = None ,
@@ -1879,7 +1883,54 @@ def test_failed_create_tx_state_gas_dominates(
18791883 blocks = [
18801884 Block (
18811885 txs = [tx ],
1882- header_verify = Header (gas_used = create_state_gas ),
1886+ header_verify = Header (gas_used = expected_gas_used ),
1887+ ),
1888+ ],
1889+ post = {},
1890+ )
1891+
1892+
1893+ @pytest .mark .pre_alloc_mutable ()
1894+ @pytest .mark .valid_from ("EIP8037" )
1895+ def test_create_tx_collision_refunds_intrinsic_new_account (
1896+ blockchain_test : BlockchainTestFiller ,
1897+ pre : Alloc ,
1898+ fork : Fork ,
1899+ ) -> None :
1900+ """
1901+ Verify the NEW_ACCOUNT × CPSB portion of intrinsic_state_gas is
1902+ refunded on creation-tx address collision, so block state-gas
1903+ excludes it and header gas_used reflects only the regular
1904+ consumption (full forwarded gas, no initcode runs).
1905+ """
1906+ intrinsic_calc = fork .transaction_intrinsic_cost_calculator ()
1907+ create_state_gas = fork .create_state_gas (code_size = 0 )
1908+
1909+ init_code = Op .STOP
1910+ intrinsic_total = intrinsic_calc (
1911+ calldata = bytes (init_code ), contract_creation = True
1912+ )
1913+ gas_limit = intrinsic_total + 1000
1914+
1915+ sender = pre .fund_eoa ()
1916+ collision_target = compute_create_address (address = sender , nonce = 0 )
1917+ pre [collision_target ] = Account (nonce = 1 )
1918+
1919+ expected_gas_used = gas_limit - create_state_gas
1920+
1921+ tx = Transaction (
1922+ to = None ,
1923+ data = init_code ,
1924+ gas_limit = gas_limit ,
1925+ sender = sender ,
1926+ )
1927+
1928+ blockchain_test (
1929+ pre = pre ,
1930+ blocks = [
1931+ Block (
1932+ txs = [tx ],
1933+ header_verify = Header (gas_used = expected_gas_used ),
18831934 ),
18841935 ],
18851936 post = {},
@@ -2131,11 +2182,6 @@ def test_inner_create_succeeds_code_deposit_state_gas(
21312182 initcode_gas = initcode .gas_cost (fork )
21322183 gas_limit = intrinsic_total + initcode_gas + inner_code_deposit + 1000
21332184
2134- if outer_outcome == "succeeds" :
2135- expected_state = outer_state_gas + inner_state_gas
2136- else :
2137- expected_state = outer_state_gas
2138-
21392185 create_address = compute_create_address (address = sender , nonce = 0 )
21402186
21412187 tx = Transaction (
@@ -2147,19 +2193,15 @@ def test_inner_create_succeeds_code_deposit_state_gas(
21472193
21482194 if outer_outcome == "succeeds" :
21492195 post : dict = {create_address : Account (code = b"" )}
2196+ block = Block (
2197+ txs = [tx ],
2198+ header_verify = Header (gas_used = outer_state_gas + inner_state_gas ),
2199+ )
21502200 else :
21512201 post = {create_address : Account .NONEXISTENT }
2202+ block = Block (txs = [tx ])
21522203
2153- blockchain_test (
2154- pre = pre ,
2155- blocks = [
2156- Block (
2157- txs = [tx ],
2158- header_verify = Header (gas_used = expected_state ),
2159- ),
2160- ],
2161- post = post ,
2162- )
2204+ blockchain_test (pre = pre , blocks = [block ], post = post )
21632205
21642206
21652207@pytest .mark .parametrize (
@@ -2355,8 +2397,6 @@ def test_inner_create_fail_refunds_in_creation_tx(
23552397 + num_inner_ops * (gas_costs .NEW_ACCOUNT + per_inner_slack )
23562398 )
23572399
2358- expected_state = outer_state_gas
2359-
23602400 create_address = compute_create_address (address = sender , nonce = 0 )
23612401
23622402 tx = Transaction (
@@ -2368,19 +2408,15 @@ def test_inner_create_fail_refunds_in_creation_tx(
23682408
23692409 if outer_outcome == "succeeds" :
23702410 post : dict = {create_address : Account (code = b"" )}
2411+ block = Block (
2412+ txs = [tx ],
2413+ header_verify = Header (gas_used = outer_state_gas ),
2414+ )
23712415 else :
23722416 post = {create_address : Account .NONEXISTENT }
2417+ block = Block (txs = [tx ])
23732418
2374- blockchain_test (
2375- pre = pre ,
2376- blocks = [
2377- Block (
2378- txs = [tx ],
2379- header_verify = Header (gas_used = expected_state ),
2380- ),
2381- ],
2382- post = post ,
2383- )
2419+ blockchain_test (pre = pre , blocks = [block ], post = post )
23842420
23852421
23862422@pytest .mark .pre_alloc_mutable
0 commit comments