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
This commit is contained in:
2023-07-10 09:52:36 +02:00
parent 7db2d30972
commit de4463136f
4 changed files with 26 additions and 25 deletions

View File

@@ -21,7 +21,7 @@ use ark_r1cs_std::{
}; };
use ark_relations::r1cs::{ConstraintSynthesizer, ConstraintSystemRef, Namespace, SynthesisError}; use ark_relations::r1cs::{ConstraintSynthesizer, ConstraintSystemRef, Namespace, SynthesisError};
pub struct PoseidonTranscripVar<F> pub struct PoseidonTranscriptVar<F>
where where
F: PrimeField, F: PrimeField,
{ {
@@ -29,11 +29,11 @@ where
pub sponge: PoseidonSpongeVar<F>, pub sponge: PoseidonSpongeVar<F>,
} }
impl<F> PoseidonTranscripVar<F> impl<F> PoseidonTranscriptVar<F>
where where
F: PrimeField, F: PrimeField,
{ {
fn new(cs: ConstraintSystemRef<F>, params: &PoseidonConfig<F>, c_var: FpVar<F>) -> Self { pub fn new(cs: ConstraintSystemRef<F>, params: &PoseidonConfig<F>, c_var: FpVar<F>) -> Self {
let mut sponge = PoseidonSpongeVar::new(cs.clone(), params); let mut sponge = PoseidonSpongeVar::new(cs.clone(), params);
sponge.absorb(&c_var).unwrap(); sponge.absorb(&c_var).unwrap();
@@ -120,16 +120,15 @@ pub struct SumcheckVerificationCircuit<F: PrimeField> {
} }
impl<F: PrimeField> SumcheckVerificationCircuit<F> { impl<F: PrimeField> SumcheckVerificationCircuit<F> {
fn verifiy_sumcheck( pub fn verify_sumcheck(
&self,
poly_vars: &[UniPolyVar<F>], poly_vars: &[UniPolyVar<F>],
claim_var: &FpVar<F>, claim_var: &FpVar<F>,
transcript_var: &mut PoseidonTranscripVar<F>, transcript_var: &mut PoseidonTranscriptVar<F>,
) -> Result<(FpVar<F>, Vec<FpVar<F>>), SynthesisError> { ) -> Result<(FpVar<F>, Vec<FpVar<F>>), SynthesisError> {
let mut e_var = claim_var.clone(); let mut e_var = claim_var.clone();
let mut r_vars: Vec<FpVar<F>> = Vec::new(); let mut r_vars: Vec<FpVar<F>> = 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(); let res = poly_var.eval_at_one() + poly_var.eval_at_zero();
res.enforce_equal(&e_var)?; res.enforce_equal(&e_var)?;
transcript_var.append_vector(&poly_var.coeffs)?; transcript_var.append_vector(&poly_var.coeffs)?;
@@ -264,7 +263,7 @@ impl<F: PrimeField> ConstraintSynthesizer<F> for R1CSVerificationCircuit<F> {
fn generate_constraints(self, cs: ConstraintSystemRef<F>) -> ark_relations::r1cs::Result<()> { fn generate_constraints(self, cs: ConstraintSystemRef<F>) -> ark_relations::r1cs::Result<()> {
let initial_challenge_var = FpVar::<F>::new_input(cs.clone(), || Ok(self.prev_challenge))?; let initial_challenge_var = FpVar::<F>::new_input(cs.clone(), || Ok(self.prev_challenge))?;
let mut transcript_var = 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 let poly_sc1_vars = self
.sc_phase1 .sc_phase1
@@ -307,10 +306,11 @@ impl<F: PrimeField> ConstraintSynthesizer<F> for R1CSVerificationCircuit<F> {
let claim_phase1_var = FpVar::<F>::new_witness(cs.clone(), || Ok(F::zero()))?; let claim_phase1_var = FpVar::<F>::new_witness(cs.clone(), || Ok(F::zero()))?;
let (claim_post_phase1_var, rx_var) = let (claim_post_phase1_var, rx_var) = SumcheckVerificationCircuit::<F>::verify_sumcheck(
self &poly_sc1_vars,
.sc_phase1 &claim_phase1_var,
.verifiy_sumcheck(&poly_sc1_vars, &claim_phase1_var, &mut transcript_var)?; &mut transcript_var,
)?;
// The prover sends (rx, ry) to the verifier for the evaluation proof so // 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 // the constraints need to ensure it is indeed the result from the first
@@ -347,10 +347,11 @@ impl<F: PrimeField> ConstraintSynthesizer<F> for R1CSVerificationCircuit<F> {
let claim_phase2_var = let claim_phase2_var =
&r_A_var * &Az_claim_var + &r_B_var * &Bz_claim_var + &r_C_var * &Cz_claim_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) = let (claim_post_phase2_var, ry_var) = SumcheckVerificationCircuit::<F>::verify_sumcheck(
self &poly_sc2_vars,
.sc_phase2 &claim_phase2_var,
.verifiy_sumcheck(&poly_sc2_vars, &claim_phase2_var, &mut transcript_var)?; &mut transcript_var,
)?;
// Because the verifier checks the commitment opening on point ry outside // Because the verifier checks the commitment opening on point ry outside
// the circuit, the prover needs to send ry to the verifier (making the // the circuit, the prover needs to send ry to the verifier (making the

View File

@@ -17,7 +17,7 @@ extern crate json;
extern crate rayon; extern crate rayon;
mod commitments; mod commitments;
mod dense_mlpoly; pub mod dense_mlpoly;
mod errors; mod errors;
#[macro_use] #[macro_use]
pub(crate) mod macros; pub(crate) mod macros;
@@ -25,20 +25,20 @@ mod math;
pub(crate) mod mipp; pub(crate) mod mipp;
mod nizk; mod nizk;
mod product_tree; mod product_tree;
mod r1csinstance; pub mod r1csinstance;
mod r1csproof; pub mod r1csproof;
mod sparse_mlpoly; mod sparse_mlpoly;
pub mod sqrt_pst; pub mod sqrt_pst;
mod sumcheck; pub mod sumcheck;
pub mod testudo_nizk; pub mod testudo_nizk;
pub mod testudo_snark; pub mod testudo_snark;
mod timer; mod timer;
pub(crate) mod transcript; pub mod transcript;
mod unipoly; mod unipoly;
pub mod parameters; pub mod parameters;
mod constraints; pub mod constraints;
pub mod poseidon_transcript; pub mod poseidon_transcript;
use core::cmp::max; use core::cmp::max;

View File

@@ -607,7 +607,7 @@ mod tests {
let inst_evals = inst.evaluate(&rx, &ry); let inst_evals = inst.evaluate(&rx, &ry);
prover_transcript.new_from_state(&c); prover_transcript.new_from_state(&c);
let verifer_proof = proof let verifier_proof = proof
.prove_verifier( .prove_verifier(
num_vars, num_vars,
num_cons, num_cons,
@@ -620,7 +620,7 @@ mod tests {
.unwrap(); .unwrap();
let mut verifier_transcript = PoseidonTranscript::new(&params.clone()); let mut verifier_transcript = PoseidonTranscript::new(&params.clone());
assert!(verifer_proof assert!(verifier_proof
.verify( .verify(
(rx, ry), (rx, ry),
&input, &input,

View File

@@ -116,7 +116,7 @@ where
// Returns the Testudo SNARK proof which has two components: // Returns the Testudo SNARK proof which has two components:
// * proof that the R1CS instance is satisfiable // * proof that the R1CS instance is satisfiable
// * proof that the evlauation of matrices A, B and C on point (x,y) // * 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( pub fn prove(
inst: &Instance<E::ScalarField>, inst: &Instance<E::ScalarField>,
comm: &ComputationCommitment<E::G1>, comm: &ComputationCommitment<E::G1>,