Skip to content

Commit

Permalink
Simplifies batch validation test/benchmark functions
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed May 22, 2024
1 parent e7ca1e0 commit d3cb964
Showing 1 changed file with 16 additions and 41 deletions.
57 changes: 16 additions & 41 deletions masp_proofs/src/sapling/verifier/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,69 +212,44 @@ impl BatchValidator {

#[cfg(feature = "benchmarks")]
impl BatchValidator {
/// Verify the signatures
/// Verify the signatures. Intended for testing purposes only.
pub fn verify_signatures<R: RngCore + CryptoRng>(
self,
mut rng: R,
) -> Result<(), redjubjub::Error> {
self.signatures.verify(&mut rng)
}

/// Get the proof verifier
#[cfg(feature = "multicore")]
pub fn get_proof_verifier() -> Box<
dyn Fn(
groth16::batch::Verifier<Bls12>,
&bellman::groth16::VerifyingKey<Bls12>,
) -> Result<(), bellman::VerificationError>,
> {
Box::new(|batch: groth16::batch::Verifier<Bls12>, vk| batch.verify_multicore(vk))
}

/// Get the proof verifier
#[cfg(not(feature = "multicore"))]
pub fn get_proof_verifier() -> Box<
dyn Fn(
groth16::batch::Verifier<Bls12>,
&bellman::groth16::VerifyingKey<Bls12>,
) -> Result<(), bellman::VerificationError>,
> {
Box::new(|batch: groth16::batch::Verifier<Bls12>, vk| batch.verify(&mut rng, vk))
}

/// Verify the spend proofs
/// Verify the spend proofs Intended for testing purposes only.
pub fn verify_spend_proofs(
self,
verify_proofs: &dyn Fn(
groth16::batch::Verifier<Bls12>,
&bellman::groth16::VerifyingKey<Bls12>,
) -> Result<(), bellman::VerificationError>,
spend_vk: &groth16::VerifyingKey<Bls12>,
) -> Result<(), bellman::VerificationError> {
verify_proofs(self.spend_proofs, spend_vk)
#[cfg(feature = "multicore")]
return self.spend_proofs.verify_multicore(spend_vk);
#[cfg(not(feature = "multicore"))]
return self.spend_proofs.verify(spend_vk);
}

/// Verify the convert proofs
/// Verify the convert proofs. Intended for testing purposes only.
pub fn verify_convert_proofs(
self,
verify_proofs: &dyn Fn(
groth16::batch::Verifier<Bls12>,
&bellman::groth16::VerifyingKey<Bls12>,
) -> Result<(), bellman::VerificationError>,
convert_vk: &groth16::VerifyingKey<Bls12>,
) -> Result<(), bellman::VerificationError> {
verify_proofs(self.convert_proofs, convert_vk)
#[cfg(feature = "multicore")]
return self.convert_proofs.verify_multicore(convert_vk);
#[cfg(not(feature = "multicore"))]
return self.convert_proofs.verify(convert_vk);
}

/// Verify the output proofs
/// Verify the output proofs. Intended for testing purposes only.
pub fn verify_output_proofs(
self,
verify_proofs: &dyn Fn(
groth16::batch::Verifier<Bls12>,
&bellman::groth16::VerifyingKey<Bls12>,
) -> Result<(), bellman::VerificationError>,
output_vk: &groth16::VerifyingKey<Bls12>,
) -> Result<(), bellman::VerificationError> {
verify_proofs(self.output_proofs, output_vk)
#[cfg(feature = "multicore")]
return self.output_proofs.verify_multicore(output_vk);
#[cfg(not(feature = "multicore"))]
return self.output_proofs.verify(output_vk);
}
}

0 comments on commit d3cb964

Please sign in to comment.