miden_tx_batch_prover/
local_batch_prover.rs1use alloc::boxed::Box;
2
3use miden_protocol::batch::{ProposedBatch, ProvenBatch};
4use miden_protocol::errors::ProvenBatchError;
5use miden_tx::TransactionVerifier;
6
7#[derive(Clone)]
13pub struct LocalBatchProver {
14 proof_security_level: u32,
15}
16
17impl LocalBatchProver {
18 pub fn new(proof_security_level: u32) -> Self {
20 Self { proof_security_level }
21 }
22
23 pub fn prove(&self, proposed_batch: ProposedBatch) -> Result<ProvenBatch, ProvenBatchError> {
34 let verifier = TransactionVerifier::new(self.proof_security_level);
35
36 for tx in proposed_batch.transactions() {
37 verifier.verify(tx).map_err(|source| {
38 ProvenBatchError::TransactionVerificationFailed {
39 transaction_id: tx.id(),
40 source: Box::new(source),
41 }
42 })?;
43 }
44
45 self.prove_inner(proposed_batch)
46 }
47
48 #[cfg(any(feature = "testing", test))]
53 pub fn prove_dummy(
54 &self,
55 proposed_batch: ProposedBatch,
56 ) -> Result<ProvenBatch, ProvenBatchError> {
57 self.prove_inner(proposed_batch)
58 }
59
60 fn prove_inner(&self, proposed_batch: ProposedBatch) -> Result<ProvenBatch, ProvenBatchError> {
64 let tx_headers = proposed_batch.transaction_headers();
65 let (
66 _transactions,
67 block_header,
68 _block_chain,
69 _authenticatable_unauthenticated_notes,
70 id,
71 updated_accounts,
72 input_notes,
73 output_notes,
74 batch_expiration_block_num,
75 ) = proposed_batch.into_parts();
76
77 ProvenBatch::new_unchecked(
78 id,
79 block_header.commitment(),
80 block_header.block_num(),
81 updated_accounts,
82 input_notes,
83 output_notes,
84 batch_expiration_block_num,
85 tx_headers,
86 )
87 }
88}