Skip to content

Add error correction (ECW) support per BIP-93#4

Open
kiwihodl wants to merge 3 commits into
FractalEncrypt:masterfrom
kiwihodl:error-correction-ecw
Open

Add error correction (ECW) support per BIP-93#4
kiwihodl wants to merge 3 commits into
FractalEncrypt:masterfrom
kiwihodl:error-correction-ecw

Conversation

@kiwihodl

@kiwihodl kiwihodl commented Feb 1, 2026

Copy link
Copy Markdown

Summary

Implements BIP-93 Error Correction Wallet (ECW) capability:

  • Up to 4 substitution errors correctable
  • Up to 8 erasure errors correctable (when positions are known)
  • User confirmation required before applying corrections (per BIP-93)

Implementation Approach

Uses validated brute-force search rather than raw BCH decoding:

  • Generates correction candidates
  • Validates each using the codex32 library's checksum
  • Guarantees correctness (every candidate is verified)
  • Safer for Bitcoin seed handling

New Files

File Purpose
src/gf32.py GF(32) Galois Field arithmetic
src/error_correction.py Error correction search algorithm
src/bch_decoder.py BCH algorithms (reference implementation)
tests/test_gf32.py 18 field arithmetic tests
tests/test_correction.py 22 edge case tests
tests/test_bch.py BCH decoder unit tests

Test Coverage

51 total tests covering:

  • Happy path (valid strings, 1-2 error correction)
  • Edge cases (empty, whitespace, None, invalid chars, wrong length)
  • Position boundaries (start, end, prefix)
  • Boundary conditions (max_errors=0, clamping)
  • Erasure edge cases (negative pos, out of range, too many)
  • Utility functions

Test Results

=== test_vectors.py ===
vector2: seed OK
vector3: seed OK

=== test_256bit.py ===
All 256-bit tests passed! (9 tests)

=== test_gf32.py ===
All GF(32) tests passed! (18 tests)

=== test_correction.py ===
All 22 tests passed!

How to Test

cd codex32_terminal
source venv/bin/activate
python tests/test_vectors.py
python tests/test_256bit.py
python tests/test_gf32.py
python tests/test_correction.py

🤖 Generated with Claude Code

kiwihodl and others added 3 commits January 31, 2026 16:02
- Support both 128-bit (48 chars, 12 words) and 256-bit (74 chars, 24 words) seeds
- Auto-detect seed size from codex32 string length
- Box mode prompts user to select seed size upfront
- Full-paste mode auto-detects from input

Changes:
- model.py: Add VALID_LENGTHS mapping, update parse/validate functions
- controller.py: Add seed size selection for box mode
- view.py: Add get_seed_size_choice(), update success display
- tests/test_256bit.py: New test file with BIP-93 Vector 4

All existing 128-bit functionality preserved (backward compatible).
- Implement validated brute-force error correction
- Support up to 4 substitution errors
- Support up to 8 erasure errors (known positions)
- User confirmation required before applying corrections
- Add GF(32) field arithmetic module
- Add comprehensive test suite (51 tests total)
- Add .gitignore for Python artifacts

New files:
- src/gf32.py: GF(32) Galois Field arithmetic
- src/error_correction.py: Error correction search
- src/bch_decoder.py: BCH algorithms (reference)
- tests/test_gf32.py: 18 field arithmetic tests
- tests/test_correction.py: 22 edge case tests
- tests/test_bch.py: BCH decoder tests

Modified files:
- src/model.py: Added try_correct_codex32_errors()
- src/controller.py: Integrated correction into entry flow
- src/view.py: Added correction UI functions
- README.md: Documented ECW capability

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove redundant if/elif in seed_bytes_to_mnemonic (same fix as other PRs)
- Remove unused VALID_LENGTHS import from controller
- Add NOTE to bch_decoder.py explaining it's kept for future optimization
- Improve test comment explaining search space calculation

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