Motivation
BIP93 currently chooses checksum type by data-part length but the checksum’s error detection boundary applies to the expanded codeword, including the five-value expansion of "ms". This will cause problems for a generic codex32_decode function in later PRs and at worst allow an HRP error to go undetected at the boundary. Both regular and long checksums permitted codewords in excess of their period.
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.
Valid lengths:
- Regular codewords will now be <= 93 expanded values
- Long codewords will now be >= 96 and <= 1023 expanded values
Invalid lengths:
- Expanded values 94 and 95
- Long codewords >1023 expanded values
Compatibility
This is a breaking change for old regular codex32 strings encoding 44-, 45-, and 46-byte seeds. However the authors do not see this is a problem due to the exceedingly rare possibility these have ever been created and used. The underlying seed lengths remain supported so users must migrate by reencoding their data with the Long codex32 checksum for modern decoders to accept them. The 43-byte regular encoding and existing 47-byte long encoding remain valid.
Testing
Thoroughly reviewed the complete diff. Ran git diff --check. Checked the new 43–47-byte boundary vectors. Checked that expanded length 1023 verifies and 1024 fails. Checked that the legacy short-checksum vectors should fail.
Discussion
Proposal: #2040 (comment) cACK #2040 (comment) Reference impl: https://github.com/BlockstreamResearch/codex32/issues/75