Repository navigation
Description
Describe the bug
bdk-cli accepts recipient addresses and silent payment codes that belong to a different network than the wallet. The address network is discarded when it is converted to a ScriptBuf, so bdk-cli never compares it with the wallet network.
This is a silent-misdirection safety issue, not 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. The risk is sending funds to an address that was intended for another network.
Network compatibility is not 1:1:
testnet,testnet4, andsignetshare address prefixes and are treated as the same network byrust-bitcoin.bitcoinis distinct.regtestis distinct from the public test networks for bech32 addresses (legacy testnet base58 addresses may be accepted on regtest).- Silent payment codes use
sp(mainnet),tsp(all test networks), andsprt(regtest);bdk_spreports everytspcode asNetwork::Testnet.
Affected commands
All of these parse user-supplied addresses or codes without checking the wallet network:
create_tx --to(includingcreate_tx --send_all --to)create_sp_tx --tocreate_sp_tx --to-sp(silent payment codes)create_dns_tx --tobump_fee --shrinksign_message --address/verify_message --address(these parse withassume_checked, so they report “does not belong to this wallet” rather than a network mismatch)
To reproduce
The wallet needs a spendable UTXO; otherwise create_tx fails with Insufficient funds before the missing network check becomes visible.
1. Generate descriptors and save a regtest wallet config
DESC=$(bdk-cli --network regtest --datadir ./dd descriptor --type tr)
EXT=$(python3 -c 'import json,sys; print(json.load(sys.stdin)["private_descriptors"]["external"])' <<<"$DESC")
INT=$(python3 -c 'import json,sys; print(json.load(sys.stdin)["private_descriptors"]["internal"])' <<<"$DESC")
bdk-cli --network regtest --datadir ./dd wallet --wallet regtest_user1 config \
--ext-descriptor "$EXT" \
--int-descriptor "$INT" \
--client-type rpc \
--database-type sqlite \
--url http://127.0.0.1:184432. Start a regtest node and fund the bdk-cli wallet
bitcoind -regtest -daemon -fallbackfee=0.0002 \
-rpcuser=user -rpcpassword=password
bitcoin-cli -regtest -rpcuser=user -rpcpassword=password createwallet miner
MINER_ADDR=$(bitcoin-cli -regtest -rpcuser=user -rpcpassword=password \
-rpcwallet=miner getnewaddress)
bitcoin-cli -regtest -rpcuser=user -rpcpassword=password \
-rpcwallet=miner generatetoaddress 101 "$MINER_ADDR"
RECV=$(bdk-cli --network regtest --datadir ./dd wallet --wallet regtest_user1 \
new_address | python3 -c 'import json,sys; print(json.load(sys.stdin)["address"])')
bitcoin-cli -regtest -rpcuser=user -rpcpassword=password \
-rpcwallet=miner sendtoaddress "$RECV" 1
bitcoin-cli -regtest -rpcuser=user -rpcpassword=password \
-rpcwallet=miner generatetoaddress 1 "$MINER_ADDR"
bdk-cli --network regtest --datadir ./dd wallet --wallet regtest_user1 full_scan3. Try to pay a testnet address from the regtest wallet
bdk-cli --network regtest --datadir ./dd wallet --wallet regtest_user1 \
create_tx --to tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx:1000Actual on master: the command builds and prints a PSBT.
Expected: the command fails before building the PSBT:
ParseError: address tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx is not valid on regtest
4. Silent payment codes
Generate a testnet tsp code, then pass it to the regtest wallet:
SP_TESTNET=$(bdk-cli --network testnet --datadir ./dd silent_payment_code \
--scan_key 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 \
--spend_key 02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 \
| python3 -c 'import json,sys; print(json.load(sys.stdin)["message"])')
bdk-cli --network regtest --datadir ./dd wallet --wallet regtest_user1 \
create_sp_tx --to-sp "$SP_TESTNET:1000"Actual on master: the code is accepted and a PSBT is built.
Expected: the command fails with:
Silent payment code tsp1... is not valid for regtest
A tsp code must still be accepted by testnet, testnet4, and signet wallets.
5. bump_fee --shrink
Create and broadcast an RBF transaction, then bump it while shrinking to a testnet address:
bdk-cli --network regtest --datadir ./dd wallet --wallet regtest_user1 \
bump_fee --txid <txid> --fee_rate 10.0 \
--shrink tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsxActual on master: a PSBT is built that pays the testnet address.
Expected: the command is rejected with the same is not valid on regtest error.
Expected behavior
create_tx,create_sp_tx,create_dns_tx, andbump_fee --shrinkvalidate the recipient against the wallet network before building the PSBT.- Silent payment codes are matched by network family, not strict
Networkequality, becausetspis shared by testnet, testnet4, and signet. sign_messageandverify_messagereject addresses from another network with a network-mismatch error.- Valid addresses on testnet/testnet4/signet remain valid across those networks.
Fix
Implemented in PR #370 (fix/360-create-tx-network-validation): recipients are carried as Address<NetworkUnchecked> and validated with require_network(wallet.network()) immediately before conversion to ScriptBuf, and silent payment codes are validated by network family.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn Progress
Activity
tvpeter commentedon Dec 3, 2026
Thank you for reporting this. While I can confirm that the bug exist, majority of the description and reproduction steps are wrong:
createsubcommand (error: unrecognized subcommand 'create'). Wallets are set up with walletconfig.--descriptorand--change_descriptordon’t exist. The flags are--ext-descriptor / -eand--int-descriptor / -i.tb1address. 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-bitcointreatstestnet,testnet4andsignetas one network for address checks.emma31-dev commentedon Dec 3, 2026
@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.
wallet -w ... --descriptor ... createdoesn't exist. Setup iswallet --wallet <name> config --ext-descriptor <desc> --int-descriptor <desc>, and I misremembered--descriptor/--change_descriptorfor--ext-descriptor/--int-descriptor. I should have verified against--helpinstead of trusting recall and then repeated the same mistake a few more times.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_txtotb1q…succeeds and the transaction broadcasts, since it pays the same witness program as thebcrt1…form. The real defect is the silent cross-network misdirection with no warning.rust-bitcointreatstestnet,testnet4, andsignetas one address network, so atb1recipient is "valid" on any of them; only mainnet/regtest boundaries are actually caught.CreateTxCommandalone. The same unchecked pattern exists increate_sp_tx,create_dns_tx, andbump_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!