Skip to content

Commit bba9340

Browse files
committed
miniscript: don't anticipate signature presence in CalcStackSize()
It's true that for any public key there'll be a signature check in a valid Miniscript. The code would previously, when computing the size of a satisfaction, account for the signature when it sees a public key push. Instead, account for it when it is required (ie when encountering the `c:` wrapper). This has two benefits: - Allows to accurately compute the net effect of a fragment on the stack size. This is necessary to track the size of the stack during the execution of a Script. - It also just makes more sense, making the code more accessible to future contributors.
1 parent a3793f2 commit bba9340

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/script/miniscript.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,8 @@ struct Node {
813813
case Fragment::JUST_1:
814814
case Fragment::OLDER:
815815
case Fragment::AFTER: return {0, {}};
816-
case Fragment::PK_K: return {1, 1};
817-
case Fragment::PK_H: return {2, 2};
816+
case Fragment::PK_K: return {0, 0};
817+
case Fragment::PK_H: return {1, 1};
818818
case Fragment::SHA256:
819819
case Fragment::RIPEMD160:
820820
case Fragment::HASH256:
@@ -837,8 +837,8 @@ struct Node {
837837
case Fragment::MULTI: return {k + 1, k + 1};
838838
case Fragment::WRAP_A:
839839
case Fragment::WRAP_N:
840-
case Fragment::WRAP_S:
841-
case Fragment::WRAP_C: return subs[0]->ss;
840+
case Fragment::WRAP_S: return subs[0]->ss;
841+
case Fragment::WRAP_C: return {subs[0]->ss.sat + 1, subs[0]->ss.dsat + 1};
842842
case Fragment::WRAP_D: return {1 + subs[0]->ss.sat, 1};
843843
case Fragment::WRAP_V: return {subs[0]->ss.sat, {}};
844844
case Fragment::WRAP_J: return {subs[0]->ss.sat, 1};

0 commit comments

Comments
 (0)