Skip to content

Split Bls into per-type files; generate G1/G2 from a shared template#10

Open
Marchhill wants to merge 2 commits into
review/fixes-tests-benchmarksfrom
refactor/generate-point-groups
Open

Split Bls into per-type files; generate G1/G2 from a shared template#10
Marchhill wants to merge 2 commits into
review/fixes-tests-benchmarksfrom
refactor/generate-point-groups

Conversation

@Marchhill

Copy link
Copy Markdown
Collaborator

Stacked on #9 (diff shown against it; retarget to main once #9 merges).

Summary

Two commits:

  1. 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 already partial.

  2. 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, the sign_pk_in_* swap) could drift apart silently. Bls.G1.cs and Bls.G2.cs are now rendered from src/Nethermind.Crypto.Bls.Gen/PointGroup.template by a small C# console project (dotnet run --project src/Nethermind.Crypto.Bls.Gen); the differences live in explicit //<<g1-only / //<<g2-only blocks 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)

  • P2 gains FromSk (parity with P1, additive API)
  • P2.Mult(BigInteger) refactored to the same PrepareMult/GetSize shape as P1
  • consistent readonly member modifiers and scoped parameters across both groups
  • constructor placement, comments and blank lines aligned

All 57 tests pass; the generator is idempotent (regenerating on a clean tree produces no diff).

🤖 Generated with Claude Code

Marchhill and others added 2 commits July 7, 2026 18:49
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>
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.

1 participant