sparrowwallet / sparrow

Desktop Bitcoin Wallet focused on security and privacy. Free and open source.
https://sparrowwallet.com/
Apache License 2.0
1.34k stars 190 forks source link

Unable to create watch only wallet using xpub/zpub #613

Closed eugenesan closed 2 years ago

eugenesan commented 2 years ago

I am trying to create a watch only wallet and I am unable to create keystore using neither xpub or zpub. The "Apply" button stays greyed-out.

Also, by default keystore derivation is set to m/84'/0'/0' and I would expect zpub to be the default for the key format but the field is xpub. If I enter xpub, the key name changes to zpub/xpub but if I press the "swap" button on the right it converts the xpub to zpub but it doesn't mach the zpub of the xpub entered originally.

Above might be related to https://github.com/sparrowwallet/sparrow/issues/3

craigraw commented 2 years ago

The ypub/zpub formats are deprecated (for example, there is no equivalent for Taproot). You can use them in Sparrow, but Sparrow displays xpubs by default.

Are any of the fields failing validation (red outline)? Have you entered the master fingerprint (can use 00000000) and the derivation path?

eugenesan commented 2 years ago

My understanding was that zpub being part of BIP84 was the current standard so I was expecting zpub to be the default. Also, iancoleman's bip39 and electrum use/export zpub by default.

Thanks for your suggestion, I found my problem. Here are my findings:

  1. Key can be either zpub or xpub, though the UI shows only xpub by default and when zpub is entered switches to xpub / zpub. Maybe since both work, xpub/zpub label should be the default to avoid confusion?
  2. The "swap" button generates incorrect keys.
  3. The fingerprint was filled with "0000000" by default which good.
  4. My main problem was derivation path, it was grayed out with default BIP84 path so I assumed it was correct but in fact the actual field was empty and it had red outline. The problem was that the red outline was almost invisible (at least in dark mode) and I couldn't see it during the day. Perhaps minor UI change could help.

Unrelated to the issue, current font used to display addresses makes it hard to differentiate number "one" and lowercase "L".

craigraw commented 2 years ago

Zpubs are specified in SLIP39, not BIP84. Output descriptors have now replaced this outmoded method of specifing script type. See https://bitcoin.stackexchange.com/questions/89261/why-does-importmulti-not-support-zpub-and-ypub

The "swap" button generates incorrect keys.

It simply changes the header on the extended public key. Please provide evidence to support your assertion.

eugenesan commented 2 years ago

Thanks for the link, looks like I was mislead by some random article on subject.

Regarding the "swap" button. Here is my test:

  1. Use "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo buddy" mnemonic to generate keys in iancoleman's bip39 tool.
  2. In bip 44 mode, Account Extended Public Key is: xpub6BqYKb2LU2yZ7r8LEBB71Yg3CeyKi5b387RqzgReorVNz86LNn4cQW5wR9r4UkkinK1jw3oXxj71ggNa9z8PmDLGDqdoj4injK2mxsGwPrM
  3. In BIP84 mode, Account Extended Public Key is: zpub6reDCQMXtY3seunJNf4jWAHZGdsoQqgDVBHLiu2ZvqtyrrN4QZMuprYd5xYi21E2rRmA56yQ9N8FB65AQwWV4YVYC3nxtdtPMBBkf8VoFfD
  4. In sparrow, create new wallter, choose "xPub/Watchonly wallet", enter xpub from 2., press "swap", resulting zpub is zpub6qW4vvNAmQ4WpSWZttkMRis3YbGDbKa2xLUHZUDRZsF96Kint6PjedQDTZmEUa4ZbbFMRzzet3p7TFbhbNxRMghTxX2ettMmGmA4k1M9cSN which is not the one in 3.
  5. In sparrow, create new wallter, choose "xPub/Watchonly wallet", enter zpub from 3., press "swap", resulting xpub is xpub6Cygb51hbAxuxKQ4hwVV5z6YvhauXbhDexEuA7EoAq9DkejbuF2najEM3YdY2BvC39XYa9nHE3R9QWr2yYgTU58LTNQ7ipFQoj4TszqYVeS which is not the one in 2.
  6. To make sure, both zpub from 3. and xpub from 2. generate first address bc1q0ncyzw38srzxyrgzywrfcz29kxc0z0d8hg3u0y
  7. In sparrow, create new wallter, choose "xPub/Watchonly wallet", use "swapped" zpub, first address is bc1qvxlldnsk7v23u9dyxdqve0m67a8snpc2udhukw different from the one in 6.
  8. In sparrow, create new wallter, choose "xPub/Watchonly wallet", use "swapped" xpub, first address is bc1q0ncyzw38srzxyrgzywrfcz29kxc0z0d8hg3u0y identical to the one in 6.

I am confused with the results of the test, especially 8. Are there several xpub/zpub formatting schemes or I am doing something wrong?

craigraw commented 2 years ago

You are missing an important factor - the derivation path. The extended keys generated in steps 2 & 3 are generated on different paths, namely m/44’/0’/0’ and m/84’/0’/0’. They have different public keys and different chaincodes (in addition to different headers in this case).

eugenesan commented 2 years ago

I see. Somehow I assumed Account Extended Public Key was not affected by derivation. Thanks for educating me.