compiler: improve logic when deciding between conjunctions and multi/multi_a#657
Merged
apoelstra merged 5 commits intorust-bitcoin:masterfrom Mar 12, 2024
Merged
Conversation
There is more to come, but do a bunch now because it's cathartic.
When you grep the codebase for FIXME it's nice if the output isn't overwhelmed by the same message repeated 20 times.
This matches the same variant in Terminal, matches the string serialization "thresh", and will avoid weird compiler errors related to collisions with the upcoming `Threshold` type. This will be an annoying API-breaking change, but fortunately(?) this PR is already breaking the API for thresholds in an annoying way.
In our threshold logic we have some special cases to handle multi, multi_a, and conjunctions. However, we were not choosing between these special cases correctly. Our logic was roughly that we would try to use multi_a if all children were pk()s, OR try to use multi if all children were pk() and there weren't too many, OR try to use a conjunction if k == n. The correct logic is: if all children are keys, and there aren't too many, try to use multi or multi_a. ALSO, if k == n, try to use a conjunction. With this fix, the compiler correctly finds that conjunctions are more efficient than CHECKMULTISIG when k == n and n < 3. When n == 3 the two cases have equal cost, but it seems to prefer the conjunction. It also correctly finds that when k == n, it is always more efficient to use a conjunction than to use CHECKSIGADD. This change necessitates changing some tests.
489c851 to
200991d
Compare
heap-coder
added a commit
to heap-coder/rust-miniscript
that referenced
this pull request
Sep 27, 2025
…deciding between conjunctions and multi/multi_a
200991dbed0411bcad36990b366feddc7580ae0b compiler: improve logic for deciding between thresholds and ands (Andrew Poelstra)
bc3b8dc2ec549d3b8e98c54f3347bac4a18b87b8 policy: rename Threshold variant to Thresh (Andrew Poelstra)
78db616daa4335f211493436d8aa27613cda4bf4 consolidate some FIXMEs (Andrew Poelstra)
0666aef121424357b7f4e254f3ac950894ab8236 error: remove some unused variants (Andrew Poelstra)
b2ec4a878d66ad660948c081c266c46a6b9ffc2a clippy: fix some nits introduced by #651 (Andrew Poelstra)
Pull request description:
The compiler logic when encountering thresholds of pks is currently a bit confused, and therefore chooses multi/multi_a in cases where this is not the most efficient compilation.
This PR fixes that, and also brings in a few other cleanup commits that I had laying around.
This does **not** fix #656, which I didn't know how to approach.
ACKs for top commit:
sanket1729:
ACK 200991dbed0411bcad36990b366feddc7580ae0b
Tree-SHA512: 252a60891cf1c1d1cd3ded88d97122fd1e76bd25807770f4843ae68bd2d854fc617518f26be86dcb57cd7fc369e1a4be81daa42ee1a6d4bc976dbad6dc1150f6
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.
The compiler logic when encountering thresholds of pks is currently a bit confused, and therefore chooses multi/multi_a in cases where this is not the most efficient compilation.
This PR fixes that, and also brings in a few other cleanup commits that I had laying around.
This does not fix #656, which I didn't know how to approach.