Skip to content

fix(SafeFiniteField): reject irreducibles not of degree n before reduction - #229

Merged
hyperpolymath merged 1 commit into
mainfrom
fix/finite-field-irr-degree
Oct 6, 2026
Merged

hyperpolymath merged 1 commit into
mainfrom
fix/finite-field-irr-degree

Conversation

@hyperpolymath

@hyperpolymath hyperpolymath commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

Summary

This is a follow-up to #228. It fixes the CodeRabbit finding on that PR (#228 (comment)), which was merged before the fix could be pushed to it.

bfMulWithIrr could hang if irr did not have degree exactly n. A polynomial of the wrong degree never cancels the top bit of the product, so polyModReduction looped forever, and the range check added in #228 never ran. For example, irr = 0 with 0x80 • 0x02 hangs. Now bfMulWithIrr returns Nothing unless bitLength irr == S n, and it checks this before reducing. When the degree is exactly n, each reduction step clears the top bit, so the loop terminates.

Type of change

  • 🐛 Bug fix (non-breaking change that fixes an issue): bfMulWithIrr hangs on an invalid polynomial
  • ✨ New feature: not applicable
  • 💥 Breaking change: no; the signature is unchanged (it already returned Maybe after fix(soundness): remove false postulates in SafeFiniteField, SafePipe, SafeTerminal #228)
  • 🕳️ Soundness fix: not applicable; this is a termination and availability bug, not a proof hole
  • 📖 Documentation: not applicable
  • 🧹 Refactor / tech debt: not applicable
  • ⚡ Performance: not applicable
  • 🔧 Build / CI / tooling: not applicable

📌 New pins

Head SHA: bb82eeb. No action, lockfile or container pins are added or changed; only src/Proven/SafeFiniteField.idr is touched.

How has this been verified?

All runs used Idris2 0.8.0 locally, on the identical file content (originally commit 178a01d, cherry-picked here):

  • idris2 -p contrib --total --check src/Proven/FFI/SafeFiniteField.idr (which builds SafeFiniteField): rc=0. The only warning is the pre-existing SIsNonZero deprecation.
  • --exec harness with bfMulWithIrr {n=8}:
    • FIPS-197 vectors with aesIrreducible: 0x57•0x83 = 193, 0x57•0x13 = 254, 0x02•0x80 = 27, all correct.
    • irr = 0 → Nothing, and irr = 0x1B (degree 4) → Nothing. Both previously hung.

CI red checks: all pre-existing on main, none caused by this diff, deferred to #230

Checklist

  • My commits are signed (SSH key).
  • I ran the project's own checks/tests locally and they pass: the module typecheck and the harness above. The full proven.ipkg build is left to CI, because the local build is memory-bound on this host.
  • New files carry the correct SPDX-License-Identifier: no new files.
  • Docs are updated, and no public claim now overstates what the code does: the docstrings for bfMulWithIrr and the new bitLength describe the behaviour.
  • I have not introduced a soundness hole: no postulates are added, and bitLength is covering, like the existing highestBit.

Notes for reviewers

🤖 Generated with Claude Code

https://claude.ai/code/session_01HZc76cZKg5tUgduxXGLQkD

…ction

A polynomial of the wrong degree never cancels the top bit, so
polyModReduction looped forever (e.g. irr = 0, 0x80 * 0x02) before the
range check could run. bfMulWithIrr now returns Nothing unless
bitLength irr == n + 1. Addresses CodeRabbit review on #228.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HZc76cZKg5tUgduxXGLQkD
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 12 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: bfd40f55-50f3-4c21-b1d0-d5d1754f2d36
📥 Commits

Reviewing files that changed from the base of the PR and between ced0ca5 and bb82eeb.

📒 Files selected for processing (1)
  • src/Proven/SafeFiniteField.idr
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@sonarqubecloud

sonarqubecloud Bot commented Oct 6, 2026

Copy link
Copy Markdown

@hyperpolymath
hyperpolymath merged commit a32c3b6 into main Oct 6, 2026
42 of 49 checks passed
@hyperpolymath
hyperpolymath deleted the fix/finite-field-irr-degree branch October 6, 2026 18:41
@coderabbitai

coderabbitai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Add Carrot credits or activate Agent usage billing to use Autopilot

hyperpolymath added a commit that referenced this pull request Oct 7, 2026
## Summary

Adds `AFFIRMATION.adoc`, the third file of the README / EXPLAINME /
AFFIRMATION trio. It is a dated snapshot, open to refutation, of what
proven can honestly claim at `main` **53600326**. It also lists what
proven does **not** claim.

- **Affirmed:**
  - `proven.ipkg` builds 305/305 modules in CI;
  - `proof-check (0.8.0)` passes;
  - there is no `believe_me` or `idris_crash` in code;
  - the false postulates are gone (#228, #229);
  - gitleaks is clean (#231).
- **Not claimed:**
  - the README's "Mathematically proven" (PROOF-NEEDS samples about 3%);
  - the bodyless declarations that act as postulates;
  - 22 escape hatches;
  - the stubbed hash FFI;
  - `tests.ipkg` (it does not build);
  - about 79 unbuilt modules;
  - the weak or empty theorems;
  - the red checks on #230;
  - a pinned CI image.

Where the README says more than this file, this file wins.

Refs #230

## Type of change

- [ ] 🐛 Bug fix: no
- [ ] ✨ New feature: no
- [ ] 💥 Breaking change: no
- [ ] 🕳️ Soundness fix: no
- [x] 📖 Documentation
- [ ] 🧹 Refactor / tech debt: no
- [ ] ⚡ Performance: no
- [ ] 🔧 Build / CI / tooling: no

## 📌 New pins

Head SHA: **c25c3b5e302b9d66e1ae945ad47c72053c7d7234**

None. This PR changes no action `uses:`, `actions.lock`, lockfile or
container digest.

## How has this been verified?

Every claim cites its evidence in the file:

- **The build:** CI job `verify-idris-build` (id 112464109461) at
5360032 ends with `305/305: Building Proven`.
- **The test build:** `idris2-ci.yml` at a32c3b6 gave proof-check
success and build failure. The failure comes from the `tests.ipkg`
renames in bdb1863.
- **The escape-hatch counts:** `grep -rnw --include=*.idr <word> src`,
with comment and doc-comment lines removed:
  - `believe_me` 0 (the 48 raw matches are all comments);
  - `idris_crash` 0;
  - `assert_total` 20;
  - `assert_smaller` 2.
- **The hash stubs:** `Hash.idr` has 9 `%foreign` lines, all commented
out.
- **The recon figures** (383 bodyless, 79 unbuilt, 52 warnings, 71 `()`
theorems) are labelled as measured at 8542e84 and not re-counted here.
- **The 3%** is quoted from `PROOF-NEEDS.adoc` (1 of 32 sampled
modules).
- **Placeholder check:** the file contains no `{{`, `TODO: update`,
`<PROJECT` or `example.com`. It has 103 substantive lines.

## Checklist

- [x] My commits are **signed** (`git log --format=%G?` → `G`).
- [x] I ran the project's own checks: no Idris source changed, so there
was nothing to rebuild. The evidence is CI's at the anchor.
- [x] New files carry the correct `SPDX-License-Identifier`:
`CC-BY-SA-4.0`, as for the repo's other `.adoc` docs, with the
attribution line from `.claude/CLAUDE.md`.
- [x] Docs: this *is* the docs change. Correcting the README overclaim
is item C4 of the follow-up and is not done here.
- [x] No soundness hole: no `.idr` file is touched.

## Notes for reviewers

- The anchor is the **parent** of this commit. A squash merge changes
the commit SHA but keeps 5360032 as the parent, so the anchor stays
valid only if nothing else lands on `main` first. If something does,
rebase this branch and re-check the anchor row.
**Pre-existing red checks** (red on `main` too; this PR does not touch
them):
- `governance / Workflow security linter`: deferred to #230 (dead OCaml
pin)
- `governance / Trusted-base reduction policy`: deferred to #230
(undocumented escape hatches)
- `governance / Validate Hypatia Baseline`: deferred to #230
(`--argjson` crash in standards)
- `Enforce Trustfile Policies`: deferred to #230 (Palimpsest licence
headers)
- `Aspect — Safety Invariants`: deferred to #230

- **Emerged, not yet on #230:** `GitHub Pages / build` is blocked by the
action allowlist on `actions/upload-artifact@v4`. The `mirror-*` ×3 jobs
have an empty host variable. Both are recorded in
`dev-notes/inbox/findings.md`.
- There are no required checks on `main`, so automerge is deliberately
**not** armed. This waits for a human squash merge.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01HZc76cZKg5tUgduxXGLQkD

Co-authored-by: Claude Opus 5.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