Skip to content

correction: Drop redundant BCH decoding paths - #150

Merged
BenWestgate merged 1 commit into
bails-v1-pinfrom
claude/simplify-correction
Oct 19, 2026
Merged

BenWestgate merged 1 commit into
bails-v1-pinfrom
claude/simplify-correction

Conversation

@BenWestgate

Copy link
Copy Markdown
Owner

Before: correction.py re-checked every BCH correction against the full residue, fell back to the linear erasure solver after any failed BCH decode, and carried erasure-product tables that were never built. It was 953 lines.

After: the same results from 884 lines (cloc 804 → 734). The package size budget goes from 4,986 to 4,921 lines. Insertion/deletion correction is untouched.

The removed paths can't change a result:

  • Residue re-check. The generator is the product of the minimal polynomials of the 8 consecutive roots. So GF(32) corrections that clear those 8 syndromes also clear the conjugate roots, and the decoder already rejects Forney values outside GF(32).
  • Linear fallback with 8 or fewer erasures. An erasure-only solution leaves the Forney syndromes at zero, so BCH already finds it. The solver now runs only when the erasures exceed the BCH roots.
  • Dead code. The erasure-product plumbing, _error_corrections (its length and limit parameters were unused) and two no-op except TypeError: raise clauses.

How: one commit to src/codex32/correction.py. Every name that indel.py, the GUI, the CLI, the tests and the tools import is still there. Swapping _small_locator for Berlekamp–Massey was tried and reverted. It gave the same results but made the bounded indel search about 15% slower, which could change truncation under the ten-second deadline.

Tests:

  • pytest -q, both normally and with python -O: 987 passed, the same as before the change.
  • ruff check, ruff format --check and mypy src/codex32 are clean.
  • tools/differential_correction.py --verify, tools/differential_wallet.py --verify and tools/verify_correction_constants.py pass.
  • An old-vs-new comparison over 6 random seeds matched exactly, including every exception. It covered about 40k decoder calls, 10k damaged strings with up to 14 errors or erasures, and 20k worksheet residues with up to 15 erasures.

The wallet oracle's pinned bip32 source wasn't reachable here, so the wallet differential ran against bip32==5.0.0 from PyPI. Separately, tools/correction_benchmark.py already fails to import on bails-v1-pin because _automatic_targets is missing.


Generated by Claude Code

Remove code from the substitution and erasure decoder that cannot change
a result.

Every BCH correction was re-checked against the full residue. The check
cannot fail. The generator is the product of the distinct minimal
polynomials of the 8 consecutive roots. GF(32) values that clear those
syndromes also clear the conjugate roots, so the generator divides the
corrected word. The linear erasure solver already rejects inconsistent
systems. Delete _corrections_reach_target.

The linear solver ran after a failed BCH decode even with at most 8
erasures. In that case an erasure-only solution leaves the Forney
syndromes zero, so BCH would already have found it. Call the solver only
when the erasures exceed the BCH roots. The worksheet path now makes the
same choice inline, so _error_corrections is gone. Its word-length and
substitution-limit parameters were unused.

The precomputed erasure-product tables were never built. Remove that
plumbing from _locator_poly, _bch_syndrome_corrections, _repair_body and
_FixedCorrector. Also drop the no-op "except TypeError: raise" clauses.

Keep the direct small-locator solve. Replacing it with Berlekamp-Massey
for every call returned identical results but made the bounded indel
search about 15% slower, which could change truncation under the ten-
second deadline.

Validation: full pytest in normal and -O modes; differential_correction
and differential_wallet --verify; verify_correction_constants; ruff
check, ruff format --check and mypy. An offline comparison against the
previous module found identical results for random BCH syndromes,
damaged ms strings with up to 14 errors or erasures, and worksheet
residues with up to 15 erasures.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T12:21:34.883391Z 35346a9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@BenWestgate BenWestgate left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

LGTM

@BenWestgate

Copy link
Copy Markdown
Owner Author

Also send this upstream to the v1 staging.

@BenWestgate
BenWestgate merged commit ad3e406 into bails-v1-pin Oct 19, 2026
12 checks passed
@BenWestgate
BenWestgate deleted the claude/simplify-correction branch October 19, 2026 20:35
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