Skip to content

Commit f9fe962

Browse files
committedNov 29, 2023
refactor: Improve code readability and error handling in zeromorph
- Updated and enhanced clarity and consistency of mathematical notation in comments across `non_hiding_kzg.rs` and `non_hiding_zeromorph.rs` files. - Implemented error handling in the `ZMPCS::verify` function within the `non_hiding_zeromorph.rs` file.
1 parent e0b5cde commit f9fe962

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed
 

‎src/provider/non_hiding_kzg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ use crate::{
2222
))]
2323
#[abomonation_omit_bounds]
2424
pub struct UVUniversalKZGParam<E: Engine> {
25-
/// Group elements of the form `{ \beta^i G }`, where `i` ranges from 0 to
25+
/// Group elements of the form `{ β^i G }`, where `i` ranges from 0 to
2626
/// `degree`.
2727
#[abomonate_with(Vec<[u64; 8]>)] // // this is a hack; we just assume the size of the element.
2828
pub powers_of_g: Vec<E::G1Affine>,
29-
/// Group elements of the form `{ \beta^i H }`, where `i` ranges from 0 to
29+
/// Group elements of the form `{ β^i H }`, where `i` ranges from 0 to
3030
/// `degree`.
3131
#[abomonate_with(Vec<[u64; 16]>)] // this is a hack; we just assume the size of the element.
3232
pub powers_of_h: Vec<E::G2Affine>,
@@ -73,7 +73,7 @@ pub struct UVKZGVerifierKey<E: Engine> {
7373
/// The generator of G2.
7474
#[abomonate_with([u64; 16])] // this is a hack; we just assume the size of the element.
7575
pub h: E::G2Affine,
76-
/// \beta times the above generator of G2.
76+
/// β times the above generator of G2.
7777
#[abomonate_with([u64; 16])] // this is a hack; we just assume the size of the element.
7878
pub beta_h: E::G2Affine,
7979
}

‎src/provider/non_hiding_zeromorph.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ where
219219
let y = transcript.squeeze(b"y")?;
220220

221221
// Compute the batched, lifted-degree quotient `\hat{q}`
222-
// q_hat = \sum_{i=0}^{num_vars-1} y^i * X^{2^{num_vars} - d_k - 1} * q_i(x)
222+
// qq_hat = ∑_{i=0}^{num_vars-1} y^i * X^(2^num_vars - d_k - 1) * q_i(x)
223223
let q_hat = batched_lifted_degree_quotient(y, &quotients_polys);
224224
// Compute and absorb the commitment C_q = [\hat{q}]
225225
let q_hat_comm = UVKZGPCS::commit(&pp.commit_pp, &q_hat)?;
@@ -232,7 +232,7 @@ where
232232
// Compute batched degree and ZM-identity quotient polynomial pi
233233
let (eval_scalar, (degree_check_q_scalars, zmpoly_q_scalars)) =
234234
eval_and_quotient_scalars(y, x, z, point);
235-
// f = z * poly.Z + q\_hat + (-z * Φ_n(x) * e) + \sum_k (q\_scalars_k * q_k)
235+
// f = z * poly.Z + q_hat + (-z * Φ_n(x) * e) + ∑_k (q_scalars_k * q_k)
236236
let mut f = UVKZGPoly::new(poly.Z.clone());
237237
f *= &z;
238238
f += &q_hat;
@@ -418,7 +418,7 @@ fn eval_and_quotient_scalars<F: Field>(y: F, x: F, z: F, point: &[F]) -> (F, (Ve
418418
let squares_of_x = iter::successors(Some(x), |&x| Some(x.square()))
419419
.take(num_vars + 1)
420420
.collect::<Vec<_>>();
421-
// offsets_of_x = [Π_{j=i}^{num_vars-1} x^{2^j}, i \in 0..=num_vars-1] = [x^{2^num_vars - d_i - 1}, i \in 0..=num_vars-1]
421+
// offsets_of_x = [Π_{j=i}^{num_vars-1} x^(2^j), i ∈ [0, num_vars-1]] = [x^(2^num_vars - d_i - 1), i ∈ [0, num_vars-1]]
422422
let offsets_of_x = {
423423
let mut offsets_of_x = squares_of_x
424424
.iter()
@@ -433,9 +433,9 @@ fn eval_and_quotient_scalars<F: Field>(y: F, x: F, z: F, point: &[F]) -> (F, (Ve
433433
offsets_of_x
434434
};
435435

436-
// vs = [ \frac{(x^{2^{num_vars}} - 1)}{x^{2^i} - 1}, i \in 0..=num_vars-1]
437-
// Note Φ_{n-i}(x^{2^i}) = \frac{(x^{2^i})^{2^{n-i|} - 1}{x^{2^i} - 1} = \frac{(x^{2^{num_vars}} - 1)}{x^{2^i} - 1} = vs[i]
438-
// Φ_{n-i-1}(x^{2^{i+1}}) = \frac{(x^{2^{i+1}})^{2^{n-i-1}} - 1}{x^{2^{i+1}} - 1} = \frac{(x^{2^{num_vars}} - 1)}{x^{2^{i+1}} - 1} = vs[i+1]
436+
// vs = [ (x^(2^num_vars) - 1) / (x^(2^i) - 1), i ∈ [0, num_vars-1]]
437+
// Note Φ_(n-i)(x^(2^i)) = (x^(2^i))^(2^(n-i) - 1) / (x^(2^i) - 1) = (x^(2^num_vars) - 1) / (x^(2^i) - 1) = vs[i]
438+
// Φ_(n-i-1)(x^(2^(i+1))) = (x^(2^(i+1)))^(2^(n-i-1)) - 1 / (x^(2^(i+1)) - 1) = (x^(2^num_vars) - 1) / (x^(2^(i+1)) - 1) = vs[i+1]
439439
let vs = {
440440
let v_numer = squares_of_x[num_vars] - F::ONE;
441441
let mut v_denoms = squares_of_x
@@ -449,8 +449,8 @@ fn eval_and_quotient_scalars<F: Field>(y: F, x: F, z: F, point: &[F]) -> (F, (Ve
449449
.collect::<Vec<_>>()
450450
};
451451

452-
// q_scalars = [- (y^i * x^{2^num_vars - d_i - 1} + z * (x^{2^i} * vs_{i+1} - u_i * vs_i)), i = 0..=num_vars-1]
453-
// = [- (y^i * x^{2^num_vars - d_i - 1} + z * (x^{2^i} * Φ_{n-i-1}(x^{2^{i+1}}) - u_i * Φ_{n-i}(x^{2^i}))), i = 0..=num_vars-1]
452+
// q_scalars = [- (y^i * x^(2^num_vars - d_i - 1) + z * (x^(2^i) * vs[i+1] - u_i * vs[i])), i ∈ [0, num_vars-1]]
453+
// = [- (y^i * x^(2^num_vars - d_i - 1) + z * (x^(2^i) * Φ_(n-i-1)(x^(2^(i+1))) - u_i * Φ_(n-i)(x^(2^i)))), i ∈ [0, num_vars-1]]
454454
let q_scalars = iter::successors(Some(F::ONE), |acc| Some(*acc * y))
455455
.zip(offsets_of_x)
456456
.zip(squares_of_x)
@@ -464,7 +464,7 @@ fn eval_and_quotient_scalars<F: Field>(y: F, x: F, z: F, point: &[F]) -> (F, (Ve
464464
)
465465
.unzip();
466466

467-
// -vs[0] * z = -z \frac{x^{2^{num\_vars}} - 1}{x - 1} = -z Φ_n(x)
467+
// -vs[0] * z = -z * (x^(2^num_vars) - 1) / (x - 1) = -z Φ_n(x)
468468
(-vs[0] * z, q_scalars)
469469
}
470470

@@ -514,7 +514,9 @@ where
514514
let commitment = ZMCommitment::from(UVKZGCommitment::from(*comm));
515515
let evaluation = ZMEvaluation(*eval);
516516

517-
ZMPCS::verify(vk, transcript, &commitment, point, &evaluation, arg)?;
517+
if !ZMPCS::verify(vk, transcript, &commitment, point, &evaluation, arg)? {
518+
return Err(NovaError::UnSat);
519+
}
518520
Ok(())
519521
}
520522
}
@@ -730,11 +732,11 @@ mod test {
730732
let u_challenge: Vec<_> = (0..num_vars).map(|_| Scalar::random(&mut rng)).collect();
731733
let z_challenge = Scalar::random(&mut rng);
732734

733-
// Construct zeta_x using the function
735+
// Construct ζ_x using the function
734736
let (_eval_scalar, (zeta_x_scalars, _right_quo_scalars)) =
735737
eval_and_quotient_scalars(y_challenge, x_challenge, z_challenge, &u_challenge);
736738

737-
// Now construct zeta_x explicitly
739+
// Now construct ζ_x explicitly
738740
let n: u64 = 1 << num_vars;
739741
// q_batched - \sum_k q_k * y^k * x^{N - deg(q_k) - 1}
740742
assert_eq!(zeta_x_scalars[0], -x_challenge.pow([n - 1]));

0 commit comments

Comments
 (0)