Split Bls into per-type files; generate G1/G2 from a shared template#10
Open
Marchhill wants to merge 2 commits into
Open
Split Bls into per-type files; generate G1/G2 from a shared template#10Marchhill wants to merge 2 commits into
Marchhill wants to merge 2 commits into
Conversation
Pure move: each nested type and the native imports it uses now live in their own partial class file Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The two point groups were near-identical copies that could drift apart silently. Bls.G1.cs and Bls.G2.cs are now rendered from PointGroup.template by the Nethermind.Crypto.Bls.Gen console project; the generated files stay checked in and reviewable, and CI verifies they match the template. Normalizations from unifying the two sides: P2 gains FromSk (parity with P1), P2.Mult(BigInteger) uses the same helper shape as P1, redundant readonly/scoped modifiers and comments are now consistent. No behavioral changes; all tests pass. Co-Authored-By: Claude Fable 5 <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.
Stacked on #9 (diff shown against it; retarget to main once #9 merges).
Summary
Two commits:
Pure move:
Bls.cs(~1,900 lines) is split into per-type partial class files —Bls.cs(loader,ERROR,BlsException, shared constants),Bls.SecretKey.cs,Bls.Scalar.cs,Bls.G1.cs,Bls.G2.cs,Bls.Gt.cs,Bls.Pairing.cs— with each type's native imports next to it. No code changes; zero API impact since the class was alreadypartial.Generate G1/G2 from one template: the two point groups were ~95% duplicated code whose subtle intentional differences (fp ordering in
P2.TryDecode, coordinate counts, thesign_pk_in_*swap) could drift apart silently.Bls.G1.csandBls.G2.csare now rendered fromsrc/Nethermind.Crypto.Bls.Gen/PointGroup.templateby a small C# console project (dotnet run --project src/Nethermind.Crypto.Bls.Gen); the differences live in explicit//<<g1-only///<<g2-onlyblocks and named tokens. A new CI job regenerates and fails on drift.Why checked-in generation rather than a Roslyn source generator
For a crypto library the shipped logic should be auditable in the repo: generated-but-committed files mean reviewers see actual C# in every PR diff, IDE navigation/debugging work on real files, and the package build stays plain (no analyzer wiring). The CI drift check gives the same can't-diverge guarantee a source generator would.
Normalizations from unifying the two sides (no behavioral change)
P2gainsFromSk(parity withP1, additive API)P2.Mult(BigInteger)refactored to the samePrepareMult/GetSizeshape asP1readonlymember modifiers andscopedparameters across both groupsAll 57 tests pass; the generator is idempotent (regenerating on a clean tree produces no diff).
🤖 Generated with Claude Code