Skip to content

Conversation

va-an
Copy link
Contributor

@va-an va-an commented Jul 26, 2025

Description

Resolves #204.

Notes to the reviewers

For creating the tr descriptor, I used the NUMS pubkey proposed in BIP-341.

There is discussion about adding NUMS key to rust-bicoin, we can use it in the future from there.

Also there is BIP draft for new descriptor key expression unspendable() for exacly this use case - we will simply use descriptor tr(unspendable(), TREE).

Changelog notice

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature
  • I've updated CHANGELOG.md

@coveralls
Copy link

coveralls commented Jul 26, 2025

Pull Request Test Coverage Report for Build 16973164527

Details

  • 51 of 63 (80.95%) changed or added relevant lines in 3 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+7.9%) to 10.586%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/utils.rs 0 2 0.0%
src/main.rs 0 3 0.0%
src/handlers.rs 51 58 87.93%
Files with Coverage Reduction New Missed Lines %
src/handlers.rs 1 14.01%
Totals Coverage Status
Change from base Build 15731603419: 7.9%
Covered Lines: 94
Relevant Lines: 888

💛 - Coveralls

Copy link
Collaborator

@tvpeter tvpeter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this @va-an .

I have left a few comments for you.
Thank you

src/handlers.rs Outdated
// This ensures the key path is effectively disabled and only script path can be used.
// See https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#constructing-and-spending-taproot-outputs
let tree = TapTree::Leaf(Arc::new(taproot_policy));
Descriptor::new_tr(NUMS_UNSPENDABLE_KEY.to_string(), Some(tree))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the NUMS_UNSPENDABLE_KEY represents XonlyPublicKey, so it is better to parse it into an XonlyPublicKey and not used as a string (since strings are used for key placeholders) to avoid type mismatch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added validation that NUMS_UNSPENDABLE_KEY is parsed as XOnlyPublicKey.
Do you mean that nums_key should be passed as XOnlyPublicKey to the new_tr function?

let json_result = result.unwrap();
let descriptor = json_result.get("descriptor").unwrap().as_str().unwrap();
assert_eq!(descriptor, EXPECTED_AND_AB);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add test cases for invalid/invalid policies and other edge cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some cases as separated test.

@va-an va-an requested a review from tvpeter August 14, 2025 18:13
@tvpeter tvpeter added this to the CLI 2.0.0 milestone Aug 25, 2025
Copy link
Collaborator

@tvpeter tvpeter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@va-an Please rebase so I can test.

Thank you.

Comment on lines +722 to +723
use bdk_wallet::miniscript::descriptor::TapTree;
use std::sync::Arc;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the imports to the top of the file and gate them.

Comment on lines +1037 to +1038
assert!(EXPECTED_PK_A.contains(NUMS_UNSPENDABLE_KEY_HEX));
assert!(EXPECTED_AND_AB.contains(NUMS_UNSPENDABLE_KEY_HEX));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering how much value these assert statements add when we are in control of the expected values ?

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

Successfully merging this pull request may close these issues.

Update compile command to support creating taproot descriptors
4 participants