perf: fold constant table column into denominator in logderivarg - #1804
Open
Fable95 wants to merge 1 commit into
Open
perf: fold constant table column into denominator in logderivarg#1804Fable95 wants to merge 1 commit into
Fable95 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Optimizes PLONK (SCS) constraint count for constant multi-column lookup tables by folding
the row's random linear combination directly into the denominator's subtraction, on the table
side of the log-derivative argument.
In the two-column case, the LogUp verification equation
sum count(f,S)/(x-f) == sum 1/(x-s), currently requires 4 PLONK gates per table entry:Add:acc = 1*i + rho*T_i(1 gate insiderandLinearCombination)Sub:denom = challenge - acc(1 gate)DivUnchecked:quotient * denom = exps[i](1 gate)Add:lp += quotient(1 gate)The constant term
1*ican be folded into the subsequent subtraction by removing the call torandLinearCombination, we can get the following three constraints:Sub:denom = challenge - rho*T_i - i(1 gate: a constraint in two variableschallengeandrho)DivUnchecked:quotient * denom = exps[i](1 gate)Add:lp += quotient(1 gate)This approach saves one gate for any column width (in case of a one-to-many LUT). For each row, we can first compute the randomized
term_j = rho_j*T_{i,j}for free sinceT_{i,j}is public. A subsequentapi.Sub(challenge, terms[0], terms[1:]...)will produce (nbRow- 1) gatesSaving:
len(table) - 1PLONK gates per circuit and R1CS is unaffected.Security: The underlying argument is not affected by the fold. The constant
iis moved from its own addition gate into the constant term of the subsequent subtraction gate.Type of change
How has this been tested?
go test ./std/internal/logderivarg/ -count=1go test ./std/lookup/logderivlookup/ -count=1: TestLookup, Examplego test ./std/rangecheck/ -count=1: unchanged path, guards against regressiongo test ./std/compress/... -count=1: constant-table callersilently regress (invisible to correctness tests)
How has this been benchmarked?
Per table entry, table side (
nbRow == 2, measured inBuild)Optimization works for large fields, while small fields are not impacted.
Downstream circuit
The test suggests the claimed improvement holds for any classical (1-to-1) LUT use case.
Checklist:
golangci-lintdoes not output errors locallyNote
Cursor Bugbot is generating a summary for commit bfdb931. Configure here.