diff --git a/src/lib.rs b/src/lib.rs index e7e36ee0..814f9d8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -571,18 +571,28 @@ where S1: RelaxedR1CSSNARKTrait, S2: RelaxedR1CSSNARKTrait, { - r_U_primary: RelaxedR1CSInstance, - l_u_primary: R1CSInstance, - nifs_primary: NIFS, - f_W_snark_primary: S1, - - r_U_secondary: RelaxedR1CSInstance, - l_u_secondary: R1CSInstance, - nifs_secondary: NIFS, - f_W_snark_secondary: S2, - - zn_primary: Vec, - zn_secondary: Vec, + /// r_U_primary + pub r_U_primary: RelaxedR1CSInstance, + /// l_u_primary + pub l_u_primary: R1CSInstance, + /// nifs_primary + pub nifs_primary: NIFS, + /// f_W_snark_primary + pub f_W_snark_primary: S1, + + /// r_U_secondary + pub r_U_secondary: RelaxedR1CSInstance, + /// l_u_secondary + pub l_u_secondary: R1CSInstance, + /// nifs_secondary + pub nifs_secondary: NIFS, + /// f_W_snark_secondary + pub f_W_snark_secondary: S2, + + /// zn primary + pub zn_primary: Vec, + /// zn secondary + pub zn_secondary: Vec, _p_c1: PhantomData, _p_c2: PhantomData, diff --git a/src/provider/hyrax_pc.rs b/src/provider/hyrax_pc.rs index 71c46615..5d80ef90 100644 --- a/src/provider/hyrax_pc.rs +++ b/src/provider/hyrax_pc.rs @@ -34,8 +34,10 @@ pub struct PolyCommit { /// Hyrax PC generators and functions to commit and prove evaluation pub struct HyraxPC { - gens_v: CommitmentGens, // generator for vectors - gens_s: CommitmentGens, // generator for scalars (eval) + /// generator for vectors + pub gens_v: CommitmentGens, // generator for vectors + /// generator for scalars (eval) + pub gens_s: CommitmentGens, // generator for scalars (eval) } impl AppendToTranscriptTrait for PolyCommit { diff --git a/src/provider/pedersen.rs b/src/provider/pedersen.rs index 4b37fc26..c3c4a5b9 100644 --- a/src/provider/pedersen.rs +++ b/src/provider/pedersen.rs @@ -21,8 +21,10 @@ use serde::{Deserialize, Serialize}; /// A type that holds commitment generators #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CommitmentGens { - gens: Vec, - h: G::PreprocessedGroupElement, + /// generator vec + pub gens: Vec, + /// temporary public for debug + pub h: G::PreprocessedGroupElement, _p: PhantomData, } @@ -30,7 +32,8 @@ pub struct CommitmentGens { #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(bound = "")] pub struct Commitment { - pub(crate) comm: G, + /// commitment elt + pub comm: G, } /// A type that holds a compressed commitment diff --git a/src/spartan/direct.rs b/src/spartan/direct.rs index a5e11e6c..4464fce8 100644 --- a/src/spartan/direct.rs +++ b/src/spartan/direct.rs @@ -69,7 +69,8 @@ where { gens: R1CSGens, S: R1CSShape, - pk: ProverKey, + /// pk + pub pk: ProverKey, } /// A type that holds Spartan's verifier's key diff --git a/src/spartan/mod.rs b/src/spartan/mod.rs index a3dba8ac..b0d83bec 100644 --- a/src/spartan/mod.rs +++ b/src/spartan/mod.rs @@ -1,7 +1,7 @@ //! This module implements RelaxedR1CSSNARKTrait and CAPRelaxedR1CSSNARKTrait using Spartan that is generic //! over the polynomial commitment and evaluation argument (i.e., a PCS) pub mod direct; -mod nizk; +pub mod nizk; pub mod polynomial; mod sumcheck; @@ -61,7 +61,8 @@ impl SumcheckGens { #[derive(Serialize, Deserialize)] #[serde(bound = "")] pub struct ProverKey> { - gens: EE::EvaluationGens, + /// gens + pub gens: EE::EvaluationGens, sumcheck_gens: SumcheckGens, S: R1CSShape, } diff --git a/src/spartan/nizk.rs b/src/spartan/nizk.rs index cd230b40..0db10446 100644 --- a/src/spartan/nizk.rs +++ b/src/spartan/nizk.rs @@ -1,3 +1,4 @@ +//! This module defines nizk proofs #![allow(clippy::too_many_arguments)] #![allow(clippy::type_complexity)] use crate::errors::NovaError; @@ -13,6 +14,7 @@ use merlin::Transcript; use rand::rngs::OsRng; use serde::{Deserialize, Serialize}; +/// KnowledgeProof #[derive(Debug, Serialize, Deserialize)] #[serde(bound = "")] pub struct KnowledgeProof { @@ -21,13 +23,17 @@ pub struct KnowledgeProof { z2: G::Scalar, } +/// EqualityProof #[derive(Debug, Serialize, Deserialize)] #[serde(bound = "")] pub struct EqualityProof { - alpha: CompressedCommitment, - z: G::Scalar, + /// alpha + pub alpha: CompressedCommitment, + /// z + pub z: G::Scalar, } +/// ProductProof #[derive(Debug, Serialize, Deserialize)] #[serde(bound = "")] pub struct ProductProof { @@ -37,6 +43,7 @@ pub struct ProductProof { z: [G::Scalar; 5], } +/// DocProductProof #[derive(Debug, Serialize, Deserialize)] #[serde(bound = "")] pub struct DotProductProof { @@ -47,11 +54,13 @@ pub struct DotProductProof { z_beta: G::Scalar, } +/// KnowledgeProof impl KnowledgeProof { fn protocol_name() -> &'static [u8] { b"knowledge proof" } + /// prove pub fn prove( gens_n: &CommitmentGens, transcript: &mut Transcript, @@ -78,6 +87,7 @@ impl KnowledgeProof { Ok((Self { alpha, z1, z2 }, C)) } + /// verify pub fn verify( &self, gens_n: &CommitmentGens, @@ -101,11 +111,14 @@ impl KnowledgeProof { } } +/// EqualityProof impl EqualityProof { - fn protocol_name() -> &'static [u8] { + /// protocol name + pub fn protocol_name() -> &'static [u8] { b"equality proof" } + /// prove pub fn prove( gens_n: &CommitmentGens, transcript: &mut Transcript, @@ -142,6 +155,7 @@ impl EqualityProof { Ok((Self { alpha, z }, C1, C2)) } + /// verify pub fn verify( &self, gens_n: &CommitmentGens, @@ -171,11 +185,14 @@ impl EqualityProof { } } +/// product proof impl ProductProof { + /// protocol name fn protocol_name() -> &'static [u8] { b"product proof" } + /// prove pub fn prove( gens_n: &CommitmentGens, transcript: &mut Transcript, @@ -247,6 +264,7 @@ impl ProductProof { )) } + /// check_equality fn check_equality( P: &CompressedCommitment, X: &CompressedCommitment, @@ -261,6 +279,7 @@ impl ProductProof { Ok(lhs == rhs) } + /// verify pub fn verify( &self, gens_n: &CommitmentGens, @@ -305,11 +324,14 @@ impl ProductProof { } } +/// DotProductProof impl DotProductProof { + /// protocol name pub fn protocol_name() -> &'static [u8] { b"dot product proof" } + /// comppute dot product pub fn compute_dotproduct(a: &[G::Scalar], b: &[G::Scalar]) -> G::Scalar { assert_eq!(a.len(), b.len()); let mut result = G::Scalar::zero(); @@ -321,6 +343,7 @@ impl DotProductProof { result } + /// prove pub fn prove( gens_1: &CommitmentGens, // generator of size 1 gens_n: &CommitmentGens, // generators of size n @@ -384,6 +407,7 @@ impl DotProductProof { ) } + /// verify pub fn verify( &self, gens_1: &CommitmentGens, // generator of size 1 diff --git a/src/spartan/polynomial.rs b/src/spartan/polynomial.rs index 5e0b53b1..19a9f9db 100644 --- a/src/spartan/polynomial.rs +++ b/src/spartan/polynomial.rs @@ -3,7 +3,8 @@ use core::ops::Index; use ff::PrimeField; use rayon::prelude::*; -pub(crate) struct EqPolynomial { +/// Polynomial struct +pub struct EqPolynomial { r: Vec, } @@ -21,6 +22,7 @@ impl EqPolynomial { .fold(Scalar::one(), |acc, item| acc * item) } + /// evals pub fn evals(&self) -> Vec { let ell = self.r.len(); let mut evals: Vec = vec![Scalar::zero(); (2_usize).pow(ell as u32)]; @@ -44,10 +46,12 @@ impl EqPolynomial { evals } + /// factored lens pub fn compute_factored_lens(ell: usize) -> (usize, usize) { (ell / 2, ell - ell / 2) } + /// factored evals pub fn compute_factored_evals(&self) -> (Vec, Vec) { let ell = self.r.len(); let (left_num_vars, _right_num_vars) = EqPolynomial::::compute_factored_lens(ell);