Skip to content

feat(prover-ray): migrate KoalaBear extension field from degree-4 to degree-6#3111

Open
gbotrel wants to merge 2 commits into
mainfrom
prover/fp6
Open

feat(prover-ray): migrate KoalaBear extension field from degree-4 to degree-6#3111
gbotrel wants to merge 2 commits into
mainfrom
prover/fp6

Conversation

@gbotrel
Copy link
Copy Markdown
Contributor

@gbotrel gbotrel commented May 14, 2026

Summary

Migrates every reference to the KoalaBear degree-4 extension field
(extensions.E4) under prover-ray/ to the degree-6 tower
(extensions.E6) shipped in
gnark-crypto@v0.20.2-0.20260514182922-df0578435b08.

Tower:

  • 𝔽_{p^6} = 𝔽_{p^2}[v] / (v³ − (u+1)) (cubic non-residue: u+1)
  • 𝔽_{p^2} = 𝔽_p[u] / (u² − 3)

Caller-visible changes:

  • field.Ext is now a six-coordinate value (24 bytes vs 16 bytes
    previously); ExtToBytes / BytesToExt change accordingly.
  • field.UintsToExt(v1..v4)UintsToExt(v1..v6); ditto IntsToExt,
    ExtToUint64s.
  • gnark circuit constructor NewExtFrom4FrontendVars
    NewExtFrom6FrontendVars.
  • ConjugateExt removed from the circuit API (was unused; the natural
    Frobenius conjugation in a cubic tower is non-trivial and would be
    misleading to expose).

Hot-path changes:

  • wiop/compilers/global/global.go: replaced the coordinate-by-coordinate
    applyBaseFFT4 helper (4 disjoint base FFTs + 4 scratch buffers per
    bucket) with a direct largeDomain.FFTInverseExt6 / FFTExt6 call.
    Walks the contiguous E6 layout once per pass instead of six times.
  • crypto/koalabear/{reedsolomon,ringsis,vortex} switched to
    FFTExt6 / FFTInverseExt6.
  • crypto/koalabear/vortex/verifier_common.go ships local
    evalFextPolyHorner / evalBasePolyHorner because gnark-crypto's
    vortex.Eval*PolyHorner is still E4-typed upstream.

Performance impact on Apple M5 Max (arm64):

Bench Before (E4) After (E6) Δ
ExtMul 5.34 ns 22.0 ns +311 %
ExtSquare 4.77 ns 15.7 ns +229 %
ExtMulByBase 2.04 ns 2.89 ns +42 %
ExtInverse 57.7 ns 83.6 ns +45 %
BatchInvertExt n=65536 1.81 ms 5.70 ms +215 %
ParBatchInvertExt n=65536 436 µs 891 µs +104 %
VecAddExtExt n=65536 109 µs 115 µs +5 %
VecMulExtExt n=65536 393 µs 1820 µs +363 %
VecScaleBaseExt n=65536 142 µs 212 µs +49 %
EvalLagrangeExtExt n=16k 669 µs 2047 µs +206 %
ComputeLagrangeAtZExt n=16k 4023 µs 5100 µs +27 %

More numbers, raw artefacts and per-bench analysis are in
prover-ray/transition_fp6_worklog.md.

Follow-ups (out of scope for this PR)

  • x86 (Linux HPC) numbers: these benches were taken on an Apple M5
    Max (arm64). gnark-crypto ships AVX-512 fast paths for E4 vector
    kernels (vectorMul_avx512, vectorScalarMul_avx512, …) but no
    AVX equivalents for E6 yet
    , so on the target x86 prover hosts the
    VecMulExtExt / VecScaleBaseExt gap is expected to be larger
    than what shows up here. Re-run the same bench suite on a
    representative x86 node and post the comparison; that will tell us
    where to focus a follow-up SIMD effort upstream in gnark-crypto.
  • End-to-end prover throughput: the microbench slowdown does not
    directly translate to prover wall-time (Vortex transversal hashing
    is unchanged; the FFT path actually gets better cache locality
    from the FFTExt6 switch). Profile the full prover on a
    representative trace and reconcile.
  • Optimise E6 hot kernels: the upstream-gnark-crypto generic
    extensions.E6.Mul is the standard Karatsuba-over-E2 (6 E2 muls).
    An accumulator-style kernel comparable to the existing E4
    montReduce-batched one (single function for all 6 coordinates)
    could close roughly 30–50 % of the per-mul gap. Worth tracking
    upstream.
  • extensions.E6 AVX kernels in gnark-crypto: SIMD Add, Mul,
    MulByElement, ScalarMul, Butterfly for E6 — the biggest
    potential win for the prover.
  • More tests / property tests at the wiop layer: the migration
    preserved the existing unit-test surface, but the wiop hot path
    (quotient computation, lagrange checking, vortex commitments)
    would benefit from a small property-test suite that randomises
    sizes/ratios and asserts correctness across the new tower.
  • Decide whether field.RootPowers is still useful — no caller uses
    it in this tree.

Test plan

  • go build ./...
  • go vet ./...
  • go test ./... -count=1 -timeout=600s
  • Baseline + after microbenches captured (Apple M5 Max); raw output
    in transition_fp6_worklog.md
  • Same microbench suite re-run on an x86 Linux prover host
  • End-to-end prover regression check on a representative trace

🤖 Generated with Claude Code


Note

High Risk
High risk because it changes the core extension-field representation (E4→E6), serialization size/constructors, and updates FFT/circuit arithmetic paths used across prover and verifier logic; subtle compatibility or correctness regressions would affect proof generation/verification.

Overview
Migrates KoalaBear extension arithmetic across prover-ray from degree-4 (E4) to degree-6 (E6) by switching field.Ext to extensions.E6 and field.ExtensionDegree to 6, updating all helpers to read/write six coordinates.

Updates transcript sampling (FiatShamir.RandomFext now consumes 6 of 8 Poseidon outputs), FFT-based code paths (Reed-Solomon, RingSIS, polynomial coefficient recovery, vortex hints) to use FFTExt6/FFTInverseExt6, and fixes equality checks to use Equal for E6 values.

Reworks the gnark circuit Ext type and arithmetic to E6 (new constructors, updated MulExt/SquareExt/MulByNonResidueExt, expanded hint IO to 6 coordinates, removes unused ConjugateExt), and simplifies wiop quotient computation by dropping coordinate-sliced FFT scratch buffers in favor of direct FFTInverseExt6.

Adds/updates tests and adds new micro-benchmarks (field/ext_bench_test.go, polynomials/lagrange_bench_test.go), and bumps gnark-crypto to an E6-capable revision.

Reviewed by Cursor Bugbot for commit 1de3283. Bugbot is set up for automated code reviews on this repo. Configure here.

…degree-6

Bumps `gnark-crypto` to v0.20.2-...-df0578435b08 which exposes the new
`extensions.E6`, `BatchInvertE6`, `VectorE6`, `FFTExt6` and
`FFTInverseExt6` APIs, and migrates every reference to the degree-4
extension under `prover-ray/` to the degree-6 tower:

  𝔽_{p^6} = 𝔽_{p^2}[v] / (v³ − (u+1))    (cubic non-residue: u+1)
  𝔽_{p^2} = 𝔽_p[u]   / (u²  − 3)

Highlights
- `maths/koalabear/field/ext.go`: full rewrite over six base-field
  coordinates (Mul/Square/Inverse/BatchInvert delegated to gnark-crypto;
  byte encoding grows from 16 to 24 bytes per element).
- `maths/koalabear/circuit/ext.go`: gnark circuit layer rewritten for E6
  using Algorithm 13/16 from eprint 2010/354 (six E2 muls per MulExt);
  hint plumbing extended from 4 → 6 limbs; new e2MulByCubicNonResidue
  helper; ConjugateExt removed (was unused and ill-defined for cubic).
- `wiop/compilers/global/global.go`: replaced the coord-by-coord
  `applyBaseFFT4` helper (four base FFTs + four scratch buffers) by a
  direct `FFTExt6` / `FFTInverseExt6` call. Removes four scratch slices
  per bucket and improves cache locality.
- `crypto/koalabear/vortex/verifier_common.go`: ships a local
  `evalFextPolyHorner` / `evalBasePolyHorner` since gnark-crypto's
  `vortex.Eval*PolyHorner` is still E4-typed upstream.
- `crypto/koalabear/{reedsolomon,ringsis,vortex}`: FFT calls switched to
  `FFTExt6` / `FFTInverseExt6`; vortex hint chunk size now driven by
  `field.ExtensionDegree (= 6)`.
- `crypto/koalabear/fiatshamir`: `RandomFext` consumes 6 of the 8 hashed
  Poseidon outputs.

Tests: `go test ./...` is green; new microbench files
`maths/koalabear/field/ext_bench_test.go` and
`maths/koalabear/polynomials/lagrange_bench_test.go` were added so the
E4 → E6 cost delta can be tracked.

See `prover-ray/transition_fp6_worklog.md` for the full file-by-file
log, benchmark numbers (Apple M5 Max), and follow-up items.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 14, 2026 20:44
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 14, 2026

linea-besu Changelog Preview (informational)

[Unreleased] diff (commits touching linea-besu/** since latest releases/linea-besu/v* tag)

[unreleased]

🐛 Bug Fixes

  • (3111) Address fp6 review comments

Generated by git-cliff-action using cliff.toml. This comment is informational and does not gate the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 14, 2026

postman Changelog Preview (informational)

[Unreleased] diff (commits touching postman/** since latest releases/postman/v* tag)

[unreleased]

🐛 Bug Fixes

  • (3111) Address fp6 review comments

Generated by git-cliff-action using cliff.toml. This comment is informational and does not gate the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 14, 2026

tx-exclusion-api Changelog Preview (informational)

[Unreleased] diff (commits touching tx-exclusion-api/** since latest releases/tx-exclusion-api/v* tag)

[unreleased]

Generated by git-cliff-action using cliff.toml. This comment is informational and does not gate the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 14, 2026

coordinator Changelog Preview (informational)

[Unreleased] diff (commits touching coordinator/** since latest releases/coordinator/v* tag)

[unreleased]

🐛 Bug Fixes

  • (3111) Address fp6 review comments

Generated by git-cliff-action using cliff.toml. This comment is informational and does not gate the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 14, 2026

prover Changelog Preview (informational)

[Unreleased] diff (commits touching prover/** since latest releases/prover/v* tag)

[unreleased]

🐛 Bug Fixes

  • (3111) Address fp6 review comments

Generated by git-cliff-action using cliff.toml. This comment is informational and does not gate the PR.

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7ddc0fe. Configure here.

Comment thread prover-ray/transition_fp6_worklog.md Outdated
@socket-security
Copy link
Copy Markdown

socket-security Bot commented May 14, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedgolang/​github.com/​consensys/​gnark-crypto@​v0.20.1 ⏵ v0.20.2-0.20260514182922-df0578435b0876 +1100100100100

View full report

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates prover-ray KoalaBear extension-field usage from E4 to E6, updating field helpers, circuit arithmetic, FFT integrations, verifier polynomial evaluation, and benchmarks/worklog documentation.

Changes:

  • Replaces E4 types/helpers with E6-aware field, circuit, FFT, and transcript handling.
  • Updates tests/benchmarks for six-coordinate extension values.
  • Adds a migration worklog with performance notes and follow-ups.

Reviewed changes

Copilot reviewed 19 out of 20 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
prover-ray/wiop/compilers/global/global.go Switches quotient-share extension FFTs to FFTExt6/FFTInverseExt6 and removes E4 coordinate scratch buffers.
prover-ray/transition_fp6_worklog.md Adds migration notes, benchmark results, and follow-up items.
prover-ray/maths/koalabear/polynomials/lagrange_test.go Extends coordinate-wise FFT test helpers to B2 coordinates.
prover-ray/maths/koalabear/polynomials/lagrange_bench_test.go Adds extension Lagrange evaluation benchmarks.
prover-ray/maths/koalabear/polynomials/canonical_test.go Updates extension random/equality helpers for E6.
prover-ray/maths/koalabear/field/vec.go Updates extension-degree and operation-cost comments.
prover-ray/maths/koalabear/field/gen.go Updates extension-degree and multiplication-cost comments.
prover-ray/maths/koalabear/field/gen_test.go Extends test equality helper to B2 coordinates.
prover-ray/maths/koalabear/field/ext.go Migrates field.Ext helpers, serialization, constructors, and inversion to E6.
prover-ray/maths/koalabear/field/ext_test.go Updates extension-field tests for six coordinates and 24-byte encodings.
prover-ray/maths/koalabear/field/ext_bench_test.go Adds extension arithmetic/vector benchmarks.
prover-ray/maths/koalabear/circuit/ext.go Reworks circuit extension type/arithmetic/hints from E4 to E6.
prover-ray/maths/koalabear/circuit/doc.go Updates package documentation to degree-6 extension fields.
prover-ray/go.mod Updates gnark-crypto to the E6-supporting pseudo-version.
prover-ray/go.sum Updates checksums for the new gnark-crypto dependency.
prover-ray/crypto/koalabear/vortex/verifier_common.go Replaces upstream E4 Horner helpers with local E6-compatible evaluators.
prover-ray/crypto/koalabear/vortex/utils.go Updates FFT inverse hint chunking and FFT call to E6.
prover-ray/crypto/koalabear/ringsis/ringsis.go Switches extension FFT calls to E6 variants.
prover-ray/crypto/koalabear/reedsolomon/reedsolomon.go Switches extension Reed-Solomon FFT paths/vector casts to E6.
prover-ray/crypto/koalabear/fiatshamir/poseidon2.go Updates transcript absorption/sampling for six extension coordinates.

Comment thread prover-ray/transition_fp6_worklog.md Outdated
Comment thread prover-ray/transition_fp6_worklog.md Outdated
Comment thread prover-ray/transition_fp6_worklog.md Outdated
Comment thread prover-ray/maths/koalabear/circuit/ext.go Outdated
Comment thread prover-ray/transition_fp6_worklog.md Outdated
Comment thread prover-ray/maths/koalabear/polynomials/lagrange_bench_test.go Outdated
Comment thread prover-ray/maths/koalabear/circuit/ext.go
Comment thread prover-ray/maths/koalabear/field/ext_test.go
Comment thread prover-ray/maths/koalabear/circuit/ext.go Outdated
Comment thread prover-ray/maths/koalabear/circuit/ext.go Outdated
Merge origin/main into prover/fp6.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants