View-only wallet import assumes native SegWit and skips the rescan #1058

Open
opened 2026-10-30 12:45:32 +00:00 by uqlidi · 1 comment
uqlidi commented 2026-10-30 12:45:32 +00:00 (Migrated from github.com)

Add wallet > View-only only takes a plain xpub, and the wallet it creates often can't see the funds it should watch.

The key is always wrapped as native SegWit, with the current time as the birth time:

github.com/bitcoin-core/gui-qml@6cdad53440/qml/walletqmlcontroller.cpp (L636-L639)

github.com/bitcoin-core/gui-qml@6cdad53440/qml/walletqmlcontroller.cpp (L661-L663)

Problems

  1. Any non-SegWit key is accepted but watches the wrong addresses. A Taproot (BIP86), nested SegWit (BIP49) or legacy (BIP44) account xpub becomes wpkh(...). The wallet is created with no error and stays empty.
  2. No rescan. Transactions from before the import are never found, so a funded wallet shows a partial or zero balance.
  3. SLIP-132 keys are rejected. ypub/zpub (upub/vpub on test networks), which many wallets export, fail with "Enter a valid extended public key (xpub)".
  4. Descriptors are not accepted at all, although they are the only format that carries the script type and both chains.
  5. No key origin is stored, so the fingerprint and path are lost if the wallet is later used with a signer.

Steps to reproduce (regtest)

  1. Create and fund a wallet hot, then pay one of its SegWit addresses:
    generatetoaddress 101 <hot bech32m address>
    sendtoaddress <hot bech32 address> 5
    generatetoaddress 1 <any address>
    
  2. From hot's listdescriptors, copy the tpub of the active receive tr(...) descriptor and of the active receive wpkh(...) descriptor.
  3. Add wallet > View-only, once with each tpub.
  4. Send 2 BTC to a new bech32m address of hot, 1 BTC to a new bech32 address of hot, and mine a block.
  5. Paste any vpub into the View-only form.

Result

Key Form Wallet
Taproot account tpub accepted wpkh(...) descriptors, 0 BTC, 0 transactions, even after the 2 BTC Taproot payment
SegWit account tpub accepted 2 transactions, both from step 4. The 5 BTC payment from step 1 is missing
vpub rejected none

Expected

The view-only wallet sees the same coins and history as the wallet it watches.

Suggestion

  • Accept descriptors, including several lines and the multipath <0;1> form, and take the address type from each descriptor.
  • Accept SLIP-132 keys and map the prefix to the script type (ypub/upub to sh(wpkh()), zpub/vpub to wpkh()).
  • For a plain xpub, ask for the address type instead of assuming SegWit.
  • Rescan after import, from a birth date the user can set (a full rescan is slow on mainnet and not possible below the prune height).
Add wallet > View-only only takes a plain xpub, and the wallet it creates often can't see the funds it should watch. The key is always wrapped as native SegWit, with the current time as the birth time: https://github.com/bitcoin-core/gui-qml/blob/6cdad5344018f35e8c33c77a23f6ba996d507549/qml/walletqmlcontroller.cpp#L636-L639 https://github.com/bitcoin-core/gui-qml/blob/6cdad5344018f35e8c33c77a23f6ba996d507549/qml/walletqmlcontroller.cpp#L661-L663 ## Problems 1. **Any non-SegWit key is accepted but watches the wrong addresses.** A Taproot (BIP86), nested SegWit (BIP49) or legacy (BIP44) account xpub becomes `wpkh(...)`. The wallet is created with no error and stays empty. 2. **No rescan.** Transactions from before the import are never found, so a funded wallet shows a partial or zero balance. 3. **SLIP-132 keys are rejected.** `ypub`/`zpub` (`upub`/`vpub` on test networks), which many wallets export, fail with "Enter a valid extended public key (xpub)". 4. **Descriptors are not accepted at all,** although they are the only format that carries the script type and both chains. 5. **No key origin is stored**, so the fingerprint and path are lost if the wallet is later used with a signer. ## Steps to reproduce (regtest) 1. Create and fund a wallet `hot`, then pay one of its SegWit addresses: ``` generatetoaddress 101 <hot bech32m address> sendtoaddress <hot bech32 address> 5 generatetoaddress 1 <any address> ``` 2. From `hot`'s `listdescriptors`, copy the `tpub` of the active receive `tr(...)` descriptor and of the active receive `wpkh(...)` descriptor. 3. Add wallet > View-only, once with each `tpub`. 4. Send 2 BTC to a new `bech32m` address of `hot`, 1 BTC to a new `bech32` address of `hot`, and mine a block. 5. Paste any `vpub` into the View-only form. ## Result | Key | Form | Wallet | |---|---|---| | Taproot account `tpub` | accepted | `wpkh(...)` descriptors, 0 BTC, 0 transactions, even after the 2 BTC Taproot payment | | SegWit account `tpub` | accepted | 2 transactions, both from step 4. The 5 BTC payment from step 1 is missing | | `vpub` | rejected | none | ## Expected The view-only wallet sees the same coins and history as the wallet it watches. ## Suggestion - Accept descriptors, including several lines and the multipath `<0;1>` form, and take the address type from each descriptor. - Accept SLIP-132 keys and map the prefix to the script type (`ypub`/`upub` to `sh(wpkh())`, `zpub`/`vpub` to `wpkh()`). - For a plain `xpub`, ask for the address type instead of assuming SegWit. - Rescan after import, from a birth date the user can set (a full rescan is slow on mainnet and not possible below the prune height).
jarolrod commented 2026-11-11 20:40:22 +00:00 (Migrated from github.com)

One more consequence of the missing rescan, at eed1f426fcb6 with Core 44901d8f64cb: Receive in the new view-only wallet hands out an address the key has already used.

The import adds both descriptors with the current time as the birth time and the next index at 0 (walletqmlcontroller.cpp#L671-L676). The wallet knows none of the key's history, so nothing tells Receive that the first address is used.

Steps (regtest)

  1. In a wallet src, receive 0.5 BTC on its first SegWit receive address and confirm it. (I also spent it again, so the balance is back to 0.)
  2. Add wallet > View only, with the tpub of src's active receive wpkh(...) descriptor.
  3. Open Receive, enter 0.25 BTC and click Create payment request.

Result

The address offered is src's first address, the one paid in step 1, and the request is saved on it: Awaiting payment, with a QR code for that address. The payer is given an address that already has history on chain. The wallet lists no transactions at this point, so nothing on screen marks the address as used.

Watching a key that already has history is the usual reason to import one, so this is the ordinary path. I only observed the first address. By source, later requests continue from the next index, which such a key has usually used as well.

Control: in an ordinary wallet I could not get a request onto a used address.

If the wallet is rescanned afterwards

This is a narrower case, because it needs the request to exist before the rescan. Running rescanblockchain in Settings > RPC console turned the request from step 3 into Payment received, with 0.50000000 BTC as the headline amount, Requested amount 0.25000000 and no QR code. Activity links the 0.5 BTC transaction from step 1 to the request. Nobody paid this request: that payment arrived and left before the wallet was imported.

Any wallet transaction paying an address marks every saved request on that address as paid, whatever the transaction's age (walletqmlmodel.cpp#L1694-L1700). The same steps with a key that has no history leave the request at Awaiting payment, and a restart without the rescan changes nothing. The amount that does not match the request is a cue, and on a real chain the linked transaction would also be older than the request.

Core's own importdescriptors RPC avoids this by itself: on a separate regtest chain where the key's first two receive addresses had been used, importing its receive descriptor with "timestamp": "now" rescanned, found that history, and getnewaddress returned an unused address. (A "now" import still rescans the last two hours, which covers a fresh regtest chain; on a real chain it would need the key's birth date.) So the rescan suggested above would avoid both problems, as long as it finishes before Receive offers an address.

Tested on macOS / Qt 6.9, isolated regtest, offscreen and native, one run each. The wallet name, key, amount and message were set into their fields directly. The console command was typed and submitted through the console's Enter handler. Every other step was a click through the test bridge. The importdescriptors comparison was run once with bitcoin-cli and no GUI.

One more consequence of the missing rescan, at `eed1f426fcb6` with Core `44901d8f64cb`: Receive in the new view-only wallet hands out an address the key has already used. The import adds both descriptors with the current time as the birth time and the next index at 0 ([walletqmlcontroller.cpp#L671-L676](https://github.com/bitcoin-core/gui-qml/blob/eed1f426fcb64daa61b004590335a03afe376274/qml/walletqmlcontroller.cpp#L671-L676)). The wallet knows none of the key's history, so nothing tells Receive that the first address is used. **Steps (regtest)** 1. In a wallet `src`, receive 0.5 BTC on its first SegWit receive address and confirm it. (I also spent it again, so the balance is back to 0.) 2. Add wallet > View only, with the `tpub` of `src`'s active receive `wpkh(...)` descriptor. 3. Open Receive, enter 0.25 BTC and click **Create payment request**. **Result** The address offered is `src`'s first address, the one paid in step 1, and the request is saved on it: **Awaiting payment**, with a QR code for that address. The payer is given an address that already has history on chain. The wallet lists no transactions at this point, so nothing on screen marks the address as used. Watching a key that already has history is the usual reason to import one, so this is the ordinary path. I only observed the first address. By source, later requests continue from the next index, which such a key has usually used as well. Control: in an ordinary wallet I could not get a request onto a used address. **If the wallet is rescanned afterwards** This is a narrower case, because it needs the request to exist before the rescan. Running `rescanblockchain` in Settings > RPC console turned the request from step 3 into **Payment received**, with 0.50000000 BTC as the headline amount, **Requested amount** 0.25000000 and no QR code. Activity links the 0.5 BTC transaction from step 1 to the request. Nobody paid this request: that payment arrived and left before the wallet was imported. Any wallet transaction paying an address marks every saved request on that address as paid, whatever the transaction's age ([walletqmlmodel.cpp#L1694-L1700](https://github.com/bitcoin-core/gui-qml/blob/eed1f426fcb64daa61b004590335a03afe376274/qml/models/walletqmlmodel.cpp#L1694-L1700)). The same steps with a key that has no history leave the request at **Awaiting payment**, and a restart without the rescan changes nothing. The amount that does not match the request is a cue, and on a real chain the linked transaction would also be older than the request. Core's own `importdescriptors` RPC avoids this by itself: on a separate regtest chain where the key's first two receive addresses had been used, importing its receive descriptor with `"timestamp": "now"` rescanned, found that history, and `getnewaddress` returned an unused address. (A "now" import still rescans the last two hours, which covers a fresh regtest chain; on a real chain it would need the key's birth date.) So the rescan suggested above would avoid both problems, as long as it finishes before Receive offers an address. Tested on macOS / Qt 6.9, isolated regtest, offscreen and native, one run each. The wallet name, key, amount and message were set into their fields directly. The console command was typed and submitted through the console's Enter handler. Every other step was a click through the test bridge. The `importdescriptors` comparison was run once with `bitcoin-cli` and no GUI.
Sign in to join this conversation.
No description provided.