Skip to content

test_state_gas_spill_header_gas_used()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_state_gas_spill_header_gas_used@5c024cbb.

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

Verify header gas_used when state gas spills into gas_left.

A transaction performs an SSTORE with state gas partially from the reservoir and partially spilling into gas_left. Verify the block header gas_used reflects the correct 2D max accounting.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
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
1498
@pytest.mark.valid_from("EIP8037")
def test_state_gas_spill_header_gas_used(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify header gas_used when state gas spills into gas_left.

    A transaction performs an SSTORE with state gas partially from
    the reservoir and partially spilling into gas_left. Verify the
    block header gas_used reflects the correct 2D max accounting.
    """
    # SSTORE zero-to-nonzero with small reservoir
    sstore_code = Op.SSTORE(0, 1) + Op.STOP
    contract = pre.deploy_contract(code=sstore_code)

    intrinsic_cost = fork.transaction_intrinsic_cost_calculator()
    intrinsic_gas = intrinsic_cost()

    sstore_state_gas = sstore_code.state_cost(fork)
    evm_regular = sstore_code.regular_cost(fork)

    # Reservoir = half the SSTORE state gas, rest spills to gas_left
    reservoir = sstore_state_gas // 2

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

    tx_regular = intrinsic_gas + evm_regular
    tx_state = sstore_state_gas
    expected_gas_used = max(tx_regular, tx_state)

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                header_verify=Header(gas_used=expected_gas_used),
            ),
        ],
        post={contract: Account(storage={0: 1})},
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.