Skip to content

test_precompile_absence()

Documentation for tests/frontier/precompiles/test_precompile_absence.py::test_precompile_absence@tests-bal@v5.7.0.

Generate fixtures for these test cases for Amsterdam with:

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

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

Source code in tests/frontier/precompiles/test_precompile_absence.py
20
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
75
76
77
78
79
80
81
82
83
84
85
@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,
) -> None:
    """
    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()
    )

    # Osaka (EIP-7825) caps tx gas at 16,777,216. Amsterdam (EIP-8037)
    # lifts the cap and increases SSTORE state gas, needing 30M for
    # ~498 cold zero-to-nonzero SSTOREs (~21.2M at cpsb=1174).
    gas_limit = 16_000_000
    if fork.is_eip_enabled(8037):
        gas_limit = 30_000_000

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

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

Parametrized Test Cases

This test generates 3 parametrized test cases across 12 forks.