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

Add ParamsVerifierKZG #318

Merged
merged 3 commits into from
May 23, 2024
Merged

Add ParamsVerifierKZG #318

merged 3 commits into from
May 23, 2024

Conversation

davidnevadoc
Copy link

@davidnevadoc davidnevadoc commented Apr 24, 2024

This is a small refactor around the PCS parameters, proposed as an alternative to this PR : #301

Changes

  1. Add new struct: ParamsVerifierKZG.
    This struct only contains s_g2 and the domain size k. Since it does not contain the SRS the verifier that uses these params is not able to commit to the public inputs. Commitment to the public inputs is currently disabled for both kzg-based versions of the verifier gwc and shplonk).
    In case the verifier wants to commit to the PI it should use the original ParamsKZG, which remain unchanged.

  2. Attempt at cleaning up.
    Methods that were exclusive for the verifier or the prover have been moved from Params to ParamsVerifier and ParamsProver respectively.
    Some structs and traits no longer contain the parameters and as a result, no longer need the explicit 'params lifetime.

Closes #280

@davidnevadoc davidnevadoc changed the title Nev@refactor pcs params Refactor PCS params Apr 25, 2024
@davidnevadoc davidnevadoc marked this pull request as ready for review April 25, 2024 17:03
@davidnevadoc davidnevadoc force-pushed the nev@refactor-pcs-params branch 2 times, most recently from 1d67d87 to d9958e2 Compare April 25, 2024 17:08
@davidnevadoc davidnevadoc requested a review from ed255 April 25, 2024 17:09
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 done an initial review. I've left some comments on points I'd like to discuss further.

pub trait ParamsVerifier<'params, C: CurveAffine>: Params<'params, C> {}
pub trait ParamsVerifier<'params, C: CurveAffine>: Params<C> {
/// Multiscalar multiplication engine
type MSM: MSM<C> + 'params;
Copy link
Member

@ed255 ed255 Apr 26, 2024

Choose a reason for hiding this comment

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

I wonder why the verifier needs an MSM engine 🤔
I guess this is the verifier that commits?

Copy link
Author

Choose a reason for hiding this comment

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

This is not obvious at all. I believe this is inherited from the original only-IPA design. At that point, it made sense to provide the MSM engine together with the CRS for IPA. When KZG was introduced, this was left here because KZG also uses an MSM, not for the final verification like IPA, but for the accumulation of partial verifications.

@@ -190,7 +178,7 @@ pub trait Verifier<'params, Scheme: CommitmentScheme> {
const QUERY_INSTANCE: bool;

/// Creates new verifier instance
fn new(params: &'params Scheme::ParamsVerifier) -> Self;
fn new() -> Self;
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 like to understand this change better.

Copy link
Author

Choose a reason for hiding this comment

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

This is part of a series of changes that remove the parameters from the traits and structs it was not used in.
The motivation originally was to try to get rid of the 'params lifetime where possible. This led me to realize that the parameters where being passed around but not used in many places: MSM and Verifier are the principal examples.
I should remark that, somewhat counter-intuitively, Verifier never verifies (and hence doesn't need the parameters). It just makes partial verifications and accumulations.

In short, it changes nothing from a functionality standpoint, it's just an attempt to make things a bit cleaner.

fn get_g(&self) -> &[C];

/// Returns verification parameters.
fn verifier_params(&'params self) -> &'params Self::ParamsVerifier;
Copy link
Member

Choose a reason for hiding this comment

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

How do we transform ParamsProver to ParamsVerifier now?

Copy link
Author

Choose a reason for hiding this comment

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

The new signature is :
fn verifier_params(&self) -> Self::ParamsVerifier
Since the new ParamsVerifier is just s_g2, no issue creating it from scratch.

1 << self.k
}

fn commit_lagrange(
Copy link
Member

@ed255 ed255 Apr 26, 2024

Choose a reason for hiding this comment

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

👀
Is there any way where we could have a clean separation between KZG prover and verifier, and then on top of that build an object that can verify large commitments and commit small vectors?

Copy link
Author

Choose a reason for hiding this comment

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

I think there is and it is very desirable!
The question is if we want to refactor that here, or work on a new version of the backend altogether.

pub fn into_verifier_params(self) -> ParamsVerifierKZG<E> {
ParamsVerifierKZG {
k: self.k,
g_lagrange: self.g_lagrange,
Copy link
Member

Choose a reason for hiding this comment

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

What's the length of this vector? Where does ParamsVerifierKZG become small?

Copy link
Author

Choose a reason for hiding this comment

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

Now, it is 0 😁

@davidnevadoc
Copy link
Author

I've addressed the comments and updated the PR description with the changes. Can you give this another pass, pls? @ed255

@davidnevadoc davidnevadoc changed the title Refactor PCS params Add ParamsVerifierKZG May 13, 2024
halo2_backend/src/poly/kzg/commitment.rs Show resolved Hide resolved
halo2_backend/src/poly/kzg/msm.rs Outdated Show resolved Hide resolved
halo2_backend/src/poly/kzg/strategy.rs Outdated Show resolved Hide resolved
halo2_backend/src/poly/kzg/strategy.rs Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented May 20, 2024

Codecov Report

Attention: Patch coverage is 64.05229% with 55 lines in your changes are missing coverage. Please review.

Project coverage is 80.86%. Comparing base (0513fb4) to head (61f55e6).

Files Patch % Lines
halo2_backend/src/poly/kzg/commitment.rs 21.66% 47 Missing ⚠️
halo2_backend/src/poly/kzg/strategy.rs 64.70% 6 Missing ⚠️
halo2_backend/src/plonk/verifier/batch.rs 0.00% 1 Missing ⚠️
halo2_backend/src/poly/kzg/msm.rs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #318      +/-   ##
==========================================
- Coverage   80.98%   80.86%   -0.13%     
==========================================
  Files          80       80              
  Lines       16532    16567      +35     
==========================================
+ Hits        13389    13397       +8     
- Misses       3143     3170      +27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

After a discussion about possible improvements on the codebase we determined that they're out of the scope of this PR, which already achieves the main goal of reducing the size of the verifier KZG params.

@davidnevadoc davidnevadoc force-pushed the nev@refactor-pcs-params branch 2 times, most recently from b16baab to 61f55e6 Compare May 23, 2024 16:57
Remove params use from `verify_proof`.
It only uses the generator of G1, and this is fixed in the curve.

refactor: rm params from GWC, SHPLONK Verifiers

The verifier just takes care of partial verification,
the pairing is not checked until the last phase.
As a result, params are not needed at that stage.

refactor: rm params from IPA Verifier

refactor: rm params from Verifier::new()

refactor: rm KZGParams from DualMSM, GuardKZG

ParamsVerifierKZG are now in the structs that implmentent
VerifierStrategy: SingleStrategy and AccumulatorStrategy.

ParamsVerifierKZG is no longer reference with explicit lifetime.
This struct should be small, only the s_g2 point, so this is fine.

refactor: rm get_g from Params

refactor: add ParamsVerifierKZG

refactor: move downsize to ParamsProver

refactor: move empty_msm to ParamsVerifier

refactor: remove 'params from Params/ProverParams

refactor: fix TODOs & leftover

refactor: verfier_params -> into_verfier_params
chore: remove leftovers

fix: remove needless From impl

chore: remove leftover TODO

chore: remove unused import

fix:compress_selector with new verifier_params
@davidnevadoc davidnevadoc merged commit 2458654 into main May 23, 2024
18 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.

ParamsVerifierKZG is ParamsKZG even though it could be smaller
3 participants