Skip to content

Bitcoin address validation does not enforce BTC_NETWORK #318

@volcano303

Description

@volcano303

Summary

BitcoinProvider.is_valid_address() currently validates address format, but it does not enforce the configured network.

In both mainnet and testnet mode, the function accepts addresses from both networks.

Why this matters

Swap destination validation relies on this function. If the validator or CLI is running on one BTC network but accepts an address from another, a user can pass validation with an address that does not match the active network.

Repro

  • Configure BTC_NETWORK=mainnet

  • is_valid_address("tb1...") returns True

  • Configure BTC_NETWORK=testnet

  • is_valid_address("bc1...") returns True

The same applies to base58 prefixes (1/3 vs m/n/2).

Expected behavior

Validation should enforce network-specific prefixes/version bytes:

  • mainnet: bc1, 1, 3
  • testnet: tb1, m/n, 2

(And bcrt1 only if regtest is intentionally supported.)

Suggested fix

After decoding bech32/base58, check the decoded HRP/version against self.network before returning True.

Add regression tests for cross-network rejection in both directions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions