Skip to content

Commit 4b160ca

Browse files
committed
Adapt proving methods onto SumcheckInstanceProof. Remove ZK proof struct.
1 parent acbc979 commit 4b160ca

File tree

3 files changed

+27
-183
lines changed

3 files changed

+27
-183
lines changed

spartan_parallel/src/dense_mlpoly.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use crate::scalar::SpartanExtensionField;
33

44
use super::errors::ProofVerifyError;
55
use super::math::Math;
6-
use super::nizk::DotProductProofLog;
76
use super::random::RandomTape;
87
use super::transcript::ProofTranscript;
8+
use super::unipoly::CompressedUniPoly;
99
use core::ops::Index;
1010
use merlin::Transcript;
1111
use serde::{Deserialize, Serialize};
@@ -309,9 +309,9 @@ impl<S: SpartanExtensionField> Index<usize> for DensePolynomial<S> {
309309
}
310310
}
311311

312-
#[derive(Clone, Debug, Serialize, Deserialize)]
312+
#[derive(Debug, Serialize, Deserialize)]
313313
pub struct PolyEvalProof<S: SpartanExtensionField> {
314-
proof: DotProductProofLog<S>,
314+
polys: Vec<CompressedUniPoly<S>>,
315315
}
316316

317317
impl<S: SpartanExtensionField> PolyEvalProof<S> {

spartan_parallel/src/r1csproof.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ use super::custom_dense_mlpoly::DensePolynomialPqx;
33
use super::dense_mlpoly::{DensePolynomial, EqPolynomial, PolyEvalProof};
44
use super::errors::ProofVerifyError;
55
use super::math::Math;
6-
use super::nizk::{EqualityProof, KnowledgeProof, ProductProof};
76
use super::r1csinstance::R1CSInstance;
87
use super::random::RandomTape;
9-
use super::sumcheck::R1CSSumcheckInstanceProof;
8+
use super::sumcheck::SumcheckInstanceProof;
109
use super::timer::Timer;
1110
use super::transcript::ProofTranscript;
1211
use crate::scalar::SpartanExtensionField;
@@ -17,8 +16,8 @@ use std::cmp::min;
1716

1817
#[derive(Serialize, Deserialize, Debug)]
1918
pub struct R1CSProof<S: SpartanExtensionField> {
20-
sc_proof_phase1: R1CSSumcheckInstanceProof<S>,
21-
sc_proof_phase2: R1CSSumcheckInstanceProof<S>,
19+
sc_proof_phase1: SumcheckInstanceProof<S>,
20+
sc_proof_phase2: SumcheckInstanceProof<S>,
2221
pok_claims_phase2: (KnowledgeProof<S>, ProductProof<S>),
2322
proof_eq_sc_phase1: EqualityProof<S>,
2423
proof_eq_sc_phase2: EqualityProof<S>,
@@ -41,13 +40,13 @@ impl<S: SpartanExtensionField> R1CSProof<S> {
4140
evals_Cz: &mut DensePolynomialPqx<S>,
4241
transcript: &mut Transcript,
4342
random_tape: &mut RandomTape<S>,
44-
) -> (R1CSSumcheckInstanceProof<S>, Vec<S>, Vec<S>) {
43+
) -> (SumcheckInstanceProof<S>, Vec<S>, Vec<S>) {
4544
let comb_func = |poly_A_comp: &S, poly_B_comp: &S, poly_C_comp: &S, poly_D_comp: &S| -> S {
4645
*poly_A_comp * (*poly_B_comp * *poly_C_comp - *poly_D_comp)
4746
};
4847

4948
let (sc_proof_phase_one, r, claims) =
50-
R1CSSumcheckInstanceProof::<S>::prove_cubic_with_additive_term_disjoint_rounds(
49+
SumcheckInstanceProof::<S>::prove_cubic_with_additive_term_disjoint_rounds(
5150
&S::field_zero(), // claim is zero
5251
num_rounds,
5352
num_rounds_x_max,
@@ -83,12 +82,12 @@ impl<S: SpartanExtensionField> R1CSProof<S> {
8382
evals_z: &mut DensePolynomialPqx<S>,
8483
transcript: &mut Transcript,
8584
random_tape: &mut RandomTape<S>,
86-
) -> (R1CSSumcheckInstanceProof<S>, Vec<S>, Vec<S>) {
85+
) -> (SumcheckInstanceProof<S>, Vec<S>, Vec<S>) {
8786
let comb_func = |poly_A_comp: &S, poly_B_comp: &S, poly_C_comp: &S| -> S {
8887
*poly_A_comp * *poly_B_comp * *poly_C_comp
8988
};
9089
let (sc_proof_phase_two, r, claims) =
91-
R1CSSumcheckInstanceProof::<S>::prove_cubic_disjoint_rounds(
90+
SumcheckInstanceProof::<S>::prove_cubic_disjoint_rounds(
9291
claim,
9392
num_rounds,
9493
num_rounds_y_max,
@@ -102,7 +101,6 @@ impl<S: SpartanExtensionField> R1CSProof<S> {
102101
evals_z,
103102
comb_func,
104103
transcript,
105-
random_tape,
106104
);
107105

108106
(sc_proof_phase_two, r, claims)

spartan_parallel/src/sumcheck.rs

Lines changed: 17 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::scalar::SpartanExtensionField;
66

77
use super::dense_mlpoly::DensePolynomial;
88
use super::errors::ProofVerifyError;
9-
use super::nizk::DotProductProof;
109
use super::random::RandomTape;
1110
use super::transcript::{AppendToTranscript, ProofTranscript};
1211
use super::unipoly::{CompressedUniPoly, UniPoly};
@@ -70,67 +69,6 @@ impl<S: SpartanExtensionField> SumcheckInstanceProof<S> {
7069
}
7170
}
7271

73-
#[derive(Serialize, Deserialize, Debug)]
74-
pub struct R1CSSumcheckInstanceProof<S: SpartanExtensionField> {
75-
proofs: Vec<DotProductProof<S>>,
76-
}
77-
78-
impl<S: SpartanExtensionField> R1CSSumcheckInstanceProof<S> {
79-
pub fn new(proofs: Vec<DotProductProof<S>>) -> Self {
80-
R1CSSumcheckInstanceProof { proofs }
81-
}
82-
83-
pub fn verify(
84-
&self,
85-
num_rounds: usize,
86-
degree_bound: usize,
87-
transcript: &mut Transcript,
88-
) -> Result<Vec<S>, ProofVerifyError> {
89-
let mut r: Vec<S> = Vec::new();
90-
91-
for i in 0..num_rounds {
92-
// derive the verifier's challenge for the next round
93-
let r_i = transcript.challenge_scalar(b"challenge_nextround");
94-
95-
// verify the proof of sum-check and evals
96-
let _res = {
97-
// produce two weights
98-
let w: Vec<S> = transcript.challenge_vector(b"combine_two_claims_to_one", 2);
99-
100-
let a = {
101-
// the vector to use to decommit for sum-check test
102-
let a_sc = {
103-
let mut a = vec![S::field_one(); degree_bound + 1];
104-
a[0] = a[0] + S::field_one();
105-
a
106-
};
107-
108-
// the vector to use to decommit for evaluation
109-
let a_eval = {
110-
let mut a = vec![S::field_one(); degree_bound + 1];
111-
for j in 1..a.len() {
112-
a[j] = a[j - 1] * r_i;
113-
}
114-
a
115-
};
116-
117-
// take weighted sum of the two vectors using w
118-
assert_eq!(a_sc.len(), a_eval.len());
119-
(0..a_sc.len())
120-
.map(|i| w[0] * a_sc[i] + w[1] * a_eval[i])
121-
.collect::<Vec<S>>()
122-
};
123-
124-
self.proofs[i].verify(transcript, &a).is_ok()
125-
};
126-
127-
r.push(r_i);
128-
}
129-
130-
Ok(r)
131-
}
132-
}
133-
13472
impl<S: SpartanExtensionField> SumcheckInstanceProof<S> {
13573
pub fn prove_cubic<F>(
13674
claim: &S,
@@ -379,9 +317,7 @@ impl<S: SpartanExtensionField> SumcheckInstanceProof<S> {
379317
claims_dotp,
380318
)
381319
}
382-
}
383320

384-
impl<S: SpartanExtensionField> R1CSSumcheckInstanceProof<S> {
385321
pub fn prove_cubic_disjoint_rounds<F>(
386322
claim: &S,
387323
num_rounds: usize,
@@ -396,7 +332,6 @@ impl<S: SpartanExtensionField> R1CSSumcheckInstanceProof<S> {
396332
poly_C: &mut DensePolynomialPqx<S>,
397333
comb_func: F,
398334
transcript: &mut Transcript,
399-
random_tape: &mut RandomTape<S>,
400335
) -> (Self, Vec<S>, Vec<S>)
401336
where
402337
F: Fn(&S, &S, &S) -> S,
@@ -410,7 +345,7 @@ impl<S: SpartanExtensionField> R1CSSumcheckInstanceProof<S> {
410345
let mut claim_per_round = *claim;
411346

412347
let mut r: Vec<S> = Vec::new();
413-
let mut proofs: Vec<DotProductProof<S>> = Vec::new();
348+
let mut cubic_polys: Vec<CompressedUniPoly<S>> = Vec::new();
414349

415350
let mut inputs_len = num_rounds_y_max.pow2();
416351
let mut witness_secs_len = num_rounds_w.pow2();
@@ -540,8 +475,12 @@ impl<S: SpartanExtensionField> R1CSSumcheckInstanceProof<S> {
540475
poly
541476
};
542477

478+
// append the prover's message to the transcript
479+
poly.append_to_transcript(b"poly", transcript);
480+
543481
//derive the verifier's challenge for the next round
544482
let r_j = transcript.challenge_scalar(b"challenge_nextround");
483+
r.push(r_j);
545484

546485
// bound all tables to the verifier's challenege
547486
if mode == MODE_P {
@@ -552,61 +491,12 @@ impl<S: SpartanExtensionField> R1CSSumcheckInstanceProof<S> {
552491
}
553492
poly_C.bound_poly(&r_j, mode);
554493

555-
// produce a proof of sum-check and of evaluation
556-
let (proof, claim_next_round) = {
557-
let eval = poly.evaluate(&r_j);
558-
559-
// we need to prove the following under homomorphic commitments:
560-
// (1) poly(0) + poly(1) = claim_per_round
561-
// (2) poly(r_j) = eval
562-
563-
// Our technique is to leverage dot product proofs:
564-
// (1) we can prove: <poly_in_coeffs_form, (2, 1, 1, 1)> = claim_per_round
565-
// (2) we can prove: <poly_in_coeffs_form, (1, r_j, r^2_j, ..) = eval
566-
// for efficiency we batch them using random weights
567-
568-
// produce two weights
569-
let w: Vec<S> = transcript.challenge_vector(b"combine_two_claims_to_one", 2);
570-
571-
// compute a weighted sum of the RHS
572-
let target = w[0] * claim_per_round + w[1] * eval;
573-
574-
let a = {
575-
// the vector to use to decommit for sum-check test
576-
let a_sc = {
577-
let mut a = vec![S::field_one(); poly.degree() + 1];
578-
a[0] = a[0] + S::field_one();
579-
a
580-
};
581-
582-
// the vector to use to decommit for evaluation
583-
let a_eval = {
584-
let mut a = vec![S::field_one(); poly.degree() + 1];
585-
for j in 1..a.len() {
586-
a[j] = a[j - 1] * r_j;
587-
}
588-
a
589-
};
590-
591-
// take weighted sum of the two vectors using w
592-
assert_eq!(a_sc.len(), a_eval.len());
593-
(0..a_sc.len())
594-
.map(|i| w[0] * a_sc[i] + w[1] * a_eval[i])
595-
.collect::<Vec<S>>()
596-
};
597-
598-
let proof = DotProductProof::prove(transcript, random_tape, &poly.as_vec(), &a, &target);
599-
600-
(proof, eval)
601-
};
602-
603-
proofs.push(proof);
604-
claim_per_round = claim_next_round;
605-
r.push(r_j);
494+
claim_per_round = poly.evaluate(&r_j);
495+
cubic_polys.push(poly.compress());
606496
}
607497

608498
(
609-
R1CSSumcheckInstanceProof::new(proofs),
499+
SumcheckInstanceProof::new(cubic_polys),
610500
r,
611501
vec![
612502
poly_A[0],
@@ -653,7 +543,7 @@ impl<S: SpartanExtensionField> R1CSSumcheckInstanceProof<S> {
653543
let mut claim_per_round = *claim;
654544

655545
let mut r: Vec<S> = Vec::new();
656-
let mut proofs: Vec<DotProductProof<S>> = Vec::new();
546+
let mut cubic_polys: Vec<CompressedUniPoly<S>> = Vec::new();
657547

658548
let mut cons_len = num_rounds_x_max.pow2();
659549
let mut proof_len = num_rounds_q_max.pow2();
@@ -798,8 +688,12 @@ impl<S: SpartanExtensionField> R1CSSumcheckInstanceProof<S> {
798688
poly
799689
};
800690

691+
// append the prover's message to the transcript
692+
poly.append_to_transcript(b"poly", transcript);
693+
801694
//derive the verifier's challenge for the next round
802695
let r_j = transcript.challenge_scalar(b"challenge_nextround");
696+
r.push(r_j);
803697

804698
// bound all tables to the verifier's challenege
805699
if mode == 1 {
@@ -813,60 +707,12 @@ impl<S: SpartanExtensionField> R1CSSumcheckInstanceProof<S> {
813707
poly_C.bound_poly(&r_j, mode);
814708
poly_D.bound_poly(&r_j, mode);
815709

816-
let (proof, claim_next_round) = {
817-
let eval = poly.evaluate(&r_j);
818-
819-
// we need to prove the following under homomorphic commitments:
820-
// (1) poly(0) + poly(1) = claim_per_round
821-
// (2) poly(r_j) = eval
822-
823-
// Our technique is to leverage dot product proofs:
824-
// (1) we can prove: <poly_in_coeffs_form, (2, 1, 1, 1)> = claim_per_round
825-
// (2) we can prove: <poly_in_coeffs_form, (1, r_j, r^2_j, ..) = eval
826-
// for efficiency we batch them using random weights
827-
828-
// produce two weights
829-
let w: Vec<S> = transcript.challenge_vector(b"combine_two_claims_to_one", 2);
830-
831-
// compute a weighted sum of the RHS
832-
let target = w[0] * claim_per_round + w[1] * eval;
833-
834-
let a = {
835-
// the vector to use to decommit for sum-check test
836-
let a_sc = {
837-
let mut a = vec![S::field_one(); poly.degree() + 1];
838-
a[0] = a[0] + S::field_one();
839-
a
840-
};
841-
842-
// the vector to use to decommit for evaluation
843-
let a_eval = {
844-
let mut a = vec![S::field_one(); poly.degree() + 1];
845-
for j in 1..a.len() {
846-
a[j] = a[j - 1] * r_j;
847-
}
848-
a
849-
};
850-
851-
// take weighted sum of the two vectors using w
852-
assert_eq!(a_sc.len(), a_eval.len());
853-
(0..a_sc.len())
854-
.map(|i| w[0] * a_sc[i] + w[1] * a_eval[i])
855-
.collect::<Vec<S>>()
856-
};
857-
858-
let proof = DotProductProof::prove(transcript, random_tape, &poly.as_vec(), &a, &target);
859-
860-
(proof, eval)
861-
};
862-
863-
proofs.push(proof);
864-
claim_per_round = claim_next_round;
865-
r.push(r_j);
710+
claim_per_round = poly.evaluate(&r_j);
711+
cubic_polys.push(poly.compress());
866712
}
867713

868714
(
869-
R1CSSumcheckInstanceProof::new(proofs),
715+
SumcheckInstanceProof::new(cubic_polys),
870716
r,
871717
vec![
872718
poly_Ap[0] * poly_Aq[0] * poly_Ax[0],
@@ -876,4 +722,4 @@ impl<S: SpartanExtensionField> R1CSSumcheckInstanceProof<S> {
876722
],
877723
)
878724
}
879-
}
725+
}

0 commit comments

Comments
 (0)