Skip to content

test_pointer_to_precompile()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs_2.py::test_pointer_to_precompile@ffe48572.

Generate fixtures for these test cases for Bogota with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs_2.py::test_pointer_to_precompile --fork Bogota

Tx -> call -> pointer A -> precompile contract.

In case a delegation designator points to a precompile address, retrieved code is considered empty and CALL, CALLCODE, STATICCALL, DELEGATECALL instructions targeting this account will execute empty code, i.e. succeed with no execution given enough gas.

So call to a pointer that points to a precompile is like call to an empty account

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs_2.py
@pytest.mark.with_all_precompiles
@pytest.mark.valid_from("Prague")
@pytest.mark.parametrize("sender_delegated", [True, False])
@pytest.mark.parametrize("sender_is_auth_signer", [True, False])
def test_pointer_to_precompile(
    state_test: StateTestFiller,
    pre: Alloc,
    sender_delegated: bool,
    sender_is_auth_signer: bool,
    precompile: int,
) -> None:
    """
    Tx -> call -> pointer A -> precompile contract.

    In case a delegation designator points to a precompile address, retrieved
    code is considered empty and CALL, CALLCODE, STATICCALL, DELEGATECALL
    instructions targeting this account will execute empty code, i.e. succeed
    with no execution given enough gas.

    So call to a pointer that points to a precompile is like call to an empty
    account
    """
    env = Environment()

    storage: Storage = Storage()

    if sender_delegated:
        sender_delegation_target = pre.deploy_contract(Op.STOP)
        sender = pre.fund_eoa(delegation=sender_delegation_target)
    else:
        sender = pre.fund_eoa()

    if sender_is_auth_signer:
        pointer_a = sender
    else:
        pointer_a = pre.fund_eoa()

    contract_test_normal = pre.deploy_contract(
        code=Op.MSTORE(
            0, Op.CALL(gas=0, address=precompile, args_size=Op.CALLDATASIZE())
        )
        + Op.RETURN(0, 32)
    )

    contract_test_pointer = pre.deploy_contract(
        code=Op.MSTORE(
            0, Op.CALL(gas=0, address=pointer_a, args_size=Op.CALLDATASIZE())
        )
        + Op.RETURN(0, 32)
    )

    contract_a = pre.deploy_contract(
        code=Op.CALL(
            gas=1_000_000,
            address=contract_test_normal,
            args_size=Op.CALLDATASIZE(),
            ret_offset=1000,
            ret_size=32,
        )
        # direct call to a precompile with 0 gas always return 0
        + Op.SSTORE(
            storage.store_next(0, "direct_call_result"), Op.MLOAD(1000)
        )
        + Op.CALL(
            gas=1_000_000,
            address=contract_test_pointer,
            args_size=Op.CALLDATASIZE(),
            ret_offset=1000,
            ret_size=32,
        )
        # pointer call to a precompile with 0 gas always return 1 as if calling
        # empty address
        + Op.SSTORE(
            storage.store_next(1, "pointer_call_result"), Op.MLOAD(1000)
        )
    )
    nonce = (
        2
        if sender_delegated and sender_is_auth_signer
        else 1
        if sender_is_auth_signer
        else 0
    )

    tx = Transaction(
        to=contract_a,
        data=[0x11] * 256,
        sender=sender,
        authorization_list=[
            AuthorizationTuple(
                address=precompile,
                nonce=nonce,
                signer=pointer_a,
            )
        ],
    )

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

Parametrized Test Cases

This test generates 72 parametrized test cases across 4 forks.