Skip to content

test_pointer_to_static_reentry()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs_2.py::test_pointer_to_static_reentry@01f496f4.

Generate fixtures for these test cases for Prague with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs_2.py::test_pointer_to_static_reentry --fork Prague

Tx call -> pointer A -> static -> code -> pointer A -> static violation Verify that static context is active when called under pointer.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs_2.py
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
@pytest.mark.valid_from("Prague")
def test_pointer_to_static_reentry(state_test: StateTestFiller, pre: Alloc):
    """
    Tx call -> pointer A -> static -> code -> pointer A -> static violation
    Verify that static context is active when called under pointer.
    """
    env = Environment()
    storage: Storage = Storage()
    sender = pre.fund_eoa()
    pointer_a = pre.fund_eoa()

    contract_b = pre.deploy_contract(
        code=Op.MSTORE(0, Op.ADD(1, Op.CALLDATALOAD(0)))
        + Conditional(
            condition=Op.EQ(Op.MLOAD(0), 2), if_true=Op.SSTORE(5, 5), if_false=Op.JUMPDEST()
        )
        + Op.CALL(gas=100_000, address=pointer_a, args_offset=0, args_size=Op.CALLDATASIZE())
    )
    contract_a = pre.deploy_contract(
        code=Op.MSTORE(0, Op.CALLDATALOAD(0))
        + Conditional(
            condition=Op.EQ(Op.MLOAD(0), 0),
            if_true=Op.SSTORE(
                storage.store_next(1, "static_call"),
                Op.STATICCALL(
                    gas=1_000_000,
                    address=contract_b,
                    args_size=Op.CALLDATASIZE(),
                    ret_offset=1000,
                    ret_size=32,
                ),
            )
            + Op.SSTORE(storage.store_next(1, "call_worked"), 1),
            if_false=Op.CALL(
                gas=1_000_000,
                address=contract_b,
                args_size=Op.CALLDATASIZE(),
                ret_offset=1000,
                ret_size=32,
            ),
        )
    )

    tx = Transaction(
        to=pointer_a,
        gas_limit=3_000_000,
        data=[0x00] * 32,
        value=0,
        sender=sender,
        authorization_list=[
            AuthorizationTuple(
                address=contract_a,
                nonce=0,
                signer=pointer_a,
            )
        ],
    )

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

Parametrized Test Cases

This test case is only parametrized by fork and fixture format.

Test ID (Abbreviated)
...fork_Prague-state_test
...fork_Prague-blockchain_test_from_state_test
...fork_Osaka-state_test
...fork_Osaka-blockchain_test_from_state_test