-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Add support for inferring tr() descriptors #22166
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
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. 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. |
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.
ACK 77466ae
ACK f9d6f9a |
re-ACK 13c6ab6 |
src/script/descriptor.cpp
Outdated
KeyOriginInfo info; | ||
if (provider.GetKeyOrigin(pubkey.GetID(), info)) { | ||
return std::make_unique<OriginPubkeyProvider>(0, std::move(info), std::move(key_provider)); | ||
} | ||
return key_provider; | ||
} | ||
|
||
std::unique_ptr<PubkeyProvider> InferXOnlyPubkey(const XOnlyPubKey& xkey, ParseScriptContext ctx, const SigningProvider& provider) | ||
{ | ||
unsigned char full_key[33] = {0x02}; |
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 would have a slight preference to use constants here instead of hardcoding 0x02
(and 0x03
below) and 33
.
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 agree with this, but prefer keeping it for a follow-up. There are several places where this is already done, and I'd like to introduce constants for it, as well as using them everywhere in the same PR - doing so here would be a distraction.
3f2ffb2
to
8349355
Compare
Addressed some comments, and also made this observable change: if (permit_uncompressed || key.IsCompressed()) {
CPubKey pubkey = key.GetPubKey();
out.keys.emplace(pubkey.GetID(), key);
- return std::make_unique<ConstPubkeyProvider>(key_exp_index, pubkey);
+ return std::make_unique<ConstPubkeyProvider>(key_exp_index, pubkey, ctx == ParseScriptContext::P2TR);
} else { Which will make descriptors with a provided private key inside |
re-ACK 8349355 |
It's too hot here to review code, but I can confirm that this correctly infers my |
Same, I propose we postpone the feature freeze a bit. Not able to concentrate at the moment. |
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.
tACK 8349355
However I glanced over InferTaprootTree
. I think it would help to include tests for the various problems that function is checking for.
subdesc = InferScript(script, ParseScriptContext::P2TR, provider); | ||
} | ||
if (!subdesc) { | ||
ok = false; |
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.
8349355: rather than failing, could we return raw()
(at least for leaf_ver == TAPROOT_LEAF_TAPSCRIPT
)? That can wait for a followup though, since we can't have tr()
descriptors with raw leaves in the wallet anyway atm, and raw()
is still limited to the top level.
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 that's exactly what this code does.
Rebased, will work on adding some tests for failure cases of |
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 something went wrong in your rebase.
For example in the original 8349355 you changed the argument bool xonly = false
to bool xonly
in the ConstPubkeyProvider
provider.
@Sjors Oops, thanks for catching that. I redid the rebase; does it look better now? |
re-ACK d637a9b Rebase looks good. |
re-utACK d637a9b Much better |
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.
Code review ACK d637a9b
std::vector<std::tuple<int, CScript, int>> ret; | ||
if (spenddata.merkle_root.IsNull()) return ret; | ||
|
||
/** Data structure to represent the nodes of the tree we're going to be build. */ |
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.
nit: to build
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.
touched up the various nits in #22323, feel free to add any others there
|
||
/** Data structure to represent the nodes of the tree we're going to be build. */ | ||
struct TreeNode { | ||
/** Hash of this none, if known; 0 otherwise. */ |
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.
nit: node
bool done = false; | ||
}; | ||
|
||
// Build tree from the provides branches. |
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.
nit: provided
184d453 script, doc: spelling update (Jon Atack) Pull request description: Clears out the report from `test/lint/lint-spelling.sh` and touches up the leftover nits in bitcoin/bitcoin#22166 (review). Happy to add any others people are aware of. ACKs for top commit: MarcoFalke: cr ACK 184d453 Sjors: utACK 184d453 Tree-SHA512: 3b0ef6bd5ff227363b0bda79eeb66763151c74f607bc3a2a7bfe7823e3eef196587bccfe639e714e8e27b918ba57e8317eda06f225143c32c736685087dbcd24
184d453 script, doc: spelling update (Jon Atack) Pull request description: Clears out the report from `test/lint/lint-spelling.sh` and touches up the leftover nits in bitcoin#22166 (review). Happy to add any others people are aware of. ACKs for top commit: MarcoFalke: cr ACK 184d453 Sjors: utACK 184d453 Tree-SHA512: 3b0ef6bd5ff227363b0bda79eeb66763151c74f607bc3a2a7bfe7823e3eef196587bccfe639e714e8e27b918ba57e8317eda06f225143c32c736685087dbcd24
08f57a0 Assert that IsComplete() in GetSpendData() (Pieter Wuille) d8f4b97 Remove default nHashTypeIn arguments to MutableTransactionSignatureCreator (Pieter Wuille) c7048aa Simplify SignTransaction precomputation loop (Pieter Wuille) addb9b5 Improve comments in taproot signing logic (Pieter Wuille) Pull request description: This addresses a few review comments from #21365 that were left at the time of merge (as well as some from #22166 applying to the commit it shared with #21365). I do not think any are blockers for a 22.0 release. ACKs for top commit: theStack: re-ACK 08f57a0 🌴 Zero-1729: crACK 08f57a0 jonatack: Code review ACK 08f57a0 per `git range-diff e9d6eb1 9336670 08f57a0` followed by re-code review per commit to swap context back into memory and debug build/run unit tests + feature_taproot.py as a sanity check Tree-SHA512: 968750109ba8d6faf3016035a38f81c6aefb724c632a3cab0bbf43cf31b9d187b6b0fddd8772768f57338df11eb07ab9c4c6dacdf3cf35b71f29699c67a301ea
08f57a0 Assert that IsComplete() in GetSpendData() (Pieter Wuille) d8f4b97 Remove default nHashTypeIn arguments to MutableTransactionSignatureCreator (Pieter Wuille) c7048aa Simplify SignTransaction precomputation loop (Pieter Wuille) addb9b5 Improve comments in taproot signing logic (Pieter Wuille) Pull request description: This addresses a few review comments from bitcoin#21365 that were left at the time of merge (as well as some from bitcoin#22166 applying to the commit it shared with bitcoin#21365). I do not think any are blockers for a 22.0 release. ACKs for top commit: theStack: re-ACK 08f57a0 🌴 Zero-1729: crACK 08f57a0 jonatack: Code review ACK 08f57a0 per `git range-diff e9d6eb1 9336670 08f57a0` followed by re-code review per commit to swap context back into memory and debug build/run unit tests + feature_taproot.py as a sanity check Tree-SHA512: 968750109ba8d6faf3016035a38f81c6aefb724c632a3cab0bbf43cf31b9d187b6b0fddd8772768f57338df11eb07ab9c4c6dacdf3cf35b71f29699c67a301ea
@@ -1847,16 +1847,14 @@ static bool ExecuteWitnessScript(const Span<const valtype>& stack_span, const CS | |||
return true; | |||
} | |||
|
|||
static bool VerifyTaprootCommitment(const std::vector<unsigned char>& control, const std::vector<unsigned char>& program, const CScript& script, uint256& tapleaf_hash) | |||
uint256 ComputeTapleafHash(uint8_t leaf_version, const CScript& script) |
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 mildly object the the use of the type CScript
here. While it is true that BIP-341 names this stack item "script", this value is only interpreted as a CScript in the case of BIP-342 where the leaf_version
is equal to TAPROOT_LEAF_TAPSCRIPT
(modulo TAPROOT_LEAF_MASK
). Otherwise it is simply a bytestring.
Includes:
getaddressinfo
report tr() descriptors as solvable (so that inferred descriptors are shown), despite not having signing code for them.