Commit 1347a09
committed
compiler: improve logic for deciding between thresholds and ands
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.1 parent 58b6578 commit 1347a09
File tree
5 files changed
+59
-43
lines changed- examples
- src
- miniscript
- policy
5 files changed
+59
-43
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
18 | | - | |
| 17 | + | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| |||
451 | 450 | | |
452 | 451 | | |
453 | 452 | | |
454 | | - | |
455 | 453 | | |
456 | | - | |
457 | | - | |
| 454 | + | |
| 455 | + | |
458 | 456 | | |
459 | 457 | | |
460 | 458 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
1065 | 1065 | | |
1066 | 1066 | | |
1067 | 1067 | | |
1068 | | - | |
1069 | | - | |
1070 | | - | |
1071 | | - | |
1072 | | - | |
1073 | | - | |
1074 | | - | |
1075 | | - | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
1076 | 1080 | | |
1077 | | - | |
1078 | | - | |
1079 | | - | |
1080 | | - | |
1081 | | - | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
1082 | 1086 | | |
1083 | | - | |
1084 | | - | |
1085 | | - | |
| 1087 | + | |
1086 | 1088 | | |
1087 | 1089 | | |
1088 | 1090 | | |
| |||
1501 | 1503 | | |
1502 | 1504 | | |
1503 | 1505 | | |
1504 | | - | |
| 1506 | + | |
1505 | 1507 | | |
1506 | | - | |
1507 | | - | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
1508 | 1516 | | |
1509 | 1517 | | |
1510 | | - | |
| 1518 | + | |
1511 | 1519 | | |
1512 | 1520 | | |
1513 | 1521 | | |
| |||
1640 | 1648 | | |
1641 | 1649 | | |
1642 | 1650 | | |
1643 | | - | |
1644 | | - | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
1645 | 1660 | | |
1646 | 1661 | | |
1647 | 1662 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
505 | 505 | | |
506 | 506 | | |
507 | 507 | | |
508 | | - | |
509 | | - | |
| 508 | + | |
| 509 | + | |
510 | 510 | | |
511 | 511 | | |
512 | | - | |
513 | | - | |
| 512 | + | |
| 513 | + | |
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
| |||
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
| 529 | + | |
529 | 530 | | |
530 | 531 | | |
531 | 532 | | |
532 | 533 | | |
533 | | - | |
534 | | - | |
| 534 | + | |
| 535 | + | |
535 | 536 | | |
536 | 537 | | |
537 | | - | |
| 538 | + | |
538 | 539 | | |
539 | | - | |
540 | | - | |
| 540 | + | |
| 541 | + | |
541 | 542 | | |
542 | 543 | | |
543 | 544 | | |
| |||
0 commit comments