Commit 5a5f749
committed
Merge #1040: fix(miniscript): count exactly k satisfactions in thresh max-size bounds
d7801d1 fix(miniscript): count exactly k satisfactions in thresh max-size bounds (russeree)
Pull request description:
A `thresh(k, ...)` witness satisfies exactly k children: the script checks
the running sum against k with `OP_EQUAL`, so any witness with a different
number of satisfied children is invalid. The maximum-satisfaction
computation in `ExtData::threshold` nevertheless selected k+1 children as
satisfied (`i <= k` instead of `i < k`), e.g. computing the maximum witness
size of `thresh(1,pk(A),s:pk(B))` as 146 bytes (two signatures) instead of
74 (one signature plus one empty dissatisfaction).
This inflates `Miniscript::max_satisfaction_weight()` and everything
derived from it, making fee/weight estimates overestimate by up to one
largest-child satisfaction per thresh node.
Found by differential testing against Bitcoin Core's miniscript
implementation (`Node::GetWitnessSize`/`GetStackSize` agree with the fixed
values, and with the reference implementation's satisfaction table,
which permits exactly k satisfactions).
ACKs for top commit:
apoelstra:
ACK d7801d1; successfully ran local tests
Tree-SHA512: 6b4a96f1d6fe27794d38c53b605630571a3333a9645ef7faf31014c67b2a693e4c72a02d321437938d121eab9bda86c4ea646ab2c5daa1cfd03dbac798b39f552 files changed
Lines changed: 18 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2112 | 2112 | | |
2113 | 2113 | | |
2114 | 2114 | | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
2115 | 2132 | | |
2116 | 2133 | | |
2117 | 2134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
901 | 901 | | |
902 | 902 | | |
903 | 903 | | |
904 | | - | |
| 904 | + | |
905 | 905 | | |
906 | 906 | | |
907 | 907 | | |
| |||
0 commit comments