Skip to content

test_create_insufficient_account_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_insufficient_account_state_gas@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_insufficient_account_state_gas --fork Amsterdam

Test CREATE OOGs when state gas is insufficient for account creation.

The gas limit covers the frame's execution gas and the required state gas minus one, so the new-account state charge has neither a reservoir nor spare gas_left to draw from. The frame halts before the account is created and the whole limit is billed.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
@EIPChecklist.GasCostChanges.Test.OutOfGas()
@pytest.mark.with_all_create_opcodes
@pytest.mark.parametrize("enough_gas", [False, True])
@pytest.mark.valid_from("EIP8037")
def test_create_insufficient_account_state_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    enough_gas: bool,
    create_opcode: Op,
) -> None:
    """
    Test CREATE OOGs when state gas is insufficient for account creation.

    The gas limit covers the frame's execution gas and the required state gas
    minus one, so the new-account state charge has neither a reservoir nor
    spare `gas_left` to draw from. The frame halts before the account is
    created and the whole limit is billed.
    """
    init_code = Op.STOP
    mstore_value, size = init_code_at_high_bytes(init_code)

    code = Op.MSTORE(0, mstore_value, new_memory_size=32) + (
        create_opcode(value=0, offset=0, size=size, init_code_size=size)
    )
    contract = pre.deploy_contract(code=code)

    gas_limit = fork.transaction_intrinsic_cost_calculator()() + (
        code.gas_cost(fork)
    )
    if not enough_gas:
        gas_limit -= 1

    assert code.state_cost(fork) > 0, (
        f"create opcode does not charge state gas at {fork}"
    )

    tx = Transaction(
        to=contract,
        gas_limit=gas_limit,
        sender=pre.fund_eoa(),
    )

    post = {
        contract: Account(storage={0: 0}),
        compute_create_address(
            address=contract, nonce=1, initcode=init_code, opcode=create_opcode
        ): (Account(nonce=1) if enough_gas else Account.NONEXISTENT),
    }
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.