-
Notifications
You must be signed in to change notification settings - Fork 400
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: range check gadget #472
Conversation
810c89d
to
4b056e1
Compare
So to continue discussion on changes to interfaces (cc @gbotrel). Configurable builder constructors As I understand, the question is that maybe we could have a configurable builder constructor with options, so for example we could have a function:
allows in the circuit to assert And in practice I think it makes sense that for every option to the builder constructor creator there is some capability (defined by an interface) what the resulting builder implements. I think that technically this is doable and wouldn't differ much from how I have implemented native range checking and committing version of PLONK builders in the snippet in the first post. |
Second proposal was to implement key-value storage using Go standard Now, looking at it, it seems that
But in our use case we want that the values propagate - for example when we initialise field emulation in ECDSA gadget, then we want field emulation to be available later in pairing gadget, for example. |
Yep maybe you're onto a nice pattern that could also allow user-defined custom gates (cc @ThomasPiellard ) |
And I just wanted to add - I think in any case the actual logic should be hidden in gadgets. In case of ECAdder, we would have a generic
|
And finally, for the callbacks/defers. I agree the implementation is ugly and imo not very sustainable long-term. I really do not like that the callbacks are called in For example, debug symbol table building has some assumption about the function names in the callstack and this messed everything up. I tried to keep everything working but I feel it is too fragile and will probably break something soon. I'm open to any suggestions to make it more clear. |
So for example, in case of range checking -- there is now rangecheck gadget which chooses between three implementations:
If the builder supports native range checking (implements |
0da2d35
to
bd0e623
Compare
bd0e623
to
6be6002
Compare
6be6002
to
a13313a
Compare
In range checking gadget we try to estimate the number of constraints given different parameters. But for estimating we need to know the costs of operations. And the costs of the operations depend on the way we arithmetize the circuit. Added an internal interface which allows to query the arithmetization method and implement this in existing builders.
5578184
to
7333ed9
Compare
FYI @ThomasPiellard, as all dependencies were merged, then rebased on top of develop. Now this PR only contains changes only related to this PR. |
Rangechecker
with a single methodCheck(var Variable, bits int)
. Right now we don't have an implementation of a builder implementing it, but the goal is that when we have PLONK+custom gates or Wizard IOP then we can detect that the builder supports native range checking and use it instead of doing it in-circuit. It is good to have the interface now though because then we can already implement the support in the range checking gadget.internal/frontendtype
package with a single interfaceFrontendTyper
. This allows the gadget to estimate constraints depending on the operation count and choose the most optimal parameters.I guess would make sense to split into smaller PRs, but for discussion is better to see the whole set of changes.
Example files of different PLONK builders. The first implementation
scs.NewCommitBuilder
implementsfrontend.Committer
and range checking uses commitments. The secondscs.NewRangecheckBuilder
implementsfrontend.Rangechecker
and range checking uses native range checking. We would use different builders asfrontend.Compile(mod, scs.NewBuilder)
,frontend.Compile(mod, scs.NewCommitBuilder)
andfrontend.Compile(mod, scs.NewRangecheckBuilder)
.PLONK builder with commitment support
PLONK builder with native range check support (PLONK + custom gate OR PLONK + Wizard):