diff --git a/tests/benchmark/compute/precompile/test_alt_bn128.py b/tests/benchmark/compute/precompile/test_alt_bn128.py index 55026a44eb..d0fdb2e53f 100644 --- a/tests/benchmark/compute/precompile/test_alt_bn128.py +++ b/tests/benchmark/compute/precompile/test_alt_bn128.py @@ -371,6 +371,7 @@ def test_alt_bn128( ) benchmark_test( + target_opcode=Op.STATICCALL, code_generator=JumpLoopGenerator( setup=Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE), attack_block=attack_block, @@ -418,7 +419,7 @@ def _generate_bn128_pairs(n: int, seed: int = 0) -> Bytes: def test_bn128_pairings_amortized( benchmark_test: BenchmarkTestFiller, fork: Fork, - gas_benchmark_value: int, + tx_gas_limit: int, ) -> None: """Test running a block with as many BN128 pairings as possible.""" base_cost = 45_000 @@ -432,9 +433,7 @@ def test_bn128_pairings_amortized( # This is a theoretical maximum number of pairings that can be done in a # block. It is only used for an upper bound for calculating the optimal # number of pairings below. - maximum_number_of_pairings = ( - gas_benchmark_value - base_cost - ) // pairing_cost + maximum_number_of_pairings = (tx_gas_limit - base_cost) // pairing_cost # Discover the optimal number of pairings balancing two dimensions: # 1. Amortize the precompile base cost as much as possible. @@ -444,7 +443,7 @@ def test_bn128_pairings_amortized( for i in range(1, maximum_number_of_pairings + 1): # We'll pass all pairing arguments via calldata. available_gas_after_intrinsic = ( - gas_benchmark_value + tx_gas_limit - intrinsic_gas_calculator( calldata=[0xFF] * size_per_pairing @@ -480,6 +479,7 @@ def test_bn128_pairings_amortized( ) benchmark_test( + target_opcode=Op.STATICCALL, code_generator=JumpLoopGenerator( setup=setup, attack_block=attack_block, diff --git a/tests/benchmark/compute/precompile/test_blake2f.py b/tests/benchmark/compute/precompile/test_blake2f.py index 20cfe71716..e332d8e63a 100644 --- a/tests/benchmark/compute/precompile/test_blake2f.py +++ b/tests/benchmark/compute/precompile/test_blake2f.py @@ -47,6 +47,7 @@ def test_blake2f( ) benchmark_test( + target_opcode=Op.STATICCALL, code_generator=JumpLoopGenerator( setup=Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE), attack_block=attack_block, diff --git a/tests/benchmark/compute/precompile/test_bls12_381.py b/tests/benchmark/compute/precompile/test_bls12_381.py index faa86c07cc..e66b8c8310 100644 --- a/tests/benchmark/compute/precompile/test_bls12_381.py +++ b/tests/benchmark/compute/precompile/test_bls12_381.py @@ -115,6 +115,7 @@ def test_bls12_381( ) benchmark_test( + target_opcode=Op.STATICCALL, code_generator=JumpLoopGenerator( setup=Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE), attack_block=attack_block, diff --git a/tests/benchmark/compute/precompile/test_ecrecover.py b/tests/benchmark/compute/precompile/test_ecrecover.py index 0871c3281f..50e3338c53 100644 --- a/tests/benchmark/compute/precompile/test_ecrecover.py +++ b/tests/benchmark/compute/precompile/test_ecrecover.py @@ -48,6 +48,7 @@ def test_ecrecover( ) benchmark_test( + target_opcode=Op.STATICCALL, code_generator=JumpLoopGenerator( setup=Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE), attack_block=attack_block, diff --git a/tests/benchmark/compute/precompile/test_identity.py b/tests/benchmark/compute/precompile/test_identity.py index 64e81a865c..b34b3875b0 100644 --- a/tests/benchmark/compute/precompile/test_identity.py +++ b/tests/benchmark/compute/precompile/test_identity.py @@ -1,5 +1,6 @@ """Benchmark IDENTITY precompile.""" +import pytest from execution_testing import ( BenchmarkTestFiller, Fork, @@ -13,11 +14,11 @@ def test_identity( benchmark_test: BenchmarkTestFiller, fork: Fork, - gas_benchmark_value: int, + tx_gas_limit: int, ) -> None: """Benchmark IDENTITY precompile.""" intrinsic_gas_calculator = fork.transaction_intrinsic_cost_calculator() - gas_available = gas_benchmark_value - intrinsic_gas_calculator() + gas_available = tx_gas_limit - intrinsic_gas_calculator() optimal_input_length = calculate_optimal_input_length( available_gas=gas_available, @@ -34,8 +35,26 @@ def test_identity( ) benchmark_test( + target_opcode=Op.STATICCALL, code_generator=JumpLoopGenerator( setup=Op.CODECOPY(0, 0, optimal_input_length), attack_block=attack_block, ), ) + + +@pytest.mark.parametrize("size", [0, 32, 256, 1024]) +def test_identity_fixed_size( + benchmark_test: BenchmarkTestFiller, size: int +) -> None: + """Benchmark IDENTITY with fixed size input.""" + attack_block = Op.POP( + Op.STATICCALL(Op.GAS, 0x04, Op.PUSH0, size, Op.PUSH0, Op.PUSH0) + ) + + benchmark_test( + target_opcode=Op.STATICCALL, + code_generator=JumpLoopGenerator( + setup=Op.CODECOPY(0, 0, size), attack_block=attack_block + ), + ) diff --git a/tests/benchmark/compute/precompile/test_modexp.py b/tests/benchmark/compute/precompile/test_modexp.py index ef196735d4..7de5ab8b9b 100644 --- a/tests/benchmark/compute/precompile/test_modexp.py +++ b/tests/benchmark/compute/precompile/test_modexp.py @@ -408,6 +408,7 @@ def test_modexp( ) ) benchmark_test( + target_opcode=Op.STATICCALL, code_generator=JumpLoopGenerator( setup=Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE), attack_block=attack_block, diff --git a/tests/benchmark/compute/precompile/test_p256verify.py b/tests/benchmark/compute/precompile/test_p256verify.py index 6218dd65fa..2859b40f01 100644 --- a/tests/benchmark/compute/precompile/test_p256verify.py +++ b/tests/benchmark/compute/precompile/test_p256verify.py @@ -79,6 +79,7 @@ def test_p256verify( ) benchmark_test( + target_opcode=Op.STATICCALL, code_generator=JumpLoopGenerator( setup=Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE), attack_block=attack_block, diff --git a/tests/benchmark/compute/precompile/test_point_evaluation.py b/tests/benchmark/compute/precompile/test_point_evaluation.py index 4ffcbb0470..e5b055d266 100644 --- a/tests/benchmark/compute/precompile/test_point_evaluation.py +++ b/tests/benchmark/compute/precompile/test_point_evaluation.py @@ -48,6 +48,7 @@ def test_point_evaluation( ) benchmark_test( + target_opcode=Op.STATICCALL, code_generator=JumpLoopGenerator( setup=Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE), attack_block=attack_block, diff --git a/tests/benchmark/compute/precompile/test_ripemd160.py b/tests/benchmark/compute/precompile/test_ripemd160.py index 24821320d6..58f1cf8538 100644 --- a/tests/benchmark/compute/precompile/test_ripemd160.py +++ b/tests/benchmark/compute/precompile/test_ripemd160.py @@ -1,5 +1,6 @@ """Benchmark RIPEMD-160 precompile.""" +import pytest from execution_testing import ( BenchmarkTestFiller, Fork, @@ -34,8 +35,26 @@ def test_ripemd160( ) benchmark_test( + target_opcode=Op.STATICCALL, code_generator=JumpLoopGenerator( setup=Op.CODECOPY(0, 0, optimal_input_length), attack_block=attack_block, ), ) + + +@pytest.mark.parametrize("size", [0, 32, 256, 1024]) +def test_ripemd160_fixed_size( + benchmark_test: BenchmarkTestFiller, size: int +) -> None: + """Benchmark RIPEMD160 with fixed size input.""" + attack_block = Op.POP( + Op.STATICCALL(Op.GAS, 0x03, Op.PUSH0, size, Op.PUSH0, Op.PUSH0) + ) + + benchmark_test( + target_opcode=Op.STATICCALL, + code_generator=JumpLoopGenerator( + setup=Op.CODECOPY(0, 0, size), attack_block=attack_block + ), + ) diff --git a/tests/benchmark/compute/precompile/test_sha256.py b/tests/benchmark/compute/precompile/test_sha256.py index 8096d5dfde..c57ec4cd6d 100644 --- a/tests/benchmark/compute/precompile/test_sha256.py +++ b/tests/benchmark/compute/precompile/test_sha256.py @@ -1,5 +1,6 @@ """Benchmark SHA256 precompile.""" +import pytest from execution_testing import ( BenchmarkTestFiller, Fork, @@ -34,8 +35,26 @@ def test_sha256( ) benchmark_test( + target_opcode=Op.STATICCALL, code_generator=JumpLoopGenerator( setup=Op.CODECOPY(0, 0, optimal_input_length), attack_block=attack_block, ), ) + + +@pytest.mark.parametrize("size", [0, 32, 256, 1024]) +def test_sha256_fixed_size( + benchmark_test: BenchmarkTestFiller, size: int +) -> None: + """Benchmark SHA256 with fixed size input.""" + attack_block = Op.POP( + Op.STATICCALL(Op.GAS, 0x02, Op.PUSH0, size, Op.PUSH0, Op.PUSH0) + ) + + benchmark_test( + target_opcode=Op.STATICCALL, + code_generator=JumpLoopGenerator( + setup=Op.CODECOPY(0, 0, size), attack_block=attack_block + ), + )