Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Doc, unit test, minors #289

Merged
merged 8 commits into from
Mar 7, 2024
Merged

chore: Doc, unit test, minors #289

merged 8 commits into from
Mar 7, 2024

Conversation

adria0
Copy link
Member

@adria0 adria0 commented Feb 26, 2024

This PR adds some documentation, improves code readeability and adds an unit test for GraphEvaluator

@CPerezz CPerezz self-requested a review February 26, 2024 19:14
Copy link
Member

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the great addition to the docs!

halo2_backend/src/plonk.rs Outdated Show resolved Hide resolved
halo2_backend/src/plonk/evaluation.rs Outdated Show resolved Hide resolved
halo2_backend/src/plonk/evaluation.rs Show resolved Hide resolved
halo2_backend/src/plonk/evaluation.rs Outdated Show resolved Hide resolved
halo2_backend/src/plonk/evaluation.rs Outdated Show resolved Hide resolved
halo2_backend/src/plonk/evaluation.rs Outdated Show resolved Hide resolved
halo2_backend/src/plonk/evaluation.rs Outdated Show resolved Hide resolved
Co-authored-by: Carlos Pérez <37264926+CPerezz@users.noreply.github.com>
Copy link
Member

@ed255 ed255 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a lot of comments, most of them are suggestions or discussions.
In particular many comments refer to bind vs blind. After seeing so many instances of bind I'm no longer sure if bind is a thing, or it's a common typo.

The documentation is just great! Specially all the details in prover/verifier, and the references to follow how the transcript is written in proving and then read in verifying, great job!

@@ -169,46 +173,59 @@ impl Calculation {
#[derive(Clone, Default, Debug)]
pub struct Evaluator<C: CurveAffine> {
/// Custom gates evalution
pub custom_gates: GraphEvaluator<C>,
custom_gates: GraphEvaluator<C>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were pub before the frontend-backend split:

pub custom_gates: GraphEvaluator<C>,
/// Lookups evalution
pub lookups: Vec<GraphEvaluator<C>>,
/// Shuffle evalution
pub shuffles: Vec<GraphEvaluator<C>>,

I wonder why...

I checked this and it comes from an improvement that Brecht did, so this is not inherited from zcash. I guess this was unneeded pub that was unnoticed.

halo2_backend/src/plonk/prover.rs Show resolved Hide resolved
halo2_backend/src/plonk/prover.rs Outdated Show resolved Hide resolved
halo2_backend/src/plonk/prover.rs Outdated Show resolved Hide resolved
halo2_backend/src/plonk/prover.rs Outdated Show resolved Hide resolved
halo2_backend/src/plonk/prover.rs Show resolved Hide resolved
/// - 4. Generate commited shuffle polys
/// - 5. Commit to the vanishing argument's random polynomial
/// - 6. Generate the advice polys
/// - 7. Evaluate the h(X) polynomial
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing for me (even if this is a reference to the original code, which has the function evaluate_h, and there was even a comment saying Evaluate the h(X) polynomial).

The way I see it, we're not evaluating h(X), instead we're calculating h(X). I say this because in my mind, if we evaluate a polynomial, the result is a field value. But the result of step 7 is a polynomial.

@@ -563,14 +643,19 @@ impl<
)
.collect();

// Evaluate the h(X) polynomial
// 7. Evaluate the h(X) polynomial -----------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change this to the following

// 7. Given `h(X) = g(X) / t(X)` where:
// - `g(X)` is the gates and arguments polynomial
// - `t(X)` is the vanishing polynomial
// - `h(X)` is the quotient polynomial
// Calculate the g(X) polynomial

The reason I say g(X) instead of h(X) is because if you look at the implementation of evaluate_h it actually returns g

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was added here 70cfe70#diff-6fd234fc283be7a2c59f305cdd5f15f4bb074fa6b56866452a06b34c6803fc1fR274

I agree on changing it, and to also update the MD book with a reference to g(X)

@davidnevadoc @CPerezz @han0110 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should ref the paper naming always.

Aside from that, happy to adapt to anything you consider better! :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, I took h and t from the halo2 book https://zcash.github.io/halo2/design/proving-system/vanishing.html
As for g, it's not called like that in the halo2 book, it just doesn't have a name.

Then the plonk paper uses different names.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we can say also evaluate_h_dividend

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Far from helping, I come to add more confusion 😅
I like the notation of the original Plonk paper, in which t is the quotient polynomial, and z_H (zero over the set H) is the vanishing poly.

I would say we should stick to the halo2 book names, h for the quotient and t for the vanishing.
With respect to g, I'm not sure if this polynomial ever needs to be computed explicitly. In any case, it could be h_times_t.

// Obtain challenge for keeping all separate gates linearly independent
// [TRANSCRIPT-13]
let y: ChallengeY<_> = self.transcript.squeeze_challenge_scalar();

let h_poly = pk.ev.evaluate_h(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change this to:

let g_poly = pk.ev.calculate_g(

Please if somebody knows why this was called evaluate_h, can they explain it to me?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

H is usually how the Vanishing polynomial is called in the Plonk paper.

Maybe it's due to that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, but in the code this variable holds the polynomial that contains gate_1(X) + alpha * gate_2(X) + alpha^2 * gate_3(X) + ..., which is not the vanishing polynomial right?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @ed255, I would rename this to g. Currently h is both the quotient poly and the quotient poly * vanishing.

// Divide by t(X) = X^{params.n} - 1.
let h_poly = domain.divide_by_vanishing_poly(h_poly);
// Obtain final h(X) polynomial
let h_poly = domain.extended_to_coeff(h_poly);

),
shuffles,
)| {
.flat_map(|((((((instance_commitments, instance_evals), advice_commitments),advice_evals),permutation),lookups),shuffles)| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is madness 😆
This must feel like home to fans of LISP.

@ed255 ed255 mentioned this pull request Feb 29, 2024
Copy link
Member

@ed255 ed255 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still some unresolved conversations but they are all about the naming around the quotient polynomial. It may take some discussion to settle that. I think we can defer that to the future and merge this PR already :)

@@ -355,7 +394,7 @@ impl<
}
}

// Compute commitments to advice column polynomials
// Compute affine commitments to advice column polynomials.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the explicit distinction between affine and projective in this section is nice, but I'd leave this comment as is. Mainly because "affine commitment" doesn't sound quite right, they are unrelated concepts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in 9e29391.

@@ -392,6 +435,9 @@ impl<
Ok(())
};

// Update bindings for each advice column

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blinding or blinding factors maybe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

halo2_backend/src/plonk/prover.rs Show resolved Hide resolved
@@ -203,6 +217,8 @@ impl<
}
}

// Convert the lagrange polynomials to coefficients

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as before, I wouldn't call these Lagrange polynomials.
Convert from evaluation to coefficient form. maybe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -563,14 +643,19 @@ impl<
)
.collect();

// Evaluate the h(X) polynomial
// 7. Evaluate the h(X) polynomial -----------------------------------------------------------

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Far from helping, I come to add more confusion 😅
I like the notation of the original Plonk paper, in which t is the quotient polynomial, and z_H (zero over the set H) is the vanishing poly.

I would say we should stick to the halo2 book names, h for the quotient and t for the vanishing.
With respect to g, I'm not sure if this polynomial ever needs to be computed explicitly. In any case, it could be h_times_t.

// Obtain challenge for keeping all separate gates linearly independent
// [TRANSCRIPT-13]
let y: ChallengeY<_> = self.transcript.squeeze_challenge_scalar();

let h_poly = pk.ev.evaluate_h(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @ed255, I would rename this to g. Currently h is both the quotient poly and the quotient poly * vanishing.

// Divide by t(X) = X^{params.n} - 1.
let h_poly = domain.divide_by_vanishing_poly(h_poly);
// Obtain final h(X) polynomial
let h_poly = domain.extended_to_coeff(h_poly);

@adria0 adria0 merged commit d6f7020 into main Mar 7, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants