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

server/asset/btc: require zpub, but offer xpub conversion #1255

Merged
merged 2 commits into from
Oct 28, 2021

Conversation

chappjc
Copy link
Member

@chappjc chappjc commented Oct 25, 2021

For a server operator to accept BTC for the registration fee, it is currently necessary to provide an extended public key with the "xpub" prefix. This is because the btcutil/hdkeychain package only recognizes such xpub strings as being from a given network, otherwise the net/version bytes are unknown. However, the derived fee addresses are P2WPKH.

The potential trouble is that wallets that generate native segwit addresses tend to return "zpub"-prefixed extended public key encodings in following BIP-84 (vpub for testnet and regnet). I have verified that Electrum does this if the wallet was created as native segwit, and Exodus actually exports both an xpub and zpub that do not seem to correspond to the same extended key (two separate derivation paths) making it potentially ill-advised to use the xpub for segwit addresses!

Prior to this PR, an operator with a wallet that provides a zpub would have to convert to an xpub. This is not hard (see here), but it is confusing and unnecessary since the dex software can do it. Further, if they got an xpub from a non-segwit wallet or non-segwit path, it's possibly they will have to go to some trouble to claim funds sent to segwit addresses derived from this extended key.

To address this, this PR now requires the key to be with a "zpub" prefix. Also, if an "xpub" is provided, it will convert it to "zpub" and return an error with this string so the operator is aware that segwit addresses will be generated if they decide to use that zpub.

@chappjc chappjc marked this pull request as draft October 25, 2021 20:03
@chappjc chappjc marked this pull request as ready for review October 25, 2021 20:15
@chappjc
Copy link
Member Author

chappjc commented Oct 26, 2021

This is running on dex-test.ssgen.io, on top of #1239.

I registered fresh there with it using a vpub. The electrum --testnet wallet for that vpub saw the fee txn.

image

Copy link
Member

@buck54321 buck54321 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine, but harness doesn't work anymore.

failed to create fee addresser for asset btc: provided extended key (prefix "tpub") not for p2wpkh, equivalent is "vpub5SLqN2bLY4WeZJ9SmNJHsyzqVKreTXD4ZnPC22MugDNcjhKX5xNX9QiQWcE4SSRzVWyHWUihpKRT7hckDGNzVc69wSX2JPcfGeNiT5c2XZy"

@chappjc chappjc merged commit 0124247 into decred:master Oct 28, 2021
@chappjc chappjc deleted the xpub-conversion branch October 28, 2021 21:31
@chappjc chappjc added this to the 0.3 milestone Oct 30, 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

Successfully merging this pull request may close these issues.

2 participants