Skip to content

test_keccak_diff_mem_msg_sizes()

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

Generate fixtures for these test cases for Amsterdam with:

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

Benchmark KECCAK256 instruction with diff memory and message sizes.

Source code in tests/benchmark/compute/instruction/test_keccak.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@pytest.mark.repricing
@pytest.mark.parametrize("mem_size", [0, 32, 256, 1024])
@pytest.mark.parametrize("msg_size", [0, 32, 256, 1024])
def test_keccak_diff_mem_msg_sizes(
    benchmark_test: BenchmarkTestFiller,
    mem_size: int,
    msg_size: int,
) -> None:
    """Benchmark KECCAK256 instruction with diff memory and message sizes."""
    # Setup expands memory to mem_size bytes (if > 0) by storing a value
    # Then the attack block hashes msg_size bytes starting from offset 0.
    setup = Op.MSTORE8(mem_size - 1, 0xFF) if mem_size > 0 else Bytecode()

    benchmark_test(
        target_opcode=Op.SHA3,
        code_generator=JumpLoopGenerator(
            setup=setup,
            attack_block=Op.MSTORE(Op.PUSH0, Op.SHA3(Op.PUSH0, msg_size)),
        ),
    )

Parametrized Test Cases

This test generates 16 parametrized test cases across 3 forks.