1313 Fork ,
1414 JumpLoopGenerator ,
1515 Op ,
16+ OpcodeTarget ,
1617 Transaction ,
1718 While ,
1819)
1920from py_ecc .bn128 import G1 , G2 , multiply
2021
21- from ..helpers import concatenate_parameters
22+ from ..helpers import Precompile , concatenate_parameters
2223
2324
2425@pytest .mark .parametrize (
25- "precompile_address,calldata" ,
26+ "precompile_address,calldata,target " ,
2627 [
2728 pytest .param (
2829 0x06 ,
3435 "06614E20C147E940F2D70DA3F74C9A17DF361706A4485C742BD6788478FA17D7" ,
3536 ]
3637 ),
38+ Precompile .BN128_ADD ,
3739 id = "bn128_add" ,
3840 marks = pytest .mark .repricing ,
3941 ),
4951 "0000000000000000000000000000000000000000000000000000000000000000" ,
5052 ]
5153 ),
54+ Precompile .BN128_ADD ,
5255 id = "bn128_add_infinities" ,
5356 marks = pytest .mark .repricing ,
5457 ),
6467 "0000000000000000000000000000000000000000000000000000000000000002" ,
6568 ]
6669 ),
70+ Precompile .BN128_ADD ,
6771 id = "bn128_add_1_2" ,
6872 ),
6973 pytest .param (
7579 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" ,
7680 ]
7781 ),
82+ Precompile .BN128_MUL ,
7883 id = "bn128_mul" ,
7984 ),
8085 # Ported from
8893 "0000000000000000000000000000000000000000000000000000000000000002" ,
8994 ]
9095 ),
96+ Precompile .BN128_MUL ,
9197 id = "bn128_mul_infinities_2_scalar" ,
9298 ),
9399 # Ported from
101107 "25f8c89ea3437f44f8fc8b6bfbb6312074dc6f983809a5e809ff4e1d076dd585" ,
102108 ]
103109 ),
110+ Precompile .BN128_MUL ,
104111 id = "bn128_mul_infinities_32_byte_scalar" ,
105112 marks = pytest .mark .repricing ,
106113 ),
115122 "0000000000000000000000000000000000000000000000000000000000000002" ,
116123 ]
117124 ),
125+ Precompile .BN128_MUL ,
118126 id = "bn128_mul_1_2_2_scalar" ,
119127 ),
120128 # Ported from
128136 "25f8c89ea3437f44f8fc8b6bfbb6312074dc6f983809a5e809ff4e1d076dd585" ,
129137 ]
130138 ),
139+ Precompile .BN128_MUL ,
131140 id = "bn128_mul_1_2_32_byte_scalar" ,
132141 ),
133142 # Ported from
141150 "0000000000000000000000000000000000000000000000000000000000000002" ,
142151 ]
143152 ),
153+ Precompile .BN128_MUL ,
144154 id = "bn128_mul_32_byte_coord_and_2_scalar" ,
145155 marks = pytest .mark .repricing ,
146156 ),
155165 "25f8c89ea3437f44f8fc8b6bfbb6312074dc6f983809a5e809ff4e1d076dd585" ,
156166 ]
157167 ),
168+ Precompile .BN128_MUL ,
158169 id = "bn128_mul_32_byte_coord_and_scalar" ,
159170 marks = pytest .mark .repricing ,
160171 ),
178189 "12C85EA5DB8C6DEB4AAB71808DCB408FE3D1E7690C43D37B4CE6CC0166FA7DAA" ,
179190 ]
180191 ),
192+ Precompile .BN128_PAIRING ,
181193 id = "bn128_two_pairings" ,
182194 ),
183195 pytest .param (
193205 "120A2A4CF30C1BF9845F20C6FE39E07EA2CCE61F0C9BB048165FE5E4DE877550" ,
194206 ]
195207 ),
208+ Precompile .BN128_PAIRING ,
196209 id = "bn128_one_pairing" ,
197210 ),
198211 # Ported from
199212 # https://github.com/NethermindEth/nethermind/blob/ceb8d57b8530ce8181d7427c115ca593386909d6/tools/EngineRequestsGenerator/TestCase.cs#L353
200- pytest .param (0x08 , [], id = "ec_pairing_zero_input" ),
213+ pytest .param (
214+ 0x08 ,
215+ [],
216+ Precompile .BN128_PAIRING ,
217+ id = "ec_pairing_zero_input" ,
218+ ),
201219 pytest .param (
202220 0x08 ,
203221 concatenate_parameters (
218236 "3a8eb0b0996252cb548a4487da97b02422ebc0e834613f954de6c7e0afdc1fc0" ,
219237 ]
220238 ),
239+ Precompile .BN128_PAIRING ,
221240 id = "ec_pairing_2_sets" ,
222241 ),
223242 pytest .param (
224243 0x08 ,
225244 concatenate_parameters (["" ]),
245+ Precompile .BN128_PAIRING ,
226246 id = "ec_pairing_1_pair" ,
227247 ),
228248 pytest .param (
245265 "12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa" ,
246266 ]
247267 ),
268+ Precompile .BN128_PAIRING ,
248269 id = "ec_pairing_2_pair" ,
249270 ),
250271 pytest .param (
272293 "12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa" ,
273294 ]
274295 ),
296+ Precompile .BN128_PAIRING ,
275297 id = "ec_pairing_3_pair" ,
276298 ),
277299 pytest .param (
308330 "2dc4cb08068b4aa5f14b7f1096ab35d5c13d78319ec7e66e9f67a1ff20cbbf03" ,
309331 ]
310332 ),
333+ Precompile .BN128_PAIRING ,
311334 id = "ec_pairing_4_pair" ,
312335 ),
313336 pytest .param (
351374 "1ac5dac62d2332faa8069faca3b0d27fcdf95d8c8bafc9074ee72b5c1f33aa70" ,
352375 ]
353376 ),
377+ Precompile .BN128_PAIRING ,
354378 id = "ec_pairing_5_pair" ,
355379 ),
356380 pytest .param (
360384 "0000000000000000000000000000000000000000000000000000000000000000" ,
361385 ]
362386 ),
387+ Precompile .BN128_PAIRING ,
363388 id = "ec_pairing_1_pair_empty" ,
364389 ),
365390 ],
@@ -368,6 +393,7 @@ def test_alt_bn128(
368393 benchmark_test : BenchmarkTestFiller ,
369394 precompile_address : Address ,
370395 calldata : bytes ,
396+ target : OpcodeTarget ,
371397) -> None :
372398 """Benchmark ALT_BN128 precompile."""
373399 attack_block = Op .POP (
@@ -377,7 +403,7 @@ def test_alt_bn128(
377403 )
378404
379405 benchmark_test (
380- target_opcode = Op . STATICCALL ,
406+ target_opcode = target ,
381407 code_generator = JumpLoopGenerator (
382408 setup = Op .CALLDATACOPY (0 , 0 , Op .CALLDATASIZE ),
383409 attack_block = attack_block ,
@@ -493,7 +519,7 @@ def test_bn128_pairings_amortized(
493519 )
494520
495521 benchmark_test (
496- target_opcode = Op . STATICCALL ,
522+ target_opcode = Precompile . BN128_PAIRING ,
497523 code_generator = JumpLoopGenerator (
498524 setup = setup ,
499525 attack_block = attack_block ,
@@ -520,7 +546,7 @@ def test_alt_bn128_benchmark(
520546 )
521547
522548 benchmark_test (
523- target_opcode = Op . STATICCALL ,
549+ target_opcode = Precompile . BN128_PAIRING ,
524550 code_generator = JumpLoopGenerator (
525551 setup = Op .CALLDATACOPY (0 , 0 , Op .CALLDATASIZE ),
526552 attack_block = attack_block ,
@@ -633,7 +659,7 @@ def test_ec_pairing(
633659 seed_offset += per_tx_variants
634660
635661 benchmark_test (
636- target_opcode = Op . STATICCALL ,
662+ target_opcode = Precompile . BN128_PAIRING ,
637663 skip_gas_used_validation = True ,
638664 blocks = [Block (txs = txs )],
639665 )
@@ -652,11 +678,21 @@ def _generate_g1_point(seed: int) -> Bytes:
652678
653679@pytest .mark .repricing
654680@pytest .mark .parametrize (
655- "precompile_address,scalar" ,
681+ "precompile_address,scalar,target " ,
656682 [
657- pytest .param (0x06 , None , id = "ec_add" ),
658- pytest .param (0x07 , 2 , id = "ec_mul_small_scalar" ),
659- pytest .param (0x07 , 2 ** 256 - 1 , id = "ec_mul_max_scalar" ),
683+ pytest .param (0x06 , None , Precompile .BN128_ADD , id = "ec_add" ),
684+ pytest .param (
685+ 0x07 ,
686+ 2 ,
687+ Precompile .BN128_MUL ,
688+ id = "ec_mul_small_scalar" ,
689+ ),
690+ pytest .param (
691+ 0x07 ,
692+ 2 ** 256 - 1 ,
693+ Precompile .BN128_MUL ,
694+ id = "ec_mul_max_scalar" ,
695+ ),
660696 ],
661697)
662698def test_alt_bn128_uncachable (
@@ -667,6 +703,7 @@ def test_alt_bn128_uncachable(
667703 tx_gas_limit : int ,
668704 precompile_address : Address ,
669705 scalar : int | None ,
706+ target : OpcodeTarget ,
670707) -> None :
671708 """
672709 Benchmark ecAdd/ecMul with unique input per call.
@@ -722,6 +759,6 @@ def test_alt_bn128_uncachable(
722759 seed += 1
723760
724761 benchmark_test (
725- target_opcode = Op . STATICCALL ,
762+ target_opcode = target ,
726763 blocks = [Block (txs = txs )],
727764 )
0 commit comments