Skip to content

test_precompile_absence()

Documentation for tests/frontier/precompiles/test_precompile_absence.py::test_precompile_absence@21fb11c8.

Generate fixtures for these test cases for Prague with:

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

Test that addresses close to zero are not precompiles unless active in the fork.

Source code in tests/frontier/precompiles/test_precompile_absence.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
@pytest.mark.parametrize(
    "calldata_size",
    [
        pytest.param(0, id="empty_calldata"),
        pytest.param(31, id="31_bytes"),
        pytest.param(32, id="32_bytes"),
    ],
)
@pytest.mark.valid_from("Byzantium")
def test_precompile_absence(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    calldata_size: int,
):
    """Test that addresses close to zero are not precompiles unless active in the fork."""
    active_precompiles = fork.precompiles()
    storage = Storage()
    call_code = Bytecode()
    for address in range(1, UPPER_BOUND + 1):
        if Address(address) in active_precompiles:
            continue
        call_code += Op.SSTORE(
            address,
            Op.CALL(gas=0, address=address, args_size=calldata_size),
        )
        storage[address] = 1
        if Op.RETURNDATASIZE in fork.valid_opcodes():
            call_code += Op.SSTORE(
                address + RETURNDATASIZE_OFFSET,
                Op.RETURNDATASIZE,
            )
            storage[address + RETURNDATASIZE_OFFSET] = 0

    call_code += Op.STOP

    entry_point_address = pre.deploy_contract(call_code, storage=storage.canary())

    tx = Transaction(
        to=entry_point_address,
        gas_limit=10_000_000,
        sender=pre.fund_eoa(),
        protected=True,
    )

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

Parametrized Test Cases

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

Test ID (Abbreviated) calldata_size
...fork_Byzantium-state_test-empty_calldata 0
...fork_Byzantium-state_test-31_bytes 31
...fork_Byzantium-state_test-32_bytes 32
...fork_Byzantium-blockchain_test_from_state_test-empty_calldata 0
...fork_Byzantium-blockchain_test_from_state_test-31_bytes 31
...fork_Byzantium-blockchain_test_from_state_test-32_bytes 32
...fork_Constantinople-state_test-empty_calldata 0
...fork_Constantinople-state_test-31_bytes 31
...fork_Constantinople-state_test-32_bytes 32
...fork_Constantinople-blockchain_test_from_state_test-empty_calldata 0
...fork_Constantinople-blockchain_test_from_state_test-31_bytes 31
...fork_Constantinople-blockchain_test_from_state_test-32_bytes 32
...fork_ConstantinopleFix-state_test-empty_calldata 0
...fork_ConstantinopleFix-state_test-31_bytes 31
...fork_ConstantinopleFix-state_test-32_bytes 32
...fork_ConstantinopleFix-blockchain_test_from_state_test-empty_calldata 0
...fork_ConstantinopleFix-blockchain_test_from_state_test-31_bytes 31
...fork_ConstantinopleFix-blockchain_test_from_state_test-32_bytes 32
...fork_Istanbul-state_test-empty_calldata 0
...fork_Istanbul-state_test-31_bytes 31
...fork_Istanbul-state_test-32_bytes 32
...fork_Istanbul-blockchain_test_from_state_test-empty_calldata 0
...fork_Istanbul-blockchain_test_from_state_test-31_bytes 31
...fork_Istanbul-blockchain_test_from_state_test-32_bytes 32
...fork_Berlin-state_test-empty_calldata 0
...fork_Berlin-state_test-31_bytes 31
...fork_Berlin-state_test-32_bytes 32
...fork_Berlin-blockchain_test_from_state_test-empty_calldata 0
...fork_Berlin-blockchain_test_from_state_test-31_bytes 31
...fork_Berlin-blockchain_test_from_state_test-32_bytes 32
...fork_London-state_test-empty_calldata 0
...fork_London-state_test-31_bytes 31
...fork_London-state_test-32_bytes 32
...fork_London-blockchain_test_from_state_test-empty_calldata 0
...fork_London-blockchain_test_from_state_test-31_bytes 31
...fork_London-blockchain_test_from_state_test-32_bytes 32
...fork_Paris-state_test-empty_calldata 0
...fork_Paris-state_test-31_bytes 31
...fork_Paris-state_test-32_bytes 32
...fork_Paris-blockchain_test_from_state_test-empty_calldata 0
...fork_Paris-blockchain_test_from_state_test-31_bytes 31
...fork_Paris-blockchain_test_from_state_test-32_bytes 32
...fork_Shanghai-state_test-empty_calldata 0
...fork_Shanghai-state_test-31_bytes 31
...fork_Shanghai-state_test-32_bytes 32
...fork_Shanghai-blockchain_test_from_state_test-empty_calldata 0
...fork_Shanghai-blockchain_test_from_state_test-31_bytes 31
...fork_Shanghai-blockchain_test_from_state_test-32_bytes 32
...fork_Cancun-state_test-empty_calldata 0
...fork_Cancun-state_test-31_bytes 31
...fork_Cancun-state_test-32_bytes 32
...fork_Cancun-blockchain_test_from_state_test-empty_calldata 0
...fork_Cancun-blockchain_test_from_state_test-31_bytes 31
...fork_Cancun-blockchain_test_from_state_test-32_bytes 32
...fork_Prague-state_test-empty_calldata 0
...fork_Prague-state_test-31_bytes 31
...fork_Prague-state_test-32_bytes 32
...fork_Prague-blockchain_test_from_state_test-empty_calldata 0
...fork_Prague-blockchain_test_from_state_test-31_bytes 31
...fork_Prague-blockchain_test_from_state_test-32_bytes 32
...fork_Osaka-state_test-empty_calldata 0
...fork_Osaka-state_test-31_bytes 31
...fork_Osaka-state_test-32_bytes 32
...fork_Osaka-blockchain_test_from_state_test-empty_calldata 0
...fork_Osaka-blockchain_test_from_state_test-31_bytes 31
...fork_Osaka-blockchain_test_from_state_test-32_bytes 32