fix(miniscript): count exactly k satisfactions in thresh max-size bounds - #1040
Merged
apoelstra merged 1 commit intoSep 4, 2026
Merged
Conversation
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).
Member
|
Nice! This is a pretty subtle difference in outputs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
thresh(k, ...)witness satisfies exactly k children: the script checksthe running sum against k with
OP_EQUAL, so any witness with a differentnumber of satisfied children is invalid. The maximum-satisfaction
computation in
ExtData::thresholdnevertheless selected k+1 children assatisfied (
i <= kinstead ofi < k), e.g. computing the maximum witnesssize of
thresh(1,pk(A),s:pk(B))as 146 bytes (two signatures) instead of74 (one signature plus one empty dissatisfaction).
This inflates
Miniscript::max_satisfaction_weight()and everythingderived 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/GetStackSizeagree with the fixedvalues, and with the reference implementation's satisfaction table,
which permits exactly k satisfactions).