Skip to content

Commit

Permalink
Fix mlkzg::EvaluationArgument fields
Browse files Browse the repository at this point in the history
  • Loading branch information
adr1anh committed Dec 20, 2023
1 parent 20b4905 commit c074119
Showing 1 changed file with 14 additions and 25 deletions.
39 changes: 14 additions & 25 deletions src/provider/mlkzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize};
deserialize = "E::G1Affine: Deserialize<'de>, E::Fr: Deserialize<'de>"
))]
pub struct EvaluationArgument<E: Engine> {
evals_r: Vec<E::G1Affine>,
evals_neg_r: Vec<E::G1Affine>,
evals_r_squared: Vec<Vec<E::Fr>>,
comms: Vec<E::G1Affine>,
w: Vec<E::G1Affine>,
evals: Vec<Vec<E::Fr>>,
}

/// Provides an implementation of a polynomial evaluation engine using KZG
Expand Down Expand Up @@ -263,7 +263,7 @@ where

// We do not need to commit to the first polynomial as it is already committed.
// Compute commitments in parallel
let com: Vec<E::G1Affine> = (1..polys.len())
let comms: Vec<E::G1Affine> = (1..polys.len())
.into_par_iter()
.map(|i| {
<NE::CE as CommitmentEngineTrait<NE>>::commit(ck, &polys[i])
Expand All @@ -275,19 +275,15 @@ where
// Phase 2
// We do not need to add x to the transcript, because in our context x was
// obtained from the transcript.
let r = Self::compute_challenge(&C.comm.preprocessed(), eval, &com, transcript);
let r = Self::compute_challenge(&C.comm.preprocessed(), eval, &comms, transcript);
let u = vec![r, -r, r * r];

// Phase 3 -- create response
let mut com_all = com.clone();
let mut com_all = comms.clone();
com_all.insert(0, C.comm.preprocessed());
let (w, v) = kzg_open_batch(&com_all, &polys, &u, transcript);
let (w, evals) = kzg_open_batch(&com_all, &polys, &u, transcript);

Ok(EvaluationArgument {
evals_r: com,
evals_neg_r: w,
evals_r_squared: v,
})
Ok(EvaluationArgument { comms, w, evals })
}

/// A method to verify purported evaluations of a batch of polynomials
Expand All @@ -308,7 +304,7 @@ where
C: &Vec<E::G1Affine>,
W: &Vec<E::G1Affine>,
u: &Vec<E::Fr>,
v: &Vec<Vec<E::Fr>>,
v: &[Vec<E::Fr>],
transcript: &mut <NE as NovaEngine>::TE|
-> bool {
let k = C.len();
Expand Down Expand Up @@ -369,7 +365,7 @@ where

let ell = x.len();

let mut com = pi.evals_r.clone();
let mut com = pi.comms.clone();

// we do not need to add x to the transcript, because in our context x was
// obtained from the transcript
Expand All @@ -383,7 +379,7 @@ where
let u = vec![r, -r, r * r];

// Setup vectors (Y, ypos, yneg) from pi.v
let v = &pi.evals_r_squared;
let v = &pi.evals;
if v.len() != 3 {
return Err(NovaError::ProofVerifyError);
}
Expand Down Expand Up @@ -412,14 +408,7 @@ where
}

// Check commitments to (Y, ypos, yneg) are valid
if !kzg_verify_batch(
vk,
&com,
&pi.evals_neg_r,
&u,
&pi.evals_r_squared,
transcript,
) {
if !kzg_verify_batch(vk, &com, &pi.w, &u, v, transcript) {
return Err(NovaError::ProofVerifyError);
}

Expand Down Expand Up @@ -543,7 +532,7 @@ mod tests {

// Change the proof and expect verification to fail
let mut bad_proof = proof.clone();
bad_proof.evals_r[0] = (bad_proof.evals_r[0] + bad_proof.evals_r[1]).to_affine();
bad_proof.comms[0] = (bad_proof.comms[0] + bad_proof.comms[1]).to_affine();
let mut verifier_transcript2 = Keccak256Transcript::<NE>::new(b"TestEval");
assert!(EvaluationEngine::<E, NE>::verify(
&vk,
Expand Down Expand Up @@ -596,7 +585,7 @@ mod tests {

// Change the proof and expect verification to fail
let mut bad_proof = proof.clone();
bad_proof.evals_r[0] = (bad_proof.evals_r[0] + bad_proof.evals_r[1]).to_affine();
bad_proof.comms[0] = (bad_proof.comms[0] + bad_proof.comms[1]).to_affine();
let mut verifier_tr2 = Keccak256Transcript::<NE>::new(b"TestEval");
assert!(EvaluationEngine::<E, NE>::verify(
&vk,
Expand Down

0 comments on commit c074119

Please sign in to comment.