Skip to content

Commit 76fb300

Browse files
committed
psbt: Check Taproot tree depth and leaf versions
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.
1 parent b6cf0f8 commit 76fb300

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/psbt.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,12 @@ struct PSBTOutput
866866
s_tree >> depth;
867867
s_tree >> leaf_ver;
868868
s_tree >> script;
869+
if (depth > TAPROOT_CONTROL_MAX_NODE_COUNT) {
870+
throw std::ios_base::failure("Output Taproot tree has as leaf greater than Taproot maximum depth");
871+
}
872+
if ((leaf_ver & ~TAPROOT_LEAF_MASK) != 0) {
873+
throw std::ios_base::failure("Output Taproot tree has a leaf with an invalid leaf version");
874+
}
869875
m_tap_tree->Add((int)depth, script, (int)leaf_ver, true /* track */);
870876
}
871877
if (!m_tap_tree->IsComplete()) {

0 commit comments

Comments
 (0)