Skip to content

test_call_stack_depth_returns_reservoir()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py::test_call_stack_depth_returns_reservoir@5c024cbb.

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

Test CALL at stack depth limit returns reservoir.

When a CALL exceeds the 1024 stack depth limit, the call fails and gas and state gas reservoir are returned. The parent can still use the reservoir for state operations.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_call.py
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
@pytest.mark.valid_from("EIP8037")
def test_call_stack_depth_returns_reservoir(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test CALL at stack depth limit returns reservoir.

    When a CALL exceeds the 1024 stack depth limit, the call fails
    and gas and state gas reservoir are returned. The parent can still
    use the reservoir for state operations.
    """
    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)

    # Contract that recursively calls itself until depth exhausted,
    # then does an SSTORE using the reservoir
    storage = Storage()
    recursive = pre.deploy_contract(
        code=(
            # Try recursive call (will eventually hit depth 1024)
            Op.POP(Op.CALL(Op.GAS, Op.ADDRESS, 0, 0, 0, 0, 0))
            # After recursion unwinds, only the outermost frame
            # reaches this SSTORE
            + Op.SSTORE(storage.store_next(1, "after_recursion"), 1)
        ),
    )

    tx = Transaction(
        to=recursive,
        state_gas_reservoir=sstore_state_gas,
        sender=pre.fund_eoa(),
    )

    post = {recursive: Account(storage=storage)}
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.