Skip to content

Commit 4ab382c

Browse files
committed
miniscript: make GetStackSize independent of P2WSH context
It was taking into account the P2WSH script push in the number of stack elements.
1 parent 7bf078f commit 4ab382c

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

src/script/miniscript.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,16 +1148,16 @@ struct Node {
11481148
return true;
11491149
}
11501150

1151-
/** Return the maximum number of stack elements needed to satisfy this script non-malleably, including
1152-
* the script push. */
1151+
/** Return the maximum number of stack elements needed to satisfy this script non-malleably.
1152+
* This does not account for the P2WSH script push. */
11531153
std::optional<uint32_t> GetStackSize() const {
11541154
if (!ss.sat.valid) return {};
1155-
return ss.sat.value + 1;
1155+
return ss.sat.value;
11561156
}
11571157

11581158
//! Check the maximum stack size for this script against the policy limit.
11591159
bool CheckStackSize() const {
1160-
if (const auto ss = GetStackSize()) return *ss - 1 <= MAX_STANDARD_P2WSH_STACK_ITEMS;
1160+
if (const auto ss = GetStackSize()) return *ss <= MAX_STANDARD_P2WSH_STACK_ITEMS;
11611161
return true;
11621162
}
11631163

src/test/fuzz/miniscript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ void TestNode(const NodeRef& node, FuzzedDataProvider& provider)
973973

974974
if (nonmal_success) {
975975
// Non-malleable satisfactions are bounded by GetStackSize().
976-
assert(witness_nonmal.stack.size() <= *node->GetStackSize());
976+
assert(witness_nonmal.stack.size() <= *node->GetStackSize() + 1);
977977
// If a non-malleable satisfaction exists, the malleable one must also exist, and be identical to it.
978978
assert(mal_success);
979979
assert(witness_nonmal.stack == witness_mal.stack);

0 commit comments

Comments
 (0)