miniscript: make GetStackSize independent of P2WSH context

It was taking into account the P2WSH script push in the number of stack
elements.
This commit is contained in:
Antoine Poinsot
2023-01-23 12:45:49 +01:00
parent 7bf078f2b7
commit 4ab382c2cd
3 changed files with 38 additions and 38 deletions

View File

@@ -1148,16 +1148,16 @@ public:
return true;
}
/** Return the maximum number of stack elements needed to satisfy this script non-malleably, including
* the script push. */
/** Return the maximum number of stack elements needed to satisfy this script non-malleably.
* This does not account for the P2WSH script push. */
std::optional<uint32_t> GetStackSize() const {
if (!ss.sat.valid) return {};
return ss.sat.value + 1;
return ss.sat.value;
}
//! Check the maximum stack size for this script against the policy limit.
bool CheckStackSize() const {
if (const auto ss = GetStackSize()) return *ss - 1 <= MAX_STANDARD_P2WSH_STACK_ITEMS;
if (const auto ss = GetStackSize()) return *ss <= MAX_STANDARD_P2WSH_STACK_ITEMS;
return true;
}