Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions tests/benchmark/compute/precompile/test_alt_bn128.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -480,6 +479,7 @@ def test_bn128_pairings_amortized(
)

benchmark_test(
target_opcode=Op.STATICCALL,
code_generator=JumpLoopGenerator(
setup=setup,
attack_block=attack_block,
Expand Down
1 change: 1 addition & 0 deletions tests/benchmark/compute/precompile/test_blake2f.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tests/benchmark/compute/precompile/test_bls12_381.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tests/benchmark/compute/precompile/test_ecrecover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 21 additions & 2 deletions tests/benchmark/compute/precompile/test_identity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Benchmark IDENTITY precompile."""

import pytest
from execution_testing import (
BenchmarkTestFiller,
Fork,
Expand All @@ -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,
Expand All @@ -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, 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
),
)
1 change: 1 addition & 0 deletions tests/benchmark/compute/precompile/test_modexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tests/benchmark/compute/precompile/test_p256verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions tests/benchmark/compute/precompile/test_ripemd160.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Benchmark RIPEMD-160 precompile."""

import pytest
from execution_testing import (
BenchmarkTestFiller,
Fork,
Expand Down Expand Up @@ -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, 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
),
)
19 changes: 19 additions & 0 deletions tests/benchmark/compute/precompile/test_sha256.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Benchmark SHA256 precompile."""

import pytest
from execution_testing import (
BenchmarkTestFiller,
Fork,
Expand Down Expand Up @@ -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
),
)
Loading