use algebra_core::Field; use core::borrow::Borrow; use r1cs_core::{Namespace, SynthesisError}; use r1cs_std::prelude::*; use crate::nizk::NIZK; pub trait NIZKVerifierGadget { type PreparedVerificationKeyVar; type VerificationKeyVar: AllocVar + ToBytesGadget; type ProofVar: AllocVar; /// Optionally allocates `N::Proof` in `cs` without performing /// subgroup checks. /// /// The default implementation doesn't omit these checks. fn new_proof_unchecked>( cs: impl Into>, f: impl FnOnce() -> Result, mode: AllocationMode, ) -> Result { Self::ProofVar::new_variable(cs, f, mode) } /// Optionally allocates `N::VerificationParameters` in `cs` /// without performing subgroup checks. /// /// The default implementation doesn't omit these checks. fn new_verification_key_unchecked>( cs: impl Into>, f: impl FnOnce() -> Result, mode: AllocationMode, ) -> Result { Self::VerificationKeyVar::new_variable(cs, f, mode) } fn verify<'a, T: 'a + ToBitsGadget + ?Sized>( verification_key: &Self::VerificationKeyVar, input: impl IntoIterator, proof: &Self::ProofVar, ) -> Result<(), SynthesisError> { Self::conditional_verify(verification_key, input, proof, &Boolean::constant(true)) } fn conditional_verify<'a, T: 'a + ToBitsGadget + ?Sized>( verification_key: &Self::VerificationKeyVar, input: impl IntoIterator, proof: &Self::ProofVar, condition: &Boolean, ) -> Result<(), SynthesisError>; fn conditional_verify_prepared<'a, T: 'a + ToBitsGadget + ?Sized>( prepared_verification_key: &Self::PreparedVerificationKeyVar, input: impl IntoIterator, proof: &Self::ProofVar, condition: &Boolean, ) -> Result<(), SynthesisError>; }