From dca7fc1aba44fd8344030f2ed55fddec053cf70e Mon Sep 17 00:00:00 2001 From: BernardLowe Date: Thu, 26 Nov 2026 20:24:38 +0800 Subject: [PATCH] perf: use sparse CPU KZG openings at every occupancy --- CHANGELOG.md | 6 +++--- README.md | 9 ++++----- auth/commitment/kzg/sparse.go | 9 +-------- auth/commitment/kzg/sparse_test.go | 4 ++-- docs/spec/commitment-proof-encoding.md | 5 ++--- 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d65dcc6..a657ca1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Changed -- Compute KZG openings for up to 128 nonzero scalars using a sparse quotient - and fixed public unit-polynomial openings. Preserve dense behavior above the - threshold, exact proof bytes, checked primitive Prove and receiver verification. +- Compute CPU KZG openings at every occupancy using a sparse quotient + and fixed public unit-polynomial openings. This preserves exact proof bytes, + checked primitive Prove and receiver verification. Generate and verify the additional writer-only table from the pinned setup; no query-time precomputation, new setup ceremony or profile change is needed. diff --git a/README.md b/README.md index e92ed78..80085c8 100644 --- a/README.md +++ b/README.md @@ -121,11 +121,10 @@ and generated-evidence reuse; proof order and serialized bytes do not depend on scheduling. The built-in KZG and IPA arithmetic also follows the process's Go scheduler budget. Applications may schedule independent ArcSet proofs separately. -The built-in KZG prover uses a sparse quotient calculation for vectors with at -most 128 nonzero scalars. Its fixed unit-polynomial opening table is generated -from the pinned public setup and loaded with the writer key; queries require -no table precomputation. Higher occupancy uses the full-vector calculation. -Both paths emit identical proof bytes and use the same verifier. Writers retain +The built-in CPU KZG prover uses a sparse quotient calculation at every +occupancy. It loads a fixed unit-polynomial opening table with the writer key. +The table is generated from the pinned public setup before queries run. +The resulting proofs match the full-vector calculation byte for byte. Writers retain an additional 384 KiB embedded table plus 384 KiB of decoded points per process; portable verifiers do not load or link either. diff --git a/auth/commitment/kzg/sparse.go b/auth/commitment/kzg/sparse.go index bc337cd..8a59ae0 100644 --- a/auth/commitment/kzg/sparse.go +++ b/auth/commitment/kzg/sparse.go @@ -8,10 +8,6 @@ import ( gokzg4844 "github.com/crate-crypto/go-kzg-4844" ) -// Sparse openings use at most occupancy+2 MSM terms instead of MaxValues. -// Keep the existing full-vector algorithm for higher occupancy. -const sparseOpeningLimit = 128 - func provePolynomialAtIndex(key *kzgWriterKey, domain *kzgDomain, polynomial []blsfr.Element, index uint64) (gokzg4844.KZGProof, gokzg4844.Scalar, error) { if key == nil || len(key.lagrangeG1) != MaxValues || len(key.unitProofs) != MaxValues { return gokzg4844.KZGProof{}, gokzg4844.Scalar{}, fmt.Errorf("KZG writer parameters are incomplete") @@ -22,12 +18,9 @@ func provePolynomialAtIndex(key *kzgWriterKey, domain *kzgDomain, polynomial []b if len(polynomial) != MaxValues || index >= MaxValues { return gokzg4844.KZGProof{}, gokzg4844.Scalar{}, fmt.Errorf("invalid KZG opening index %d", index) } - indices := make([]int, 0, sparseOpeningLimit) + indices := make([]int, 0, 128) for i := range polynomial { if !polynomial[i].IsZero() { - if len(indices) == sparseOpeningLimit { - return provePolynomialAtIndexDense(key, domain, polynomial, index) - } indices = append(indices, i) } } diff --git a/auth/commitment/kzg/sparse_test.go b/auth/commitment/kzg/sparse_test.go index b69aed9..5bc5109 100644 --- a/auth/commitment/kzg/sparse_test.go +++ b/auth/commitment/kzg/sparse_test.go @@ -19,8 +19,8 @@ func TestSparseOpeningsEqualDenseQuotients(t *testing.T) { if err != nil { t.Fatal(err) } - // Include zero and occupied targets, both ends of the domain, and both - // sides of the dispatch boundary. Dense outputs are the byte-level oracle. + // Compare empty and occupied targets against the dense reference, + // including both ends of the domain and a fully populated vector. for _, occupancy := range []int{0, 1, 2, 32, 127, 128, 129, 1024, MaxValues} { t.Run(fmt.Sprint(occupancy), func(t *testing.T) { polynomial := make([]blsfr.Element, MaxValues) diff --git a/docs/spec/commitment-proof-encoding.md b/docs/spec/commitment-proof-encoding.md index d1af5f4..77782fc 100644 --- a/docs/spec/commitment-proof-encoding.md +++ b/docs/spec/commitment-proof-encoding.md @@ -77,9 +77,8 @@ point `domain[i]`. ### Opening Computation -The CPU prover selects a sparse computation when at most 128 evaluations are -nonzero; higher occupancy uses the full 4096-element quotient. This is an -implementation choice and does not change KZG4096 parameters or proof bytes. +The CPU prover uses the sparse quotient computation at every occupancy, +including a fully populated 4096-element vector. Let `L_j` be the Lagrange basis for the index domain, `omega_i` the opening point, and `p_j` the supplied evaluations. The writer embeds one public point