Skip to content

test_set_code_max_depth_call_stack()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_max_depth_call_stack@20373115.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_max_depth_call_stack --fork Amsterdam

Test re-entry to delegated account until the max call stack depth possible in a transaction is reached.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
@pytest.mark.execute(pytest.mark.skip(reason="excessive gas"))
@pytest.mark.eels_base_coverage
def test_set_code_max_depth_call_stack(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test re-entry to delegated account until the max call stack depth possible
    in a transaction is reached.
    """
    storage = Storage()
    auth_signer = pre.fund_eoa(auth_account_start_balance)
    tx_gas_limit_cap = fork.transaction_gas_limit_cap()
    match tx_gas_limit_cap:
        case None:
            gas_limit = 100_000_000_000_000
            max_depth = 1025
        case 16_777_216:
            gas_limit = tx_gas_limit_cap
            max_depth = 389
        case _:
            raise NotImplementedError(
                f"Unexpected transaction gas limit cap: {tx_gas_limit_cap}"
            )

    set_code = Conditional(
        condition=Op.ISZERO(Op.TLOAD(0)),
        if_true=Op.TSTORE(0, 1)
        + Op.CALL(address=auth_signer)
        + Op.SSTORE(storage.store_next(max_depth), Op.TLOAD(0)),
        if_false=Op.TSTORE(0, Op.ADD(1, Op.TLOAD(0)))
        + Op.CALL(address=auth_signer),
    )
    set_code_to_address = pre.deploy_contract(set_code)

    tx = Transaction(
        gas_limit=gas_limit,
        to=auth_signer,
        authorization_list=[
            AuthorizationTuple(
                address=set_code_to_address,
                nonce=0,
                signer=auth_signer,
            ),
        ],
        sender=pre.fund_eoa(),
    )

    state_test(
        env=Environment(gas_limit=tx.gas_limit),
        pre=pre,
        tx=tx,
        post={
            set_code_to_address: Account(storage={}),
            auth_signer: Account(
                nonce=1,
                code=Spec.delegation_designation(set_code_to_address),
                storage=storage,
                balance=auth_account_start_balance,
            ),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 3 forks.