Skip to content

Reject Bech32 checksums on witness v1 and later - #325

Open
SashaMIT wants to merge 1 commit into
petertodd:masterfrom
SashaMIT:codered-bech32m-witness-v1
Open

SashaMIT wants to merge 1 commit into
petertodd:masterfrom
SashaMIT:codered-bech32m-witness-v1

Conversation

@SashaMIT

Copy link
Copy Markdown

Summary

decode() treated checksum constant 1 as valid for every witness version. BIP350 keeps Bech32 for v0 and requires Bech32m (0x2bc830a3) for v1 and later. Encoding a 32-byte v1 program with Bech32 still returned (1, [0..31]).

encode() now uses Bech32 for v0 and Bech32m otherwise. bech32_decode() returns (hrp, data, spec). The only caller in this repo is decode().

Test plan

  • test_v1_rejects_bech32_checksum is red on master (decode returns the program) and green here
  • python3 -m unittest discover -s bitcoin/tests (150 tests OK)
  • The three BIP173 v1+ vectors are updated to their Bech32m strings, and the old strings are in bech32_invalid.json

Made with Cursor

BIP350 requires Bech32m for those versions. decode() treated checksum constant 1 as valid for every witness version, so a v1 program encoded with Bech32 still decoded.
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