Skip to content

test_precompiles()

Documentation for tests/frontier/precompiles/test_precompiles.py::test_precompiles@14a7429a.

Generate fixtures for these test cases for Prague with:

fill -v tests/frontier/precompiles/test_precompiles.py::test_precompiles --fork Prague

Tests the behavior of precompiled contracts in the Ethereum state test.

Parameters:

Name Type Description Default
state_test StateTestFiller

The state test filler object used to run the test.

required
address str

The address of the precompiled contract to test.

required
precompile_exists bool

A flag indicating whether the precompiled contract exists at the given address.

required
pre Alloc

The allocation object used to deploy the contract and set up the initial state.

required

This test deploys a contract that performs two CALL operations to the specified address and a fixed address (0x10000), measuring the gas used for each call. It then stores the difference in gas usage in storage slot 0. The test verifies the expected storage value based on whether the precompiled contract exists at the given address.

Source code in tests/frontier/precompiles/test_precompiles.py
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
@pytest.mark.valid_from("Berlin")
@pytest.mark.parametrize_by_fork("address,precompile_exists", precompile_addresses)
def test_precompiles(
    state_test: StateTestFiller, address: str, precompile_exists: bool, pre: Alloc
):
    """
    Tests the behavior of precompiled contracts in the Ethereum state test.

    Args:
        state_test (StateTestFiller): The state test filler object used to run the test.
        address (str): The address of the precompiled contract to test.
        precompile_exists (bool): A flag indicating whether the precompiled contract exists at the
            given address.
        pre (Alloc): The allocation object used to deploy the contract and set up the initial
            state.

    This test deploys a contract that performs two CALL operations to the specified address and a
    fixed address (0x10000), measuring the gas used for each call. It then stores the difference
    in gas usage in storage slot 0. The test verifies the expected storage value based on
    whether the precompiled contract exists at the given address.

    """
    env = Environment()

    account = pre.deploy_contract(
        Op.MSTORE(0, 0)  # Pre-expand the memory so the gas costs are exactly the same
        + Op.GAS
        + Op.CALL(
            address=address,
            value=0,
            args_offset=0,
            args_size=32,
            output_offset=32,
            output_size=32,
        )
        + Op.POP
        + Op.SUB(Op.SWAP1, Op.GAS)
        + Op.GAS
        + Op.CALL(
            address=pre.fund_eoa(amount=0),
            value=0,
            args_offset=0,
            args_size=32,
            output_offset=32,
            output_size=32,
        )
        + Op.POP
        + Op.SUB(Op.SWAP1, Op.GAS)
        + Op.SWAP1
        + Op.SUB
        + Op.SSTORE(0, Op.ISZERO)
        + Op.STOP,
        storage={0: 0xDEADBEEF},
    )

    tx = Transaction(
        to=account,
        sender=pre.fund_eoa(),
        gas_limit=1_000_000,
        protected=True,
    )

    # A high gas cost will result from calling a precompile
    # Expect 0x00 when a precompile exists at the address, 0x01 otherwise
    post = {account: Account(storage={0: "0x00" if precompile_exists else "0x01"})}

    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) address precompile_exists
...fork_Berlin-address_0x1-precompile_exists_True-state_test 0x1 True
...fork_Berlin-address_0x1-precompile_exists_True-blockchain_test_from_state_test 0x1 True
...fork_Berlin-address_0x2-precompile_exists_True-state_test 0x2 True
...fork_Berlin-address_0x2-precompile_exists_True-blockchain_test_from_state_test 0x2 True
...fork_Berlin-address_0x3-precompile_exists_True-state_test 0x3 True
...fork_Berlin-address_0x3-precompile_exists_True-blockchain_test_from_state_test 0x3 True
...fork_Berlin-address_0x4-precompile_exists_True-state_test 0x4 True
...fork_Berlin-address_0x4-precompile_exists_True-blockchain_test_from_state_test 0x4 True
...fork_Berlin-address_0x5-precompile_exists_True-state_test 0x5 True
...fork_Berlin-address_0x5-precompile_exists_True-blockchain_test_from_state_test 0x5 True
...fork_Berlin-address_0x6-precompile_exists_True-state_test 0x6 True
...fork_Berlin-address_0x6-precompile_exists_True-blockchain_test_from_state_test 0x6 True
...fork_Berlin-address_0x7-precompile_exists_True-state_test 0x7 True
...fork_Berlin-address_0x7-precompile_exists_True-blockchain_test_from_state_test 0x7 True
...fork_Berlin-address_0x8-precompile_exists_True-state_test 0x8 True
...fork_Berlin-address_0x8-precompile_exists_True-blockchain_test_from_state_test 0x8 True
...fork_Berlin-address_0x9-precompile_exists_True-state_test 0x9 True
...fork_Berlin-address_0x9-precompile_exists_True-blockchain_test_from_state_test 0x9 True
...fork_Berlin-address_0xa-precompile_exists_False-state_test 0xa False
...fork_Berlin-address_0xa-precompile_exists_False-blockchain_test_from_state_test 0xa False
...fork_London-address_0x1-precompile_exists_True-state_test 0x1 True
...fork_London-address_0x1-precompile_exists_True-blockchain_test_from_state_test 0x1 True
...fork_London-address_0x2-precompile_exists_True-state_test 0x2 True
...fork_London-address_0x2-precompile_exists_True-blockchain_test_from_state_test 0x2 True
...fork_London-address_0x3-precompile_exists_True-state_test 0x3 True
...fork_London-address_0x3-precompile_exists_True-blockchain_test_from_state_test 0x3 True
...fork_London-address_0x4-precompile_exists_True-state_test 0x4 True
...fork_London-address_0x4-precompile_exists_True-blockchain_test_from_state_test 0x4 True
...fork_London-address_0x5-precompile_exists_True-state_test 0x5 True
...fork_London-address_0x5-precompile_exists_True-blockchain_test_from_state_test 0x5 True
...fork_London-address_0x6-precompile_exists_True-state_test 0x6 True
...fork_London-address_0x6-precompile_exists_True-blockchain_test_from_state_test 0x6 True
...fork_London-address_0x7-precompile_exists_True-state_test 0x7 True
...fork_London-address_0x7-precompile_exists_True-blockchain_test_from_state_test 0x7 True
...fork_London-address_0x8-precompile_exists_True-state_test 0x8 True
...fork_London-address_0x8-precompile_exists_True-blockchain_test_from_state_test 0x8 True
...fork_London-address_0x9-precompile_exists_True-state_test 0x9 True
...fork_London-address_0x9-precompile_exists_True-blockchain_test_from_state_test 0x9 True
...fork_London-address_0xa-precompile_exists_False-state_test 0xa False
...fork_London-address_0xa-precompile_exists_False-blockchain_test_from_state_test 0xa False
...fork_Paris-address_0x1-precompile_exists_True-state_test 0x1 True
...fork_Paris-address_0x1-precompile_exists_True-blockchain_test_from_state_test 0x1 True
...fork_Paris-address_0x2-precompile_exists_True-state_test 0x2 True
...fork_Paris-address_0x2-precompile_exists_True-blockchain_test_from_state_test 0x2 True
...fork_Paris-address_0x3-precompile_exists_True-state_test 0x3 True
...fork_Paris-address_0x3-precompile_exists_True-blockchain_test_from_state_test 0x3 True
...fork_Paris-address_0x4-precompile_exists_True-state_test 0x4 True
...fork_Paris-address_0x4-precompile_exists_True-blockchain_test_from_state_test 0x4 True
...fork_Paris-address_0x5-precompile_exists_True-state_test 0x5 True
...fork_Paris-address_0x5-precompile_exists_True-blockchain_test_from_state_test 0x5 True
...fork_Paris-address_0x6-precompile_exists_True-state_test 0x6 True
...fork_Paris-address_0x6-precompile_exists_True-blockchain_test_from_state_test 0x6 True
...fork_Paris-address_0x7-precompile_exists_True-state_test 0x7 True
...fork_Paris-address_0x7-precompile_exists_True-blockchain_test_from_state_test 0x7 True
...fork_Paris-address_0x8-precompile_exists_True-state_test 0x8 True
...fork_Paris-address_0x8-precompile_exists_True-blockchain_test_from_state_test 0x8 True
...fork_Paris-address_0x9-precompile_exists_True-state_test 0x9 True
...fork_Paris-address_0x9-precompile_exists_True-blockchain_test_from_state_test 0x9 True
...fork_Paris-address_0xa-precompile_exists_False-state_test 0xa False
...fork_Paris-address_0xa-precompile_exists_False-blockchain_test_from_state_test 0xa False
...fork_Shanghai-address_0x1-precompile_exists_True-state_test 0x1 True
...fork_Shanghai-address_0x1-precompile_exists_True-blockchain_test_from_state_test 0x1 True
...fork_Shanghai-address_0x2-precompile_exists_True-state_test 0x2 True
...fork_Shanghai-address_0x2-precompile_exists_True-blockchain_test_from_state_test 0x2 True
...fork_Shanghai-address_0x3-precompile_exists_True-state_test 0x3 True
...fork_Shanghai-address_0x3-precompile_exists_True-blockchain_test_from_state_test 0x3 True
...fork_Shanghai-address_0x4-precompile_exists_True-state_test 0x4 True
...fork_Shanghai-address_0x4-precompile_exists_True-blockchain_test_from_state_test 0x4 True
...fork_Shanghai-address_0x5-precompile_exists_True-state_test 0x5 True
...fork_Shanghai-address_0x5-precompile_exists_True-blockchain_test_from_state_test 0x5 True
...fork_Shanghai-address_0x6-precompile_exists_True-state_test 0x6 True
...fork_Shanghai-address_0x6-precompile_exists_True-blockchain_test_from_state_test 0x6 True
...fork_Shanghai-address_0x7-precompile_exists_True-state_test 0x7 True
...fork_Shanghai-address_0x7-precompile_exists_True-blockchain_test_from_state_test 0x7 True
...fork_Shanghai-address_0x8-precompile_exists_True-state_test 0x8 True
...fork_Shanghai-address_0x8-precompile_exists_True-blockchain_test_from_state_test 0x8 True
...fork_Shanghai-address_0x9-precompile_exists_True-state_test 0x9 True
...fork_Shanghai-address_0x9-precompile_exists_True-blockchain_test_from_state_test 0x9 True
...fork_Shanghai-address_0xa-precompile_exists_False-state_test 0xa False
...fork_Shanghai-address_0xa-precompile_exists_False-blockchain_test_from_state_test 0xa False
...fork_Cancun-address_0x1-precompile_exists_True-state_test 0x1 True
...fork_Cancun-address_0x1-precompile_exists_True-blockchain_test_from_state_test 0x1 True
...fork_Cancun-address_0x2-precompile_exists_True-state_test 0x2 True
...fork_Cancun-address_0x2-precompile_exists_True-blockchain_test_from_state_test 0x2 True
...fork_Cancun-address_0x3-precompile_exists_True-state_test 0x3 True
...fork_Cancun-address_0x3-precompile_exists_True-blockchain_test_from_state_test 0x3 True
...fork_Cancun-address_0x4-precompile_exists_True-state_test 0x4 True
...fork_Cancun-address_0x4-precompile_exists_True-blockchain_test_from_state_test 0x4 True
...fork_Cancun-address_0x5-precompile_exists_True-state_test 0x5 True
...fork_Cancun-address_0x5-precompile_exists_True-blockchain_test_from_state_test 0x5 True
...fork_Cancun-address_0x6-precompile_exists_True-state_test 0x6 True
...fork_Cancun-address_0x6-precompile_exists_True-blockchain_test_from_state_test 0x6 True
...fork_Cancun-address_0x7-precompile_exists_True-state_test 0x7 True
...fork_Cancun-address_0x7-precompile_exists_True-blockchain_test_from_state_test 0x7 True
...fork_Cancun-address_0x8-precompile_exists_True-state_test 0x8 True
...fork_Cancun-address_0x8-precompile_exists_True-blockchain_test_from_state_test 0x8 True
...fork_Cancun-address_0x9-precompile_exists_True-state_test 0x9 True
...fork_Cancun-address_0x9-precompile_exists_True-blockchain_test_from_state_test 0x9 True
...fork_Cancun-address_0xa-precompile_exists_True-state_test 0xa True
...fork_Cancun-address_0xa-precompile_exists_True-blockchain_test_from_state_test 0xa True
...fork_Cancun-address_0xb-precompile_exists_False-state_test 0xb False
...fork_Cancun-address_0xb-precompile_exists_False-blockchain_test_from_state_test 0xb False
...fork_Prague-address_0x1-precompile_exists_True-state_test 0x1 True
...fork_Prague-address_0x1-precompile_exists_True-blockchain_test_from_state_test 0x1 True
...fork_Prague-address_0x2-precompile_exists_True-state_test 0x2 True
...fork_Prague-address_0x2-precompile_exists_True-blockchain_test_from_state_test 0x2 True
...fork_Prague-address_0x3-precompile_exists_True-state_test 0x3 True
...fork_Prague-address_0x3-precompile_exists_True-blockchain_test_from_state_test 0x3 True
...fork_Prague-address_0x4-precompile_exists_True-state_test 0x4 True
...fork_Prague-address_0x4-precompile_exists_True-blockchain_test_from_state_test 0x4 True
...fork_Prague-address_0x5-precompile_exists_True-state_test 0x5 True
...fork_Prague-address_0x5-precompile_exists_True-blockchain_test_from_state_test 0x5 True
...fork_Prague-address_0x6-precompile_exists_True-state_test 0x6 True
...fork_Prague-address_0x6-precompile_exists_True-blockchain_test_from_state_test 0x6 True
...fork_Prague-address_0x7-precompile_exists_True-state_test 0x7 True
...fork_Prague-address_0x7-precompile_exists_True-blockchain_test_from_state_test 0x7 True
...fork_Prague-address_0x8-precompile_exists_True-state_test 0x8 True
...fork_Prague-address_0x8-precompile_exists_True-blockchain_test_from_state_test 0x8 True
...fork_Prague-address_0x9-precompile_exists_True-state_test 0x9 True
...fork_Prague-address_0x9-precompile_exists_True-blockchain_test_from_state_test 0x9 True
...fork_Prague-address_0xa-precompile_exists_True-state_test 0xa True
...fork_Prague-address_0xa-precompile_exists_True-blockchain_test_from_state_test 0xa True
...fork_Prague-address_0xb-precompile_exists_True-state_test 0xb True
...fork_Prague-address_0xb-precompile_exists_True-blockchain_test_from_state_test 0xb True
...fork_Prague-address_0xc-precompile_exists_True-state_test 0xc True
...fork_Prague-address_0xc-precompile_exists_True-blockchain_test_from_state_test 0xc True
...fork_Prague-address_0xd-precompile_exists_True-state_test 0xd True
...fork_Prague-address_0xd-precompile_exists_True-blockchain_test_from_state_test 0xd True
...fork_Prague-address_0xe-precompile_exists_True-state_test 0xe True
...fork_Prague-address_0xe-precompile_exists_True-blockchain_test_from_state_test 0xe True
...fork_Prague-address_0xf-precompile_exists_True-state_test 0xf True
...fork_Prague-address_0xf-precompile_exists_True-blockchain_test_from_state_test 0xf True
...fork_Prague-address_0x10-precompile_exists_True-state_test 0x10 True
...fork_Prague-address_0x10-precompile_exists_True-blockchain_test_from_state_test 0x10 True
...fork_Prague-address_0x11-precompile_exists_True-state_test 0x11 True
...fork_Prague-address_0x11-precompile_exists_True-blockchain_test_from_state_test 0x11 True
...fork_Prague-address_0x12-precompile_exists_False-state_test 0x12 False
...fork_Prague-address_0x12-precompile_exists_False-blockchain_test_from_state_test 0x12 False
...fork_Osaka-address_0x1-precompile_exists_True-state_test 0x1 True
...fork_Osaka-address_0x1-precompile_exists_True-blockchain_test_from_state_test 0x1 True
...fork_Osaka-address_0x2-precompile_exists_True-state_test 0x2 True
...fork_Osaka-address_0x2-precompile_exists_True-blockchain_test_from_state_test 0x2 True
...fork_Osaka-address_0x3-precompile_exists_True-state_test 0x3 True
...fork_Osaka-address_0x3-precompile_exists_True-blockchain_test_from_state_test 0x3 True
...fork_Osaka-address_0x4-precompile_exists_True-state_test 0x4 True
...fork_Osaka-address_0x4-precompile_exists_True-blockchain_test_from_state_test 0x4 True
...fork_Osaka-address_0x5-precompile_exists_True-state_test 0x5 True
...fork_Osaka-address_0x5-precompile_exists_True-blockchain_test_from_state_test 0x5 True
...fork_Osaka-address_0x6-precompile_exists_True-state_test 0x6 True
...fork_Osaka-address_0x6-precompile_exists_True-blockchain_test_from_state_test 0x6 True
...fork_Osaka-address_0x7-precompile_exists_True-state_test 0x7 True
...fork_Osaka-address_0x7-precompile_exists_True-blockchain_test_from_state_test 0x7 True
...fork_Osaka-address_0x8-precompile_exists_True-state_test 0x8 True
...fork_Osaka-address_0x8-precompile_exists_True-blockchain_test_from_state_test 0x8 True
...fork_Osaka-address_0x9-precompile_exists_True-state_test 0x9 True
...fork_Osaka-address_0x9-precompile_exists_True-blockchain_test_from_state_test 0x9 True
...fork_Osaka-address_0xa-precompile_exists_True-state_test 0xa True
...fork_Osaka-address_0xa-precompile_exists_True-blockchain_test_from_state_test 0xa True
...fork_Osaka-address_0xb-precompile_exists_True-state_test 0xb True
...fork_Osaka-address_0xb-precompile_exists_True-blockchain_test_from_state_test 0xb True
...fork_Osaka-address_0xc-precompile_exists_True-state_test 0xc True
...fork_Osaka-address_0xc-precompile_exists_True-blockchain_test_from_state_test 0xc True
...fork_Osaka-address_0xd-precompile_exists_True-state_test 0xd True
...fork_Osaka-address_0xd-precompile_exists_True-blockchain_test_from_state_test 0xd True
...fork_Osaka-address_0xe-precompile_exists_True-state_test 0xe True
...fork_Osaka-address_0xe-precompile_exists_True-blockchain_test_from_state_test 0xe True
...fork_Osaka-address_0xf-precompile_exists_True-state_test 0xf True
...fork_Osaka-address_0xf-precompile_exists_True-blockchain_test_from_state_test 0xf True
...fork_Osaka-address_0x10-precompile_exists_True-state_test 0x10 True
...fork_Osaka-address_0x10-precompile_exists_True-blockchain_test_from_state_test 0x10 True
...fork_Osaka-address_0x11-precompile_exists_True-state_test 0x11 True
...fork_Osaka-address_0x11-precompile_exists_True-blockchain_test_from_state_test 0x11 True
...fork_Osaka-address_0x12-precompile_exists_False-state_test 0x12 False
...fork_Osaka-address_0x12-precompile_exists_False-blockchain_test_from_state_test 0x12 False