@@ -118,6 +118,7 @@ impl Prover {
118118 let real_chunk_count = chunk_hashes_proofs. len ( ) ;
119119 assert ! ( ( 1 ..=MAX_AGG_SNARKS ) . contains( & real_chunk_count) ) ;
120120
121+ check_chunk_hashes ( name, & chunk_hashes_proofs) ?;
121122 let ( mut chunk_hashes, chunk_proofs) : ( Vec < _ > , Vec < _ > ) =
122123 chunk_hashes_proofs. into_iter ( ) . unzip ( ) ;
123124
@@ -167,3 +168,81 @@ impl Prover {
167168 }
168169 }
169170}
171+
172+ macro_rules! compare_field {
173+ ( $name: expr, $idx: expr, $field: ident, $lhs: ident, $rhs: ident) => {
174+ if $lhs. $field != $rhs. $field {
175+ bail!(
176+ "{} chunk-no-{}, different {}: {} != {}" ,
177+ $name,
178+ $idx,
179+ stringify!( $field) ,
180+ $lhs. $field,
181+ $rhs. $field
182+ ) ;
183+ }
184+ } ;
185+ }
186+
187+ fn check_chunk_hashes ( name : & str , chunk_hashes_proofs : & [ ( ChunkHash , ChunkProof ) ] ) -> Result < ( ) > {
188+ for ( idx, ( in_arg, chunk_proof) ) in chunk_hashes_proofs. iter ( ) . enumerate ( ) {
189+ if let Some ( in_proof) = chunk_proof. chunk_hash {
190+ compare_field ! ( name, idx, chain_id, in_arg, in_proof) ;
191+ compare_field ! ( name, idx, prev_state_root, in_arg, in_proof) ;
192+ compare_field ! ( name, idx, post_state_root, in_arg, in_proof) ;
193+ compare_field ! ( name, idx, withdraw_root, in_arg, in_proof) ;
194+ compare_field ! ( name, idx, data_hash, in_arg, in_proof) ;
195+ }
196+ }
197+
198+ Ok ( ( ) )
199+ }
200+
201+ #[ cfg( test) ]
202+ mod tests {
203+ use super :: * ;
204+ use eth_types:: H256 ;
205+
206+ #[ test]
207+ fn test_check_chunk_hashes ( ) {
208+ let chunk_hashes_proofs = vec ! [
209+ ( ChunkHash :: default ( ) , ChunkProof :: default ( ) ) ,
210+ (
211+ ChunkHash {
212+ chain_id: 1 ,
213+ prev_state_root: H256 :: zero( ) ,
214+ data_hash: [ 100 ; 32 ] . into( ) ,
215+ ..Default :: default ( )
216+ } ,
217+ ChunkProof {
218+ chunk_hash: Some ( ChunkHash {
219+ chain_id: 1 ,
220+ prev_state_root: [ 0 ; 32 ] . into( ) ,
221+ data_hash: [ 100 ; 32 ] . into( ) ,
222+ ..Default :: default ( )
223+ } ) ,
224+ ..Default :: default ( )
225+ } ,
226+ ) ,
227+ (
228+ ChunkHash {
229+ post_state_root: H256 :: zero( ) ,
230+ ..Default :: default ( )
231+ } ,
232+ ChunkProof {
233+ chunk_hash: Some ( ChunkHash {
234+ post_state_root: [ 1 ; 32 ] . into( ) ,
235+ ..Default :: default ( )
236+ } ) ,
237+ ..Default :: default ( )
238+ } ,
239+ ) ,
240+ ] ;
241+
242+ let result = check_chunk_hashes ( "test-batch" , & chunk_hashes_proofs) ;
243+ assert_eq ! (
244+ result. unwrap_err( ) . downcast_ref:: <String >( ) . unwrap( ) ,
245+ "test-batch chunk-no-2, different post_state_root: 0x0000…0000 != 0x0101…0101"
246+ ) ;
247+ }
248+ }
0 commit comments