Skip to content

Commit

Permalink
Nit: Simplified Vector Initialization (#278)
Browse files Browse the repository at this point in the history
* Remove an unnecessary clone in PolyEvalWitness

* Enhance code efficiency by direct vector initialization
  • Loading branch information
zk-Lee authored Dec 6, 2023
1 parent c3f79bd commit ffd4a9d
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/spartan/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,38 +255,29 @@ impl<E: Engine, EE: EvaluationEngineTrait<E>> RelaxedR1CSSNARKTrait<E> 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<PolyEvalWitness<E>>, Vec<PolyEvalInstance<E>>) =
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)?;
Expand Down

0 comments on commit ffd4a9d

Please sign in to comment.