@@ -48,7 +48,9 @@ use std::{
4848 collections:: { BTreeMap , HashMap } ,
4949 iter,
5050} ;
51- pub use transaction:: { Transaction , TransactionContext , TxL1Fee , TX_L1_FEE_PRECISION } ;
51+ pub use transaction:: {
52+ Transaction , TransactionContext , TxL1Fee , TX_L1_COMMIT_EXTRA_COST , TX_L1_FEE_PRECISION ,
53+ } ;
5254
5355/// Circuit Setup Parameters
5456#[ derive( Debug , Clone , Copy ) ]
@@ -587,19 +589,18 @@ pub fn keccak_inputs(block: &Block, code_db: &CodeDB) -> Result<Vec<Vec<u8>>, Er
587589 let mut keccak_inputs = Vec :: new ( ) ;
588590 // Tx Circuit
589591 let txs: Vec < geth_types:: Transaction > = block. txs . iter ( ) . map ( |tx| tx. into ( ) ) . collect ( ) ;
590- keccak_inputs. extend_from_slice ( & keccak_inputs_tx_circuit ( & txs, block . chain_id ( ) ) ?) ;
592+ keccak_inputs. extend_from_slice ( & keccak_inputs_tx_circuit ( & txs) ?) ;
591593 log:: debug!(
592594 "keccak total len after txs: {}" ,
593595 keccak_inputs. iter( ) . map( |i| i. len( ) ) . sum:: <usize >( )
594596 ) ;
595597 // PI circuit
596- keccak_inputs. push ( keccak_inputs_pi_circuit (
597- block. chain_id ( ) ,
598+ keccak_inputs. extend ( keccak_inputs_pi_circuit (
599+ block. chain_id ,
598600 block. prev_state_root ,
599601 block. withdraw_root ,
600602 & block. headers ,
601603 block. txs ( ) ,
602- block. circuits_params . max_txs ,
603604 ) ) ;
604605 // Bytecode Circuit
605606 for _bytecode in code_db. 0 . values ( ) {
@@ -645,10 +646,10 @@ pub fn keccak_inputs_sign_verify(sigs: &[SignData]) -> Vec<Vec<u8>> {
645646 inputs
646647}
647648
648- /// Generate a dummy tx in which
649- /// (nonce=0, gas=0, gas_price=0, to=0, value=0, data="", chain_id )
649+ /// Generate a dummy pre-eip155 tx in which
650+ /// (nonce=0, gas=0, gas_price=0, to=0, value=0, data="")
650651/// using the dummy private key = 1
651- pub fn get_dummy_tx ( chain_id : u64 ) -> ( TransactionRequest , Signature ) {
652+ pub fn get_dummy_tx ( ) -> ( TransactionRequest , Signature ) {
652653 let mut sk_be_scalar = [ 0u8 ; 32 ] ;
653654 sk_be_scalar[ 31 ] = 1_u8 ;
654655
@@ -661,22 +662,28 @@ pub fn get_dummy_tx(chain_id: u64) -> (TransactionRequest, Signature) {
661662 . gas_price ( U256 :: zero ( ) )
662663 . to ( Address :: zero ( ) )
663664 . value ( U256 :: zero ( ) )
664- . data ( Bytes :: default ( ) )
665- . chain_id ( chain_id ) ;
665+ . data ( Bytes :: default ( ) ) ;
666+ let sighash : H256 = keccak256 ( tx . rlp_unsigned ( ) ) . into ( ) ;
666667
667668 // FIXME: need to check if this is deterministic which means sig is fixed.
668- let sig = wallet. sign_transaction_sync ( & tx. clone ( ) . into ( ) ) ;
669+ let sig = wallet. sign_hash ( sighash) ;
670+ assert_eq ! ( sig. v, 28 ) ;
669671
670672 ( tx, sig)
671673}
672674
673675/// Get the tx hash of the dummy tx (nonce=0, gas=0, gas_price=0, to=0, value=0,
674- /// data="") for any chain_id
675- pub fn get_dummy_tx_hash ( chain_id : u64 ) -> H256 {
676- let ( tx, sig) = get_dummy_tx ( chain_id ) ;
676+ /// data="")
677+ pub fn get_dummy_tx_hash ( ) -> H256 {
678+ let ( tx, sig) = get_dummy_tx ( ) ;
677679
678680 let tx_hash = keccak256 ( tx. rlp_signed ( & sig) ) ;
679681
682+ assert_eq ! (
683+ hex:: encode( tx_hash) ,
684+ "137c41d53f2e633af81c75e938f6ccf7298ad6d2fa698b19a50545c1ae5b2b85"
685+ ) ;
686+
680687 H256 ( tx_hash)
681688}
682689
@@ -686,59 +693,43 @@ fn keccak_inputs_pi_circuit(
686693 withdraw_trie_root : Word ,
687694 block_headers : & BTreeMap < u64 , BlockHead > ,
688695 transactions : & [ Transaction ] ,
689- max_txs : usize ,
690- ) -> Vec < u8 > {
691- let dummy_tx_hash = get_dummy_tx_hash ( chain_id) ;
692-
693- let result = iter:: empty ( )
694- // state roots
695- . chain ( prev_state_root. to_be_bytes ( ) )
696- . chain (
697- block_headers
698- . last_key_value ( )
699- . map ( |( _, blk) | blk. eth_block . state_root )
700- . unwrap_or ( H256 ( prev_state_root. to_be_bytes ( ) ) )
701- . to_fixed_bytes ( ) ,
702- )
703- // withdraw trie root
704- . chain ( withdraw_trie_root. to_be_bytes ( ) )
696+ ) -> Vec < Vec < u8 > > {
697+ let data_bytes = iter:: empty ( )
705698 . chain ( block_headers. iter ( ) . flat_map ( |( block_num, block) | {
706699 let num_txs = transactions
707700 . iter ( )
708701 . filter ( |tx| tx. block_num == * block_num)
709702 . count ( ) as u16 ;
710- let parent_hash = block. eth_block . parent_hash ;
711- let block_hash = block. eth_block . hash . unwrap_or ( H256 :: zero ( ) ) ;
712- let num_l1_msgs = 0_u16 ; // 0 for now
713703
714704 iter:: empty ( )
715705 // Block Values
716- . chain ( block_hash. to_fixed_bytes ( ) )
717- . chain ( parent_hash. to_fixed_bytes ( ) ) // parent hash
718706 . chain ( block. number . as_u64 ( ) . to_be_bytes ( ) )
719707 . chain ( block. timestamp . as_u64 ( ) . to_be_bytes ( ) )
720708 . chain ( block. base_fee . to_be_bytes ( ) )
721709 . chain ( block. gas_limit . to_be_bytes ( ) )
722710 . chain ( num_txs. to_be_bytes ( ) )
723- . chain ( num_l1_msgs. to_be_bytes ( ) )
724711 } ) )
725712 // Tx Hashes
726713 . chain ( transactions. iter ( ) . flat_map ( |tx| tx. hash . to_fixed_bytes ( ) ) )
727- . chain (
728- ( 0 ..( max_txs - transactions. len ( ) ) )
729- . into_iter ( )
730- . flat_map ( |_| dummy_tx_hash. to_fixed_bytes ( ) ) ,
731- )
714+ . collect :: < Vec < u8 > > ( ) ;
715+ let data_hash = H256 ( keccak256 ( & data_bytes) ) ;
716+ let after_state_root = block_headers
717+ . last_key_value ( )
718+ . map ( |( _, blk) | blk. eth_block . state_root )
719+ . unwrap_or ( H256 ( prev_state_root. to_be_bytes ( ) ) ) ;
720+ let pi_bytes = iter:: empty ( )
721+ . chain ( chain_id. to_be_bytes ( ) )
722+ . chain ( prev_state_root. to_be_bytes ( ) )
723+ . chain ( after_state_root. to_fixed_bytes ( ) )
724+ . chain ( withdraw_trie_root. to_be_bytes ( ) )
725+ . chain ( data_hash. to_fixed_bytes ( ) )
732726 . collect :: < Vec < u8 > > ( ) ;
733727
734- result
728+ vec ! [ data_bytes , pi_bytes ]
735729}
736730
737731/// Generate the keccak inputs required by the Tx Circuit from the transactions.
738- pub fn keccak_inputs_tx_circuit (
739- txs : & [ geth_types:: Transaction ] ,
740- chain_id : u64 ,
741- ) -> Result < Vec < Vec < u8 > > , Error > {
732+ pub fn keccak_inputs_tx_circuit ( txs : & [ geth_types:: Transaction ] ) -> Result < Vec < Vec < u8 > > , Error > {
742733 let mut inputs = Vec :: new ( ) ;
743734
744735 let hash_datas = txs
@@ -747,7 +738,7 @@ pub fn keccak_inputs_tx_circuit(
747738 . collect :: < Vec < Vec < u8 > > > ( ) ;
748739 let dummy_hash_data = {
749740 // dummy tx is a legacy tx.
750- let ( dummy_tx, dummy_sig) = get_dummy_tx ( chain_id ) ;
741+ let ( dummy_tx, dummy_sig) = get_dummy_tx ( ) ;
751742 dummy_tx. rlp_signed ( & dummy_sig) . to_vec ( )
752743 } ;
753744 inputs. extend_from_slice ( & hash_datas) ;
@@ -783,8 +774,9 @@ pub fn keccak_inputs_tx_circuit(
783774 // one that we use in get_dummy_tx, so we only need to include the tx sign
784775 // hash of the dummy tx.
785776 let dummy_sign_input = {
786- let ( dummy_tx, _) = get_dummy_tx ( chain_id) ;
787- dummy_tx. rlp ( ) . to_vec ( )
777+ let ( dummy_tx, _) = get_dummy_tx ( ) ;
778+ // dummy tx is of type pre-eip155
779+ dummy_tx. rlp_unsigned ( ) . to_vec ( )
788780 } ;
789781 inputs. push ( dummy_sign_input) ;
790782
0 commit comments