Skip to content

Commit ad53c07

Browse files
committed
remove clone term_1 and term_2
1 parent edd89d2 commit ad53c07

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

crates/provers/gkr/src/prover.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ impl Prover {
5353
///
5454
/// See our blog post: <https://blog.lambdaclass.com/gkr-protocol-a-step-by-step-example/>
5555
///
56-
/// This function is only known to the prover. It returns the components of `f` grouped
57-
/// into two terms, ready to be used by the sumcheck prover, which expects a product of multilinear polynomials.
56+
/// This function is only known to the prover.
57+
///
58+
/// It returns the components of `f` grouped into two terms, ready to be used by the sumcheck prover, which expects
59+
/// a product of multilinear polynomials.
5860
/// Both terms are the product of two multilinear polynomials.
5961
/// The first term is `add_i(r_i, b, c) * (W_{i+1}(b) + W_{i+1}(c))`.
6062
/// And the second term is `mul_i(r_i, b, c) * (W_{i+1}(b) * W_{i+1}(c))`.
@@ -63,7 +65,13 @@ impl Prover {
6365
r_i: &[FieldElement<F>],
6466
w_next_evals: &[FieldElement<F>],
6567
layer_idx: usize,
66-
) -> Result<Vec<Vec<DenseMultilinearPolynomial<F>>>, ProverError>
68+
) -> Result<
69+
(
70+
Vec<DenseMultilinearPolynomial<F>>,
71+
Vec<DenseMultilinearPolynomial<F>>,
72+
),
73+
ProverError,
74+
>
6775
where
6876
<F as IsField>::BaseType: Send + Sync + Copy,
6977
{
@@ -98,7 +106,7 @@ impl Prover {
98106
// Corresponds to mul_i(r_i,b,c) * W_{i+1}(b) * W_{i+1}(c)
99107
let term2 = vec![mul_i_ext, w_mul_ext];
100108

101-
Ok(vec![term1, term2])
109+
Ok((term1, term2))
102110
}
103111

104112
/// Given `b` and `c` (challenges for the input of the gates),
@@ -179,10 +187,10 @@ impl Prover {
179187
let w_next_evals = &evaluation.layers[layer_idx + 1];
180188

181189
// Build the GKR polynomial terms
182-
let gkr_poly_terms =
190+
let (term_1, term_2) =
183191
Prover::build_gkr_polynomial(circuit, &r_i, w_next_evals, layer_idx)?;
184192

185-
let sumcheck_proof = gkr_sumcheck_prove(gkr_poly_terms, &mut transcript)?;
193+
let sumcheck_proof = gkr_sumcheck_prove(term_1, term_2, &mut transcript)?;
186194

187195
let sumcheck_challenges = &sumcheck_proof.challenges;
188196

crates/provers/gkr/src/sumcheck.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ pub struct GKRSumcheckProof<F: IsField> {
1919
}
2020

2121
/// GKR-specific sumcheck prover.
22-
/// This function will recieve a vector of two terms. Each term contains two multilinear polynomials.
22+
/// This function will recieves two terms. Each term contains two multilinear polynomials.
2323
/// This separation of terms is necessary because the classic/original sumcheck only accepts a product of multilinear polynomials.
24-
/// In this way, we apply the sumcheck to two products, each consisting of two factors.
24+
/// In this way, we apply the sumcheck to two terms, each consisting of two factors.
2525
pub fn gkr_sumcheck_prove<F, T>(
26-
terms: Vec<Vec<DenseMultilinearPolynomial<F>>>,
26+
term_1: Vec<DenseMultilinearPolynomial<F>>,
27+
term_2: Vec<DenseMultilinearPolynomial<F>>,
2728
transcript: &mut T,
2829
) -> Result<GKRSumcheckProof<F>, ProverError>
2930
where
@@ -32,16 +33,9 @@ where
3233
FieldElement<F>: ByteConversion,
3334
T: IsTranscript<F> + Channel<F>,
3435
{
35-
if terms.len() != 2 {
36-
return Err(ProverError::SumcheckError);
37-
}
38-
39-
let factors_term_1 = terms[0].clone();
40-
let factors_term_2 = terms[1].clone();
41-
4236
// Create two separate sumcheck provers for each term.
43-
let mut prover_term_1 = Prover::new(factors_term_1).map_err(|_| ProverError::SumcheckError)?;
44-
let mut prover_term_2 = Prover::new(factors_term_2).map_err(|_| ProverError::SumcheckError)?;
37+
let mut prover_term_1 = Prover::new(term_1).map_err(|_| ProverError::SumcheckError)?;
38+
let mut prover_term_2 = Prover::new(term_2).map_err(|_| ProverError::SumcheckError)?;
4539

4640
// Both terms have the same number of variables.
4741
let num_vars = prover_term_1.num_vars();

0 commit comments

Comments
 (0)