You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
f3a50c9 miniscript: rename IsSane and IsSaneSubexpression to prevent misuse (Antoine Poinsot)
c5fe516 miniscript: nit: don't return after assert(false) (Antoine Poinsot)
7bbaca9 miniscript: explicit the threshold size computation in multi() (Antoine Poinsot)
8323e42 miniscript: add an OpCode typedef for readability (Antoine Poinsot)
7a549c6 miniscript: mark nodes with duplicate keys as insane (Antoine Poinsot)
8c0f8bf fuzz: add a Miniscript target for string representation roundtripping (Antoine Poinsot)
be34d50 fuzz: rename and improve the Miniscript Script roundtrip target (Antoine Poinsot)
7eb70f0 miniscript: tiny doc fixups (Antoine Poinsot)
5cea85f miniscript: split ValidSatisfactions from IsSane (Antoine Poinsot)
a0f064d miniscript: introduce a CheckTimeLocksMix helper (Antoine Poinsot)
ed45ee3 miniscript: use optional instead of bool/outarg (Antoine Poinsot)
1ab8d89 miniscript: make equality operator non-recursive (Antoine Poinsot)
5922c66 scripted-diff: miniscript: rename 'nodetype' variables to 'fragment' (Antoine Poinsot)
c5f65db miniscript: remove a workaround for a GCC 4.8 bug (Antoine Poinsot)
Pull request description:
The Miniscript repository and the Miniscript integration PR here have been a moving target for the past months, and some final cleanups were done there that were not included here. I initially intended to add some small followup commits to bitcoin#24148 but i think there are enough of them to be worth a followup PR on its own.
Some parts of the code did not change since it was initially written in 2019, and the code could use some modernization. (Use std::optional instead of out args, remove old compiler workarounds).
We refactored the helpers to be more meaningful, and also did some renaming. A new fuzz target was also added and both were merged in a single file. 2 more will be added in bitcoin#24149 that will be contained in this file too.
The only behaviour change in this PR is to rule out Miniscript with duplicate keys from sane Miniscripts. In a P2WSH context, signatures can be rebounded (Miniscript does not use CODESEPARATOR) and it's reasonable to assume that reusing keys across the Script drops the malleability guarantees.
It was previously assumed such Miniscript would never exist in the first place since a compiler should never create them. We finally agreed that if one were to exist (say, written by hand or from a buggy compiler) it would be very confusing if an imported Miniscript descriptor (after bitcoin#24148) with duplicate keys was deemed sane (ie, "safe to use") by Bitcoin Core. We now check for duplicate keys in the constructor.
This is (still) joint work with Pieter Wuille. (Actually he entirely authored the cleanups and code modernization.)
ACKs for top commit:
sipa:
utACK f3a50c9 (with the caveat that a lot of it is my own code)
sanket1729:
code review ACK f3a50c9. Did not review the fuzz tests.
Tree-SHA512: c043325e4936fe25e8ece4266b46119e000c6745f88cea530fed1edf01c80f03ee6f9edc83b6e9d42ca01688d184bad16bfd967c5bb8037744e726993adf3deb
Copy file name to clipboardExpand all lines: src/script/miniscript.cpp
+44-51Lines changed: 44 additions & 51 deletions
Original file line number
Diff line number
Diff line change
@@ -17,69 +17,67 @@ Type SanitizeType(Type e) {
17
17
int num_types = (e << "K"_mst) + (e << "V"_mst) + (e << "B"_mst) + (e << "W"_mst);
18
18
if (num_types == 0) return""_mst; // No valid type, don't care about the rest
19
19
assert(num_types == 1); // K, V, B, W all conflict with each other
20
-
bool ok = // Work around a GCC 4.8 bug that breaks user-defined literals in macro calls.
21
-
(!(e << "z"_mst) || !(e << "o"_mst)) && // z conflicts with o
22
-
(!(e << "n"_mst) || !(e << "z"_mst)) && // n conflicts with z
23
-
(!(e << "n"_mst) || !(e << "W"_mst)) && // n conflicts with W
24
-
(!(e << "V"_mst) || !(e << "d"_mst)) && // V conflicts with d
25
-
(!(e << "K"_mst) || (e << "u"_mst)) && // K implies u
26
-
(!(e << "V"_mst) || !(e << "u"_mst)) && // V conflicts with u
27
-
(!(e << "e"_mst) || !(e << "f"_mst)) && // e conflicts with f
28
-
(!(e << "e"_mst) || (e << "d"_mst)) && // e implies d
29
-
(!(e << "V"_mst) || !(e << "e"_mst)) && // V conflicts with e
30
-
(!(e << "d"_mst) || !(e << "f"_mst)) && // d conflicts with f
31
-
(!(e << "V"_mst) || (e << "f"_mst)) && // V implies f
32
-
(!(e << "K"_mst) || (e << "s"_mst)) && // K implies s
33
-
(!(e << "z"_mst) || (e << "m"_mst)); // z implies m
34
-
assert(ok);
20
+
assert(!(e << "z"_mst) || !(e << "o"_mst)); // z conflicts with o
21
+
assert(!(e << "n"_mst) || !(e << "z"_mst)); // n conflicts with z
22
+
assert(!(e << "n"_mst) || !(e << "W"_mst)); // n conflicts with W
23
+
assert(!(e << "V"_mst) || !(e << "d"_mst)); // V conflicts with d
24
+
assert(!(e << "K"_mst) || (e << "u"_mst)); // K implies u
25
+
assert(!(e << "V"_mst) || !(e << "u"_mst)); // V conflicts with u
26
+
assert(!(e << "e"_mst) || !(e << "f"_mst)); // e conflicts with f
27
+
assert(!(e << "e"_mst) || (e << "d"_mst)); // e implies d
28
+
assert(!(e << "V"_mst) || !(e << "e"_mst)); // V conflicts with e
29
+
assert(!(e << "d"_mst) || !(e << "f"_mst)); // d conflicts with f
30
+
assert(!(e << "V"_mst) || (e << "f"_mst)); // V implies f
31
+
assert(!(e << "K"_mst) || (e << "s"_mst)); // K implies s
32
+
assert(!(e << "z"_mst) || (e << "m"_mst)); // z implies m
35
33
return e;
36
34
}
37
35
38
-
Type ComputeType(Fragment nodetype, Type x, Type y, Type z, const std::vector<Type>& sub_types, uint32_t k, size_t data_size, size_t n_subs, size_t n_keys) {
36
+
Type ComputeType(Fragment fragment, Type x, Type y, Type z, const std::vector<Type>& sub_types, uint32_t k, size_t data_size, size_t n_subs, size_t n_keys) {
39
37
// Sanity check on data
40
-
if (nodetype == Fragment::SHA256 || nodetype == Fragment::HASH256) {
38
+
if (fragment == Fragment::SHA256 || fragment == Fragment::HASH256) {
0 commit comments