Skip to content

test_create_onto_alive_refunds_to_gas_left()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_onto_alive_refunds_to_gas_left@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_onto_alive_refunds_to_gas_left --fork Amsterdam

Verify a refunded CREATE NEW_ACCOUNT charge returns to gas_left.

A CREATE2 onto an already-alive (pre-funded, code-less) address spills the NEW_ACCOUNT charge from the empty reservoir into gas_left, succeeds, and refunds it. gas_limit leaves exactly NEW_ACCOUNT after the create, so the following SSTORE runs only if the refund returned to gas_left (LIFO) rather than the reservoir.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
@pytest.mark.valid_from("EIP8037")
def test_create_onto_alive_refunds_to_gas_left(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify a refunded CREATE NEW_ACCOUNT charge returns to gas_left.

    A CREATE2 onto an already-alive (pre-funded, code-less) address
    spills the NEW_ACCOUNT charge from the empty reservoir into
    gas_left, succeeds, and refunds it. `gas_limit` leaves exactly
    `NEW_ACCOUNT` after the create, so the following SSTORE runs only
    if the refund returned to gas_left (LIFO) rather than the reservoir.
    """
    salt = 0
    create = Op.POP(Op.CREATE2(0, 0, 0, salt))
    storage = Storage()
    contract = pre.deploy_contract(
        code=create + Op.SSTORE(storage.store_next(1), 1)
    )
    target = compute_create2_address(address=contract, salt=salt, initcode=b"")
    pre.fund_address(target, amount=1)

    gas_limit = (
        fork.transaction_intrinsic_cost_calculator()()
        + create.regular_cost(fork)
        + fork.gas_costs().NEW_ACCOUNT
    )
    tx = Transaction(to=contract, gas_limit=gas_limit, sender=pre.fund_eoa())

    post = {
        contract: Account(storage=storage),
        target: Account(nonce=1, balance=1),
    }
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.