Skip to content

test_identity()

Documentation for tests/benchmark/compute/precompile/test_identity.py::test_identity@20373115.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/compute/precompile/test_identity.py::test_identity --gas-benchmark-values 1

Benchmark IDENTITY precompile.

Source code in tests/benchmark/compute/precompile/test_identity.py
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
def test_identity(
    benchmark_test: BenchmarkTestFiller,
    fork: Fork,
    tx_gas_limit: int,
) -> None:
    """Benchmark IDENTITY precompile."""
    intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator()
    gas_available = tx_gas_limit - intrinsic_gas_calculator()

    gas_costs = fork.gas_costs()
    optimal_input_length = calculate_optimal_input_length(
        available_gas=gas_available,
        fork=fork,
        static_cost=gas_costs.PRECOMPILE_IDENTITY_BASE,
        per_word_dynamic_cost=gas_costs.PRECOMPILE_IDENTITY_PER_WORD,
        bytes_per_unit_of_work=1,
    )

    attack_block = Op.POP(
        Op.STATICCALL(
            Op.GAS,
            IdentitySpec.IDENTITY,
            Op.PUSH0,
            optimal_input_length,
            Op.PUSH0,
            Op.PUSH0,
        )
    )

    benchmark_test(
        target_opcode=Precompile.IDENTITY,
        code_generator=JumpLoopGenerator(
            setup=Op.CODECOPY(0, 0, optimal_input_length),
            attack_block=attack_block,
        ),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 3 forks.