Skip to content

checksums: XOR CRC2-CRC4 padding with all ones - #216

Open
BenWestgate wants to merge 1 commit into
reviewability-v1from
claude/project-thread-v4jzcb
Open

BenWestgate wants to merge 1 commit into
reviewability-v1from
claude/project-thread-v4jzcb

Conversation

@BenWestgate

@BenWestgate BenWestgate commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Before: generated ms strings fill their spare bits with a CRC that starts from 1 and has no final XOR. A 24-byte seed extended with zero bits and read as a 64-byte seed keeps valid CRC3 padding, so the padding cannot tell the two apart.

After: CRC2 to CRC4 end with an all-ones XOR, matching the spare-bit CRC in the codex32 key-expressions draft. That extension never keeps valid padding, because the 320 added bits are not a multiple of CRC3's period of 7. CRC1 stays odd parity, because an XOR there would give every all-zero 28-byte seed valid padding.

Strings made before this change still parse, since padding is never enforced. When correction finds several equally good candidates, it now prefers the new padding, then the old no-XOR padding, then neither. The wallet fingerprint hint still comes after both.

How: the CRC2 to CRC4 constants in checksums.py become 0b11, 0b111 and 0b1111. _has_legacy_generation_padding in profiles/ms32.py recognises the old padding, and correction.py uses it as a second hint in _best and as a sort key. CorrectionCandidate is unchanged. The frozen-convention section in docs/developer/api.md gives the new representative outputs and the reason for the XOR.

BIP93 vectors 3 and 4 now generate their secret_s_alternate_3 and secret_s_alternate_7 strings, not secret_s. The vector 3 test derives its shares from the official secret_s. A new test checks the tie-break order and fails without the correction.py change. Strings from v0.4.0, which started the CRC from 0, get no preference.

Validation: python -O -m pytest -q gave 913 passed on this commit. python -m pytest -q gave 911 passed before the two vector-test updates, which then passed on rerun. Ruff check and format, and python -m mypy src/codex32, passed.

🤖 Generated with Claude Code

https://claude.ai/code/session_019DuBKzoVE7oBFRnzoGH2ps

Match the spare-bit CRC of the codex32 key-expressions draft. Without
the XOR, a 24-byte seed extended with zero bits to 64 bytes keeps valid
CRC3 padding; with it, that extension never matches, since 320 bits is
not a multiple of CRC3's period of 7. CRC1 keeps no XOR, because one
would give every all-zero 28-byte seed valid padding.

Correction tie-breaks prefer the new padding, then the padding written
before this change, then neither. BIP93 vectors 3 and 4 now generate
their alternate 3 and 7 strings.

pytest: 913 passed. Ruff check and format, mypy: passed.

Claude-Session: https://claude.ai/code/session_019DuBKzoVE7oBFRnzoGH2ps
@BenWestgate
BenWestgate marked this pull request as ready for review November 6, 2026 19:11
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 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-11-06T19:15:00.171678Z a3d7296 Manual request
ℹ️ 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

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: a3d729607c

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

This branch has not been deployed

No deployments
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