Skip to content

test_sha256()

Documentation for tests/benchmark/compute/precompile/test_sha256.py::test_sha256@tests-snobal-devnet-6@v1.1.0.

Generate fixtures for these test cases for Amsterdam 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
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
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.PRECOMPILE_SHA256_BASE,
        per_word_dynamic_cost=gas_costs.PRECOMPILE_SHA256_PER_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=Precompile.SHA256,
        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.