@@ -587,19 +587,18 @@ pub fn keccak_inputs(block: &Block, code_db: &CodeDB) -> Result<Vec<Vec<u8>>, Er
587
587
let mut keccak_inputs = Vec :: new ( ) ;
588
588
// Tx Circuit
589
589
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 ( ) ) ?) ;
590
+ keccak_inputs. extend_from_slice ( & keccak_inputs_tx_circuit ( & txs) ?) ;
591
591
log:: debug!(
592
592
"keccak total len after txs: {}" ,
593
593
keccak_inputs. iter( ) . map( |i| i. len( ) ) . sum:: <usize >( )
594
594
) ;
595
595
// PI circuit
596
- keccak_inputs. push ( keccak_inputs_pi_circuit (
597
- block. chain_id ( ) ,
596
+ keccak_inputs. extend ( keccak_inputs_pi_circuit (
597
+ block. chain_id ,
598
598
block. prev_state_root ,
599
599
block. withdraw_root ,
600
600
& block. headers ,
601
601
block. txs ( ) ,
602
- block. circuits_params . max_txs ,
603
602
) ) ;
604
603
// Bytecode Circuit
605
604
for _bytecode in code_db. 0 . values ( ) {
@@ -645,10 +644,10 @@ pub fn keccak_inputs_sign_verify(sigs: &[SignData]) -> Vec<Vec<u8>> {
645
644
inputs
646
645
}
647
646
648
- /// Generate a dummy tx in which
649
- /// (nonce=0, gas=0, gas_price=0, to=0, value=0, data="", chain_id )
647
+ /// Generate a dummy pre-eip155 tx in which
648
+ /// (nonce=0, gas=0, gas_price=0, to=0, value=0, data="")
650
649
/// using the dummy private key = 1
651
- pub fn get_dummy_tx ( chain_id : u64 ) -> ( TransactionRequest , Signature ) {
650
+ pub fn get_dummy_tx ( ) -> ( TransactionRequest , Signature ) {
652
651
let mut sk_be_scalar = [ 0u8 ; 32 ] ;
653
652
sk_be_scalar[ 31 ] = 1_u8 ;
654
653
@@ -661,22 +660,28 @@ pub fn get_dummy_tx(chain_id: u64) -> (TransactionRequest, Signature) {
661
660
. gas_price ( U256 :: zero ( ) )
662
661
. to ( Address :: zero ( ) )
663
662
. value ( U256 :: zero ( ) )
664
- . data ( Bytes :: default ( ) )
665
- . chain_id ( chain_id ) ;
663
+ . data ( Bytes :: default ( ) ) ;
664
+ let sighash : H256 = keccak256 ( tx . rlp_unsigned ( ) ) . into ( ) ;
666
665
667
666
// FIXME: need to check if this is deterministic which means sig is fixed.
668
- let sig = wallet. sign_transaction_sync ( & tx. clone ( ) . into ( ) ) ;
667
+ let sig = wallet. sign_hash ( sighash) ;
668
+ assert_eq ! ( sig. v, 28 ) ;
669
669
670
670
( tx, sig)
671
671
}
672
672
673
673
/// 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 ) ;
674
+ /// data="")
675
+ pub fn get_dummy_tx_hash ( ) -> H256 {
676
+ let ( tx, sig) = get_dummy_tx ( ) ;
677
677
678
678
let tx_hash = keccak256 ( tx. rlp_signed ( & sig) ) ;
679
679
680
+ assert_eq ! (
681
+ hex:: encode( tx_hash) ,
682
+ "137c41d53f2e633af81c75e938f6ccf7298ad6d2fa698b19a50545c1ae5b2b85"
683
+ ) ;
684
+
680
685
H256 ( tx_hash)
681
686
}
682
687
@@ -686,59 +691,43 @@ fn keccak_inputs_pi_circuit(
686
691
withdraw_trie_root : Word ,
687
692
block_headers : & BTreeMap < u64 , BlockHead > ,
688
693
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 ( ) )
694
+ ) -> Vec < Vec < u8 > > {
695
+ let data_bytes = iter:: empty ( )
705
696
. chain ( block_headers. iter ( ) . flat_map ( |( block_num, block) | {
706
697
let num_txs = transactions
707
698
. iter ( )
708
699
. filter ( |tx| tx. block_num == * block_num)
709
700
. 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
701
714
702
iter:: empty ( )
715
703
// Block Values
716
- . chain ( block_hash. to_fixed_bytes ( ) )
717
- . chain ( parent_hash. to_fixed_bytes ( ) ) // parent hash
718
704
. chain ( block. number . as_u64 ( ) . to_be_bytes ( ) )
719
705
. chain ( block. timestamp . as_u64 ( ) . to_be_bytes ( ) )
720
706
. chain ( block. base_fee . to_be_bytes ( ) )
721
707
. chain ( block. gas_limit . to_be_bytes ( ) )
722
708
. chain ( num_txs. to_be_bytes ( ) )
723
- . chain ( num_l1_msgs. to_be_bytes ( ) )
724
709
} ) )
725
710
// Tx Hashes
726
711
. 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
- )
712
+ . collect :: < Vec < u8 > > ( ) ;
713
+ let data_hash = H256 ( keccak256 ( & data_bytes) ) ;
714
+ let after_state_root = block_headers
715
+ . last_key_value ( )
716
+ . map ( |( _, blk) | blk. eth_block . state_root )
717
+ . unwrap_or ( H256 ( prev_state_root. to_be_bytes ( ) ) ) ;
718
+ let pi_bytes = iter:: empty ( )
719
+ . chain ( chain_id. to_be_bytes ( ) )
720
+ . chain ( prev_state_root. to_be_bytes ( ) )
721
+ . chain ( after_state_root. to_fixed_bytes ( ) )
722
+ . chain ( withdraw_trie_root. to_be_bytes ( ) )
723
+ . chain ( data_hash. to_fixed_bytes ( ) )
732
724
. collect :: < Vec < u8 > > ( ) ;
733
725
734
- result
726
+ vec ! [ data_bytes , pi_bytes ]
735
727
}
736
728
737
729
/// 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 > {
730
+ pub fn keccak_inputs_tx_circuit ( txs : & [ geth_types:: Transaction ] ) -> Result < Vec < Vec < u8 > > , Error > {
742
731
let mut inputs = Vec :: new ( ) ;
743
732
744
733
let hash_datas = txs
@@ -747,7 +736,7 @@ pub fn keccak_inputs_tx_circuit(
747
736
. collect :: < Vec < Vec < u8 > > > ( ) ;
748
737
let dummy_hash_data = {
749
738
// dummy tx is a legacy tx.
750
- let ( dummy_tx, dummy_sig) = get_dummy_tx ( chain_id ) ;
739
+ let ( dummy_tx, dummy_sig) = get_dummy_tx ( ) ;
751
740
dummy_tx. rlp_signed ( & dummy_sig) . to_vec ( )
752
741
} ;
753
742
inputs. extend_from_slice ( & hash_datas) ;
@@ -783,8 +772,9 @@ pub fn keccak_inputs_tx_circuit(
783
772
// one that we use in get_dummy_tx, so we only need to include the tx sign
784
773
// hash of the dummy tx.
785
774
let dummy_sign_input = {
786
- let ( dummy_tx, _) = get_dummy_tx ( chain_id) ;
787
- dummy_tx. rlp ( ) . to_vec ( )
775
+ let ( dummy_tx, _) = get_dummy_tx ( ) ;
776
+ // dummy tx is of type pre-eip155
777
+ dummy_tx. rlp_unsigned ( ) . to_vec ( )
788
778
} ;
789
779
inputs. push ( dummy_sign_input) ;
790
780
0 commit comments