BIP93: Fix checksum selection bounds and restrict ms sizes - #2258
BIP93: Fix checksum selection bounds and restrict ms sizes#2258BenWestgate wants to merge 2 commits into
ms sizes#2258Conversation
This comment was marked as low quality.
This comment was marked as low quality.
I added "reproducible boundary vectors." Edit: Unsure if I should have done this to satisfy a review comment that was later marked "low quality". For vectors, we need at minimum:
Willing to revert the "reproducible" vectors added in a9d8246 if reviews also find it overkill or open to another suggestion. What I would keep: Similarly ms32_create_regular_checksum creates the short checksum for data, while ms32_create_checksum selects the required checksum by expanded codewode length and creates it. It should be easier to generate test vectors and test them now, as well as to reuse our checksums for non-codex32 data. |
Account for the HRP expansion when selecting and slicing regular and long checksums. Enforce the invalid 94–95 value gap and update the affected test vectors. Aligns the reference implementation with bitcoin/bips#2258.
|
Based on my comment at #2040 (comment) which received some thumbs up by all parties here, I wonder if it everyone would find it preferable to simply restrict BIP-93 to seed lengths 128, 160, 192, 224, 256 and 512. I think I slightly prefer that, and if we are going to make such a change it would be better to do it from the get go. |
|
cACK
To prepare to generalize BIP-93 we still must also correct the checksum-period coverage or it leaves the unsafe checksum-selection question for every later application: For an Since restricting
|
Include the expanded human-readable part when selecting the codex32 checksum. This keeps regular codewords within the 93-symbol BCH period and rejects the 94- and 95-symbol gap before the long checksum starts at 96 symbols. Split regular and long checksum construction and verification so their periods can be tested independently. Add assertions for both selection boundaries and the long checksum upper limit. Refs: bitcoin#2258 (comment)
Include the expanded human-readable part when selecting the codex32 checksum. This keeps regular codewords within the 93-symbol BCH period and rejects the 94- and 95-symbol gap before the long checksum starts at 96 symbols. Split regular and long checksum construction and verification so their periods can be tested independently. Add assertions for both selection boundaries and the long checksum upper limit. Refs: bitcoin#2258 (comment)
53203a9 to
c201536
Compare
|
c201536 is ready for review. I drafted the next commit "BIP93: Restrict ms seed lengths", working on the vectors. Each commit is stand alone complete. |
Restrict codex32-encoded BIP32 master seeds to 16, 20, 24, 28, 32, or 64 bytes. These sizes correspond to the BIP39 entropy sizes and the 512-bit BIP32 seed produced by BIP39 recovery and provide minimum six-character length gaps to reduce target length ambiguity during optional insertion/deletion correction. Move payload decoding out of the generic codex32 secret definition and make it application-specific. Define the byte conversion and length requirements under the master seed format instead. Additionally: - Enforce the new valid encoded lengths (48, 54, 61, 67, 74, 127) in the Python `ms32_decode` in-line reference. - Remove obsolete short-checksum backward compatibility constraints and unsupported length test vectors. - Add test vectors for 160, 192, and 224-bit master seeds - Update rationale, compatibility, and reference implementation links.
ms sizes
Motivation
BIP93 currently admits expanded codewords beyond the checksum’s stated period, so its detection guarantee no longer applies to the complete codeword. This is a problem for a generic
codex32_decodefunction in later PRs. Both regular and long checksums permitted codewords in excess of their period.Meanwhile, fixing the above will invalidate very uncommon
msstrings or leave an ugly disjoint checksum selection rule forlen(hrp) == 2. A better solution is immediately follow up with by restricting master seeds to the most commonly used seed and entropy sizes. This reduces target length ambiguity for optional insert/delete correcting wallets and my benchmarks show improvements in both false-correction risk and performance at the same indel search depths.Changes
ms32_verify_checksumandms32_create_checksumnow include the expanded "ms" HRP length when selecting regular vs. long checksums.ms32_create_checksumusesif 5 + len(data) > 80:as the switch toms32_create_long_checksum.ms32_create_regular_checksumandms32_verify_regular_checksum.ms32_decodeenforces the newmsstring lengths.codex32 lengths:
invalid codex32 lengths:
codex32-encoded master seed sizes:
unsupported
mssizes:Compatibility
This is a breaking change for old strings encoding deprecated byte-length seeds. However the authors do not see this is a problem due to the exceedingly rare possibility these have ever been created and used.
Testing
Thoroughly reviewed the complete diff.
Checked the new vectors.
Checked that expanded length 1023 verifies and 1024 fails.
Checked that the legacy short-checksum vectors should fail.
Checked that
ms32_decoderejects newly invalid lengths, even when they have valid header, incomplete group and checksum.Discussion
Proposal: #2040 (comment)
cACK #2040 (comment)
Reference impl issue: BlockstreamResearch/codex32#75
rust-codex32 PR: BlockstreamResearch/codex32#76
Restrict
mssizes suggestion: #2258 (comment)