Skip to content

test_pointer_call_followed_by_direct_call()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs_2.py::test_pointer_call_followed_by_direct_call@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_call_followed_by_direct_call --fork Bogota

If we first call by pointer then direct call, will the call/sload be hot.

The direct call will warm because pointer access marks it warm. But the sload is still cold because storage marked hot from pointer's account in a pointer call.

Under EIP-8037 the inner SSTORE's state part is paid from the implicit reservoir, so GAS sees execution cost only; see test_gas_diff_pointer_vs_direct_call.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs_2.py
@pytest.mark.valid_from("Prague")
def test_pointer_call_followed_by_direct_call(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    If we first call by pointer then direct call, will the
    call/sload be hot.

    The direct call will warm because pointer access marks it warm.
    But the sload is still cold because storage marked hot from
    pointer's account in a pointer call.

    Under EIP-8037 the inner SSTORE's state part is paid from the
    implicit reservoir, so `GAS` sees execution cost only; see
    test_gas_diff_pointer_vs_direct_call.
    """
    env = Environment()

    sender = pre.fund_eoa()
    pointer_a = pre.fund_eoa()
    call_worked = 1
    opcodes_price: int = 37
    pointer_call_gas = (
        Op.SSTORE(key_warm=True).execution_cost(fork)  # key warm
        + Op.CALL(address_warm=True).gas_cost(fork)  # pointer is warm
        + Op.CALL(address_warm=False).gas_cost(fork)  # contract is cold
        + Op.SLOAD(key_warm=False).gas_cost(fork)  # storage is cold
        + opcodes_price
    )
    direct_call_gas = (
        Op.SSTORE(key_warm=True).execution_cost(fork)  # key warm
        + Op.CALL(address_warm=True).gas_cost(fork)  # contract is now warm
        + Op.SLOAD(key_warm=False).gas_cost(fork)  # storage is cold
        + opcodes_price
    )

    contract = pre.deploy_contract(
        code=Op.SSTORE(call_worked, Op.ADD(Op.SLOAD(call_worked), 1))
    )

    storage_test_gas: Storage = Storage()
    contract_test_gas = pre.deploy_contract(
        code=Op.GAS()
        + Op.POP(Op.CALL(gas=100_000, address=pointer_a))
        + Op.SSTORE(
            storage_test_gas.store_next(
                pointer_call_gas, "pointer_call_price"
            ),
            Op.SUB(Op.SWAP1(), Op.GAS()),
        )
        + Op.GAS()
        + Op.POP(Op.CALL(gas=100_000, address=contract))
        + Op.SSTORE(
            storage_test_gas.store_next(direct_call_gas, "direct_call_price"),
            Op.SUB(Op.SWAP1(), Op.GAS()),
        )
    )

    tx = Transaction(
        to=contract_test_gas,
        sender=sender,
        authorization_list=(
            [
                AuthorizationTuple(
                    address=contract,
                    nonce=0,
                    signer=pointer_a,
                )
            ]
        ),
    )

    post = {
        contract: Account(storage={call_worked: 1}),
        pointer_a: Account(storage={call_worked: 1}),
        contract_test_gas: Account(storage=storage_test_gas),
    }
    state_test(
        env=env,
        pre=pre,
        post=post,
        tx=tx,
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 4 forks.