Skip to content

test_call_value_stipend_is_usable()

Documentation for tests/amsterdam/eip8038_state_access_gas_cost_increase/test_call_gas.py::test_call_value_stipend_is_usable@636b5f17.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip8038_state_access_gas_cost_increase/test_call_gas.py::test_call_value_stipend_is_usable --fork Bogota

The CALL value-transfer stipend CALL_STIPEND is forwarded to the callee and usable for execution.

The caller forwards gas=0, so the callee receives only the stipend when a positive value is sent, and nothing otherwise. The callee runs a small amount of work (well under the stipend) then stops: with the stipend the call succeeds (returns 1); without value (no stipend, zero forwarded gas) the work runs out of gas and the call fails (returns 0). This proves the stipend is not merely returned but is spendable by the callee.

Source code in tests/amsterdam/eip8038_state_access_gas_cost_increase/test_call_gas.py
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@pytest.mark.parametrize(
    "value", [0, 1], ids=["no_value_no_stipend", "value_grants_stipend"]
)
def test_call_value_stipend_is_usable(
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    value: int,
) -> None:
    """
    The ``CALL`` value-transfer stipend ``CALL_STIPEND`` is
    forwarded to the callee and usable for execution.

    The caller forwards ``gas=0``, so the callee receives only the stipend
    when a positive value is sent, and nothing otherwise. The
    callee runs a small amount of work (well under the stipend) then
    stops:
    with the stipend the call succeeds (returns 1); without value (no
    stipend, zero forwarded gas) the work runs out of gas and the call
    fails (returns 0). This proves the stipend is not merely returned but
    is spendable by the callee.
    """
    # ~250 gas of cheap work: comfortably within the stipend, far
    # above the zero gas forwarded when no value (so no stipend) is sent.
    work = (Op.PUSH1(0) + Op.POP) * 50 + Op.STOP
    callee = pre.deploy_contract(code=work)

    caller = pre.deploy_contract(
        code=Op.SSTORE(0, Op.CALL(0, callee, value, 0, 0, 0, 0)),
        balance=1,
    )

    tx = Transaction(to=caller, sender=pre.fund_eoa())

    # 1 when the stipend funded the callee's work, 0 when it ran out.
    post = {caller: Account(storage={0: 1 if value else 0})}
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 2 parametrized test cases across 2 forks.