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

descriptors: disallow hybrid public keys #28587

Merged
merged 1 commit into from Oct 5, 2023

Conversation

sipa
Copy link
Member

@sipa sipa commented Oct 4, 2023

Fixes #28511

The descriptor documentation (doc/descriptors.md) and BIP380 explicitly require that hex-encoded public keys start with 02 or 03 (compressed) or 04 (uncompressed). However, the current parsing/inference code permit 06 and 07 (hybrid) encoding as well. Fix this.

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 4, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK darosior, achow101

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #27255 (MiniTapscript: port Miniscript to Tapscript by darosior)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@sipa sipa changed the title miniscript: disallow hybrid public keys descriptors: disallow hybrid public keys Oct 4, 2023
The descriptor documentation (doc/descriptors.md) and BIP380 explicitly
require that hex-encoded public keys start with 02 or 03 (compressed) or
04 (uncompressed). However, the current parsing/inference code permit 06
and 07 (hybrid) encoding as well. Fix this.
@darosior
Copy link
Member

darosior commented Oct 4, 2023

Concept ACK.

@sipa sipa force-pushed the 202310_no_hybrid_descriptors branch from 7da67f9 to c1e6c54 Compare October 4, 2023 15:28
@darosior
Copy link
Member

darosior commented Oct 4, 2023

So this was permitted in both the legacy wallet and descriptor wallets, but only for watchonly wallets. Since we wouldn't generate one from a privkey. Right?

Trying to create a legacy wallet, importing a hybrid pubkey and migrating the wallet currently doesn't return an error (??) but does give a helpful message:

2023-10-04T17:17:54Z [test_hybrid_key_3] Error: Unrecognized descriptor found in wallet test_hybrid_key_3. The database might be corrupted or the software version is not compatible with one of your wallet descriptors. Please try running the latest software version
Details: Invalid descriptor: pkh(): Hybrid public keys are not allowed: iostream error

Trying to load a descriptor wallet containing a descriptor with a hybrid pubkey does return an error, although a slightly misleading one:

error code: -4
error message:
Wallet loading failed. Unrecognized descriptor found. Loading wallet /home/darosior/.bitcoin/regtest/wallets/test_hybrid_key_2/wallet.dat

The wallet might had been created on a newer version.
Please try running the latest software version.

And it still logs a helpful error message mentioning hybrid keys.

So this looks good to me overall. A node wouldn't start with a wallet containing a descriptor with a hybrid pubkey and we do log the right error message so a user would be able to figure out why it's failing. The migration not returning an error is a bit more concerning but also orthogonal to this PR. I'll ACK with a fresh head tomorrow morning.

@darosior
Copy link
Member

darosior commented Oct 5, 2023

ACK c1e6c54

@DrahtBot DrahtBot removed the request for review from darosior October 5, 2023 10:14
@fanquake fanquake added this to the 26.0 milestone Oct 5, 2023
@achow101
Copy link
Member

achow101 commented Oct 5, 2023

ACK c1e6c54

@DrahtBot DrahtBot removed the request for review from achow101 October 5, 2023 15:48
@achow101 achow101 merged commit 6e5cf8e into bitcoin:master Oct 5, 2023
16 checks passed
Frank-GER pushed a commit to syscoin/syscoin that referenced this pull request Oct 13, 2023
c1e6c54 descriptors: disallow hybrid public keys (Pieter Wuille)

Pull request description:

  Fixes bitcoin#28511

  The descriptor documentation (`doc/descriptors.md`) and [BIP380](https://github.com/bitcoin/bips/blob/master/bip-0380.mediawiki) explicitly require that hex-encoded public keys start with 02 or 03 (compressed) or 04 (uncompressed). However, the current parsing/inference code permit 06 and 07 (hybrid) encoding as well. Fix this.

ACKs for top commit:
  darosior:
    ACK c1e6c54
  achow101:
    ACK c1e6c54

Tree-SHA512: 23b674fb420619b2536d12da10008bb87cf7bc0333ec59e618c0d02c3574b468cc71248475ece37f76658d743ef51e68566948e903bca79fda5f7d75416fea4d
luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Oct 18, 2023
The descriptor documentation (doc/descriptors.md) and BIP380 explicitly
require that hex-encoded public keys start with 02 or 03 (compressed) or
04 (uncompressed). However, the current parsing/inference code permit 06
and 07 (hybrid) encoding as well. Fix this.

Github-Pull: bitcoin#28587
Rebased-From: c1e6c54
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Oct 19, 2023
The descriptor documentation (doc/descriptors.md) and BIP380 explicitly
require that hex-encoded public keys start with 02 or 03 (compressed) or
04 (uncompressed). However, the current parsing/inference code permit 06
and 07 (hybrid) encoding as well. Fix this.

Github-Pull: bitcoin#28587
Rebased-From: c1e6c54
@fanquake
Copy link
Member

fanquake commented Dec 7, 2023

Release note to be added in #29023.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule out hybrid keys in output descriptors
5 participants