Skip to content

test_sha256()

Documentation for tests/benchmark/compute/precompile/test_sha256.py::test_sha256@7b8124a7.

Generate fixtures for these test cases for Osaka with:

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

Benchmark SHA256 precompile.

Source code in tests/benchmark/compute/precompile/test_sha256.py
14
15
16
17
18
19
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
def test_sha256(
    benchmark_test: BenchmarkTestFiller,
    fork: Fork,
    tx_gas_limit: int,
) -> None:
    """Benchmark SHA256 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.G_PRECOMPILE_SHA256_BASE,
        per_word_dynamic_cost=gas_costs.G_PRECOMPILE_SHA256_WORD,
        bytes_per_unit_of_work=64,
    )

    attack_block = Op.POP(
        Op.STATICCALL(
            Op.GAS, 0x02, Op.PUSH0, optimal_input_length, Op.PUSH0, Op.PUSH0
        )
    )

    benchmark_test(
        target_opcode=Op.STATICCALL,
        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 2 forks.