Skip to content

psbt: require output taproot trees to be complete - #566

Open
bitcoisas wants to merge 1 commit into
ElementsProject:masterfrom
bitcoisas:psbt-taptree-complete
Open

bitcoisas wants to merge 1 commit into
ElementsProject:masterfrom
bitcoisas:psbt-taptree-complete

Conversation

@bitcoisas

@bitcoisas bitcoisas commented Nov 23, 2026 •

Copy link
Copy Markdown

Fixes #565.

Follows Bitcoin Core's TaprootBuilder::ValidDepths(): track which depths hold a node waiting for its sibling and reject trees with a missing sibling (1), leaves after the tree is complete (0,0), or a leaf above an unfinished branch (2,1,2).

The valid value in test_taproot_tree was itself incomplete (1,2,128), so it's replaced by a complete tree that still reaches depth 128, and an incomplete tree is now also checked through wally_psbt_from_bytes. The new tests fail without the fix.

@bitcoisas
bitcoisas force-pushed the psbt-taptree-complete branch from aa8a2f7 to a3fd77a Compare November 23, 2026 17:58
@bitcoisas
bitcoisas marked this pull request as ready for review November 23, 2026 17:59
Comment thread src/psbt.c Resolved
Comment thread src/psbt.c Resolved
taproot_tree_value_verify() checked each leaf but not the tree as a
whole, so leaves that don't form a complete binary tree were accepted,
while Bitcoin Core rejects them. Track the depths waiting for a sibling
and reject trees with a missing sibling, leaves after the tree is
complete, or a leaf above an unfinished branch.

Fixes ElementsProject#565.
@bitcoisas
bitcoisas force-pushed the psbt-taptree-complete branch from a3fd77a to 7227257 Compare November 23, 2026 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PSBT_OUT_TAP_TREE: incomplete trees are accepted in strict mode

2 participants