feat(fields): add fast Goldilocks arithmetic - #262
Conversation
🤖 PR SummaryOverviewThis PR adds a complete, verified, high-performance implementation of the Goldilocks prime field Mathematical Formalization
Proof Completion (no sorries added) Protocols / Soundness
Infrastructure / CI
Documentation
Refactoring
Tests
The core mathematical and verification work is concentrated in the Note on PR body: The PR body was empty; this summary is based entirely on the per-file summaries. Statistics
Lean Declarations ✏️ Removed: 3 declaration(s)
✏️ Added: 151 declaration(s)
…and 1 more not listed.
📋 **Additional Analysis**The PR introduces a fast native-word implementation of the Goldilocks field, including verified reduction arithmetic, a transferred field structure, extern-backed performance primitives, and tests. The contribution is substantial and well-structured, but several violations of the project's style guide and pull request guidelines are present. The most significant issue is the absence of updates to 📄 **Per-File Summaries**
Last updated: 2026-07-20 08:30 UTC. |
dhsorens
left a comment
There was a problem hiding this comment.
Summary
Verified Goldilocks.Fast looks solid: modular split (Internal/Reduction/Arithmetic/Theorems), Goldilocks reduction (not Montgomery), toField_* bridge, and #guard tests match the Baby/Koala Fast bar. C/FastExt is fine as experimental perf scaffolding.
Blockers: green CI (namespace), keep FastExt out of the default TCB (import + link), rebase onto current main.
Inline notes are the actionable items.
| -/ | ||
|
|
||
| namespace Goldilocks | ||
| namespace Basic |
There was a problem hiding this comment.
Build break. Nested namespace Basic renames the public API to Goldilocks.Basic.fieldSize / .Field. CI fails in benches that still use Goldilocks.fieldSize / Goldilocks.is_prime.
Prefer namespace Goldilocks only (like BabyBear/KoalaBear) so callers keep Goldilocks.Field.
| import CompPoly.Fields.Goldilocks.Fast.Internal | ||
| import CompPoly.Fields.Goldilocks.Fast.Reduction | ||
| import CompPoly.Fields.Goldilocks.Fast.Theorems | ||
| import CompPoly.Fields.Goldilocks.FastExt |
There was a problem hiding this comment.
TCB / packaging. Drop this umbrella import.
FastExt should stay experimental/test-only (and later optional benches). Default import CompPoly must not pull @[extern] opaques into the main library surface. Only the FastExt test (and future opt-in consumers) should import it.
| @[default_target] | ||
| lean_lib CompPoly | ||
| lean_lib CompPoly where | ||
| moreLinkArgs := nativeLinkArgs "goldilocks_native" |
There was a problem hiding this comment.
TCB / packaging. Don't link goldilocks_native into the main CompPoly (or CompPolyTests) libs.
Keep moreLinkArgs only on CompPolyGoldilocksFastExtTests (and later any exe that deliberately uses Ext). Verified Fast needs no C; everyday builds shouldn't expand the trust/link surface.
| operations to external code for performance, so their arithmetic correctness | ||
| depends on the linked extern implementations. | ||
|
|
||
| These declarations are a trusted native boundary: Lean checks that the wrappers |
There was a problem hiding this comment.
Docs nit. Please state explicitly that this module is not for production CompPoly proofs / default field use: experimental performance path + regression against verified Goldilocks.Fast only. C is outside the Lean TCB.
(Also fine to note: nothing in-tree uses Ext for benches yet — tests only for now.)
| * therefore part of the trusted native boundary for the extern-backed API. | ||
| * | ||
| * The verified Lean implementation remains the default field implementation; | ||
| * this native code is used only by the opt-in FastExt module. |
There was a problem hiding this comment.
Follow-ups:
- Rebase onto current main (Lean/Mathlib 4.32).
- Update
Fields/README.mdfor the Basic/Fast split. - Optional later: a small bench comparing Lean Fast mul vs
mulNativeso the perf-spec story is real — not required to merge once packaging is test-only.
No description provided.