@@ -50,17 +50,15 @@ impl AggregationModeVerificationData {
5050
5151// We use a newtype wrapper around `[u8; 32]` because Rust's orphan rule
5252// prevents implementing a foreign trait (`IsMerkleTreeBackend`) for a foreign type (`[u8; 32]`).
53- #[ derive( Default , PartialEq , Eq ) ]
53+ #[ derive( Default , Debug , PartialEq , Eq ) ]
5454struct Hash32 ( [ u8 ; 32 ] ) ;
5555
5656impl IsMerkleTreeBackend for Hash32 {
5757 type Data = Hash32 ;
5858 type Node = [ u8 ; 32 ] ;
5959
6060 fn hash_data ( leaf : & Self :: Data ) -> Self :: Node {
61- let mut hasher = Keccak256 :: new ( ) ;
62- hasher. update ( leaf. 0 ) ;
63- hasher. finalize ( ) . into ( )
61+ leaf. 0
6462 }
6563
6664 fn hash_leaves ( leaves : & [ Self :: Data ] ) -> Vec < Self :: Node > {
@@ -139,8 +137,10 @@ pub async fn verify_agg_proof_on_chain(
139137 eth_rpc_url : String ,
140138 beacon_client_url : String ,
141139 from_block : Option < u64 > ,
142- proof_commitment : [ u8 ; 32 ] ,
140+ verification_data : AggregationModeVerificationData ,
143141) -> Result < bool , ProofVerificationAggModeError > {
142+ let proof_commitment = verification_data. commitment ( ) ;
143+
144144 let Some ( merkle_path) = get_merkle_path_for_proof (
145145 network. clone ( ) ,
146146 eth_rpc_url. clone ( ) ,
@@ -162,7 +162,7 @@ pub async fn verify_agg_proof_on_chain(
162162 . await
163163 . map_err ( |e| ProofVerificationAggModeError :: EthereumProviderError ( e. to_string ( ) ) ) ?;
164164
165- let res: bool = contract_provider
165+ let res = contract_provider
166166 . verify_proof_inclusion ( merkle_path, proof_commitment)
167167 . call ( )
168168 . await
@@ -181,7 +181,7 @@ pub async fn get_merkle_path_for_proof(
181181 let logs = get_aggregated_proofs_logs ( network, eth_rpc_url. clone ( ) , from_block) . await ?;
182182
183183 for log in logs {
184- let ( _merkle_root , leaves) =
184+ let ( merkle_root , leaves) =
185185 get_blob_data_from_log ( eth_rpc_url. clone ( ) , beacon_client_url. clone ( ) , log) . await ?;
186186
187187 let leaves: Vec < Hash32 > = leaves. iter ( ) . map ( |leaf| Hash32 ( * leaf) ) . collect ( ) ;
@@ -190,8 +190,16 @@ pub async fn get_merkle_path_for_proof(
190190 let Some ( pos) = leaves. iter ( ) . position ( |p| p. 0 == proof_commitment) else {
191191 continue ;
192192 } ;
193+ let Some ( proof) = merkle_tree. get_proof_by_pos ( pos) else {
194+ continue ;
195+ } ;
196+
197+ let result = proof. verify :: < Hash32 > ( & merkle_root, pos, & Hash32 ( proof_commitment) ) ;
198+ if !result {
199+ return Ok ( None ) ;
200+ }
193201
194- return Ok ( Some ( merkle_tree . get_proof_by_pos ( pos ) . unwrap ( ) . merkle_path ) ) ;
202+ return Ok ( Some ( proof . merkle_path ) ) ;
195203 }
196204
197205 Ok ( None )
0 commit comments