Skip to content

Commit 6900162

Browse files
committed
Merge bitcoin/bitcoin#25513: psbt: Check Taproot tree depth and leaf versions
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/bitcoin#22558 (comment) ACKs for top commit: Sjors: utACK 76fb300 sipa: utACK 76fb300 w0xlt: ACK bitcoin/bitcoin@76fb300 Tree-SHA512: 94b288bc1453d10bce9a8a6389bc866f2c71c76579b7908e22d6b5770ac387086f6221af8597668e62977d4d6861fe2d72ec7b052002a2c36769d056b2e66360
2 parents 9c97ba5 + 76fb300 commit 6900162

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)