Skip to content

test_keccak()

Documentation for tests/benchmark/compute/instruction/test_keccak.py::test_keccak@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/compute/instruction/test_keccak.py::test_keccak --gas-benchmark-values 1

Benchmark KECCAK256 instruction with diff input data and offsets.

Source code in tests/benchmark/compute/instruction/test_keccak.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
@pytest.mark.parametrize("mem_alloc", [b"", b"ff", b"ff" * 32])
@pytest.mark.parametrize("offset", [0, 31, 1024])
@pytest.mark.parametrize("mem_update", [True, False])
def test_keccak(
    benchmark_test: BenchmarkTestFiller,
    offset: int,
    mem_alloc: bytes,
    mem_update: bool,
) -> None:
    """Benchmark KECCAK256 instruction with diff input data and offsets."""
    code_hash = Op.SHA3(offset, Op.CALLDATASIZE)
    attack_block = (
        Op.MSTORE(Op.PUSH0, code_hash) if mem_update else Op.POP(code_hash)
    )

    benchmark_test(
        target_opcode=Op.SHA3,
        code_generator=JumpLoopGenerator(
            setup=Op.CALLDATACOPY(offset, Op.PUSH0, Op.CALLDATASIZE),
            attack_block=attack_block,
            tx_kwargs={"data": mem_alloc},
        ),
    )

Parametrized Test Cases

This test generates 18 parametrized test cases across 3 forks.