Skip to content

test_sstore_oog_no_reservoir_inflation()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_sstore_oog_no_reservoir_inflation@636b5f17.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_sstore_oog_no_reservoir_inflation --fork Bogota

Verify SSTORE does not inflate the parent reservoir on execution OOG.

With zero reservoir, all state gas spills into gas_left. The exact-gas case succeeds; one gas less makes the factory's SSTORE fail its execution gas check. The failing frame has no surviving state charge, so its full gas allowance must be reported as execution gas. The exact receipt and header catch state gas charged before the execution OOG and incorrectly returned to the parent as reservoir gas.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
1381
1382
1383
1384
1385
1386
1387
1388
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
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
@pytest.mark.parametrize(
    "gas_shortfall",
    [
        pytest.param(0, id="exact_gas"),
        pytest.param(1, id="short_one_gas"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_sstore_oog_no_reservoir_inflation(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    gas_shortfall: int,
) -> None:
    """
    Verify SSTORE does not inflate the parent reservoir on execution OOG.

    With zero reservoir, all state gas spills into gas_left. The exact-gas
    case succeeds; one gas less makes the factory's SSTORE fail its execution
    gas check. The failing frame has no surviving state charge, so its full
    gas allowance must be reported as execution gas. The exact receipt and
    header catch state gas charged before the execution OOG and incorrectly
    returned to the parent as reservoir gas.
    """
    initcode = Initcode(deploy_code=Op.STOP)
    initcode_len = len(initcode)

    factory_code = Op.CALLDATACOPY(
        0,
        0,
        Op.CALLDATASIZE,
        data_size=initcode_len,
        new_memory_size=initcode_len,
    ) + Op.SSTORE(
        0,
        Op.CREATE(
            value=0,
            offset=0,
            size=Op.CALLDATASIZE,
            init_code_size=initcode_len,
        ),
    )
    factory = pre.deploy_contract(factory_code)
    create_address = compute_create_address(address=factory, nonce=1)

    # Total gas includes both execution and state components since
    # reservoir is zero — all state gas comes from gas_left.
    factory_gas = (
        factory_code.gas_cost(fork)
        + initcode.evm_gas(fork)
        + initcode.deployment_gas(fork)
    )

    # Caller forwards total gas (execution + state) through CALL. With zero
    # reservoir, the CALL gas parameter is the factory's only source.
    caller_code = Op.CALLDATACOPY(
        0,
        0,
        Op.CALLDATASIZE,
        data_size=initcode_len,
        new_memory_size=initcode_len,
    ) + Op.CALL(
        gas=factory_gas - gas_shortfall,
        address=factory,
        value=0,
        args_offset=0,
        args_size=Op.CALLDATASIZE,
        ret_offset=0,
        ret_size=0,
    )
    caller = pre.deploy_contract(caller_code)

    expected_cumulative = (
        fork.transaction_intrinsic_cost_calculator()(
            calldata=bytes(initcode),
            return_cost_deducted_prior_execution=True,
        )
        + fork.transaction_top_frame_execution_gas(contract_creation=False)
        + caller_code.execution_cost(fork)
        + factory_gas
        - gas_shortfall
    )
    code_deposit = Op.RETURN(code_deposit_size=len(Op.STOP))
    expected_state = (
        factory_code.state_cost(fork) + code_deposit.state_cost(fork)
        if gas_shortfall == 0
        else 0
    )
    expected_execution = expected_cumulative - expected_state

    sender = pre.fund_eoa()
    tx = Transaction(
        sender=sender,
        to=caller,
        data=bytes(initcode),
        state_gas_reservoir=0,
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=expected_cumulative,
        ),
    )

    created = not gas_shortfall
    post = {
        create_address: Account(code=Op.STOP)
        if created
        else Account.NONEXISTENT,
        factory: Account(storage={0: create_address if created else 0}),
    }

    state_test(
        pre=pre,
        tx=tx,
        post=post,
        blockchain_test_header_verify=Header(
            gas_used=max(expected_execution, expected_state)
        ),
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 2 forks.