Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown derivation path from Coldcard-generated multisig xpubs #7088

Closed
yuvadm opened this issue Mar 6, 2021 · 11 comments
Closed

Unknown derivation path from Coldcard-generated multisig xpubs #7088

yuvadm opened this issue Mar 6, 2021 · 11 comments

Comments

@yuvadm
Copy link

yuvadm commented Mar 6, 2021

I've imported three xpubs from three different air-gapped Coldcard mk3 which should form a 2-of-3 mulsitig watch-only wallet.

The original export from the coldcards was P2WSH with m/48'/0'/0'/2' but it seems the Electrum import was erroneously marked as P2SH:

>>> [k.dump() for k in wallet.get_keystores()]
[
  {'type': 'bip32', 'pw_hash_version': 1, 'xpub': 'xpub6Dd4h9bkYaMaJpBjkqntomteQh89x2tu2qjfzQngnnf2j7QBVXixkT8o3sRMU1eUcYRYuXwMGCPEeUZmrFEyH7YF48BiFPZRuvcCrwjUk1G', 'xprv': None, 'derivation': None, 'root_fingerprint': None},
  {'type': 'bip32', 'pw_hash_version': 1, 'xpub': 'xpub6DnicnxAfnaG2jSBJyNwzn8DYu8X78LQdHmczszWJhkdzvmQqSGnTUWBzTQvRwKQ7Ys5mFiCtjh3a2JR7geuMTenNBvpGegnvDGFMdbrTp1', 'xprv': None, 'derivation': None, 'root_fingerprint': None},
  {'type': 'bip32', 'pw_hash_version': 1, 'xpub': 'xpub6FA5F2s3ogg6BeRBGJjsVjks5Dfm6ZeoEbHWYQjz1FjtwmzdLrMU8CqqenBmn2Jpn7QprBunKmnbqo4BLb1KVBjZfpM59VVx9oApgo1p83C', 'xprv': None, 'derivation': None, 'root_fingerprint': None}
]

All keystores have no derivation path data. In this wallet the first derived receiving address is 3FjFdHR5S6c7bweCME2bgBBChr4p4tqUMc and was sent some funds for testing purposes, but are currently unrecoverable due to the missing derivation path data and the P2SH-mismatch.

Given the BIP39 seeds, what is the proper way to import the privkeys to a new wallet and sign a valid transaction for this UTXO?

@SomberNight
Copy link
Member

see #5715 (comment)

@yuvadm
Copy link
Author

yuvadm commented Mar 6, 2021

@SomberNight thanks for the quick response, but I think that workaround will only sync the Electrum wallet with the xpubs going forward. What about the existing P2SH address? How can I derive the correct transaction to unlock those funds?

@SomberNight
Copy link
Member

Oh I've missed the script type issue. That is because we store type information in the xpub. You need to convert them to Zpubs for p2wsh.

async def convert_xkey(self, xkey, xtype):

>>> convert_xkey("xpub6Dd4h9bkYaMaJpBjkqntomteQh89x2tu2qjfzQngnnf2j7QBVXixkT8o3sRMU1eUcYRYuXwMGCPEeUZmrFEyH7YF48BiFPZRuvcCrwjUk1G", "p2wsh")
"Zpub74BgRig2QtzuRyjMNDq842RTURTK3dZVBLRnUTqzvaFCTVbYmFSN5hJztzJ12GBDfHj9H58b4jUqYDQfasDx2527dGgxpcfQM71NE1rGi9A"

see the linked issue for related discussion

@yuvadm
Copy link
Author

yuvadm commented Mar 6, 2021

@SomberNight I might be missing something, but how does convert_xkey help? To sign a UTXO spend I only have the BIP39 seeds, and I'm not sure how to get from those to the right derivation path.

@SomberNight
Copy link
Member

How did you obtain the three xpubs? Do you know what derivation paths were used for them?

You said you have a 2of3 p2wsh multisig wallet.
To create such a wallet in Electrum, select multisig, select 2of3, and add the three master keys, but in Zpub form (this signals p2wsh).
Then, use the console (add_key_origin) to add derivation path and root fingerprint info to the wallet. You are supposed to know what the derivation path and the root fingerprint is, for the coldcard to be able to sign.

@SomberNight
Copy link
Member

If you don't have the coldcards anymore, and just want to sign in software, you can do the following instead:

  1. if you don't care about security at all:
    • create new wallet in Electrum, select multisig, select 2of3, add all three cosigners one-by-one as bip39 seeds, and enter derivation path and select p2wsh as part of the wizard
      This should be straightforward but your PC becomes a single point of failure.
  2. more safe would be to have three different PCs running Electrum
    • on PC1, create new wallet in Electrum, select multisig, select 2of3
      • add one cosigner as bip39 seed, enter derivation path, select p2wsh
      • add other two cosigners as master public keys, in Zpub form
    • on PC2, do the same but rotate the cosigners (order does not matter but seed should correspond to different cosigner), i.e. add cosigner2 as bip39 seed, other cosigners as Zpubs
    • on PC3, same, add cosigner3 as bip39, other cosigners as Zpubs

@yuvadm
Copy link
Author

yuvadm commented Mar 6, 2021

@SomberNight the xpubs were originally created with P2WSH and m/48'/0'/0'/2' so I somehow need Electrum to support these seeds but to generate P2SH addresses.

(I also don't care about security at all, this is just a small test and I mainly want to understand how to fix the broken UTXO)

@SomberNight
Copy link
Member

the xpubs were originally created with P2WSH and m/48'/0'/0'/2' so I somehow need Electrum to support these seeds but to generate P2SH addresses.

If restoring from bip39 seed, the wizard asks you for derivation path and script type; that should be sufficient to "fix" your problem. Please try that.

@yuvadm
Copy link
Author

yuvadm commented Mar 6, 2021

@SomberNight so the question becomes how to I generate P2SH addresses, or handle P2SH UTXOs, in a wallet that is already configured as P2WSH

@SomberNight
Copy link
Member

just create a new wallet file in Electrum with the same keys but different script type.

@yuvadm
Copy link
Author

yuvadm commented Mar 6, 2021

Success! It took me a while but I finally figured it out, I just had to create a P2SH wallet but with m/48'/0'/0'/2' as the derivation path.

Thanks so much @SomberNight for your guidance and assistance 🙏

@yuvadm yuvadm closed this as completed Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants