1818 HeaderNonce ,
1919 HexNumber ,
2020 Number ,
21- to_json ,
2221)
2322from ethereum_test_exceptions import BlockException , EngineAPIError , TransactionException
2423from ethereum_test_fixtures import BaseFixture , FixtureFormats
3433 FixtureTransaction ,
3534 FixtureWithdrawal ,
3635 FixtureWithdrawalRequest ,
36+ FixtureWitness ,
3737 InvalidFixtureBlock ,
3838)
3939from ethereum_test_forks import EIP6800Transition , Fork , Verkle
4545 Removable ,
4646 Requests ,
4747 Transaction ,
48- VerkleTree ,
4948 Withdrawal ,
5049 WithdrawalRequest ,
5150)
51+ from ethereum_test_types .verkle import VerkleTree , Witness
5252from evm_transition_tool import TransitionTool
5353
5454from .base import BaseTest , verify_result , verify_transactions
@@ -328,6 +328,7 @@ class BlockchainTest(BaseTest):
328328 def make_genesis (
329329 self ,
330330 fork : Fork ,
331+ t8n : TransitionTool ,
331332 ) -> Tuple [Alloc , FixtureBlock ]:
332333 """
333334 Create a genesis block from the blockchain test definition.
@@ -346,7 +347,14 @@ def make_genesis(
346347 )
347348 if empty_accounts := pre_alloc .empty_accounts ():
348349 raise Exception (f"Empty accounts in pre state: { empty_accounts } " )
349- state_root = pre_alloc .state_root ()
350+
351+ state_root : bytes
352+ # TODO: refine, currently uses `evm verkle state-root` to get this.
353+ if fork < Verkle or fork is EIP6800Transition :
354+ state_root = pre_alloc .state_root ()
355+ else :
356+ state_root = t8n .get_verkle_state_root (mpt_alloc = pre_alloc )
357+
350358 genesis = FixtureHeader (
351359 parent_hash = 0 ,
352360 ommers_hash = EmptyOmmersRoot ,
@@ -404,6 +412,7 @@ def generate_block_data(
404412 Alloc ,
405413 Optional [Requests ],
406414 Optional [VerkleTree ],
415+ Optional [Witness ],
407416 ]:
408417 """
409418 Generate common block data for both make_fixture and make_hive_fixture.
@@ -436,7 +445,7 @@ def generate_block_data(
436445 txs = txs ,
437446 env = env ,
438447 fork = fork ,
439- vkt = to_json ( previous_vkt ) if previous_vkt is not None else None ,
448+ vkt = previous_vkt ,
440449 chain_id = self .chain_id ,
441450 reward = fork .get_reward (env .number , env .timestamp ),
442451 eips = eips ,
@@ -446,13 +455,17 @@ def generate_block_data(
446455 try :
447456 rejected_txs = verify_transactions (txs , transition_tool_output .result )
448457 verify_result (transition_tool_output .result , env )
458+ # TODO: add verify witness (against vkt)
459+ # verify_witness(transition_tool_output.witness, transition_tool_output.vkt)
449460 except Exception as e :
450461 print_traces (t8n .get_traces ())
451462 pprint (transition_tool_output .result )
452463 pprint (previous_alloc )
453464 pprint (transition_tool_output .alloc )
454465 if transition_tool_output .vkt is not None :
455466 pprint (transition_tool_output .vkt )
467+ if transition_tool_output .witness is not None :
468+ pprint (transition_tool_output .witness )
456469 raise e
457470
458471 if len (rejected_txs ) > 0 and block .exception is None :
@@ -525,6 +538,11 @@ def generate_block_data(
525538 )
526539 )
527540 transition_tool_output .alloc = previous_alloc
541+ # TODO: hack for now
542+ transition_tool_output .witness = Witness (
543+ verkle_proof = transition_tool_output .result .verkle_proof ,
544+ state_diff = transition_tool_output .result .state_diff ,
545+ )
528546
529547 return (
530548 env ,
@@ -533,6 +551,7 @@ def generate_block_data(
533551 transition_tool_output .alloc ,
534552 requests ,
535553 transition_tool_output .vkt ,
554+ transition_tool_output .witness ,
536555 )
537556
538557 def network_info (self , fork : Fork , eips : Optional [List [int ]] = None ):
@@ -556,7 +575,7 @@ def verify_post_state(
556575 Verifies the post state after all block/s or payload/s are generated.
557576 """
558577 try :
559- if env .verkle_conversion_started :
578+ if env .verkle_conversion_started or env . verkle_conversion_ended :
560579 if vkt is not None :
561580 pass # TODO: skip exact account verify checks
562581 # verify_post_vkt(t8n=t8n, expected_post=self.post, got_vkt=vkt)
@@ -579,13 +598,19 @@ def make_fixture(
579598 """
580599 fixture_blocks : List [FixtureBlock | InvalidFixtureBlock ] = []
581600
582- pre , genesis = self .make_genesis (fork )
601+ pre , genesis = self .make_genesis (fork , t8n )
583602
584603 alloc = pre
585604 env = environment_from_parent_header (genesis .header )
586605 head = genesis .header .block_hash
587606 vkt : Optional [VerkleTree ] = None
588607
608+ # Filling for verkle genesis tests
609+ if fork is Verkle :
610+ env .verkle_conversion_ended = True
611+ # convert alloc to vkt
612+ vkt = t8n .from_mpt_to_vkt (alloc )
613+
589614 # Hack for filling naive verkle transition tests
590615 if fork is EIP6800Transition :
591616 # Add a dummy block before the fork transition
@@ -603,14 +628,16 @@ def make_fixture(
603628 # This is the most common case, the RLP needs to be constructed
604629 # based on the transactions to be included in the block.
605630 # Set the environment according to the block to execute.
606- new_env , header , txs , new_alloc , requests , new_vkt = self .generate_block_data (
607- t8n = t8n ,
608- fork = fork ,
609- block = block ,
610- previous_env = env ,
611- previous_alloc = alloc ,
612- previous_vkt = vkt ,
613- eips = eips ,
631+ new_env , header , txs , new_alloc , requests , new_vkt , witness = (
632+ self .generate_block_data (
633+ t8n = t8n ,
634+ fork = fork ,
635+ block = block ,
636+ previous_env = env ,
637+ previous_alloc = alloc ,
638+ previous_vkt = vkt ,
639+ eips = eips ,
640+ )
614641 )
615642 fixture_block = FixtureBlockBase (
616643 header = header ,
@@ -645,6 +672,7 @@ def make_fixture(
645672 if requests is not None
646673 else None
647674 ),
675+ witness = FixtureWitness .from_witness (witness ) if witness is not None else None ,
648676 ).with_rlp (txs = txs , requests = requests )
649677 if block .exception is None :
650678 fixture_blocks .append (fixture_block )
@@ -699,7 +727,7 @@ def make_hive_fixture(
699727 """
700728 fixture_payloads : List [FixtureEngineNewPayload ] = []
701729
702- pre , genesis = self .make_genesis (fork )
730+ pre , genesis = self .make_genesis (fork , t8n )
703731 alloc = pre
704732 env = environment_from_parent_header (genesis .header )
705733 head_hash = genesis .header .block_hash
@@ -718,7 +746,8 @@ def make_hive_fixture(
718746 self .blocks .append (Block ())
719747
720748 for block in self .blocks :
721- new_env , header , txs , new_alloc , requests , new_vkt = self .generate_block_data (
749+ # TODO: fix witness for hive fixture? Do we need it?
750+ new_env , header , txs , new_alloc , requests , new_vkt , _ = self .generate_block_data (
722751 t8n = t8n ,
723752 fork = fork ,
724753 block = block ,
@@ -762,7 +791,7 @@ def make_hive_fixture(
762791 # Most clients require the header to start the sync process, so we create an empty
763792 # block on top of the last block of the test to send it as new payload and trigger the
764793 # sync process.
765- _ , sync_header , _ , _ , requests , _ = self .generate_block_data (
794+ _ , sync_header , _ , _ , requests , _ , _ = self .generate_block_data (
766795 t8n = t8n ,
767796 fork = fork ,
768797 block = Block (),
0 commit comments