Nova/src/snark.rs
src/snark.rsRaw
1//! A collection of traits that define the behavior of a zkSNARK for RelaxedR1CS
2use super::{
3 errors::NovaError,
4 r1cs::{R1CSGens, R1CSShape, RelaxedR1CSInstance, RelaxedR1CSWitness},
5 traits::Group,
6};
7
8/// A trait that defines the behavior of a zkSNARK's prover key
9pub trait ProverKeyTrait<G: Group>: Send + Sync {
10 /// Produces a new prover's key
11 fn new(gens: &R1CSGens<G>, S: &R1CSShape<G>) -> Self;
12}
13
14/// A trait that defines the behavior of a zkSNARK's verifier key
15pub trait VerifierKeyTrait<G: Group>: Send + Sync {
16 /// Produces a new verifier's key
17 fn new(gens: &R1CSGens<G>, S: &R1CSShape<G>) -> Self;
18}
19
20/// A trait that defines the behavior of a zkSNARK
21pub trait RelaxedR1CSSNARKTrait<G: Group>: Sized + Send + Sync {
22 /// A type that represents the prover's key
23 type ProverKey: ProverKeyTrait<G>;
24
25 /// A type that represents the verifier's key
26 type VerifierKey: VerifierKeyTrait<G>;
27
28 /// Produces a prover key
29 fn prover_key(gens: &R1CSGens<G>, S: &R1CSShape<G>) -> Self::ProverKey {
30 Self::ProverKey::new(gens, S)
31 }
32
33 /// Produces a verifier key
34 fn verifier_key(gens: &R1CSGens<G>, S: &R1CSShape<G>) -> Self::VerifierKey {
35 Self::VerifierKey::new(gens, S)
36 }
37
38 /// Produces a new SNARK for a relaxed R1CS
39 fn prove(
40 pk: &Self::ProverKey,
41 U: &RelaxedR1CSInstance<G>,
42 W: &RelaxedR1CSWitness<G>,
43 ) -> Result<Self, NovaError>;
44
45 /// Verifies a SNARK for a relaxed R1CS
46 fn verify(&self, vk: &Self::VerifierKey, U: &RelaxedR1CSInstance<G>) -> Result<(), NovaError>;
47}