From ffd4a9d957ce65b219b67dcd5d6701090f6e94d3 Mon Sep 17 00:00:00 2001 From: Junhee Lee <101318348+Jun-Hee-Lee@users.noreply.github.com> Date: Thu, 7 Dec 2023 03:39:38 +0900 Subject: [PATCH] Nit: Simplified Vector Initialization (#278) * Remove an unnecessary clone in PolyEvalWitness * Enhance code efficiency by direct vector initialization --- src/spartan/snark.rs | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/spartan/snark.rs b/src/spartan/snark.rs index 104c5dfd..33d739e6 100644 --- a/src/spartan/snark.rs +++ b/src/spartan/snark.rs @@ -255,38 +255,29 @@ impl> RelaxedR1CSSNARKTrait for Relax &mut transcript, )?; - // add additional claims about W and E polynomials to the list from CC - let mut w_u_vec = Vec::new(); + // Add additional claims about W and E polynomials to the list from CC + // We will reduce a vector of claims of evaluations at different points into claims about them at the same point. + // For example, eval_W =? W(r_y[1..]) and eval_E =? E(r_x) into + // two claims: eval_W_prime =? W(rz) and eval_E_prime =? E(rz) + // We can them combine the two into one: eval_W_prime + gamma * eval_E_prime =? (W + gamma*E)(rz), + // where gamma is a public challenge + // Since commitments to W and E are homomorphic, the verifier can compute a commitment + // to the batched polynomial. let eval_W = MultilinearPolynomial::evaluate_with(&W.W, &r_y[1..]); - w_u_vec.push(( - PolyEvalWitness { p: W.W.clone() }, + + let w_vec = vec![PolyEvalWitness { p: W.W }, PolyEvalWitness { p: W.E }]; + let u_vec = vec![ PolyEvalInstance { c: U.comm_W, x: r_y[1..].to_vec(), e: eval_W, }, - )); - - w_u_vec.push(( - PolyEvalWitness { p: W.E }, PolyEvalInstance { c: U.comm_E, x: r_x, e: eval_E, }, - )); - - // We will now reduce a vector of claims of evaluations at different points into claims about them at the same point. - // For example, eval_W =? W(r_y[1..]) and eval_E =? E(r_x) into - // two claims: eval_W_prime =? W(rz) and eval_E_prime =? E(rz) - // We can them combine the two into one: eval_W_prime + gamma * eval_E_prime =? (W + gamma*E)(rz), - // where gamma is a public challenge - // Since commitments to W and E are homomorphic, the verifier can compute a commitment - // to the batched polynomial. - assert!(w_u_vec.len() >= 2); - - let (w_vec, u_vec): (Vec>, Vec>) = - w_u_vec.into_iter().unzip(); + ]; let (batched_u, batched_w, sc_proof_batch, claims_batch_left) = batch_eval_prove(u_vec, w_vec, &mut transcript)?;