@@ -48,7 +48,9 @@ use std::{
48
48
collections:: { BTreeMap , HashMap } ,
49
49
iter,
50
50
} ;
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
+ } ;
52
54
53
55
/// Circuit Setup Parameters
54
56
#[ derive( Debug , Clone , Copy ) ]
@@ -587,19 +589,18 @@ pub fn keccak_inputs(block: &Block, code_db: &CodeDB) -> Result<Vec<Vec<u8>>, Er
587
589
let mut keccak_inputs = Vec :: new ( ) ;
588
590
// Tx Circuit
589
591
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) ?) ;
591
593
log:: debug!(
592
594
"keccak total len after txs: {}" ,
593
595
keccak_inputs. iter( ) . map( |i| i. len( ) ) . sum:: <usize >( )
594
596
) ;
595
597
// 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 ,
598
600
block. prev_state_root ,
599
601
block. withdraw_root ,
600
602
& block. headers ,
601
603
block. txs ( ) ,
602
- block. circuits_params . max_txs ,
603
604
) ) ;
604
605
// Bytecode Circuit
605
606
for _bytecode in code_db. 0 . values ( ) {
@@ -645,10 +646,10 @@ pub fn keccak_inputs_sign_verify(sigs: &[SignData]) -> Vec<Vec<u8>> {
645
646
inputs
646
647
}
647
648
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="")
650
651
/// 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 ) {
652
653
let mut sk_be_scalar = [ 0u8 ; 32 ] ;
653
654
sk_be_scalar[ 31 ] = 1_u8 ;
654
655
@@ -661,22 +662,28 @@ pub fn get_dummy_tx(chain_id: u64) -> (TransactionRequest, Signature) {
661
662
. gas_price ( U256 :: zero ( ) )
662
663
. to ( Address :: zero ( ) )
663
664
. 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 ( ) ;
666
667
667
668
// 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 ) ;
669
671
670
672
( tx, sig)
671
673
}
672
674
673
675
/// 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 ( ) ;
677
679
678
680
let tx_hash = keccak256 ( tx. rlp_signed ( & sig) ) ;
679
681
682
+ assert_eq ! (
683
+ hex:: encode( tx_hash) ,
684
+ "137c41d53f2e633af81c75e938f6ccf7298ad6d2fa698b19a50545c1ae5b2b85"
685
+ ) ;
686
+
680
687
H256 ( tx_hash)
681
688
}
682
689
@@ -686,59 +693,43 @@ fn keccak_inputs_pi_circuit(
686
693
withdraw_trie_root : Word ,
687
694
block_headers : & BTreeMap < u64 , BlockHead > ,
688
695
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 ( )
705
698
. chain ( block_headers. iter ( ) . flat_map ( |( block_num, block) | {
706
699
let num_txs = transactions
707
700
. iter ( )
708
701
. filter ( |tx| tx. block_num == * block_num)
709
702
. 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
713
703
714
704
iter:: empty ( )
715
705
// Block Values
716
- . chain ( block_hash. to_fixed_bytes ( ) )
717
- . chain ( parent_hash. to_fixed_bytes ( ) ) // parent hash
718
706
. chain ( block. number . as_u64 ( ) . to_be_bytes ( ) )
719
707
. chain ( block. timestamp . as_u64 ( ) . to_be_bytes ( ) )
720
708
. chain ( block. base_fee . to_be_bytes ( ) )
721
709
. chain ( block. gas_limit . to_be_bytes ( ) )
722
710
. chain ( num_txs. to_be_bytes ( ) )
723
- . chain ( num_l1_msgs. to_be_bytes ( ) )
724
711
} ) )
725
712
// Tx Hashes
726
713
. 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 ( ) )
732
726
. collect :: < Vec < u8 > > ( ) ;
733
727
734
- result
728
+ vec ! [ data_bytes , pi_bytes ]
735
729
}
736
730
737
731
/// 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 > {
742
733
let mut inputs = Vec :: new ( ) ;
743
734
744
735
let hash_datas = txs
@@ -747,7 +738,7 @@ pub fn keccak_inputs_tx_circuit(
747
738
. collect :: < Vec < Vec < u8 > > > ( ) ;
748
739
let dummy_hash_data = {
749
740
// 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 ( ) ;
751
742
dummy_tx. rlp_signed ( & dummy_sig) . to_vec ( )
752
743
} ;
753
744
inputs. extend_from_slice ( & hash_datas) ;
@@ -783,8 +774,9 @@ pub fn keccak_inputs_tx_circuit(
783
774
// one that we use in get_dummy_tx, so we only need to include the tx sign
784
775
// hash of the dummy tx.
785
776
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 ( )
788
780
} ;
789
781
inputs. push ( dummy_sign_input) ;
790
782
0 commit comments