-
Notifications
You must be signed in to change notification settings - Fork 414
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
Fix/plonk constraints #186
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.
looks good, couple of comment in the review.
- Also, refactoring error "compiled.Variable" appears multiple time in comments where "variable" was fine :)
- dealing better with marking boolean constrain variables (ie Variable == LinearExpression) would remove also some of these changes (everywhere v.LinExp appears)
- minor conflicts with develop to fix before merging
internal/generator/backend/template/representations/r1cs.go.tmpl
Outdated
Show resolved
Hide resolved
type LinearExpression []Term | ||
|
||
// Variable represent a linear expression of wires | ||
type Variable struct { |
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.
here I would just merge the compiled.Variable and compiled.LinearExpression. Ie define:
type Variable []Term
Managing boolean constrained variables with a pointer seems a bit risky to me; while it may not bug with our current API, cloning a Variable, adding terms to the linear expressions, boolean constraining it will incorrectly mark the first variable as boolean constrained.
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.
We can restore the map to track boolean constrained variables, however we still need to store an ID field in Variable, right?
…to fix/plonk_constraints
Summary
This PR changes the way PLONK circuits are compiled. It is now faster and every cases are covered, contrary to the previous attempt at reducing the number of constraints where some cases where ignored, resulting in blowing up the number of constraints in some "big" circuits (like scalar multiplication, pairing...).
Description
The previous solution relied on factoring linear expression in Groth16 to not split them twice in PLONK. Here it is a different and simpler approach. The API has now a method that returns the backendID. If the backendID is PLONK, then the ADD and SUB methods add a new variable and the linear expression is really recorded as a constraint (it is not in GROTH16). With that, when a linear expression is reused later in the circuit, then it is the variable equal to the sum that is used, so the linear expression is split only once. Several methods in the API needed to be refactored to avoid bugs or to decrease the number of constraints, and to be consistant with the splitting algo (splitting from r1cs to sparse_r1cs).
Internal changes
Some refactoring on the constraint system has been done, to put the right fields to the right place:
Internal changes:
Status
Ex perfs:
305765908 ns/op, 7928 constraints
[develop] vs10602651 ns/op, 7543 constraints
[this branch]1762081141 ns/op, 324432 constraints
[develop] vs67556893 ns/op, 64059 constraints
[this branch]