Fix BTC segwit regex to accept testnet (tb) addresses - #477
Open
uttam12331 wants to merge 1 commit into
Open
Conversation
The bech32/segwit branch guard routes both `bc` (mainnet) and `tb` (testnet) HRPs into the regex, but the regex accepted `(bc|tc)`. `tc` is not a valid Bitcoin HRP (mainnet is `bc`, testnet is `tb`), and since the guard never lets a `tc`-prefixed value reach the regex, that alternative was dead code. As a result every valid testnet segwit address was rejected. Change the regex alternative to `(bc|tb)` and add a testnet address test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
btc_address()rejects every valid testnet bech32/segwit address.The segwit branch is guarded by:
so both mainnet (
bc) and testnet (tb) HRPs are routed into the regex — but the regex only acceptsbcortc:tcis not a valid Bitcoin human-readable part (mainnet isbc, testnet istb— see BIP173). Because the guard never lets atc-prefixed value reach the regex, thetcalternative is dead code; the intended prefix is clearlytb. As written, anytb...address matches the guard, then fails the regex, andbtc_addressreturns aValidationError.Reproduction
Fix
Tests
Added the canonical BIP173 testnet address to the valid-address cases in
tests/crypto_addresses/test_btc_address.py. It fails on the current code and passes with the fix; the full file passes (9 tests).