Skip to content

test_soft_failed_value_call_refund_through_child_halt()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_soft_failed_value_call_refund_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_soft_failed_value_call_refund_through_child_halt --fork Amsterdam

Verify a same-frame NEW_ACCOUNT charge-and-refund (a value CALL soft-failing the balance check) performed after a reverted child call, merged into a frame with its own spilled set that then exceptionally halts, charges the sender the halted frame's budget exactly once — pinned by the receipt.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
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
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
@pytest.mark.valid_from("EIP8037")
def test_soft_failed_value_call_refund_through_child_halt(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify a same-frame NEW_ACCOUNT charge-and-refund (a value CALL
    soft-failing the balance check) performed after a reverted child
    call, merged into a frame with its own spilled set that then
    exceptionally halts, charges the sender the halted frame's budget
    exactly once — pinned by the receipt.
    """
    intrinsic_cost = fork.transaction_intrinsic_cost_calculator()()
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)
    child_budget = 600_000

    grandchild = pre.deploy_contract(code=Op.SSTORE(0, 1) + Op.REVERT(0, 0))
    fresh = pre.nonexistent_account()
    # Zero balance: the value CALL soft-fails its balance check after
    # the up-front NEW_ACCOUNT state charge, refunded in-frame.
    middle = pre.deploy_contract(
        code=(
            Op.POP(Op.CALL(gas=Op.GAS, address=grandchild))
            + Op.POP(Op.CALL(gas=Op.GAS, address=fresh, value=1))
            + Op.STOP
        ),
    )
    child = pre.deploy_contract(
        code=(
            Op.SSTORE(0, 1)
            + Op.POP(Op.CALL(gas=Op.GAS, address=middle))
            + 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),
        child: Account(storage={0: 0}),
        fresh: Account.NONEXISTENT,
    }
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.