arnaucube
arnaucube/ark-r1cs-stdPublic Self-hosted repository
ark-r1cs-std/crypto-primitives/src/nizk/constraints.rs
crypto-primitives/src/nizk/constraints.rsRaw
 1use algebra_core::Field;
 2use core::borrow::Borrow;
 3use r1cs_core::{Namespace, SynthesisError};
 4use r1cs_std::prelude::*;
 5
 6use crate::nizk::NIZK;
 7
 8pub trait NIZKVerifierGadget<N: NIZK, ConstraintF: Field> {
 9    type PreparedVerificationKeyVar;
10    type VerificationKeyVar: AllocVar<N::VerificationParameters, ConstraintF>
11        + ToBytesGadget<ConstraintF>;
12    type ProofVar: AllocVar<N::Proof, ConstraintF>;
13
14    /// Optionally allocates `N::Proof` in `cs` without performing
15    /// subgroup checks.
16    ///
17    /// The default implementation doesn't omit these checks.
18    fn new_proof_unchecked<T: Borrow<N::Proof>>(
19        cs: impl Into<Namespace<ConstraintF>>,
20        f: impl FnOnce() -> Result<T, SynthesisError>,
21        mode: AllocationMode,
22    ) -> Result<Self::ProofVar, SynthesisError> {
23        Self::ProofVar::new_variable(cs, f, mode)
24    }
25
26    /// Optionally allocates `N::VerificationParameters` in `cs`
27    /// without performing subgroup checks.
28    ///
29    /// The default implementation doesn't omit these checks.
30    fn new_verification_key_unchecked<T: Borrow<N::VerificationParameters>>(
31        cs: impl Into<Namespace<ConstraintF>>,
32        f: impl FnOnce() -> Result<T, SynthesisError>,
33        mode: AllocationMode,
34    ) -> Result<Self::VerificationKeyVar, SynthesisError> {
35        Self::VerificationKeyVar::new_variable(cs, f, mode)
36    }
37
38    fn verify<'a, T: 'a + ToBitsGadget<ConstraintF> + ?Sized>(
39        verification_key: &Self::VerificationKeyVar,
40        input: impl IntoIterator<Item = &'a T>,
41        proof: &Self::ProofVar,
42    ) -> Result<Boolean<ConstraintF>, SynthesisError>;
43
44    fn verify_prepared<'a, T: 'a + ToBitsGadget<ConstraintF> + ?Sized>(
45        prepared_verification_key: &Self::PreparedVerificationKeyVar,
46        input: impl IntoIterator<Item = &'a T>,
47        proof: &Self::ProofVar,
48    ) -> Result<Boolean<ConstraintF>, SynthesisError>;
49}