Skip to content

Accept 35-character testnet P2SH BTC addresses - #541

Open
Plastic-time wants to merge 1 commit into
python-validators:masterfrom
Plastic-time:fix/btc-testnet-p2sh-length
Open

Plastic-time wants to merge 1 commit into
python-validators:masterfrom
Plastic-time:fix/btc-testnet-p2sh-length

Conversation

@Plastic-time

Copy link
Copy Markdown

btc_address("2MzQwSSnBHWHqSAqtTVQ6v47XtaisrJa1Vc") currently fails even though it is a valid testnet P2SH address. Base58Check encodings of a 25-byte payload with version byte 0xc4 are always 35 characters long, but _validate_old_btc_address only admits lengths 25–34, so every testnet P2SH address is rejected before its checksum is checked.

This change raises the upper bound to 35 characters. Some 35-character strings decode to more than 25 bytes; int.to_bytes(25) would then raise OverflowError, which the @validator decorator does not catch, so those values are now rejected explicitly before the checksum check.

Tests add a valid testnet P2SH address, the same address with a corrupted checksum, and a 35-character value that exceeds 25 bytes.

Validation on Python 3.12:

  • Before the fix, the new valid-address case fails; after it, all 13 BTC tests pass.
  • Full suite: the only failures are the 28 ETH address tests that need the optional crypto-eth-addresses extra, which fail identically on master in this environment.
  • ruff check, ruff format --check and git diff --check pass.

Relation to #540: both PRs edit _validate_old_btc_address, so whichever merges second will need a small rebase. With #540's byte-preserving decoder, the explicit length check there already covers the oversized case, and only the range(25, 36) change from this PR is needed; I checked that combination passes all BTC tests from both PRs.

Prepared with AI assistance.

This branch has not been deployed

No deployments
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