A non-descriptor watch-only wallet with imported sh(wpkh(
descriptor can generate Bech32 addresses that don’t match the descriptor.
Steps to reproduce:
0$ bitcoind -regtest -daemon -addresstype=bech32
1$ bitcoin-cli -regtest createwallet test true
2$ bitcoin-cli -regtest -rpcwallet=test importmulti \
3 '[{"desc":"sh(wpkh(tpubDCJtdt5dgJpdhW4MtaVYDhG4T4tF6jcLR1PxL43q9pq1mxvXgMS9Mzw1HnXG15vxUGQJMMSqCQHMTy3F1eW5VkgVroWzchsPD5BUojrcWs8/0/*))#e8nc36sh",
4 "timestamp":0, "range":1000, "watchonly":true, "keypool":true}]'
5[
6 {
7 "success": true
8 }
9]
10$ bitcoin-cli -regtest -rpcwallet="test" getnewaddress
11bcrt1quecj0a95x3s570h0rs7l2rxgmcudhphzl0g2q4
12$ bitcoin-cli -regtest -rpcwallet="test" getaddressinfo bcrt1quecj0a95x3s570h0rs7l2rxgmcudhphzl0g2q4
13{
14 "address": "bcrt1quecj0a95x3s570h0rs7l2rxgmcudhphzl0g2q4",
15 "scriptPubKey": "0014e67127f4b434614f3eef1c3df50cc8de38db86e2",
16 "ismine": false,
17 "solvable": false,
18 "iswatchonly": false,
19 "isscript": false,
20 "iswitness": true,
21 "witness_version": 0,
22 "witness_program": "e67127f4b434614f3eef1c3df50cc8de38db86e2",
23 "ischange": false,
24 "labels": [
25 ""
26 ]
27}
This is quite unexpected. It’s generating Bech32 address from a sh(wpkh(
descriptor. And not only that, the wallet isn’t watching the generated address. So it can be quite a footgun, which could lead to (perceived) funds loss.
For example with HWI, coming from Trezor software which defaults to p2sh-segwit, people will be importing, say, sh(wpkh(m/49'/1'/0'/0/*))
. If they forget to set the address type to p2sh-segwit
, they’ll generate addresses that seem to come out of the blue.
Expected behavior: getnewaddress
fails with no key available.