From de4463136f9f9e5b3c08b227fdc829a6b108d265 Mon Sep 17 00:00:00 2001 From: arnaucube Date: Mon, 10 Jul 2023 09:52:36 +0200 Subject: [PATCH] make modules&methods pub, rm unused self in gadget - remove unused self for SumcheckVerificationCircuit gadget (verifiy_sumcheck) - make some modules & methods pub to be used from outside of the repo - small typos fixes --- src/constraints.rs | 33 +++++++++++++++++---------------- src/lib.rs | 12 ++++++------ src/r1csproof.rs | 4 ++-- src/testudo_snark.rs | 2 +- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/constraints.rs b/src/constraints.rs index 931d3f0..5621f06 100644 --- a/src/constraints.rs +++ b/src/constraints.rs @@ -21,7 +21,7 @@ use ark_r1cs_std::{ }; use ark_relations::r1cs::{ConstraintSynthesizer, ConstraintSystemRef, Namespace, SynthesisError}; -pub struct PoseidonTranscripVar +pub struct PoseidonTranscriptVar where F: PrimeField, { @@ -29,11 +29,11 @@ where pub sponge: PoseidonSpongeVar, } -impl PoseidonTranscripVar +impl PoseidonTranscriptVar where F: PrimeField, { - fn new(cs: ConstraintSystemRef, params: &PoseidonConfig, c_var: FpVar) -> Self { + pub fn new(cs: ConstraintSystemRef, params: &PoseidonConfig, c_var: FpVar) -> Self { let mut sponge = PoseidonSpongeVar::new(cs.clone(), params); sponge.absorb(&c_var).unwrap(); @@ -120,16 +120,15 @@ pub struct SumcheckVerificationCircuit { } impl SumcheckVerificationCircuit { - fn verifiy_sumcheck( - &self, + pub fn verify_sumcheck( poly_vars: &[UniPolyVar], claim_var: &FpVar, - transcript_var: &mut PoseidonTranscripVar, + transcript_var: &mut PoseidonTranscriptVar, ) -> Result<(FpVar, Vec>), SynthesisError> { let mut e_var = claim_var.clone(); let mut r_vars: Vec> = Vec::new(); - for (poly_var, _poly) in poly_vars.iter().zip(self.polys.iter()) { + for poly_var in poly_vars.iter() { let res = poly_var.eval_at_one() + poly_var.eval_at_zero(); res.enforce_equal(&e_var)?; transcript_var.append_vector(&poly_var.coeffs)?; @@ -264,7 +263,7 @@ impl ConstraintSynthesizer for R1CSVerificationCircuit { fn generate_constraints(self, cs: ConstraintSystemRef) -> ark_relations::r1cs::Result<()> { let initial_challenge_var = FpVar::::new_input(cs.clone(), || Ok(self.prev_challenge))?; let mut transcript_var = - PoseidonTranscripVar::new(cs.clone(), &self.params, initial_challenge_var); + PoseidonTranscriptVar::new(cs.clone(), &self.params, initial_challenge_var); let poly_sc1_vars = self .sc_phase1 @@ -307,10 +306,11 @@ impl ConstraintSynthesizer for R1CSVerificationCircuit { let claim_phase1_var = FpVar::::new_witness(cs.clone(), || Ok(F::zero()))?; - let (claim_post_phase1_var, rx_var) = - self - .sc_phase1 - .verifiy_sumcheck(&poly_sc1_vars, &claim_phase1_var, &mut transcript_var)?; + let (claim_post_phase1_var, rx_var) = SumcheckVerificationCircuit::::verify_sumcheck( + &poly_sc1_vars, + &claim_phase1_var, + &mut transcript_var, + )?; // The prover sends (rx, ry) to the verifier for the evaluation proof so // the constraints need to ensure it is indeed the result from the first @@ -347,10 +347,11 @@ impl ConstraintSynthesizer for R1CSVerificationCircuit { let claim_phase2_var = &r_A_var * &Az_claim_var + &r_B_var * &Bz_claim_var + &r_C_var * &Cz_claim_var; - let (claim_post_phase2_var, ry_var) = - self - .sc_phase2 - .verifiy_sumcheck(&poly_sc2_vars, &claim_phase2_var, &mut transcript_var)?; + let (claim_post_phase2_var, ry_var) = SumcheckVerificationCircuit::::verify_sumcheck( + &poly_sc2_vars, + &claim_phase2_var, + &mut transcript_var, + )?; // Because the verifier checks the commitment opening on point ry outside // the circuit, the prover needs to send ry to the verifier (making the diff --git a/src/lib.rs b/src/lib.rs index 44893a9..ca95ea4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,7 @@ extern crate json; extern crate rayon; mod commitments; -mod dense_mlpoly; +pub mod dense_mlpoly; mod errors; #[macro_use] pub(crate) mod macros; @@ -25,20 +25,20 @@ mod math; pub(crate) mod mipp; mod nizk; mod product_tree; -mod r1csinstance; -mod r1csproof; +pub mod r1csinstance; +pub mod r1csproof; mod sparse_mlpoly; pub mod sqrt_pst; -mod sumcheck; +pub mod sumcheck; pub mod testudo_nizk; pub mod testudo_snark; mod timer; -pub(crate) mod transcript; +pub mod transcript; mod unipoly; pub mod parameters; -mod constraints; +pub mod constraints; pub mod poseidon_transcript; use core::cmp::max; diff --git a/src/r1csproof.rs b/src/r1csproof.rs index 9253852..3b1e724 100644 --- a/src/r1csproof.rs +++ b/src/r1csproof.rs @@ -607,7 +607,7 @@ mod tests { let inst_evals = inst.evaluate(&rx, &ry); prover_transcript.new_from_state(&c); - let verifer_proof = proof + let verifier_proof = proof .prove_verifier( num_vars, num_cons, @@ -620,7 +620,7 @@ mod tests { .unwrap(); let mut verifier_transcript = PoseidonTranscript::new(¶ms.clone()); - assert!(verifer_proof + assert!(verifier_proof .verify( (rx, ry), &input, diff --git a/src/testudo_snark.rs b/src/testudo_snark.rs index e6cb430..5d1997f 100644 --- a/src/testudo_snark.rs +++ b/src/testudo_snark.rs @@ -116,7 +116,7 @@ where // Returns the Testudo SNARK proof which has two components: // * proof that the R1CS instance is satisfiable // * proof that the evlauation of matrices A, B and C on point (x,y) - // resulted from the two rounda of sumcheck are correct + // resulted from the two rounds of sumcheck are correct pub fn prove( inst: &Instance, comm: &ComputationCommitment,