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

[BASE] Plonk #49

Open
wants to merge 161 commits into
base: develop
Choose a base branch
from
Open

[BASE] Plonk #49

wants to merge 161 commits into from

Conversation

vesselinux
Copy link
Collaborator

Initial implementation of the Plonk zk-SNARK proof system.

@AntoineRondelet
Copy link
Contributor

Thanks for opening this Draft PR @vesselinux.
It's a draft, so by definition it's not finished, but please make sure to clean the history with a rebase when you are done with this PR.

Commits doing similar things like

plonk: computing alpha powers
plonk: computing alpha powers
plonk: computing alpha powers

(and many more) should be squashed together + formatting commits should normally not be needed if you have your text editor configured to run the script on saving.

Copy link
Contributor

@AntoineRondelet AntoineRondelet left a comment

Choose a reason for hiding this comment

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

Here are a couple of high level comments on the draft

.gitignore Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/common_input.tcc Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/common_input.tcc Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/plonk.hpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/plonk.tcc Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/plonk.tcc Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/plonk.tcc Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/prover.hpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/srs.hpp Outdated Show resolved Hide resolved
Copy link
Contributor

@dtebbs dtebbs 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 made a first round of comments. Please apply these comments to everywhere it makes sense (e.g. I've commented about const refs only once or twice, but this applies to many places in the code). I'll then do another review. Thanks.

libsnark/CMakeLists.txt Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/common_input.hpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/common_input.hpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/common_input.hpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/common_input.hpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/prover.tcc Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/prover.tcc Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/srs.hpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/srs.hpp Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/tests/example.tcc Outdated Show resolved Hide resolved
vesselinux pushed a commit that referenced this pull request Jun 8, 2022
…ly accumulate result thus removing the need to reserve additional memory for intermediate results (following draft PR #49 review comment)
vesselinux pushed a commit that referenced this pull request Jun 9, 2022
…function plonk_usrs_derive_from_secret that directly returns a correctly initialized usrs object. this change addresses a review comment on draft PR #49.
Copy link
Contributor

@dtebbs dtebbs left a comment

Choose a reason for hiding this comment

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

Some more comments. There seem to be some old code versions creeping back in.

libsnark/gadgetlib1/pb_variable.hpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/plonk.hpp Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
libsnark/gadgetlib1/gadget.hpp Outdated Show resolved Hide resolved
libsnark/gadgetlib1/gadget.tcc Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/plonk.hpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/plonk.hpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/plonk.tcc Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/plonk.tcc Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/prover.hpp Show resolved Hide resolved
@vesselinux vesselinux force-pushed the plonk branch 3 times, most recently from c29db3b to 967fe3e Compare June 30, 2022 13:14
@vesselinux vesselinux requested a review from dtebbs July 1, 2022 13:33
Copy link
Contributor

@dtebbs dtebbs left a comment

Choose a reason for hiding this comment

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

Looking better. I didn't manage to dig into every file, but I'll leave this partial review for now and come back to look at the remaining files in a second pass.

libsnark/zk_proof_systems/plonk/circuit.hpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/circuit.tcc Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/circuit.hpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/plonk.hpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/plonk.hpp Outdated Show resolved Hide resolved
{
assert(omega.size() == NUM_HSETS);
assert(omega[0].size() > 0);
size_t num_gates = omega[0].size();
Copy link
Contributor

Choose a reason for hiding this comment

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

There could be a lot of room for error if this is passed in implicitly in the length of the first array. Should it also be checked to ensure it's a power of 2? Also that it's less than 2^(ppT::s) (I think it's s)

Copy link
Contributor

Choose a reason for hiding this comment

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

Potentially this and plonk_roots_of_unity_omega_to_subgroup_H can be replaced by a single function which takes an $n$, expected to be a power of 2, checks the validity of $n$ for the current curve, and returns the "H_gen" vector. Then the caller doesn't have to be involved in the allocation of the vector.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Proposed change accepted and applied. More specifically, replaced function plonk_roots_of_unity_omega_to_subgroup_H with plonk_multiplicative_subgroups_H_k1H_k2H, which recomputes the vector omega in order to avoid passing it as an input parameter potentially with the wrong size (as was done in plonk_roots_of_unity_omega_to_subgroup_H). Note that the function plonk_compute_roots_of_unity_omega is still kept (and used in plonk_multiplicative_subgroups_H_k1H_k2H) since (as mentioned in a reply to an earlier review comment) the omega vector is used in multiple places (e.g. as the omega_roots member of the srs class and the circuit_t structure).

libsnark/zk_proof_systems/plonk/plonk.tcc Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/prover.tcc Outdated Show resolved Hide resolved
const srs<ppT> &srs)
{
using Field = libff::Fr<ppT>;
int nwitness = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

const size_t ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. Fixed.

libsnark/zk_proof_systems/plonk/prover.tcc Outdated Show resolved Hide resolved
Copy link
Contributor

@dtebbs dtebbs left a comment

Choose a reason for hiding this comment

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

Very close. Many of the comments can be addressed in subsequent PRs, but could you ensure that each one is captured in an issue? (Could have a single issue for all perf related stuff, and one for test code removal, etc, as you prefer).

libsnark/zk_proof_systems/plonk/tests/test_plonk.cpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/plonk.hpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/tests/example.tcc Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/plonk.hpp Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/plonk.hpp Outdated Show resolved Hide resolved
}

// break this->t_poly_long into three parts: lo, mid, hi, each of degree
// 7. note: (srs.num_gates+3) is the length of the CRS =
Copy link
Contributor

Choose a reason for hiding this comment

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

"7"? Is that for the example circuit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, degree 7 comes from the example circuit which has 8 gates (6 gates + 2 dummy to make power of 2 for the FFT). Corrected to degree (num_gates - 1)

libfqfft::_polynomial_addition<Field>(r_poly, r_poly, r_part[3]);

// TODO: make a separate unit test for r_poly
#if 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this going to be moved into a test. It seems example is already not in scope, so can it be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the idea is to have a separate unit test under tests/ to check the value of r_poly (and the #if 0 guard is meant as a reminder). However this involves breaking down the function plonk_prover<ppT>::round_five() into several sub-functions which may require a bit more effort. Similar refactoring is desirable for plonk_prover<ppT>::round_three() . I added all of these points as TODO in Issue #52 .

libsnark/zk_proof_systems/plonk/prover.tcc Outdated Show resolved Hide resolved
libsnark/zk_proof_systems/plonk/prover.tcc Outdated Show resolved Hide resolved
transcript_hash_t<ppT> &transcript_hash)
{
// step 4 output
libff::Fr<ppT> beta;
Copy link
Contributor

Choose a reason for hiding this comment

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

This function declares, then copies, then moves. I think you can just pass Field(transcript_hash.beta) directly to the constructor.

Copy link
Contributor

Choose a reason for hiding this comment

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

Move semantics don't do anything for field elements, so step_four_t should just take const references, and you can just pass transcript_hash.beta, ... directly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good points. Fixed.

@dtebbs
Copy link
Contributor

dtebbs commented Jul 15, 2022

OK. I think we can call this v0.1. Let's keep this branch as the stable version, and we can make issues against this and future changes in PRs tagretting this branch. This should make future PRs a bit quicker and easier to review.
🥳

@dtebbs
Copy link
Contributor

dtebbs commented Oct 11, 2022

@vesselinux can you rebase onto the latest origin/develop, please. There may be some warnings to fix as a result. Thanks.

@vesselinux
Copy link
Collaborator Author

@vesselinux can you rebase onto the latest origin/develop, please. There may be some warnings to fix as a result. Thanks.

Done.

Vesselin Velichkov and others added 30 commits November 30, 2022 13:55
… test function and removed redundant check 3 from the bls12-381-specific unit test (#94 (comment))
…es taking only the number of PIs as opposed to a vector of their indices (#97 (comment)); added utility function to compute teh values of the PIs from the witness to be passed to the verifier.
Plonk: helper function to build gates matrix (depends on #70)
…d unit tests for the simple quadratic residue circuit for all curves (addresses issue #103)
…-curves

Test simple Plonk circuit on all curves
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.

3 participants