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
8 changes: 7 additions & 1 deletion packages/testing/src/execution_testing/specs/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class BenchmarkTest(BaseTest):
post: Alloc = Field(default_factory=Alloc)
tx: Transaction | None = None
setup_blocks: List[Block] = Field(default_factory=list)
setup_txs: List[Transaction] = Field(default_factory=list)
blocks: List[Block] | None = None
block_exception: (
List[TransactionException | BlockException]
Expand Down Expand Up @@ -338,6 +339,8 @@ def model_post_init(self, __context: Any, /) -> None:
)

transactions = self.split_transaction(self.tx, gas_limit)
if self.setup_txs is not None:
transactions = self.setup_txs + transactions

blocks.append(Block(txs=transactions))

Expand Down Expand Up @@ -440,7 +443,10 @@ def generate_fixed_opcode_count_transactions(self) -> List[Block]:
benchmark_tx = self.code_generator.generate_transaction(
pre=self.pre, gas_benchmark_value=gas_limit
)
execution_block = Block(txs=[benchmark_tx])

if self.setup_txs is not None:
txs = self.setup_txs + [benchmark_tx]
execution_block = Block(txs=txs)
return [execution_block]

def generate_blockchain_test(self) -> BlockchainTest:
Expand Down
27 changes: 17 additions & 10 deletions tests/benchmark/compute/instruction/test_tx_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
- BLOBHASH
"""

from typing import Any, Dict

import pytest
from execution_testing import (
Alloc,
BenchmarkTestFiller,
ExtCallGenerator,
Fork,
Op,
Transaction,
TransactionType,
add_kzg_version,
)
Expand Down Expand Up @@ -55,22 +55,29 @@ def test_blobhash(
fork: Fork,
benchmark_test: BenchmarkTestFiller,
blob_index: int,
pre: Alloc,
blobs_present: bool,
) -> None:
"""Benchmark BLOBHASH instruction."""
tx_kwargs: Dict[str, Any] = {}
if blobs_present > 0:
tx_kwargs["ty"] = TransactionType.BLOB_TRANSACTION
tx_kwargs["max_fee_per_blob_gas"] = fork.min_base_fee_per_blob_gas()
tx_kwargs["blob_versioned_hashes"] = add_kzg_version(
[i.to_bytes() * 32 for i in range(blobs_present)],
BlobsSpec.BLOB_COMMITMENT_VERSION_KZG,
setup_tx = []
if blobs_present:
setup_tx.append(
Transaction(
ty=TransactionType.BLOB_TRANSACTION,
max_fee_per_blob_gas=fork.min_base_fee_per_blob_gas(),
blob_versioned_hashes=add_kzg_version(
[i.to_bytes() * 32 for i in range(blobs_present)],
BlobsSpec.BLOB_COMMITMENT_VERSION_KZG,
),
sender=pre.fund_eoa(),
to=pre.fund_eoa(),
)
)

benchmark_test(
target_opcode=Op.BLOBHASH,
setup_txs=setup_tx,
code_generator=ExtCallGenerator(
attack_block=Op.BLOBHASH(blob_index),
tx_kwargs=tx_kwargs,
),
)
Loading