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

[feat] Make selector compression optional #212

Conversation

jonathanpwang
Copy link

Selector compression is an optimization, but often it can lead to unexpected behavior / makes life complicated when doing more complicated proof composability like with SNARK recursion or universal verifiers such as in snark-verifier and halo2-solidity-verifier. As such, it is useful to be able to optionally turn it off.

This PR does the following:

  • Addresses Update serialization format according to upstream #176 by adding a version byte to vkey serialization and using little endian everywhere for consistency.
  • Adds keygen_vk_custom function where user can choose whether to turn on selector compression(=combination) or not.
  • For backwards compatibility, keygen_vk will be set so the default is with selector compression, so it matches current behavior.
  • When selector compression is off, the VerifyingKey does not need to store anything about selectors. After keygen_vk_custom, the ConstraintSystem has entirely replaced selectors with fixed columns, and fixed commitments have been updated. The verify_proof function does not use selectors in any way. In keygen_pk you still need to know about selectors, but it reconstructs the ConstraintSystem from scratch anyways.
  • I think I've modified the VerifyingKey::read and write functions accordingly, where there is now a new byte recording whether selector compression is on or off. When off, I skip serializing selectors since they are unnecessary for reasons mentioned above.

I also did not realize until now how inefficient keygen_vk and keygen_pk are: it re-does the FFTs for all fixed columns twice, once in keygen_vk and again in keygen_pk because VerifyingKey can't store the results of the FFT. The fact that you need to re-generate the constraint system to handle selectors is also a bad design pattern in many ways, but for now I opted for the path of least code changes.

@han0110 han0110 self-requested a review September 20, 2023 07:09
Copy link

@han0110 han0110 left a comment

Choose a reason for hiding this comment

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

LGTM! Just a nitpick.

Also I noticed that bytes_length doesn't reflect real size (since we added different format), but it seems fine because it's not a public api and just used for estimating capacity.

halo2_proofs/src/plonk.rs Outdated Show resolved Hide resolved
@jonathanpwang
Copy link
Author

jonathanpwang commented Sep 20, 2023

LGTM! Just a nitpick.

Also I noticed that bytes_length doesn't reflect real size (since we added different format), but it seems fine because it's not a public api and just used for estimating capacity.

Ah yea I noticed this too when I was reviewing. Let me see if I can fix quickly.

I fixed the bytes_length from 8 -> 10 but also realized that previously the estimate was way off when using RawBytes because it was using 33 bytes per curve element instead of 64.

Copy link

@han0110 han0110 left a comment

Choose a reason for hiding this comment

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

LGTM!

@han0110 han0110 merged commit 9899a5c into privacy-scaling-explorations:main Nov 8, 2023
12 checks passed
iquerejeta pushed a commit to input-output-hk/halo2 that referenced this pull request May 8, 2024
…ns#212)

* feat: add `keygen_vk_custom` function to turn off selector compression

* feat(vkey): add `version` and `compress_selectors` bytes to serialization

* feat: do not serialize selectors when `compress_selectors = false`

* feat: make `keygen_vk` have `compress_selectors = true` by default

* chore: fix clippy

* fix: pass empty poly to fake_selectors

* fix: byte_length calculation
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.

2 participants