mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-09-19 17:21:55 +02:00
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.
This commit is contained in:
@@ -866,6 +866,12 @@ struct PSBTOutput
|
|||||||
s_tree >> depth;
|
s_tree >> depth;
|
||||||
s_tree >> leaf_ver;
|
s_tree >> leaf_ver;
|
||||||
s_tree >> script;
|
s_tree >> script;
|
||||||
|
if (depth > TAPROOT_CONTROL_MAX_NODE_COUNT) {
|
||||||
|
throw std::ios_base::failure("Output Taproot tree has as leaf greater than Taproot maximum depth");
|
||||||
|
}
|
||||||
|
if ((leaf_ver & ~TAPROOT_LEAF_MASK) != 0) {
|
||||||
|
throw std::ios_base::failure("Output Taproot tree has a leaf with an invalid leaf version");
|
||||||
|
}
|
||||||
m_tap_tree->Add((int)depth, script, (int)leaf_ver, true /* track */);
|
m_tap_tree->Add((int)depth, script, (int)leaf_ver, true /* track */);
|
||||||
}
|
}
|
||||||
if (!m_tap_tree->IsComplete()) {
|
if (!m_tap_tree->IsComplete()) {
|
||||||
|
Reference in New Issue
Block a user