From aef6168082036236327bd4d9b54e603cd9ad6de0 Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Mon, 9 Oct 2023 10:49:50 -0700 Subject: [PATCH] temporary fix for duplicate shape in prover keys --- src/lib.rs | 10 +++------- src/spartan/mod.rs | 6 ++++-- src/spartan/snark.rs | 19 +++++++++---------- src/traits/snark.rs | 1 + 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b6b8970..df8c607 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,11 +33,7 @@ use core::marker::PhantomData; use errors::SpartanError; use r1cs::{R1CSShape, RelaxedR1CSInstance, RelaxedR1CSWitness}; use serde::{Deserialize, Serialize}; -use traits::{ - commitment::{CommitmentEngineTrait, CommitmentTrait}, - snark::RelaxedR1CSSNARKTrait, - Group, -}; +use traits::{commitment::CommitmentEngineTrait, snark::RelaxedR1CSSNARKTrait, Group}; /// A type that holds the prover key #[derive(Clone, Serialize, Deserialize)] @@ -112,7 +108,7 @@ impl, C: Circuit> SNARK, C: Circuit> SNARK = <::CE as CommitmentEngineTrait>::CommitmentKey; type Commitment = <::CE as CommitmentEngineTrait>::Commitment; -type CompressedCommitment = <<::CE as CommitmentEngineTrait>::Commitment as CommitmentTrait>::CompressedCommitment; +//type CompressedCommitment = <<::CE as CommitmentEngineTrait>::Commitment as CommitmentTrait>::CompressedCommitment; type CE = ::CE; #[cfg(test)] diff --git a/src/spartan/mod.rs b/src/spartan/mod.rs index c0d223f..c38bcce 100644 --- a/src/spartan/mod.rs +++ b/src/spartan/mod.rs @@ -7,13 +7,13 @@ //! In polynomial.rs we also provide foundational types and functions for manipulating multilinear polynomials. pub(crate) mod math; pub mod polys; -pub mod ppsnark; +// pub mod ppsnark; pub mod snark; mod sumcheck; use crate::{traits::Group, Commitment}; use ff::Field; -use polys::multilinear::SparsePolynomial; +//use polys::multilinear::SparsePolynomial; fn powers(s: &G::Scalar, n: usize) -> Vec { assert!(n >= 1); @@ -57,6 +57,7 @@ impl PolyEvalWitness { PolyEvalWitness { p } } + #[allow(dead_code)] fn batch(p_vec: &[&Vec], s: &G::Scalar) -> PolyEvalWitness { let powers_of_s = powers::(s, p_vec.len()); let mut p = vec![G::Scalar::ZERO; p_vec[0].len()]; @@ -96,6 +97,7 @@ impl PolyEvalInstance { } } + #[allow(dead_code)] fn batch( c_vec: &[Commitment], x: &[G::Scalar], diff --git a/src/spartan/snark.rs b/src/spartan/snark.rs index 2e8780d..7b39300 100644 --- a/src/spartan/snark.rs +++ b/src/spartan/snark.rs @@ -30,7 +30,6 @@ use serde::{Deserialize, Serialize}; #[serde(bound = "")] pub struct ProverKey> { pk_ee: EE::ProverKey, - S: R1CSShape, vk_digest: G::Scalar, // digest of the verifier's key } @@ -100,7 +99,6 @@ impl> RelaxedR1CSSNARKTrait for Relaxe let pk = ProverKey { pk_ee, - S, vk_digest: vk.digest(), }; @@ -111,14 +109,15 @@ impl> RelaxedR1CSSNARKTrait for Relaxe fn prove( ck: &CommitmentKey, pk: &Self::ProverKey, + S: &R1CSShape, U: &RelaxedR1CSInstance, W: &RelaxedR1CSWitness, ) -> Result { - let W = W.pad(&pk.S); // pad the witness + let W = W.pad(S); // pad the witness let mut transcript = G::TE::new(b"RelaxedR1CSSNARK"); // sanity check that R1CSShape has certain size characteristics - pk.S.check_regular_shape(); + S.check_regular_shape(); // append the digest of vk (which includes R1CS matrices) and the RelaxedR1CSInstance to the transcript transcript.absorb(b"vk", &pk.vk_digest); @@ -128,8 +127,8 @@ impl> RelaxedR1CSSNARKTrait for Relaxe let mut z = [W.W.clone(), vec![U.u], U.X.clone()].concat(); let (num_rounds_x, num_rounds_y) = ( - usize::try_from(pk.S.num_cons.ilog2()).unwrap(), - (usize::try_from(pk.S.num_vars.ilog2()).unwrap() + 1), + usize::try_from(S.num_cons.ilog2()).unwrap(), + (usize::try_from(S.num_vars.ilog2()).unwrap() + 1), ); // outer sum-check @@ -139,8 +138,8 @@ impl> RelaxedR1CSSNARKTrait for Relaxe let mut poly_tau = MultilinearPolynomial::new(EqPolynomial::new(tau).evals()); let (mut poly_Az, mut poly_Bz, poly_Cz, mut poly_uCz_E) = { - let (poly_Az, poly_Bz, poly_Cz) = pk.S.multiply_vec(&z)?; - let poly_uCz_E = (0..pk.S.num_cons) + let (poly_Az, poly_Bz, poly_Cz) = S.multiply_vec(&z)?; + let poly_uCz_E = (0..S.num_cons) .map(|i| U.u * poly_Cz[i] + W.E[i]) .collect::>(); ( @@ -221,7 +220,7 @@ impl> RelaxedR1CSSNARKTrait for Relaxe (A_evals, B_evals, C_evals) }; - let (evals_A, evals_B, evals_C) = compute_eval_table_sparse(&pk.S, &evals_rx); + let (evals_A, evals_B, evals_C) = compute_eval_table_sparse(S, &evals_rx); assert_eq!(evals_A.len(), evals_B.len()); assert_eq!(evals_A.len(), evals_C.len()); @@ -232,7 +231,7 @@ impl> RelaxedR1CSSNARKTrait for Relaxe }; let poly_z = { - z.resize(pk.S.num_vars * 2, G::Scalar::ZERO); + z.resize(S.num_vars * 2, G::Scalar::ZERO); z }; diff --git a/src/traits/snark.rs b/src/traits/snark.rs index 8b136b5..5ed56c8 100644 --- a/src/traits/snark.rs +++ b/src/traits/snark.rs @@ -28,6 +28,7 @@ pub trait RelaxedR1CSSNARKTrait: fn prove( ck: &CommitmentKey, pk: &Self::ProverKey, + S: &R1CSShape, U: &RelaxedR1CSInstance, W: &RelaxedR1CSWitness, ) -> Result;