Skip to content

test_create_insufficient_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_insufficient_state_gas@c74f1a67.

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

Test CREATE OOGs when state gas is insufficient.

Provide enough gas for CREATE's regular gas cost but not enough to cover the new-account state gas. The CREATE should fail, returning 0.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
@EIPChecklist.GasCostChanges.Test.OutOfGas()
@pytest.mark.valid_from("EIP8037")
def test_create_insufficient_state_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test CREATE OOGs when state gas is insufficient.

    Provide enough gas for CREATE's regular gas cost but not enough
    to cover the new-account state gas. The CREATE should fail,
    returning 0.
    """
    init_code = Op.STOP

    storage = Storage()
    contract = pre.deploy_contract(
        code=(
            Op.MSTORE(
                0,
                int.from_bytes(bytes(init_code), "big")
                << (256 - 8 * len(init_code)),
            )
            + Op.SSTORE(
                storage.store_next(0),  # CREATE returns 0 on OOG
                Op.CREATE(0, 0, len(init_code)),
            )
        ),
    )

    # Tight gas — enough for intrinsic + CREATE regular gas but not
    # enough for the new account state gas
    gas_costs = fork.gas_costs()
    intrinsic_cost = fork.transaction_intrinsic_cost_calculator()
    regular_create_gas = gas_costs.OPCODE_CREATE_BASE
    gas_limit = intrinsic_cost() + regular_create_gas + 10_000

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

    post = {contract: Account(storage=storage)}
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.