Skip to content

test_create_oog_full_burn_no_state_credit()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_ordering.py::test_create_oog_full_burn_no_state_credit@2119b382.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_ordering.py::test_create_oog_full_burn_no_state_credit --fork Amsterdam

Verify a CREATE OOG inside a non-creation tx burns the whole tx gas_limit — no state-gas leftover is credited at tx-end.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_ordering.py
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
@pytest.mark.parametrize(
    "oog_step",
    [
        pytest.param("create_base", id="oog_on_create_base"),
        pytest.param("init_code_word_cost", id="oog_on_init_code_word_cost"),
    ],
)
@pytest.mark.with_all_create_opcodes()
@pytest.mark.valid_from("EIP8037")
def test_create_oog_full_burn_no_state_credit(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    create_opcode: Op,
    oog_step: str,
) -> None:
    """
    Verify a CREATE OOG inside a non-creation tx burns the whole
    tx gas_limit — no state-gas leftover is credited at tx-end.
    """
    gas_costs = fork.gas_costs()
    new_account_state_gas = gas_costs.NEW_ACCOUNT

    if oog_step == "create_base":
        initcode_size = 0
        setup_gas = 0
        init_code_word_cost = 0
    else:
        initcode_size = WORD_SIZE
        setup_gas = (
            2 * gas_costs.VERY_LOW
            + gas_costs.OPCODE_MSTORE_BASE
            + gas_costs.MEMORY_PER_WORD
        )
        init_code_word_cost = gas_costs.CODE_INIT_PER_WORD

    if create_opcode == Op.CREATE:
        create_op = create_opcode(value=0, offset=0, size=initcode_size)
    else:
        create_op = create_opcode(
            value=0, offset=0, size=initcode_size, salt=0
        )
    pushes_gas = create_opcode.popped_stack_items * gas_costs.VERY_LOW

    if oog_step == "create_base":
        factory_code = create_op
    else:
        factory_code = Op.MSTORE(0, 0) + create_op
    factory = pre.deploy_contract(factory_code)

    create_regular_gas = gas_costs.OPCODE_CREATE_BASE + init_code_word_cost
    body_gas = (
        setup_gas + pushes_gas + create_regular_gas + new_account_state_gas - 1
    )

    intrinsic_calc = fork.transaction_intrinsic_cost_calculator()
    tx_gas_limit = intrinsic_calc() + body_gas

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

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                header_verify=Header(gas_used=tx_gas_limit),
            ),
        ],
        post={},
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.