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@622620d8.

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
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
@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_execution = sstore_code.execution_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_execution = intrinsic_gas + evm_execution
    tx_state = sstore_state_gas
    expected_gas_used = max(tx_execution, 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.