Skip to content

feat: add LowLevel.GF16Mul for GF(2^16) field multiplication#327

Merged
klauspost merged 6 commits intoklauspost:masterfrom
rootulp:add-gf16-public-api
Mar 6, 2026
Merged

feat: add LowLevel.GF16Mul for GF(2^16) field multiplication#327
klauspost merged 6 commits intoklauspost:masterfrom
rootulp:add-gf16-public-api

Conversation

@rootulp
Copy link
Contributor

@rootulp rootulp commented Mar 6, 2026

Summary

Expose a thin public wrapper around the existing internal GF(2^16) log/exp table arithmetic in leopard.go, as a method on the existing LowLevel type:

  • LowLevel.GF16Mul(a, b uint16) uint16 — multiplies two elements in GF(2^16) using the existing logLUT/expLUT tables. Initializes lazily on first use via the existing sync.Once-guarded initConstants.

No new math or tables are introduced — this is purely a public API surface over already-existing internals.

Motivation

Celestia currently maintains a fork of this repository solely to access GF(2^16) field multiplication for their data availability layer. The diff is small: master...celestiaorg:reedsolomon:master

Upstreaming this allows us to drop the fork and depend on this repo directly.

Test plan

  • TestGF16MulZero — anything × 0 = 0
  • TestGF16MulOne — multiplicative identity
  • TestGF16MulCommutativity — a×b = b×a
  • TestGF16MulAssociativity — (a×b)×c = a×(b×c)
  • TestGF16MulDistributivity — a×(b⊕c) = a×b ⊕ a×c (GF addition is XOR)
  • TestGF16MulConsistentWithInternal — agrees with internal mulLog

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added GF(2^16) multiplication functionality for finite field operations.
  • Tests

    • Added comprehensive unit tests validating mathematical properties including zero behavior, multiplicative identity, commutativity, associativity, and distributivity.

Expose two thin wrappers around the existing internal GF(2^16) log/exp
table arithmetic in leopard.go:

- GF16Init: explicitly pre-initializes the lookup tables (optional;
  useful for amortizing startup cost)
- GF16Mul: multiplies two GF(2^16) elements, auto-initializing lazily
  on first use via the existing sync.Once-guarded initConstants

This allows downstream consumers (e.g. celestia-app) to perform
standalone GF(2^16) field arithmetic without maintaining a fork of this
repository.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: af8e96f3-1cea-4c14-a4bd-f5ebd85e878d

📥 Commits

Reviewing files that changed from the base of the PR and between 1840903 and 9eac6ab.

📒 Files selected for processing (2)
  • gf16.go
  • gf16_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • gf16_test.go
  • gf16.go

📝 Walkthrough

Walkthrough

Adds a new method GF16Mul to the reedsolomon package implementing GF(2^16) multiplication using precomputed log/exp lookup tables with lazy initialization via initConstants(), plus unit tests validating algebraic properties and edge cases.

Changes

Cohort / File(s) Summary
Implementation
gf16.go
Adds func (l LowLevel) GF16Mul(a, b uint16) uint16 which lazily calls initConstants(), returns 0 if either operand is 0, computes multiplication via logLUT/expLUT with modular reduction, and uses a LowLevel receiver. No other public declarations changed.
Tests
gf16_test.go
Adds tests verifying multiplication by zero and one, commutativity, associativity, distributivity (XOR as addition), and consistency with internal mulLog/lookup-table behavior across representative and boundary values.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a GF16Mul method to the LowLevel type for GF(2^16) field multiplication, which is exactly what the changeset delivers.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rootulp rootulp changed the title Add public GF16Init and GF16Mul for GF(2^16) field arithmetic feat: add GF16Init and GF16Mul for GF(2^16) field arithmetic Mar 6, 2026
@rootulp rootulp marked this pull request as ready for review March 6, 2026 00:17
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@gf16.go`:
- Around line 3-7: The doc comment on GF16Init is misleading—update it to state
that GF16Init is optional (it calls initConstants()) and not required because
GF16Mul performs lazy initialization on first use; specifically, change the
sentence "This must be called before using GF16Mul" to indicate the function
precomputes tables for performance but GF16Mul will call initConstants() itself
if needed. Reference: GF16Init, GF16Mul, and initConstants.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3194888a-155f-4bdd-bba6-a12a1e4b7555

📥 Commits

Reviewing files that changed from the base of the PR and between 182993e and 987764f.

📒 Files selected for processing (2)
  • gf16.go
  • gf16_test.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@rootulp
Copy link
Contributor Author

rootulp commented Mar 6, 2026

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rootulp
Copy link
Contributor Author

rootulp commented Mar 6, 2026

CI passed on re-trigger

Co-authored-by: Klaus Post <klauspost@gmail.com>
@rootulp rootulp marked this pull request as draft March 6, 2026 15:35
Co-authored-by: Klaus Post <klauspost@gmail.com>
@rootulp rootulp changed the title feat: add GF16Init and GF16Mul for GF(2^16) field arithmetic Add LowLevel.GF16Mul for GF(2^16) field multiplication Mar 6, 2026
…e tests

- Remove stale doc comment referencing deleted GF16Init()
- Remove extra blank line in gf16.go
- Update all tests to call GF16Mul as a LowLevel method
- Remove TestGF16Init (function was deleted per maintainer feedback)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rootulp rootulp changed the title Add LowLevel.GF16Mul for GF(2^16) field multiplication feat: add LowLevel.GF16Mul for GF(2^16) field multiplication Mar 6, 2026
@rootulp rootulp marked this pull request as ready for review March 6, 2026 15:44
@rootulp
Copy link
Contributor Author

rootulp commented Mar 6, 2026

Thanks for the review @klauspost! I addressed feedback.

@rootulp rootulp requested a review from klauspost March 6, 2026 16:00
@klauspost klauspost merged commit c9e2c2e into klauspost:master Mar 6, 2026
17 checks passed
@klauspost
Copy link
Owner

arm64 crash in #328

I will probably do a release once that is in.

@rootulp rootulp deleted the add-gf16-public-api branch March 6, 2026 18:07
rootulp added a commit to celestiaorg/celestia-app that referenced this pull request Mar 6, 2026
…dsolomon

klauspost/reedsolomon#327 merged the GF16Mul API upstream, so we no
longer need to maintain the celestiaorg fork. This updates the two
packages that imported the fork (rsema1d/field and rsema1d/encoding)
to use the upstream LowLevel.GF16Mul method instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rootulp
Copy link
Contributor Author

rootulp commented Mar 9, 2026

I see #328 was resolved so will wait for the release and bump to it in celestia-app.

Thanks for your hard work maintaining this repo!

@klauspost
Copy link
Owner

Didn't want to release on a Friday, since I wouldn't be available for fixes. Released https://github.com/klauspost/reedsolomon/releases/tag/v1.13.3

github-merge-queue bot pushed a commit to celestiaorg/celestia-app that referenced this pull request Mar 9, 2026
…dsolomon

klauspost/reedsolomon#327 merged the GF16Mul API upstream, so we no
longer need to maintain the celestiaorg fork. This updates the two
packages that imported the fork (rsema1d/field and rsema1d/encoding)
to use the upstream LowLevel.GF16Mul method instead.

Co-Authored-By: Claude Opus 4.6 <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.

2 participants