Repository navigation
feat(fields): fast secp256k1 fields on the eight-limb Montgomery stack - #389
Conversation
🤖 PR SummaryThis pull request adds fast secp256k1 scalar and base field arithmetic using the shared eight-limb Montgomery stack, while simultaneously generalizing the stack to support moduli up to 2^256 (previously capped at 2^255). The change touches core arithmetic definitions, proofs, type classes, and adds new module files, benchmarks, and regression tests. Statistics
Lean Declarations ✏️ Removed: 9 declaration(s)
✏️ Added: 40 declaration(s)
✏️ Affected: 3 declaration(s) (line number changed)
📋 **Additional Analysis**The diff is relevant to the supplied instructions. Below are findings organized by the categories emphasized in the deployment-supplied guidelines. 📄 **Per-File Summaries**
Last updated: 2026-10-20 10:50 UTC. |
|
Thanks! I actually needed this today and was about to work on a PR for this! |
The merge with main kept main's imports in Secp256k1.lean, so the facade no longer re-exported Secp256k1.Basic and Secp256k1.Fast. Restore them, and move the Mathlib.Algebra.Field.ZMod import that the Lean v4.35.0 bump (Verified-zkEVM#400) added to Secp256k1/Basic.lean, which now holds the ZMod models.
dhsorens
left a comment
There was a problem hiding this comment.
awesome, thank for this! merging
Fast secp256k1 scalar and base field arithmetic on the shared eight-limb Montgomery stack, in pure Lean, no externs, no native_decide.
Earlier drafts folded the carry into the existing branch (short-circuit || and a single flag word); both cost 5-8% on mul or add through a join point or a serialized select, so the carry got its own never-taken branch. The 4x64 special-form secp reduction from PR #271 was benched against this: mul 3-5% faster at the secp order, add 4x slower, Fermat inverse 8x slower, so it was dropped.