Skip to content

Commit 5e8b461

Browse files
authored
feat(tests/zkevm): add BLOBHASH test (#1666)
* zkevm: add BLOBHASH benchs Signed-off-by: Ignacio Hagopian <[email protected]> * generalize params Signed-off-by: Ignacio Hagopian <[email protected]> * improvements Signed-off-by: Ignacio Hagopian <[email protected]> --------- Signed-off-by: Ignacio Hagopian <[email protected]>
1 parent a1c3984 commit 5e8b461

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/zkevm/test_worst_compute.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from ethereum_test_base_types.base_types import Bytes
1616
from ethereum_test_forks import Fork
17+
from ethereum_test_specs.tests.test_fixtures import TransactionType
1718
from ethereum_test_tools import (
1819
Address,
1920
Alloc,
@@ -23,6 +24,7 @@
2324
Environment,
2425
StateTestFiller,
2526
Transaction,
27+
add_kzg_version,
2628
)
2729
from ethereum_test_tools.code.generators import While
2830
from ethereum_test_tools.vm.opcode import Opcodes as Op
@@ -823,6 +825,62 @@ def select_shift_amount(shift_fn, v):
823825
)
824826

825827

828+
@pytest.mark.valid_from("Cancun")
829+
@pytest.mark.parametrize(
830+
"blob_index, blobs_present",
831+
[
832+
pytest.param(0, 0, id="no blobs"),
833+
pytest.param(0, 1, id="one blob and accessed"),
834+
pytest.param(1, 1, id="one blob but access non-existent index"),
835+
pytest.param(5, 6, id="six blobs, access latest"),
836+
],
837+
)
838+
def test_worst_blobhash(
839+
fork: Fork,
840+
state_test: StateTestFiller,
841+
pre: Alloc,
842+
blob_index: int,
843+
blobs_present: bool,
844+
):
845+
"""Test running a block with as many BLOBHASH instructions as possible."""
846+
env = Environment()
847+
848+
code_prefix = Op.PUSH1(blob_index) + Op.JUMPDEST
849+
code_suffix = Op.JUMP(len(code_prefix) - 1)
850+
loop_iter = Op.POP(Op.BLOBHASH(Op.DUP1))
851+
code_body_len = (MAX_CODE_SIZE - len(code_prefix) - len(code_suffix)) // len(loop_iter)
852+
code_body = loop_iter * code_body_len
853+
code = code_prefix + code_body + code_suffix
854+
assert len(code) <= MAX_CODE_SIZE
855+
856+
tx_type = TransactionType.LEGACY
857+
blob_versioned_hashes = None
858+
max_fee_per_blob_gas = None
859+
if blobs_present > 0:
860+
tx_type = TransactionType.BLOB_TRANSACTION
861+
max_fee_per_blob_gas = fork.min_base_fee_per_blob_gas()
862+
blob_versioned_hashes = add_kzg_version(
863+
[i.to_bytes() * 32 for i in range(blobs_present)],
864+
BlobsSpec.BLOB_COMMITMENT_VERSION_KZG,
865+
)
866+
867+
tx = Transaction(
868+
ty=tx_type,
869+
to=pre.deploy_contract(code=code),
870+
gas_limit=env.gas_limit,
871+
max_fee_per_blob_gas=max_fee_per_blob_gas,
872+
blob_versioned_hashes=blob_versioned_hashes,
873+
sender=pre.fund_eoa(),
874+
)
875+
876+
state_test(
877+
env=env,
878+
pre=pre,
879+
post={},
880+
tx=tx,
881+
)
882+
883+
826884
@pytest.mark.valid_from("Cancun")
827885
@pytest.mark.parametrize("mod_bits", [255, 191, 127, 63])
828886
@pytest.mark.parametrize("op", [Op.MOD, Op.SMOD])

0 commit comments

Comments
 (0)