Skip to content

test_create_onto_alive_skips_new_account_charge()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_onto_alive_skips_new_account_charge@8acae1b0.

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_skips_new_account_charge --fork Amsterdam

Verify CREATE2 skips the NEW_ACCOUNT charge for an alive target.

A pre-funded, code-less target is alive but remains deployable. The transaction budget includes the static NEW_ACCOUNT estimate; because runtime must skip that charge, the unused gas lets the following SSTORE succeed. Charging NEW_ACCOUNT incorrectly consumes that headroom and prevents the storage probe.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
@pytest.mark.valid_from("EIP8037")
def test_create_onto_alive_skips_new_account_charge(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify CREATE2 skips the NEW_ACCOUNT charge for an alive target.

    A pre-funded, code-less target is alive but remains deployable. The
    transaction budget includes the static NEW_ACCOUNT estimate; because
    runtime must skip that charge, the unused gas lets the following SSTORE
    succeed. Charging NEW_ACCOUNT incorrectly consumes that headroom and
    prevents the storage probe.
    """
    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.gas_cost(fork)
    )
    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.