77
88 Add a function that is named `test_<test_name>` and takes at least the following arguments:
99
10- - blockchain_test
10+ - blockchain_test | state_test
1111 - pre
1212 - tx
1313 - post
3131import glob
3232import json
3333import os
34- from typing import Dict , Iterator , List
34+ from typing import Dict , Iterator , List , Optional
3535
3636import pytest
3737
3838from ethereum_test_tools import (
3939 Account ,
40- Auto ,
4140 Block ,
4241 BlockchainTestFiller ,
42+ Environment ,
43+ StateTestFiller ,
4344 Storage ,
4445 TestAddress ,
4546 Transaction ,
5455REFERENCE_SPEC_GIT_PATH = ref_spec_4844 .git_path
5556REFERENCE_SPEC_VERSION = ref_spec_4844 .version
5657
57- auto = Auto ()
58-
5958
6059@pytest .fixture
6160def precompile_input (
62- versioned_hash : bytes | int | Auto ,
61+ versioned_hash : Optional [ bytes | int ] ,
6362 kzg_commitment : bytes | int ,
6463 z : bytes | int ,
6564 y : bytes | int ,
@@ -76,7 +75,7 @@ def precompile_input(
7675 kzg_commitment = kzg_commitment .to_bytes (48 , "big" )
7776 if isinstance (kzg_proof , int ):
7877 kzg_proof = kzg_proof .to_bytes (48 , "big" )
79- if isinstance ( versioned_hash , Auto ) :
78+ if versioned_hash is None :
8079 versioned_hash = Spec .kzg_to_versioned_hash (kzg_commitment )
8180 elif isinstance (versioned_hash , int ):
8281 versioned_hash = versioned_hash .to_bytes (32 , "big" )
@@ -245,13 +244,13 @@ def post(
245244@pytest .mark .parametrize (
246245 "z,y,kzg_commitment,kzg_proof,versioned_hash" ,
247246 [
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" ),
249248 ],
250249)
251250@pytest .mark .parametrize ("success" , [True ])
252251@pytest .mark .valid_from ("Cancun" )
253252def test_valid_precompile_calls (
254- blockchain_test : BlockchainTestFiller ,
253+ state_test : StateTestFiller ,
255254 pre : Dict ,
256255 tx : Transaction ,
257256 post : Dict ,
@@ -262,25 +261,26 @@ def test_valid_precompile_calls(
262261 - `kzg_commitment` and `kzg_proof` are set to values such that `p(z)==0` for all values of `z`,
263262 hence `y` is tested to be zero, and call to be successful.
264263 """
265- blockchain_test (
264+ state_test (
265+ env = Environment (),
266266 pre = pre ,
267267 post = post ,
268- blocks = [ Block ( txs = [ tx ])] ,
268+ tx = tx ,
269269 )
270270
271271
272272@pytest .mark .parametrize (
273273 "z,y,kzg_commitment,kzg_proof,versioned_hash" ,
274274 [
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 ),
281281 (bytes (), bytes (), bytes (), bytes (), bytes ()),
282282 (0 , 0 , 0 , 0 , 0 ),
283- (0 , 0 , 0 , 0 , auto ),
283+ (0 , 0 , 0 , 0 , None ),
284284 (Z , 0 , INF_POINT , INF_POINT , Spec .kzg_to_versioned_hash (0xC0 << 376 , 0x00 )),
285285 (Z , 0 , INF_POINT , INF_POINT , Spec .kzg_to_versioned_hash (0xC0 << 376 , 0x02 )),
286286 (Z , 0 , INF_POINT , INF_POINT , Spec .kzg_to_versioned_hash (0xC0 << 376 , 0xFF )),
@@ -303,7 +303,7 @@ def test_valid_precompile_calls(
303303@pytest .mark .parametrize ("success" , [False ])
304304@pytest .mark .valid_from ("Cancun" )
305305def test_invalid_precompile_calls (
306- blockchain_test : BlockchainTestFiller ,
306+ state_test : StateTestFiller ,
307307 pre : Dict ,
308308 tx : Transaction ,
309309 post : Dict ,
@@ -317,10 +317,11 @@ def test_invalid_precompile_calls(
317317 - Zero inputs
318318 - Correct proof, commitment, z and y, but incorrect version versioned hash
319319 """
320- blockchain_test (
320+ state_test (
321+ env = Environment (),
321322 pre = pre ,
322323 post = post ,
323- blocks = [ Block ( txs = [ tx ])] ,
324+ tx = tx ,
324325 )
325326
326327
@@ -417,10 +418,10 @@ def all_external_vectors() -> List:
417418 "z,y,kzg_commitment,kzg_proof,success" ,
418419 all_external_vectors (),
419420)
420- @pytest .mark .parametrize ("versioned_hash" , [auto ])
421+ @pytest .mark .parametrize ("versioned_hash" , [None ])
421422@pytest .mark .valid_from ("Cancun" )
422423def test_point_evaluation_precompile_external_vectors (
423- blockchain_test : BlockchainTestFiller ,
424+ state_test : StateTestFiller ,
424425 pre : Dict ,
425426 tx : Transaction ,
426427 post : Dict ,
@@ -431,10 +432,11 @@ def test_point_evaluation_precompile_external_vectors(
431432 - `go_kzg_4844_verify_kzg_proof.json`: test vectors from the
432433 [go-kzg-4844](https://github.com/crate-crypto/go-kzg-4844) repository.
433434 """
434- blockchain_test (
435+ state_test (
436+ env = Environment (),
435437 pre = pre ,
436438 post = post ,
437- blocks = [ Block ( txs = [ tx ])] ,
439+ tx = tx ,
438440 )
439441
440442
@@ -458,12 +460,12 @@ def test_point_evaluation_precompile_external_vectors(
458460)
459461@pytest .mark .parametrize (
460462 "z,kzg_commitment,kzg_proof,versioned_hash" ,
461- [[Z , INF_POINT , INF_POINT , auto ]],
463+ [[Z , INF_POINT , INF_POINT , None ]],
462464 ids = ["" ],
463465)
464466@pytest .mark .valid_from ("Cancun" )
465467def test_point_evaluation_precompile_calls (
466- blockchain_test : BlockchainTestFiller ,
468+ state_test : StateTestFiller ,
467469 pre : Dict ,
468470 tx : Transaction ,
469471 post : Dict ,
@@ -476,10 +478,11 @@ def test_point_evaluation_precompile_calls(
476478 - Using correct and incorrect proofs
477479 - Using barely insufficient gas
478480 """
479- blockchain_test (
481+ state_test (
482+ env = Environment (),
480483 pre = pre ,
481484 post = post ,
482- blocks = [ Block ( txs = [ tx ])] ,
485+ tx = tx ,
483486 )
484487
485488
@@ -495,14 +498,14 @@ def test_point_evaluation_precompile_calls(
495498@pytest .mark .parametrize (
496499 "z,y,kzg_commitment,kzg_proof,versioned_hash,proof_correct" ,
497500 [
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 ],
500503 ],
501504 ids = ["correct_proof" , "incorrect_proof" ],
502505)
503506@pytest .mark .valid_from ("Cancun" )
504507def test_point_evaluation_precompile_gas_tx_to (
505- blockchain_test : BlockchainTestFiller ,
508+ state_test : StateTestFiller ,
506509 precompile_input : bytes ,
507510 call_gas : int ,
508511 proof_correct : bool ,
@@ -554,20 +557,80 @@ def test_point_evaluation_precompile_gas_tx_to(
554557 )
555558 }
556559
557- blockchain_test (
560+ state_test (
561+ env = Environment (),
558562 pre = pre ,
559563 post = post ,
560- blocks = [ Block ( txs = [ tx ])] ,
564+ tx = tx ,
561565 )
562566
563567
564568@pytest .mark .parametrize (
565569 "z,y,kzg_commitment,kzg_proof,versioned_hash" ,
566- [[Z , 0 , INF_POINT , INF_POINT , auto ]],
570+ [[Z , 0 , INF_POINT , INF_POINT , None ]],
567571 ids = ["correct_proof" ],
568572)
569573@pytest .mark .valid_at_transition_to ("Cancun" )
570574def 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 (
571634 blockchain_test : BlockchainTestFiller ,
572635 pre : Dict ,
573636 tx : Transaction ,
@@ -620,7 +683,7 @@ def tx_generator() -> Iterator[Transaction]:
620683 post = {
621684 precompile_caller_address : Account (
622685 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.
624687 ),
625688 to_address (Spec .POINT_EVALUATION_PRECOMPILE_ADDRESS ): Account (
626689 balance = len (PRE_FORK_BLOCK_RANGE ),
0 commit comments