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

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 + execution 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 execution 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
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
@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 + execution 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 execution 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.execution_cost(fork)
        + inner_code.execution_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.