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_decode function in later PRs. Both regular and long checksums permitted codewords in excess of their period.
Meanwhile, fixing the above will invalidate very uncommon ms strings or leave an ugly disjoint checksum selection rule for len(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.- added
ms32_create_regular_checksumandms32_verify_regular_checksum. - The Python reference code, specification, rationale, and vectors are updated.
ms32_decodeenforces the newmsstring lengths.- Obsolete tests/vectors from the seed size restrictions are removed.
codex32 lengths:
- Regular codewords will now be <= 93 expanded values
- Long codewords will now be >= 96 and <= 1023 expanded values
invalid codex32 lengths:
- Expanded values 94, 95 and > 1023.
codex32-encoded master seed sizes:
- 16-, 20-, 24-, 28-, 32- and 64-bytes
unsupported ms sizes:
- All from 16- to 64-bytes besides the six above.
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_decode rejects newly invalid lengths, even when they have valid header, incomplete group and checksum.
Discussion
Proposal: #2040 (comment)
cACK #2040 (comment)
Reference impl issue: https://github.com/BlockstreamResearch/codex32/issues/75
rust-codex32 PR: https://github.com/BlockstreamResearch/codex32/pull/76
Restrict ms sizes suggestion: #2258 (comment)