Skip to content

Fix logic mismatch in newR1C for better Groth16 optimization #1482

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions frontend/cs/r1cs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,10 @@ func (builder *builder[E]) newR1C(l, r, o frontend.Variable) constraint.R1C {
R := builder.getLinearExpression(r)
O := builder.getLinearExpression(o)

// interestingly, this is key to groth16 performance.
// l * r == r * l == o
// but the "l" linear expression is going to end up in the A matrix
// the "r" linear expression is going to end up in the B matrix
// the less Variable we have appearing in the B matrix, the more likely groth16.Setup
// is going to produce infinity points in pk.G1.B and pk.G2.B, which will speed up proving time
if len(L) > len(R) {
// TODO @gbotrel shouldn't we do the opposite? Code doesn't match comment.
// We want R (the B matrix) to have fewer variables to increase the chance
// of infinity points in pk.G1.B / pk.G2.B during Groth16 setup,
// which improves proving time. Therefore, we swap L and R if R has more terms.
if len(R) > len(L) {
L, R = R, L
}

Expand Down