Separate prover and verifier keys in CompressedSNARK (#145)

* checkpoint

* simplify further

* checkpoint

* gens --> ck

* update benches

* address clippy

* cleanup

* update version
This commit is contained in:
Srinath Setty
2023-03-02 18:36:13 -08:00
committed by GitHub
parent 01ae6446a9
commit 1e4995274b
17 changed files with 391 additions and 344 deletions

View File

@@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};
/// This trait defines the behavior of commitment key
#[allow(clippy::len_without_is_empty)]
pub trait CommitmentGensTrait<G: Group>:
pub trait CommitmentKeyTrait<G: Group>:
Clone + Debug + Send + Sync + Serialize + for<'de> Deserialize<'de>
{
/// Holds the type of the commitment that can be produced
@@ -99,11 +99,11 @@ pub trait CommitmentEngineTrait<G: Group>:
Clone + Send + Sync + Serialize + for<'de> Deserialize<'de>
{
/// Holds the type of the commitment key
type CommitmentGens: CommitmentGensTrait<G, Commitment = Self::Commitment>;
type CommitmentKey: CommitmentKeyTrait<G, Commitment = Self::Commitment>;
/// Holds the type of the commitment
type Commitment: CommitmentTrait<G>;
/// Commits to the provided vector using the provided generators
fn commit(gens: &Self::CommitmentGens, v: &[G::Scalar]) -> Self::Commitment;
fn commit(ck: &Self::CommitmentKey, v: &[G::Scalar]) -> Self::Commitment;
}

View File

@@ -14,18 +14,24 @@ pub trait EvaluationEngineTrait<G: Group>:
/// A type that holds the associated commitment engine
type CE: CommitmentEngineTrait<G>;
/// A type that holds generators
type EvaluationGens: Clone + Send + Sync + Serialize + for<'de> Deserialize<'de>;
/// A type that holds the prover key
type ProverKey: Clone + Send + Sync + Serialize + for<'de> Deserialize<'de>;
/// A type that holds the verifier key
type VerifierKey: Clone + Send + Sync + Serialize + for<'de> Deserialize<'de>;
/// A type that holds the evaluation argument
type EvaluationArgument: Clone + Send + Sync + Serialize + for<'de> Deserialize<'de>;
/// A method to perform any additional setup needed to produce proofs of evaluations
fn setup(gens: &<Self::CE as CommitmentEngineTrait<G>>::CommitmentGens) -> Self::EvaluationGens;
fn setup(
ck: &<Self::CE as CommitmentEngineTrait<G>>::CommitmentKey,
) -> (Self::ProverKey, Self::VerifierKey);
/// A method to prove the evaluation of a multilinear polynomial
fn prove(
gens: &Self::EvaluationGens,
ck: &<Self::CE as CommitmentEngineTrait<G>>::CommitmentKey,
pk: &Self::ProverKey,
transcript: &mut G::TE,
comm: &<Self::CE as CommitmentEngineTrait<G>>::Commitment,
poly: &[G::Scalar],
@@ -35,7 +41,7 @@ pub trait EvaluationEngineTrait<G: Group>:
/// A method to verify the purported evaluation of a multilinear polynomials
fn verify(
gens: &Self::EvaluationGens,
vk: &Self::VerifierKey,
transcript: &mut G::TE,
comm: &<Self::CE as CommitmentEngineTrait<G>>::Commitment,
point: &[G::Scalar],

View File

@@ -1,46 +1,29 @@
//! This module defines a collection of traits that define the behavior of a zkSNARK for RelaxedR1CS
use crate::{
errors::NovaError,
r1cs::{R1CSGens, R1CSShape, RelaxedR1CSInstance, RelaxedR1CSWitness},
r1cs::{R1CSShape, RelaxedR1CSInstance, RelaxedR1CSWitness},
traits::Group,
CommitmentKey,
};
use serde::{Deserialize, Serialize};
/// A trait that defines the behavior of a zkSNARK's prover key
pub trait ProverKeyTrait<G: Group>: Send + Sync {
/// Produces a new prover's key
fn new(gens: &R1CSGens<G>, S: &R1CSShape<G>) -> Self;
}
/// A trait that defines the behavior of a zkSNARK's verifier key
pub trait VerifierKeyTrait<G: Group>: Send + Sync {
/// Produces a new verifier's key
fn new(gens: &R1CSGens<G>, S: &R1CSShape<G>) -> Self;
}
/// A trait that defines the behavior of a zkSNARK
pub trait RelaxedR1CSSNARKTrait<G: Group>:
Sized + Send + Sync + Serialize + for<'de> Deserialize<'de>
{
/// A type that represents the prover's key
type ProverKey: ProverKeyTrait<G> + Serialize + for<'de> Deserialize<'de>;
type ProverKey: Send + Sync + Serialize + for<'de> Deserialize<'de>;
/// A type that represents the verifier's key
type VerifierKey: VerifierKeyTrait<G> + Serialize + for<'de> Deserialize<'de>;
type VerifierKey: Send + Sync + Serialize + for<'de> Deserialize<'de>;
/// Produces a prover key
fn prover_key(gens: &R1CSGens<G>, S: &R1CSShape<G>) -> Self::ProverKey {
Self::ProverKey::new(gens, S)
}
/// Produces a verifier key
fn verifier_key(gens: &R1CSGens<G>, S: &R1CSShape<G>) -> Self::VerifierKey {
Self::VerifierKey::new(gens, S)
}
/// Produces the keys for the prover and the verifier
fn setup(ck: &CommitmentKey<G>, S: &R1CSShape<G>) -> (Self::ProverKey, Self::VerifierKey);
/// Produces a new SNARK for a relaxed R1CS
fn prove(
ck: &CommitmentKey<G>,
pk: &Self::ProverKey,
U: &RelaxedR1CSInstance<G>,
W: &RelaxedR1CSWitness<G>,