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@2867859a.

Generate fixtures for these test cases for Amsterdam with:

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

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
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
@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 1 fork.