Skip to content

test_create_oog_during_state_gas_charge()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_create_oog_during_state_gas_charge@a9abd46e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_create_oog_during_state_gas_charge --fork Amsterdam

Verify the parent reservoir is refunded when a child's CREATE OOGs while charging account-creation state gas. The grandchild SSTORE is forwarded only its regular stipend, so it succeeds only if the refund landed in the reservoir (not in gas_left).

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
@pytest.mark.with_all_create_opcodes()
@pytest.mark.valid_from("EIP8037")
def test_create_oog_during_state_gas_charge(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    create_opcode: Op,
) -> None:
    """
    Verify the parent reservoir is refunded when a child's CREATE
    OOGs while charging account-creation state gas. The grandchild
    SSTORE is forwarded only its regular stipend, so it succeeds
    only if the refund landed in the reservoir (not in `gas_left`).
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    init_code = Op.STOP
    inner_create_call = (
        create_opcode(value=0, offset=31, size=1, salt=0)
        if create_opcode == Op.CREATE2
        else create_opcode(value=0, offset=31, size=1)
    )

    inner = pre.deploy_contract(
        code=(
            Op.MSTORE(
                0,
                int.from_bytes(bytes(init_code), "big") << 248,
            )
            + Op.POP(inner_create_call)
        ),
    )

    grandchild_storage = Storage()
    grandchild_code = Op.SSTORE(grandchild_storage.store_next(1, "ran"), 1)
    grandchild = pre.deploy_contract(code=grandchild_code)

    grandchild_stipend = grandchild_code.regular_cost(fork)

    parent = pre.deploy_contract(
        code=(
            Op.POP(Op.CALL(gas=20_000, address=inner))
            + Op.POP(Op.CALL(gas=grandchild_stipend, address=grandchild))
        ),
    )

    tx = Transaction(
        to=parent,
        state_gas_reservoir=sstore_state_gas,
        sender=pre.fund_eoa(),
    )

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

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.