Merge bitcoin/bitcoin#25513: psbt: Check Taproot tree depth and leaf versions

76fb300b63 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 https://github.com/bitcoin/bitcoin/pull/22558#issuecomment-1170935136

ACKs for top commit:
  Sjors:
    utACK 76fb300b63
  sipa:
    utACK 76fb300b63
  w0xlt:
    ACK 76fb300b63

Tree-SHA512: 94b288bc1453d10bce9a8a6389bc866f2c71c76579b7908e22d6b5770ac387086f6221af8597668e62977d4d6861fe2d72ec7b052002a2c36769d056b2e66360
This commit is contained in:
fanquake 2022-07-19 20:52:52 +01:00
commit 6900162aea
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1

View File

@ -866,6 +866,12 @@ struct PSBTOutput
s_tree >> depth;
s_tree >> leaf_ver;
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 */);
}
if (!m_tap_tree->IsComplete()) {