mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 09:11:37 +00:00
descriptor: Expose key expression parsing #35918
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35918
Loading…
Reference in a new issue
No description provided.
Delete branch "parse-key-expression-v2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR exposes a utility function to parse and validate a standalone descriptor key expression.
This is particularly useful in GUI multisig setup flows where the UI accepts a pasted key expression. The GUI can use this parser to validate input, inspect the parsed key, and apply setup-specific policy i.e. reject private keys, uncompressed keys etc. (Multisig Wizard tracking issue: https://github.com/bitcoin/bitcoin/issues/35645)
PubkeyProvideris the existing internal representation of a parsed key expression. This PR exposes its interface indescriptor.hand adds a publicParsePubkey()overload that returns the providers produced by the existing parser.Key changes
GetOriginInfo()for retrieving explicitly provided key origin information.Also, while I'm here, I noticed that
musigparser accepted trailing characters apart from/.musig()expressionThe following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
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.
🐙 This pull request conflicts with the target branch and needs rebase.
ACK 93600f9f0360bf48a1f616f0f5db3c9ce985ce4b
🐙 This pull request conflicts with the target branch and needs rebase.
I see you hardcoded it for p2tr. shouldn't be for all script types? Why are you making the overload follow the p2tr rules only?
@pseudoramdom can you follow up here?
Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive linked from the Review report for their assessments.
🔵 Suggestion · Failed
musig()parsing leavesoutpartially populated without an explicit contractThe new
ParsePubkey()API can fail after adding participant private keys toout, but its failure contract and tests do not describe this; no current production caller was found.Location:
src/script/descriptor.cpp:2930(head).🔵 Suggestion · Standalone
PubkeyProviderresults lack an explicit cache-isolation contractSeparately parsed BIP32 keys reuse cache indices, so sharing a
DescriptorCachecan return another key's derived public key; no current caller doing this was found.Location:
src/script/descriptor.h:94(head).🔵 Suggestion ·
HavePrivateKeys()leaves its all-participant MuSig semantics undocumentedFor
musig(),HavePrivateKeys()requires all participants' private keys, making it unsuitable for rejecting any private material; no current caller using it for that policy was found.Location:
src/script/descriptor.h:143(head).Review coverage was incomplete.
Reviewed:
fdad1e48e855· Review report · Previous reportspermalink
Ping for rebase @pseudoramdom
Using P2TR here is intentional, as mentioned in the PR description. Its key parsing rules match what we want for standalone key expressions: accept compressed, x-only, extended, and musig() expressions, while rejecting uncompressed keys.
Rebased & force-pushed to https://github.com/bitcoin/bitcoin/pull/35918/commits/17ddfdc0edc3ac35b1a87c884d61db2a58941bce. No other changes.
The first commit,
7835e0ef70, fixes a bug I also found on v31.1:tr(musig(X)xyz)is accepted andxyzis dropped. The worse case is a typo such astr(musig(X)0/*), missing the/, which v31.1 turns into a non-rangedtr(musig(X))without an error. Since it is a parser fix and the rest of the PR adds a new API, would you split it into its own PR? It could then be reviewed and backported on its own.reACK
17ddfdc0edConcept ACK
A couple of nits in commits:
In 2nd commit (
c17a6ab) message body, it mentions "Mostly a move-only commit. Implementation of operator< is retained in descriptor.cpp" but there's no operator< indescriptor.cppordescriptor.h. What remains in the .cpp are the implementations ofHavePrivateKeys()andDetermineApostropheUse(). Perhaps a leftover of a previous version of this change?In 3rd commit (
17ddfdc), tiny nit: the title specifies ParsePubKey but the function name isParsePubkey.Please keep in mind that #36442 changes the internal
ParsePubkeyto return a single provider for multipath expressions, so the new public overload may need to follow, depending on which one gets merged first.I left another couple of non-blocking nits inline.
nit: maybe worth noting that it only covers the key's own origin, e.g. a musig() returns none even when its participants have one (there's no test for this yet; I'll suggest one later with some other test cases):
nit: "P2TR key rules" may not be obvious to callers, so perhaps spell out what it means, and that multipath returns more than one provider (?):
Fixed
Fixed in
b0f139d512Force-pushed to
b0f139d512to address @pablomartin4btc's feedback. Cleaned up commit messages and the code comments.reACK
b0f139d512Thanks! Here's the test I mentioned, the musig() case at the end of
parse_pubkey_origin_info, together with a few otherGetOriginInfo()cases (github.com/pablomartin4btc/bitcoin@9eea6bf07d):ACK
b0f139d512Thanks for addressing the nits.
I added some extra test cases for the new API in pablomartin4btc@ pr35918-tests (on top of
b0f139d), feel free to cherry-pick any of them (non-blocking):parse_pubkey_origin_info:GetOriginInfo()on each multipath expansion, with a fingerprint and no path, on a constant key, and on a musig() whose participant has an origin.parse_pubkey_invalid_expressions: input a "paste a key" field could receive (empty, leading whitespace, a whole descriptor, musig(...)0/*) is rejected without adding private keys. It doesn't assert messages that quote the input, so it won't conflict with #36648.parse_pubkey_hardened_after_xpub: xpub/0h/* parses butCanSelfExpand()is false, so callers validating a cosigner key know what to check.Mostly note to self: I got through the first two commits so far.
crACK
086b0cd0b0In
b0f139d512"descriptor: Add public ParsePubkey overload"This is a lot of boilerplate. Can this be deduplicated in a way similar to how descriptor tests use
Check?ACK
b0f139d512Concept ACK but Approach NACK
The first commit
7a81907c34descriptor: Reject trailing text after musig() should be a separate PR. It's a bug fix unrelated to the goal of this PR and can be reviewed, merged, and back-ported separately.Thanks for the review. While I agree that the musig() fix stands on its own, I kept it here because it's in the same parser this PR exposes through the new
ParsePubkey()overload. A key expression pasted into the GUI goes through this path, somusig(A,B)garbagewould otherwise be accepted. So the fix is not unrelated.If it should be backported, I'm happy to split it into its own PR.
Apart from the first commit, is there any concern with the rest of the approach?
Done in
fdad1e48e8. Added two helpers,CheckParsePubkey()andCheckUnparsablePubkey(), similar toCheck/CheckUnparsable.Force-pushed to
github.com/bitcoin/bitcoin@fdad1e48e8Deduplicated the
ParsePubkey()tests to useCheckParsePubkey()/CheckUnparsablePubkey()helpers, following theCheck/CheckUnparsablepattern.reACK
fdad1e48e8re-ACK
fdad1e48e8Since my last review, @achow101 feedback was addressed.
reACK
fdad1e48e8Rest all is pretty straightforward.
In
48ad4dfb96"descriptor: Reject trailing text after musig()"While this is fine, a more realistic test case would read more appropriately. Like the one mentioned in https://github.com/bitcoin/bitcoin/pull/35918#issuecomment-6246540048.