-
Notifications
You must be signed in to change notification settings - Fork 37.8k
psbt: Check Taproot tree depth and leaf versions #25513
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
Since TaprootBuilder has assertions for the depth and leaf versions, the PSBT decoder should check these values before calling TaprootBuilder::Add so that the assertions are not triggered on malformed taproot trees.
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 76fb300
utACK 76fb300 Maybe reject |
I don't think the annex byte has any effect on the leaf version. AFAICT, a future leaf version could b |
From BIP341:
I guess it's in theory possible to use 0x50 as leaf version, but it would be only be usable in spends that also have an annex. |
If we want to add direct PSBT support for annexes later, presumably in the form of additional https://github.com/bitcoin/bips/blob/master/bip-0371.mediawiki |
I don't see how annexes are at all related to a field which only contains leaf scripts. We wouldn't be adding annexes to this field - they would be in a separate field. |
@achow101 The leaf version is the first byte of the last witness stack element in a P2TR script path spend, after skipping over the annex field if present, which would follow the control block. So while there is no actual consensus rule against leaf version 0x50, constructing a spend for it would imply the spend must have an annex as well, because otherwise the control block would be interpreted as an annex. For this reason, the BIP does state that leaf version cannot be 0x50. |
I get that, but I don't see why we should be checking that in a leaf script deserializer. Sure, it may not be a good idea and we shouldn't consider signing scripts with such a leaf version unless there is an annex, but that doesn't mean that the deserializer should be enforcing it. Frankly, I don't think we should even be adding these depth and leaf version checks in the first place, and the only reason I'm adding them is to avoid hitting asserts that exist elsewhere. If the user wants to do something stupid like using bad leaf versions or having things be too deep, then the signer should be dealing with it, not the deserializer. And even if they do, if those paths are never revealed or used, then it doesn't matter. |
@achow101 Fair point, I see where you're coming from. There is perhaps another reason why depth checking makes sense too, as a DoS prevention mechanism (e.g. put script paths with 1000000 levels in a PSBT, which would hurt the users passing around such PSBTs, even if those script paths are unused). |
utACK 76fb300 |
76fb300 psbt: Check Taproot tree depth and leaf versions (Andrew Chow) Pull request description: Since TaprootBuilder has assertions for the depth and leaf versions, the PSBT decoder should check these values before calling TaprootBuilder::Add so that the assertions are not triggered on malformed taproot trees. Fixes bitcoin#22558 (comment) ACKs for top commit: Sjors: utACK 76fb300 sipa: utACK 76fb300 w0xlt: ACK bitcoin@76fb300 Tree-SHA512: 94b288bc1453d10bce9a8a6389bc866f2c71c76579b7908e22d6b5770ac387086f6221af8597668e62977d4d6861fe2d72ec7b052002a2c36769d056b2e66360
Since TaprootBuilder has assertions for the depth and leaf versions, the
PSBT decoder should check these values before calling
TaprootBuilder::Add so that the assertions are not triggered on
malformed taproot trees.
Fixes #22558 (comment)