Skip to content

Commit

Permalink
fixup! miniscript: check maximum stack size during execution
Browse files Browse the repository at this point in the history
  • Loading branch information
darosior committed Oct 7, 2023
1 parent 4c3fc73 commit 5861427
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/script/miniscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -1457,16 +1457,21 @@ struct Node {
return true;
}

/** Whether this node is of type B, K or W. (That is, anything but V.) */
bool IsBKW() const {
return !((GetType() & "BKW"_mst) == ""_mst);
}

/** Return the maximum number of stack elements needed to satisfy this script non-malleably. */
std::optional<uint32_t> GetStackSize() const {
if (!ss.sat.valid) return {};
return ss.sat.netdiff + 1;
return ss.sat.netdiff + static_cast<int32_t>(IsBKW());
}

//! Return the maximum size of the stack during execution of this script.
std::optional<uint32_t> GetExecStackSize() const {
if (!ss.sat.valid) return {};
return ss.sat.exec + 1;
return ss.sat.exec + static_cast<int32_t>(IsBKW());
}

//! Check the maximum stack size for this script against the policy limit.
Expand Down

0 comments on commit 5861427

Please sign in to comment.