Repository navigation
fix: validate taproot control block conversion - #1083
Conversation
thunderbiscuit
left a comment
There was a problem hiding this comment.
This looks like it solves the problem. Trying to review it alongside with Claude I have 1 piece of feedback I would keep, and it's the fact that the leaf-version equality check is reject PSBTs that rust-bitcoin itself accepts?
rust-bitcoin apparently doesn't check that the two leaf versions match. This allows creating a PSBT that cannot be finalized because it would create an invalid transaction. The check/guard here doesn't really hurt, but also is adding a layer of check not done elsewhere.
The other 2 parts of the PR are good and worth adding for sure.
Yeah, I think that rust-bitcoin accepts PSBTs where the control block and script value have different leaf versions. I added the check because our current conversion otherwise uses the control block’s version for both fields. Removing only the check would silently change the script value’s version. We could keep the check and reject mismatches, or convert each version separately and preserve both values (matching rust-bitcoin’s behavior?) Any preference? |
|
I reproduced this case and confirmed current master is lossy here: when the two versions differ, the tap-script leaf version is silently replaced by the control-block version. One nuance though: rust-bitcoin can preserve and round-trip both values independently, and BIP341 consensus derives the actual spend leaf version from the control block itself. The mismatch does break normal Miniscript finalization, but the separate BIP371 leaf-version field is PSBT metadata rather than part of the final witness. Since our FFI types already carry both values independently, would preserving both here be closer to upstream rust-bitcoin semantics than rejecting the mismatch? |
There was a problem hiding this comment.
ACK c5f7f2b. Sorry it took me so long to get to this! A quick rebase and this is ready for merge.
Description
Reject invalid Taproot output key parity and mismatched leaf versions during PSBT input conversion (which prevents silent control block corruption).
Notes to the reviewers
Documentation
bdk_walletbitcoinuniffiChangelog
Checklists
All Submissions:
cargo fmtandcargo clippybefore committingchangelog:*labelNew Features:
Bugfixes: