Skip to content

create_tx accepts recipient addresses from the wrong network #360

In review

Description

@emma31-dev

Describe the bug

create_tx accepts a recipient address belonging to a different network than the wallet, with no warning. The address is parsed as Address<NetworkUnchecked> and converted straight to ScriptBuf via .script_pubkey(), discarding the network information before the wallet's network is known, so bdk-cli never compares the two.

This is a silent-misdirection safety issue rather than an unspendable-transaction bug: consensus validates the output scriptPubKey, not the address HRP, so a regtest node will accept a transaction paying to the witness program behind a tb1 address. Also, rust-bitcoin treats testnet, testnet4, and signet as a single network for address checks, so only mainnet/regtest (and similar) boundaries are genuinely invalid.

To Reproduce

  1. Set up a regtest wallet:
    bdk-cli --network regtest --datadir ./dd wallet --wallet regtest_user1 config \
      --ext-descriptor "<external descriptor>" \
      --int-descriptor "<internal descriptor>" \
      --client-type rpc --database-type sqlite --url http://127.0.0.1:18443
    
  2. Attempt to send to a testnet address:
    bdk-cli --network regtest --datadir ./dd wallet --wallet regtest_user1 \
      create_tx --to tb1q...:1000
    
  3. Observe: the command succeeds and returns a PSBT, with no warning about the network mismatch. (The PSBT is still broadcastable; the node does not reject it.)

Expected behavior

create_tx should reject the recipient at construction time with a specific error naming the mismatch, rather than silently building a PSBT that pays an address meant for another network. The recipient should be carried through as Address<NetworkUnchecked> and validated with require_network(wallet.network()) inside execute, immediately before conversion to ScriptBuf.

Affected commands

The same unchecked pattern exists in create_tx, create_sp_tx, create_dns_tx, and bump_fee --shrink; silent payment codes are likewise unchecked.

Build environment

  • BDK-CLI tag/commit: master
  • OS+version: macOS 12.7.6 (Monterey)
  • Rust/Cargo version: rustc 1.97.1
  • Rust/Cargo target: x86_64-apple-darwin

Additional context

The fix touches the shared recipient parsing/validation path used by those commands; no changes to the wallet API are needed.

Activity

  1. added
    bug
    on Oct 18, 2026
  2. moved this from Todo to In Progress in BDK-CLIon Oct 30, 2026
  3. tvpeter commented on Dec 3, 2026

    @tvpeter
    Collaborator

    Describe the bug

    create_tx accepts a recipient address belonging to a different network than the wallet. The transaction is built successfully, but the resulting PSBT is unspendable on the target network and only fails later at broadcast time with a node-side rejection. The cause is in parse_recipient: it calls Address::from_str (which yields Address<NetworkUnchecked>) and immediately converts to ScriptBuf via .script_pubkey(), discarding the network information before the wallet's network is known. bdk-cli therefore never compares the two.

    To Reproduce

    1. Create a regtest wallet:
      bdk-cli --network regtest wallet -w regtest_user1 --descriptor "..." --change_descriptor "..." create
    2. Attempt to send to a testnet address:
      bdk-cli --network regtest wallet -w regtest_user1 create_tx --to tb1qdgxnu...:1000
    3. Observe: the command succeeds and returns a PSBT.
    4. Broadcasting that PSBT against the regtest node fails with an address/script error, because tb1... does not belong to the regtest network.

    Expected behavior

    create_tx should reject the recipient at construction time with a specific error naming the mismatch, rather than producing a PSBT that can never be spent. BDKCliError::InvalidNetwork { requested, found } should be created for this purpose. The recipient should be carried through as Address<NetworkUnchecked> and validated with require_network(ctx.state.wallet.network()) inside execute, immediately before conversion to ScriptBuf.

    Build environment

    • BDK-CLI tag/commit: master
    • OS+version: macOS 12.7.6 (Monterey)
    • Rust/Cargo version: rustc 1.97.1
    • Rust/Cargo target: x86_64-apple-darwin

    Additional context

    The fix is confined to CreateTxCommand and parse_recipient; no changes to the wallet API are needed.

    Thank you for reporting this. While I can confirm that the bug exist, majority of the description and reproduction steps are wrong:

    • There is no create subcommand (error: unrecognized subcommand 'create'). Wallets are set up with wallet config.
    • --descriptor and --change_descriptor don’t exist. The flags are --ext-descriptor / -e and --int-descriptor / -i.
    • Broadcast would not fail, and the PSBT is not unspendable. Nodes validate output scripts, not addresses. A regtest node would accept a transaction paying to the witness program behind a tb1 address. So steps 3–4 and the “only fails later at broadcast” claim are wrong. The real problem is that funds go silently to a script the user meant for a different network, with no warning.
    • rust-bitcoin treats testnet, testnet4 and signet as one network for address checks.
  4. emma31-dev commented on Dec 3, 2026

    @emma31-dev
    ContributorAuthor

    @tvpeter Thanks for the detailed review!

    you're right on all counts, and I want to own the inaccuracies. I wrote the repro from memory and let AI fill in the template, which is how the wrong subcommand/flags and the broadcast claim slipped in. And i forgot to update it as scope of PR changed.

    • CLI / config: wallet -w ... --descriptor ... create doesn't exist. Setup is wallet --wallet <name> config --ext-descriptor <desc> --int-descriptor <desc>, and I misremembered --descriptor / --change_descriptor for --ext-descriptor / --int-descriptor. I should have verified against --help instead of trusting recall and then repeated the same mistake a few more times.
    • Validation & spendability: I just confirmed this. consensus validates the scriptPubKey, not the HRP, so the output is spendable and a regtest node accepts it. I re-ran it end-to-end against regtest: create_tx to tb1q… succeeds and the transaction broadcasts, since it pays the same witness program as the bcrt1… form. The real defect is the silent cross-network misdirection with no warning.
    • Network grouping: I agree. rust-bitcoin treats testnet, testnet4, and signet as one address network, so a tb1 recipient is "valid" on any of them; only mainnet/regtest boundaries are actually caught.
    • Also worth noting: the fix is broader than CreateTxCommand alone. The same unchecked pattern exists in create_sp_tx, create_dns_tx, and bump_fee --shrink, so the PR covers those too.

    I'll update the issue description and reproduction steps to reflect the exact CLI flags and actual behavior. Thanks again for the detailed review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

  • Status
    In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions