Feat/curve generic zolt arith#76
Merged
Merged
Conversation
Add a curve-generic MontgomeryField(N, modulus, r2, inv) factory and extension field factories (Fp2, Fp6, Fp12) to zolt-arith, enabling multi-curve support alongside the existing BN254 stack. Architecture: - src/curves/montgomery_field.zig: comptime-N generic field with 40+ methods, x86 BMI2+ADX asm mul, ARM64 asm dispatch, LLVM adc/sbb intrinsics for add/sub, ProductAccum for deferred reduction - src/curves/extensions.zig: generic Fp2(BaseFp), Fp6(Fp2, mulByXi), Fp12(Fp6, Fp2) factories - src/curves/bn254/: BN254 params + instantiation through generic factory - src/curves/bls12_381/: full BLS12-381 implementation (G1/G2/pairing/ hash-to-curve/BLS sign+verify) for zyli's validator verification - src/bigint.zig: generic N-limb arithmetic BN254 migration: - BN254Scalar = curves.bn254.Fr (generic factory replaces 1000+ line bespoke struct) - BN254BaseField uses in-file MontgomeryField for optimal codegen - Fp2 = curves.extensions.Fp2(Fp) (generic factory) - Fp6 = curves.extensions.Fp6(Fp2, bn254MulByXi) (generic factory) - UnreducedProductAccum = BN254Scalar.ProductAccum (generic) Performance: zero regression — generated assembly is byte-for-byte identical to the original (verified via objdump diff). All x86-64 BMI2+ADX and AArch64 inline asm paths preserved. Also fixes pre-existing build breakage from llvm.x86.addcarry.u64 intrinsics (mode-guarded: Release uses intrinsics, Debug uses u128). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ity with OG - inverse: replace `inline for (0..N*64)` with runtime inner loop to avoid icache blowout from 256+ inlined square/mul blocks (80% Fr inverse regression) - Fp2.mul: use sumOfProducts fusion when BaseFp supports it (2 reductions instead of 3 via Karatsuba) - Fp2.square: use addNoReduce for (a+b) when available (saves 1 reduction) - Move @setEvalBranchQuota before arm64 early-return in add/sub/ subtractModulus to fix comptime branch limit errors on N=6 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
No description provided.