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
miniscript: replace decode_with_ext(., Ext::allow_all) with decode_consensus
Currently we have decode() and decode_insane() (which were both called
parse_* before PR #845). In practice though, throughout the codebase we
see that when decoding from script we want to relax more than sanity.
In particular, we frequently with ExtParams::allow_all, which beyond
relaxing the sanity rules, also allows raw pubkeyhashes. We do this in
the script interpreter and in PSBT, on the basis that once we're working
with a script, we should just deal with whatever the library is capable
of dealing with. (Is this the right decision? IMO yes. It could be
argued. But regardless, it's the decision we've made for the past many
versions of rust-miniscript.)
I also propose to backport this with deprecation, telling users that if
they really want parse_insane, they now need to call decode_with_ext and
specify ExtParams::insane. But if their goal was "parse anything that
might be allowed", they actually want decode_consensus.
There is now an asymmetry between parsing from string and parsing from
script: with strings we have parse() and parse_insane(). With script we
have decode() and decode_consensus(). I think this is correct, and
reflects the fact that somebody "breaking the rules" with a string is
likely trying to use syntactically valid Miniscripts without the library
whining at him, while somebody "breaking the rules" with a Script is
probably trying to deal with some immutable on-chain thing and wants the
library to work if at-all possible.
Right now the distinction is simply "do we support raw pkh or not" but I
think we could accept more-or-less arbitrary extensions to Miniscript in
this library that worked the same way (allowed when decoded from script
but disallowed from strings since there's no serialization).
let deser = Segwitv0Script::decode_insane(&ser).expect("deserialize result of serialize");
1167
+
let deser =
1168
+
Segwitv0Script::decode_consensus(&ser).expect("deserialize result of serialize");
1175
1169
assert_eq!(*tree, deser);
1176
1170
}
1177
1171
@@ -1312,19 +1306,19 @@ mod tests {
1312
1306
fnverify_parse(){
1313
1307
let ms = "and_v(v:hash160(20195b5a3d650c17f0f29f91c33f8f6335193d07),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))";
1314
1308
let ms:Segwitv0Script = Miniscript::from_str_insane(ms).unwrap();
let ms = "and_v(v:sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))";
1318
1312
let ms:Segwitv0Script = Miniscript::from_str_insane(ms).unwrap();
let ms = "and_v(v:ripemd160(20195b5a3d650c17f0f29f91c33f8f6335193d07),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))";
1322
1316
let ms:Segwitv0Script = Miniscript::from_str_insane(ms).unwrap();
let ms = "and_v(v:hash256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),or_d(sha256(96de8fc8c256fa1e1556d41af431cace7dca68707c78dd88c3acab8b17164c47),older(16)))";
1326
1320
let ms:Segwitv0Script = Miniscript::from_str_insane(ms).unwrap();
0 commit comments