mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
descriptor, rpc, wallet: do not echo key material in error messages #36648
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!36648
Loading…
Reference in a new issue
No description provided.
Delete branch "descriptor-errors-no-keys"
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?
Some descriptor error messages quote the string the caller sent, and a descriptor can hold a private key. The error then carries the key, or part of it, into places the request may not go: an application's log, an error reporter, a screenshot shared for help.
This PR stops the quoting. A failing key is named by its position, a failing entry of
solving_data.descriptorsby its index, and a function name is quoted only where the parser accepts it. The commit message lists each changed error.key '<key>' is not validkey is not validMulti: key '<key>' is not validMulti: key 3: key is not valid'wpkh(<key>)x' is not a valid descriptor functionUnexpected text after the closing ')' of wpkh()'<start of a key>(<rest>' is not a valid descriptor functionNot a valid descriptor expressionUnable to parse descriptor '<descriptor>': Missing checksumUnable to parse descriptor at index 1: Missing checksumCould not add descriptor '<descriptor>': ...The 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:
wallet_importdescriptorsto separaterun_test()contents into specific functions by nebula-21)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.
🟠 Minor · Removing
<iterator>leaves its declarations used without a direct includedescriptor.cpp still uses std::back_inserter, so removing
<iterator>introduces a transitive-header dependency and will likely cause the enforced IWYU job to restore it and fail.Location:
src/script/descriptor.cpp:38(base).🔵 Suggestion · Taproot key errors no longer identify the failing leaf
After removing the quoted key, malformed keys in different tr() leaves can produce identical errors because the new positions are local to each leaf.
Location:
src/script/descriptor.cpp:2055(head).🔵 Suggestion · A colon alone selects the miniscript diagnostic
descriptor.cpp:2834-2850: with no '(',
nameis the whole expression, so any ':' selects 'Not a valid miniscript expression'. An uppercase BITCOIN:BC1Q... input gets it although miniscript's wrapper scan found no wrappers. getdescriptorinfo returns it unchanged.Location:
src/script/descriptor.cpp:2833(head).🔵 Suggestion ·
CheckUnparsablediscards the private-input diagnosticCheckUnparsable (descriptor_tests.cpp:26-35) parses prv then pub into one
errorand asserts only the second, so private-input diagnostics in the existing cases (e.g. line 624's malformed WIF) go unchecked for echoed key text.Location:
src/test/descriptor_tests.cpp:26(head).Review coverage was incomplete.
Reviewed:
ad18016046b4· Full review report · Previous reportspermalink
ACK
ad18016046In a descriptor with many keys, the error doesn't say which one failed. For
wsh(multi(2,KEY1,KEY2,KEY3))with a typo in KEY3, the error is only:With 15 keys, the user has to check each one by hand.
You can print the key's position.
key_exp_indexalready counts the keys parsed before the failing one, so no key text is needed.Something like that:
Note: the count includes each musig() aggregate key, so a key after a musig() gets a number one higher than a user would count. The test expectations for these messages still need updating.
In a descriptor with many keys, the error doesn't say which one failed. For
wsh(multi(2,KEY1,KEY2,KEY3))with a typo in KEY3, the error is only:With 15 keys, the user has to check each one by hand.
You can print the key's position.
key_exp_indexalready counts the keys parsed before the failing one, so no key text is needed.Something like that:
Note: the count includes each musig() aggregate key, so a key after a musig() gets a number one higher than a user would count. The test expectations for these messages still need updating.
For
wpkh(KEY)x, the error is now 'wpkh(...' is not a valid descriptor function.wpkhis a valid function; the real problem is the trailing x. The old message echoed the full text, so the mistake was visible.you can make it skip the key inside the function print the chars that is connected to
).somethiing like that:
suggested diff:
i see you are using the same value of
MAX_QUOTED_CHARSin https://github.com/bitcoin/bitcoin/pull/36648/changes#diff-dcb25ae6b5207f65ae6a1cd364c9e62e5a9df69a1cd21b9ed79849cc99c2150bR1880you can define it here and reuse it inside descriptor.cpp
similar to the key index solving_data.descriptors is a list, now that the descriptor is no longer printed, the error doesn't say which one failed:
You can print its index in the list.
should be:
we could do something like that instead:
Done:
wpkh(KEY)xnow givesUnexpected text after the closing ')' of wpkh(), which quotes the name only because it is a function the parser accepts, and never the text after the), which can be the end of a key.Done: the error gives the key's position in its list, counted from 1, as in
Multi: key 3: key is not valid, and a key after amusig()is not counted one higher.Done, as in the other copy of this comment:
Multi: key 3: key is not valid, counted within the list.Done with your loop:
Unable to parse descriptor at index 1: Missing checksum.MAX_QUOTED_CHARSis gone: no error quotes text by length any more, so there is nothing left to share withbip32.cpp.@uqlidi Thanks, I addressed all four points; the replies are inline.
🚧 At least one of the CI tasks failed.
Task
iwyu: https://github.com/bitcoin/bitcoin/actions/runs/41338732479/job/124943987697LLM reason (✨ experimental): CI failed because IWYU/clang-format modified
src/script/descriptor.cpp(adding<ranges>), so the lint check detected uncommitted formatting/include changes.Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
I pushed a fix for the CI failure, and one of the two suggestions in the Ralph review.
The iwyu task wanted
#include <ranges>indescriptor.cpp, andrpc_getdescriptoractivity.pystill expected the old message foraddrx(...). Both are fixed.An expression with miniscript wrappers that fails to parse, such as
z:pk(K)orvv:pk(K), now gives "Not a valid miniscript expression" instead of "Not a valid pk() expression". The wrappers may be what is wrong, andpk(K)itself can be valid.The other suggestion adds the position of the failing
tr()leaf and key path element, as in "tr(): leaf 2: pk(): key is not valid". It rewords errors master already has: 22 expectations change indescriptor_tests.cpp, 12 of them in master's own tests (+33 −27 in two files). I can add it here if a maintainer wants it.🐙 This pull request conflicts with the target branch and needs rebase.