6
6
"""
7
7
8
8
import math
9
- from typing import SupportsBytes
9
+ from typing import cast
10
10
11
11
import pytest
12
12
@@ -337,7 +337,7 @@ def test_worst_modexp(
337
337
pytest .param (
338
338
bls12381_spec .Spec .G2MSM ,
339
339
[
340
- # TODO: the //2 is only required due to a limitation of the max contract size limit.
340
+ # TODO: the //2 is required due to a limitation of the max contract size limit.
341
341
# In a further iteration we can insert the inputs as calldata or storage and avoid
342
342
# having to do PUSHes which has this limtiation. This also applies to G1MSM.
343
343
(bls12381_spec .Spec .P2 + bls12381_spec .Scalar (bls12381_spec .Spec .Q ))
@@ -348,7 +348,8 @@ def test_worst_modexp(
348
348
pytest .param (
349
349
bls12381_spec .Spec .PAIRING ,
350
350
[
351
- bls12381_spec .Spec .G1 + bls12381_spec .Spec .INF_G2 ,
351
+ bls12381_spec .Spec .G1 ,
352
+ bls12381_spec .Spec .G2 ,
352
353
],
353
354
id = "bls12_pairing_check" ,
354
355
),
@@ -373,17 +374,24 @@ def test_worst_precompile_fixed_cost(
373
374
pre : Alloc ,
374
375
fork : Fork ,
375
376
precompile_address : Address ,
376
- parameters : list [str ] | list [BytesConcatenation ],
377
+ parameters : list [str ] | list [BytesConcatenation ] | list [ bytes ] ,
377
378
):
378
379
"""Test running a block filled with a precompile with fixed cost."""
379
380
env = Environment ()
380
381
381
- concatenated_bytes = bytes ()
382
- if isinstance (parameters [0 ], str ):
383
- concatenated_hex_string = "" .join (parameters )
382
+ concatenated_bytes : bytes
383
+ if all (isinstance (p , str ) for p in parameters ):
384
+ parameters_str = cast (list [str ], parameters )
385
+ concatenated_hex_string = "" .join (parameters_str )
384
386
concatenated_bytes = bytes .fromhex (concatenated_hex_string )
387
+ elif all (isinstance (p , (bytes , BytesConcatenation )) for p in parameters ):
388
+ parameters_bytes_list = [bytes (p ) for p in parameters ]
389
+ concatenated_bytes = b"" .join (parameters_bytes_list )
385
390
else :
386
- concatenated_bytes = b"" .join (bytes (p ) for p in parameters )
391
+ raise TypeError (
392
+ "parameters must be a list of strings (hex) "
393
+ "or a list of byte-like objects (bytes or BytesConcatenation)."
394
+ )
387
395
388
396
padding_length = (32 - (len (concatenated_bytes ) % 32 )) % 32
389
397
input_bytes = concatenated_bytes + b"\x00 " * padding_length
0 commit comments