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@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs_2.py::test_pointer_call_followed_by_direct_call --fork Amsterdam

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.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs_2.py
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
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
@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.
    """
    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).gas_cost(fork)  # key warmed by prior SLOAD
        + 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).gas_cost(fork)  # key warmed by prior SLOAD
        + 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,
        gas_limit=3_000_000,
        data=b"",
        value=0,
        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 3 forks.