7
7
8
8
Add a function that is named `test_<test_name>` and takes at least the following arguments:
9
9
10
- - blockchain_test
10
+ - blockchain_test | state_test
11
11
- pre
12
12
- tx
13
13
- post
31
31
import glob
32
32
import json
33
33
import os
34
- from typing import Dict , Iterator , List
34
+ from typing import Dict , Iterator , List , Optional
35
35
36
36
import pytest
37
37
38
38
from ethereum_test_tools import (
39
39
Account ,
40
- Auto ,
41
40
Block ,
42
41
BlockchainTestFiller ,
42
+ Environment ,
43
+ StateTestFiller ,
43
44
Storage ,
44
45
TestAddress ,
45
46
Transaction ,
54
55
REFERENCE_SPEC_GIT_PATH = ref_spec_4844 .git_path
55
56
REFERENCE_SPEC_VERSION = ref_spec_4844 .version
56
57
57
- auto = Auto ()
58
-
59
58
60
59
@pytest .fixture
61
60
def precompile_input (
62
- versioned_hash : bytes | int | Auto ,
61
+ versioned_hash : Optional [ bytes | int ] ,
63
62
kzg_commitment : bytes | int ,
64
63
z : bytes | int ,
65
64
y : bytes | int ,
@@ -76,7 +75,7 @@ def precompile_input(
76
75
kzg_commitment = kzg_commitment .to_bytes (48 , "big" )
77
76
if isinstance (kzg_proof , int ):
78
77
kzg_proof = kzg_proof .to_bytes (48 , "big" )
79
- if isinstance ( versioned_hash , Auto ) :
78
+ if versioned_hash is None :
80
79
versioned_hash = Spec .kzg_to_versioned_hash (kzg_commitment )
81
80
elif isinstance (versioned_hash , int ):
82
81
versioned_hash = versioned_hash .to_bytes (32 , "big" )
@@ -245,13 +244,13 @@ def post(
245
244
@pytest .mark .parametrize (
246
245
"z,y,kzg_commitment,kzg_proof,versioned_hash" ,
247
246
[
248
- pytest .param (Spec .BLS_MODULUS - 1 , 0 , INF_POINT , INF_POINT , auto , id = "in_bounds_z" ),
247
+ pytest .param (Spec .BLS_MODULUS - 1 , 0 , INF_POINT , INF_POINT , None , id = "in_bounds_z" ),
249
248
],
250
249
)
251
250
@pytest .mark .parametrize ("success" , [True ])
252
251
@pytest .mark .valid_from ("Cancun" )
253
252
def test_valid_precompile_calls (
254
- blockchain_test : BlockchainTestFiller ,
253
+ state_test : StateTestFiller ,
255
254
pre : Dict ,
256
255
tx : Transaction ,
257
256
post : Dict ,
@@ -262,25 +261,26 @@ def test_valid_precompile_calls(
262
261
- `kzg_commitment` and `kzg_proof` are set to values such that `p(z)==0` for all values of `z`,
263
262
hence `y` is tested to be zero, and call to be successful.
264
263
"""
265
- blockchain_test (
264
+ state_test (
265
+ env = Environment (),
266
266
pre = pre ,
267
267
post = post ,
268
- blocks = [ Block ( txs = [ tx ])] ,
268
+ tx = tx ,
269
269
)
270
270
271
271
272
272
@pytest .mark .parametrize (
273
273
"z,y,kzg_commitment,kzg_proof,versioned_hash" ,
274
274
[
275
- (Spec .BLS_MODULUS , 0 , INF_POINT , INF_POINT , auto ),
276
- (0 , Spec .BLS_MODULUS , INF_POINT , INF_POINT , auto ),
277
- (Z , 0 , INF_POINT , INF_POINT [:- 1 ], auto ),
278
- (Z , 0 , INF_POINT , INF_POINT [0 :1 ], auto ),
279
- (Z , 0 , INF_POINT , INF_POINT + bytes ([0 ]), auto ),
280
- (Z , 0 , INF_POINT , INF_POINT + bytes ([0 ] * 1023 ), auto ),
275
+ (Spec .BLS_MODULUS , 0 , INF_POINT , INF_POINT , None ),
276
+ (0 , Spec .BLS_MODULUS , INF_POINT , INF_POINT , None ),
277
+ (Z , 0 , INF_POINT , INF_POINT [:- 1 ], None ),
278
+ (Z , 0 , INF_POINT , INF_POINT [0 :1 ], None ),
279
+ (Z , 0 , INF_POINT , INF_POINT + bytes ([0 ]), None ),
280
+ (Z , 0 , INF_POINT , INF_POINT + bytes ([0 ] * 1023 ), None ),
281
281
(bytes (), bytes (), bytes (), bytes (), bytes ()),
282
282
(0 , 0 , 0 , 0 , 0 ),
283
- (0 , 0 , 0 , 0 , auto ),
283
+ (0 , 0 , 0 , 0 , None ),
284
284
(Z , 0 , INF_POINT , INF_POINT , Spec .kzg_to_versioned_hash (0xC0 << 376 , 0x00 )),
285
285
(Z , 0 , INF_POINT , INF_POINT , Spec .kzg_to_versioned_hash (0xC0 << 376 , 0x02 )),
286
286
(Z , 0 , INF_POINT , INF_POINT , Spec .kzg_to_versioned_hash (0xC0 << 376 , 0xFF )),
@@ -303,7 +303,7 @@ def test_valid_precompile_calls(
303
303
@pytest .mark .parametrize ("success" , [False ])
304
304
@pytest .mark .valid_from ("Cancun" )
305
305
def test_invalid_precompile_calls (
306
- blockchain_test : BlockchainTestFiller ,
306
+ state_test : StateTestFiller ,
307
307
pre : Dict ,
308
308
tx : Transaction ,
309
309
post : Dict ,
@@ -317,10 +317,11 @@ def test_invalid_precompile_calls(
317
317
- Zero inputs
318
318
- Correct proof, commitment, z and y, but incorrect version versioned hash
319
319
"""
320
- blockchain_test (
320
+ state_test (
321
+ env = Environment (),
321
322
pre = pre ,
322
323
post = post ,
323
- blocks = [ Block ( txs = [ tx ])] ,
324
+ tx = tx ,
324
325
)
325
326
326
327
@@ -417,10 +418,10 @@ def all_external_vectors() -> List:
417
418
"z,y,kzg_commitment,kzg_proof,success" ,
418
419
all_external_vectors (),
419
420
)
420
- @pytest .mark .parametrize ("versioned_hash" , [auto ])
421
+ @pytest .mark .parametrize ("versioned_hash" , [None ])
421
422
@pytest .mark .valid_from ("Cancun" )
422
423
def test_point_evaluation_precompile_external_vectors (
423
- blockchain_test : BlockchainTestFiller ,
424
+ state_test : StateTestFiller ,
424
425
pre : Dict ,
425
426
tx : Transaction ,
426
427
post : Dict ,
@@ -431,10 +432,11 @@ def test_point_evaluation_precompile_external_vectors(
431
432
- `go_kzg_4844_verify_kzg_proof.json`: test vectors from the
432
433
[go-kzg-4844](https://github.com/crate-crypto/go-kzg-4844) repository.
433
434
"""
434
- blockchain_test (
435
+ state_test (
436
+ env = Environment (),
435
437
pre = pre ,
436
438
post = post ,
437
- blocks = [ Block ( txs = [ tx ])] ,
439
+ tx = tx ,
438
440
)
439
441
440
442
@@ -458,12 +460,12 @@ def test_point_evaluation_precompile_external_vectors(
458
460
)
459
461
@pytest .mark .parametrize (
460
462
"z,kzg_commitment,kzg_proof,versioned_hash" ,
461
- [[Z , INF_POINT , INF_POINT , auto ]],
463
+ [[Z , INF_POINT , INF_POINT , None ]],
462
464
ids = ["" ],
463
465
)
464
466
@pytest .mark .valid_from ("Cancun" )
465
467
def test_point_evaluation_precompile_calls (
466
- blockchain_test : BlockchainTestFiller ,
468
+ state_test : StateTestFiller ,
467
469
pre : Dict ,
468
470
tx : Transaction ,
469
471
post : Dict ,
@@ -476,10 +478,11 @@ def test_point_evaluation_precompile_calls(
476
478
- Using correct and incorrect proofs
477
479
- Using barely insufficient gas
478
480
"""
479
- blockchain_test (
481
+ state_test (
482
+ env = Environment (),
480
483
pre = pre ,
481
484
post = post ,
482
- blocks = [ Block ( txs = [ tx ])] ,
485
+ tx = tx ,
483
486
)
484
487
485
488
@@ -495,14 +498,14 @@ def test_point_evaluation_precompile_calls(
495
498
@pytest .mark .parametrize (
496
499
"z,y,kzg_commitment,kzg_proof,versioned_hash,proof_correct" ,
497
500
[
498
- [Z , 0 , INF_POINT , INF_POINT , auto , True ],
499
- [Z , 1 , INF_POINT , INF_POINT , auto , False ],
501
+ [Z , 0 , INF_POINT , INF_POINT , None , True ],
502
+ [Z , 1 , INF_POINT , INF_POINT , None , False ],
500
503
],
501
504
ids = ["correct_proof" , "incorrect_proof" ],
502
505
)
503
506
@pytest .mark .valid_from ("Cancun" )
504
507
def test_point_evaluation_precompile_gas_tx_to (
505
- blockchain_test : BlockchainTestFiller ,
508
+ state_test : StateTestFiller ,
506
509
precompile_input : bytes ,
507
510
call_gas : int ,
508
511
proof_correct : bool ,
@@ -554,20 +557,80 @@ def test_point_evaluation_precompile_gas_tx_to(
554
557
)
555
558
}
556
559
557
- blockchain_test (
560
+ state_test (
561
+ env = Environment (),
558
562
pre = pre ,
559
563
post = post ,
560
- blocks = [ Block ( txs = [ tx ])] ,
564
+ tx = tx ,
561
565
)
562
566
563
567
564
568
@pytest .mark .parametrize (
565
569
"z,y,kzg_commitment,kzg_proof,versioned_hash" ,
566
- [[Z , 0 , INF_POINT , INF_POINT , auto ]],
570
+ [[Z , 0 , INF_POINT , INF_POINT , None ]],
567
571
ids = ["correct_proof" ],
568
572
)
569
573
@pytest .mark .valid_at_transition_to ("Cancun" )
570
574
def test_point_evaluation_precompile_before_fork (
575
+ state_test : StateTestFiller ,
576
+ pre : Dict ,
577
+ tx : Transaction ,
578
+ ):
579
+ """
580
+ Test calling the Point Evaluation Precompile before the appropriate fork.
581
+ """
582
+ precompile_caller_code = Op .SSTORE (
583
+ Op .NUMBER ,
584
+ Op .CALL (
585
+ Op .GAS ,
586
+ Spec .POINT_EVALUATION_PRECOMPILE_ADDRESS ,
587
+ 1 , # Value
588
+ 0 , # Zero-length calldata
589
+ 0 ,
590
+ 0 , # Zero-length return
591
+ 0 ,
592
+ ),
593
+ )
594
+ precompile_caller_address = to_address (0x100 )
595
+
596
+ pre = {
597
+ TestAddress : Account (
598
+ nonce = 0 ,
599
+ balance = 0x10 ** 18 ,
600
+ ),
601
+ precompile_caller_address : Account (
602
+ nonce = 0 ,
603
+ code = precompile_caller_code ,
604
+ balance = 0x10 ** 18 ,
605
+ ),
606
+ }
607
+
608
+ post = {
609
+ precompile_caller_address : Account (
610
+ storage = {1 : 1 },
611
+ # The call succeeds because precompile is not there yet
612
+ ),
613
+ to_address (Spec .POINT_EVALUATION_PRECOMPILE_ADDRESS ): Account (
614
+ balance = 1 ,
615
+ ),
616
+ }
617
+
618
+ state_test (
619
+ tag = "point_evaluation_precompile_before_fork" ,
620
+ pre = pre ,
621
+ env = Environment (timestamp = 7_500 ),
622
+ post = post ,
623
+ tx = tx ,
624
+ )
625
+
626
+
627
+ @pytest .mark .parametrize (
628
+ "z,y,kzg_commitment,kzg_proof,versioned_hash" ,
629
+ [[Z , 0 , INF_POINT , INF_POINT , None ]],
630
+ ids = ["correct_proof" ],
631
+ )
632
+ @pytest .mark .valid_at_transition_to ("Cancun" )
633
+ def test_point_evaluation_precompile_during_fork (
571
634
blockchain_test : BlockchainTestFiller ,
572
635
pre : Dict ,
573
636
tx : Transaction ,
@@ -620,7 +683,7 @@ def tx_generator() -> Iterator[Transaction]:
620
683
post = {
621
684
precompile_caller_address : Account (
622
685
storage = {b : 1 for b in range (1 , len (PRE_FORK_BLOCK_RANGE ) + 1 )},
623
- # The tx in last block succeeds ; storage 0 by default.
686
+ # Only the call in the last block's tx fails ; storage 0 by default.
624
687
),
625
688
to_address (Spec .POINT_EVALUATION_PRECOMPILE_ADDRESS ): Account (
626
689
balance = len (PRE_FORK_BLOCK_RANGE ),
0 commit comments