Skip to content

test_reverted_grandchild_spill_through_child_halt()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_reverted_grandchild_spill_through_child_halt@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_reverted_grandchild_spill_through_child_halt --fork Amsterdam

Verify a grandchild's reverted spill does not ride through the child's exceptional halt into the caller's accounting: the receipt pins that the sender pays the halted child's forwarded budget exactly once, not the grandchild's refilled spill on top.

The tx gas limit sits below the EIP-7825 cap, so the reservoir is empty and the grandchild's set spills from gas_left.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
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
@pytest.mark.valid_from("EIP8037")
def test_reverted_grandchild_spill_through_child_halt(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify a grandchild's reverted spill does not ride through the
    child's exceptional halt into the caller's accounting: the receipt
    pins that the sender pays the halted child's forwarded budget
    exactly once, not the grandchild's refilled spill on top.

    The tx gas limit sits below the EIP-7825 cap, so the reservoir is
    empty and the grandchild's set spills from `gas_left`.
    """
    intrinsic_cost = fork.transaction_intrinsic_cost_calculator()()
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)
    child_budget = 400_000

    grandchild = pre.deploy_contract(code=Op.SSTORE(0, 1) + Op.REVERT(0, 0))
    child = pre.deploy_contract(
        code=Op.POP(Op.CALL(gas=Op.GAS, address=grandchild)) + Op.INVALID,
    )

    storage = Storage()
    # The child call halts and returns 0, so the caller's first SSTORE
    # is a cold no-op (0 to 0) on a fresh slot rather than the cold set
    # `execution_cost` assumes by default.
    caller_code = Op.SSTORE.with_metadata(
        key_warm=False,
        original_value=0,
        current_value=0,
        new_value=0,
    )(
        storage.store_next(0, "child_halted"),
        Op.CALL(gas=child_budget, address=child),
    ) + Op.SSTORE(storage.store_next(1, "caller_completed"), 1)
    caller = pre.deploy_contract(code=caller_code)

    # The halted child consumes its whole forwarded budget as execution
    # gas; the caller's slot-1 set is the only surviving state charge.
    expected_cumulative = (
        intrinsic_cost
        + caller_code.execution_cost(fork)
        + child_budget
        + sstore_state_gas
    )

    tx = Transaction(
        to=caller,
        gas_limit=1_000_000,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=expected_cumulative,
        ),
    )

    post = {
        caller: Account(storage=storage),
        grandchild: Account(storage={0: 0}),
    }
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.