-
Notifications
You must be signed in to change notification settings - Fork 88
fix(descriptor): reject bare descriptors in check_wallet_descriptor #457
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
Open
tharu-jwd
wants to merge
2
commits into
bitcoindevkit:master
Choose a base branch
from
tharu-jwd:fix/reject-bare-descriptors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+42
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -321,6 +321,22 @@ | |
| )); | ||
| } | ||
|
|
||
| // Reject descriptor types that have no standard address form (e.g. bare scripts, raw scripts). | ||
| // Using an allowlist guards against any future unsupported types as well. | ||
| match descriptor.desc_type() { | ||
| DescriptorType::Pkh | ||
| | DescriptorType::Wpkh | ||
| | DescriptorType::ShWpkh | ||
| | DescriptorType::Sh | ||
| | DescriptorType::ShSortedMulti | ||
| | DescriptorType::Wsh | ||
| | DescriptorType::ShWsh | ||
| | DescriptorType::ShWshSortedMulti | ||
| | DescriptorType::WshSortedMulti | ||
| | DescriptorType::Tr => {} | ||
| _ => return Err(DescriptorError::UnsupportedDescriptorType), | ||
| } | ||
|
|
||
| // Run miniscript's sanity check, which will look for duplicated keys and other potential | ||
| // issues. | ||
| descriptor.sanity_check()?; | ||
|
|
@@ -912,11 +928,29 @@ | |
| let result = check_wallet_descriptor(&descriptor); | ||
|
|
||
| assert!(result.is_err()); | ||
|
|
||
| // Bare descriptors (e.g. pk()) have no standard address form and must be rejected. | ||
| let descriptor = Descriptor::<DescriptorPublicKey>::from_str( | ||
| "pk(tpubD6NzVbkrYhZ4XHndKkuB8FifXm8r5FQHwrN6oZuWCz13qb93rtgKvD4PQsqC4HP4yhV3tA2fqr2RbY5mNXfM7RxXUoeABoDtsFUq2zJq6YK/0/*)", | ||
| ) | ||
| .expect("must parse"); | ||
| assert_matches!( | ||
| check_wallet_descriptor(&descriptor), | ||
| Err(DescriptorError::UnsupportedDescriptorType) | ||
| ); | ||
|
|
||
| // Raw script descriptors have no standard address form and must be rejected. | ||
| let descriptor = Descriptor::<DescriptorPublicKey>::from_str("raw(deadbeef)") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test is failing because of this. You cannot parse raw, (as @ValuedMammal mentioned) so this error is expected. Your pk works because thats a bare descriptor. Might want to take this out. I think fmt issue as well. |
||
| .expect("must parse"); | ||
| assert_matches!( | ||
| check_wallet_descriptor(&descriptor), | ||
| Err(DescriptorError::UnsupportedDescriptorType) | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_sh_wsh_sortedmulti_redeemscript() { | ||
| use miniscript::psbt::PsbtInputExt; | ||
|
|
||
| let secp = Secp256k1::new(); | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'll be also worth fixing the case for
let descriptor = "raw(deadbeef)";I wrote a while back the reproducing of this audit report: https://gist.github.com/sdmg15/54ee406e3826ba4acc51312e30054df2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since DescriptorType::Raw does not exist as one of the types in DescriptorType, it might be best to match desc.type on all supported types and then return Err is its not part of any of those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is reproducing an error which is expected, and technically not a panic.