Skip to content

test_call_value_new_account_state_gas_returned_on_caller_revert()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_value_new_account_state_gas_returned_on_caller_revert@c74f1a67.

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_call_value_new_account_state_gas_returned_on_caller_revert --fork Amsterdam

Return a spilled NEW_ACCOUNT charge when the caller cleanly reverts.

Same value CALL to the absent account target as the halt case, but the caller ends with REVERT. A revert refills the frame state gas in LIFO order: the spilled portion returns to gas_left and the reservoir-funded portion restores the reservoir, both refunded to the sender. The sender pays only the regular execution gas, the same value in-cap and over-cap, and the value transfer is rolled back.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
1770
1771
1772
1773
1774
1775
1776
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
1823
1824
1825
1826
@pytest.mark.parametrize("reservoir", ["in_cap", "over_cap"])
@pytest.mark.valid_from("EIP8037")
def test_call_value_new_account_state_gas_returned_on_caller_revert(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    reservoir: str,
) -> None:
    """
    Return a spilled NEW_ACCOUNT charge when the caller cleanly reverts.

    Same value CALL to the absent account `target` as the halt case, but the
    caller ends with `REVERT`. A revert refills the frame state gas in LIFO
    order: the spilled portion returns to `gas_left` and the reservoir-funded
    portion restores the reservoir, both refunded to the sender. The sender
    pays only the regular execution gas, the same value in-cap and over-cap,
    and the value transfer is rolled back.
    """
    value = 1
    target = pre.nonexistent_account()
    caller_code = Op.CALL(gas=0, address=target, value=value) + Op.REVERT(0, 0)
    caller = pre.deploy_contract(code=caller_code, balance=value)
    sender = pre.fund_eoa()

    gas_costs = fork.gas_costs()
    # Only regular execution is billed: the spilled and reservoir-funded parts
    # of the NEW_ACCOUNT charge are both refunded, so the cost matches in-cap
    # and over-cap. `gas_cost` covers the pushes and cold access; the value
    # transfer is added on top and the empty child returns its stipend unused.
    expected_gas_used = (
        fork.transaction_intrinsic_cost_calculator()()
        + caller_code.gas_cost(fork)
        + gas_costs.CALL_VALUE
        - gas_costs.CALL_STIPEND
    )
    receipt = TransactionReceipt(cumulative_gas_used=expected_gas_used)

    gas_limit_cap = fork.transaction_gas_limit_cap()
    assert gas_limit_cap is not None
    gas_limit = (
        gas_limit_cap + gas_costs.NEW_ACCOUNT // 2
        if reservoir == "over_cap"
        else 1_000_000
    )

    tx = Transaction(
        to=caller,
        sender=sender,
        gas_limit=gas_limit,
        expected_receipt=receipt,
    )

    post = {
        caller: Account(balance=value),
        target: Account.NONEXISTENT,
    }
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.