Repository navigation
descriptor: Expose key expression parsing - #35918
pseudoramdom wants to merge 3 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, 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. |
b5eb6a8 to
93600f9
Compare
|
Ping for rebase @pseudoramdom |
93600f9 to
17ddfdc
Compare
|
Rebased & force-pushed to 17ddfdc. No other changes. |
|
The first commit, 7835e0e, fixes a bug I also found on v31.1: |
pablomartin4btc
left a comment
There was a problem hiding this comment.
Concept 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< in
descriptor.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 is
ParsePubkey.
Please keep in mind that #36442 changes the internal ParsePubkey to 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.
17ddfdc to
b0f139d
Compare
|
Force-pushed to b0f139d to address @pablomartin4btc's feedback. Cleaned up commit messages and the code comments. |
pablomartin4btc
left a comment
There was a problem hiding this comment.
ACK b0f139d
Thanks 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):
- 9eea6bf
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. - 959f099
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. - 32e2bcf
parse_pubkey_hardened_after_xpub: xpub/0h/* parses butCanSelfExpand()is false, so callers validating a cosigner key know what to check.
murchandamus
left a comment
There was a problem hiding this comment.
Mostly note to self: I got through the first two commits so far.
crACK 086b0cd
rkrux
left a comment
There was a problem hiding this comment.
Concept ACK but Approach NACK
The first commit 7a81907 descriptor: 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
Apart from the first commit, is there any concern with the rest of the approach? |
The musig() parser split the input at the closing parenthesis without validating the remaining text. This allowed unexpected characters after the expression to be ignored. Add a requirement for nonempty char after musig() to begin with '/'.
Expose the abstract interface by moving to descriptor.h to allow other modules to consume parsed key expressions. Mostly move-only. `HavePrivateKeys()` and `DetermineApostropheUse()` now have their impl in descriptor.cpp.
Add an overload for parsing standalone key expressions using P2TR key rules. Also, expose explicitly provided origin information through GetOriginInfo(), allowing callers to inspect the fingerprint and derivation path without re-parsing the expression.
b0f139d to
fdad1e4
Compare
|
Force-pushed to fdad1e4 |
rkrux
left a comment
There was a problem hiding this comment.
Apart from the first commit, is there any concern with the rest of the approach?
Rest all is pretty straightforward.
| CheckUnparsable("tr(musig(xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc/<0;1>,xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/<2;3>)/<3;4>)","tr(musig(xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL/<0;1>,xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/<2;3>)/<3;4>)", "tr(): musig(): Cannot have multipath participant keys if musig() is also multipath"); | ||
| CheckUnparsable("tr(musig()/0)", "tr(musig()/0)", "tr(): musig(): Must contain key expressions"); | ||
| CheckUnparsable("tr(musig(xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc/*,xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/*)/0)","tr(musig(xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL/*,xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/*)/0)", "tr(): musig(): Cannot have ranged participant keys if musig() also has derivation"); | ||
| CheckUnparsable("","rawtr(musig(02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9,03dff1d77f2a671c5f36183726db2341be58feae1da2deced843240f7b502ba659)unexpected_chars)","rawtr(): Unexpected characters after musig() expression"); |
There was a problem hiding this comment.
In 48ad4df "descriptor: Reject trailing text after musig()"
While this is fine, a more realistic test case would read more appropriately. Like the one mentioned in #35918 (comment).
+ CheckUnparsable("tr(musig(xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc,xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi)0/*)","tr(musig(xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL,xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8)0/*)","tr(): Unexpected characters after musig() expression");
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: #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()expression