use alloc::boxed::Box;
use miden_protocol::batch::{ProposedBatch, ProvenBatch};
use miden_protocol::errors::ProvenBatchError;
use miden_tx::TransactionVerifier;
#[derive(Clone)]
pub struct LocalBatchProver {
proof_security_level: u32,
}
impl LocalBatchProver {
pub fn new(proof_security_level: u32) -> Self {
Self { proof_security_level }
}
pub fn prove(&self, proposed_batch: ProposedBatch) -> Result<ProvenBatch, ProvenBatchError> {
let verifier = TransactionVerifier::new(self.proof_security_level);
for tx in proposed_batch.transactions() {
verifier.verify(tx).map_err(|source| {
ProvenBatchError::TransactionVerificationFailed {
transaction_id: tx.id(),
source: Box::new(source),
}
})?;
}
self.prove_inner(proposed_batch)
}
#[cfg(any(feature = "testing", test))]
pub fn prove_dummy(
&self,
proposed_batch: ProposedBatch,
) -> Result<ProvenBatch, ProvenBatchError> {
self.prove_inner(proposed_batch)
}
fn prove_inner(&self, proposed_batch: ProposedBatch) -> Result<ProvenBatch, ProvenBatchError> {
let tx_headers = proposed_batch.transaction_headers();
let (
_transactions,
block_header,
_block_chain,
_authenticatable_unauthenticated_notes,
id,
updated_accounts,
input_notes,
output_notes,
batch_expiration_block_num,
) = proposed_batch.into_parts();
ProvenBatch::new_unchecked(
id,
block_header.commitment(),
block_header.block_num(),
updated_accounts,
input_notes,
output_notes,
batch_expiration_block_num,
tx_headers,
)
}
}