@@ -14,6 +14,7 @@ use async_trait::async_trait;
1414use mockall:: automock;
1515use starknet_api:: block:: BlockNumber ;
1616use starknet_api:: consensus_transaction:: InternalConsensusTransaction ;
17+ use starknet_api:: rpc_transaction:: { InternalRpcTransactionWithoutTxHash , RpcInvokeTransaction } ;
1718use starknet_api:: transaction:: TransactionHash ;
1819use thiserror:: Error ;
1920
@@ -166,7 +167,6 @@ impl TransactionProvider for ProposeTransactionProvider {
166167}
167168
168169pub struct ProofValidator {
169- #[ allow( dead_code) ]
170170 proof_manager_client : SharedProofManagerClient ,
171171}
172172
@@ -177,8 +177,31 @@ impl ProofValidator {
177177
178178 /// Validates the proof embedded in the transaction.
179179 /// Returns Ok(()) if validation succeeds, Err with error message otherwise.
180- pub fn validate_proof ( & self , _tx : & InternalConsensusTransaction ) -> Result < ( ) , String > {
181- // TODO(Einat): Implement proof validation.
180+ pub async fn validate_proof ( & self , tx : & InternalConsensusTransaction ) -> Result < ( ) , String > {
181+ if let InternalConsensusTransaction :: RpcTransaction ( internal_rpc_tx) = tx {
182+ if let InternalRpcTransactionWithoutTxHash :: Invoke ( RpcInvokeTransaction :: V3 ( tx) ) =
183+ & internal_rpc_tx. tx
184+ {
185+ // Only validate if proof_facts is not empty
186+ if !tx. proof_facts . is_empty ( ) {
187+ let proof_facts_hash = tx. proof_facts . hash ( ) ;
188+ let contains_proof = self
189+ . proof_manager_client
190+ . contains_proof ( proof_facts_hash)
191+ . await
192+ . map_err ( |e| format ! ( "Failed to check proof existence: {e}" ) ) ?;
193+
194+ if !contains_proof {
195+ // TODO(Einat): Verify the proof before setting it in the proof manager.
196+ // Return an error if the proof is not valid.
197+ self . proof_manager_client
198+ . set_proof ( proof_facts_hash, tx. proof . clone ( ) )
199+ . await
200+ . map_err ( |e| format ! ( "Failed to set proof: {e}" ) ) ?;
201+ }
202+ }
203+ }
204+ }
182205 Ok ( ( ) )
183206 }
184207}
@@ -243,7 +266,7 @@ impl TransactionProvider for ValidateTransactionProvider {
243266 continue ;
244267 }
245268 // TODO(Einat): Filter out transactions with empty proof field.
246- self . proof_validator . validate_proof ( tx) . map_err ( |e| {
269+ self . proof_validator . validate_proof ( tx) . await . map_err ( |e| {
247270 TransactionProviderError :: ProofValidationFailed { tx_hash : tx. tx_hash ( ) , error : e }
248271 } ) ?;
249272 }
0 commit comments