Skip to content

test_subcall_set_clear_revert_pays_no_state_gas()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py::test_subcall_set_clear_revert_pays_no_state_gas@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py::test_subcall_set_clear_revert_pays_no_state_gas --fork Amsterdam

A child frame doing SSTORE 0 to x to 0 then REVERT must bill the sender only intrinsic + regular costs.

Both SSTOREs roll back with the REVERT, so the matching state-gas charge and refund cancel cleanly. The receipt's cumulative_gas_used equals the regular baseline; a leftover sstore_state_gas would surface a double-charge at the failure boundary.

spill_mode toggles whether the set draws from the reservoir directly (no_spill, reservoir sized to sstore_state_gas) or spills into gas_left (spill, reservoir = 0).

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
@pytest.mark.parametrize(
    "spill_mode",
    [
        pytest.param("no_spill", id="no_spill"),
        pytest.param("spill", id="spill"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_subcall_set_clear_revert_pays_no_state_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    spill_mode: str,
) -> None:
    """
    A child frame doing SSTORE 0 to x to 0 then REVERT must bill the
    sender only intrinsic + regular costs.

    Both SSTOREs roll back with the REVERT, so the matching
    state-gas charge and refund cancel cleanly. The receipt's
    `cumulative_gas_used` equals the regular baseline; a leftover
    `sstore_state_gas` would surface a double-charge at the failure
    boundary.

    `spill_mode` toggles whether the set draws from the reservoir
    directly (`no_spill`, reservoir sized to `sstore_state_gas`) or
    spills into `gas_left` (`spill`, reservoir = 0).
    """
    intrinsic_cost = fork.transaction_intrinsic_cost_calculator()()
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    set_op = Op.SSTORE.with_metadata(
        key_warm=False,
        original_value=0,
        current_value=0,
        new_value=1,
    )(0, 1)
    clear_op = Op.SSTORE.with_metadata(
        key_warm=True,
        original_value=0,
        current_value=1,
        new_value=0,
    )(0, 0)
    inner_code = set_op + clear_op + Op.REVERT(0, 0)
    inner = pre.deploy_contract(code=inner_code)

    top_code = Op.POP(Op.CALL(gas=Op.GAS, address=inner)) + Op.STOP
    top = pre.deploy_contract(code=top_code)

    reservoir = 0 if spill_mode == "spill" else sstore_state_gas

    expected_cumulative = (
        intrinsic_cost
        + top_code.regular_cost(fork)
        + inner_code.regular_cost(fork)
    )

    tx = Transaction(
        to=top,
        state_gas_reservoir=reservoir,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=expected_cumulative,
        ),
    )
    state_test(
        pre=pre,
        post={top: Account(), inner: Account(storage={0: 0})},
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=expected_cumulative),
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.