perf(plonk): reduce LRO commitment MSM size via s0-padding identity#1716
Open
perf(plonk): reduce LRO commitment MSM size via s0-padding identity#1716
Conversation
L, R, O polynomials are padded with s0 (first public input) to reach the power-of-2 domain size. Using the identity Σ G1_lag[i] = [1]₁ = G1[0], we rewrite each commitment as: [P] = MSM((P[i]-s0), G1_lag[i]) + s0·G1[0] The (P[i]-s0) terms are zero in the padding region, so the MSM only needs the non-padding entries. For a 2.2M-constraint circuit on a 4M domain this nearly halves each MSM (measured 1.94x on the commit step). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements a performance optimization for the PLONK prover by reducing the size of multi-scalar multiplications (MSMs) used when committing to the L, R, and O polynomials. The optimization exploits the mathematical identity that the sum of all Lagrange basis polynomial commitments equals the identity element in G1.
Changes:
- Rewrites L, R, O polynomial commitments to use partial MSMs covering only non-padding entries
- For circuits with significant padding (e.g., 2.2M constraints on a 4M domain), this nearly halves the MSM size for each commitment
- Adds
BenchmarkLargeProverto demonstrate the optimization with a 2.2M-constraint circuit showing ~1.94x MSM speedup
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
internal/generator/backend/template/zkpschemes/plonk/plonk.prove.go.tmpl |
Template implementing the optimized commitToLRO function with detailed mathematical documentation |
backend/plonk/bn254/prove.go |
Generated implementation for BN254 curve |
backend/plonk/bls12-377/prove.go |
Generated implementation for BLS12-377 curve |
backend/plonk/bls12-381/prove.go |
Generated implementation for BLS12-381 curve |
backend/plonk/bw6-761/prove.go |
Generated implementation for BW6-761 curve |
backend/plonk/plonk_test.go |
Adds benchmark test for large circuits to validate the optimization |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Σ G1_lag[i] = [1]₁ = Kzg.G1[0]to rewrite L, R, O commitments as partial MSMs over only the non-padding entries, plus a single scalar multiplication corrections0·G1[0]BenchmarkLargeProverwith a 2.2M-constraint circuit (domain 1<<22, ~47.5% padding)How it works
L, R, O are defined on a domain of size
n = 2^k, but onlyoffset = nbPublic + nbConstraintsentries carry actual values. The rest ares0 = witness[0].The
(P[i]-s0)terms are zero in the padding region, so the MSM only covers[0, offset)for L and[nbPublic, offset)for R/O.Benchmark (BN254, 2.2M constraints, Apple M1 Max)
Test plan
TestProverpasses on all 4 curves (bn254, bls12-377, bls12-381, bw6-761)TestCustomHashToField,TestCustomChallengeHash,TestCustomKZGFoldingHashpass on all curves🤖 Generated with Claude Code
Note
Medium Risk
Touches core proving cryptography (KZG commitments) and introduces in-place coefficient adjustments and partial-slice MSMs, so subtle indexing/padding assumptions could affect proof correctness despite being a contained, well-motivated optimization.
Overview
Speeds up PLONK proving by rewriting
commitToLROcommitments forL,R, andOto avoid MSM work over padding/public-placeholder regions: it subtracts the padding values0from the relevant Lagrange coefficients, runs a reduced-sizeMultiExponly over the non-zero slice, then adds back a single correction points0·Kzg.G1[0]plus the existing blinding contribution.Applies the same optimization across all generated curve backends (
bn254,bls12-377,bls12-381,bw6-761) and updates the codegen template accordingly. AddsBenchmarkLargeProverto exercise the optimization on a ~2.2M-constraint circuit with substantial domain padding.Written by Cursor Bugbot for commit 63d4dad. This will update automatically on new commits. Configure here.