Skip to content

Commit 4587f49

Browse files
apollo_batcher: use proof manager to verify the the proofs
1 parent d356a9c commit 4587f49

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

crates/apollo_batcher/src/transaction_provider.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use async_trait::async_trait;
1414
use mockall::automock;
1515
use starknet_api::block::BlockNumber;
1616
use starknet_api::consensus_transaction::InternalConsensusTransaction;
17+
use starknet_api::rpc_transaction::{InternalRpcTransactionWithoutTxHash, RpcInvokeTransaction};
1718
use starknet_api::transaction::TransactionHash;
1819
use thiserror::Error;
1920

@@ -166,7 +167,6 @@ impl TransactionProvider for ProposeTransactionProvider {
166167
}
167168

168169
pub 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

Comments
 (0)