-
Notifications
You must be signed in to change notification settings - Fork 130
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
[feat] Make selector compression optional #212
Conversation
There was a problem hiding this 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.
Ah yea I noticed this too when I was reviewing. Let me see if I can fix quickly. I fixed the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…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
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
andhalo2-solidity-verifier
. As such, it is useful to be able to optionally turn it off.This PR does the following:
keygen_vk_custom
function where user can choose whether to turn on selector compression(=combination) or not.keygen_vk
will be set so the default is with selector compression, so it matches current behavior.VerifyingKey
does not need to store anything about selectors. Afterkeygen_vk_custom
, theConstraintSystem
has entirely replaced selectors with fixed columns, and fixed commitments have been updated. Theverify_proof
function does not use selectors in any way. Inkeygen_pk
you still need to know about selectors, but it reconstructs theConstraintSystem
from scratch anyways.VerifyingKey::read
andwrite
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
andkeygen_pk
are: it re-does the FFTs for all fixed columns twice, once inkeygen_vk
and again inkeygen_pk
becauseVerifyingKey
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.