Skip to content

Commit b11cdc2

Browse files
committed
Merge #737: Misc compatibility-with-12.x things
1259375 miniscript: make display prefer 'u' over 'l' in the fragment l:0 (Andrew Poelstra) 67fdc50 descriptor: reject strings of the form "tr(<key>,)" (Andrew Poelstra) 00cac40 descriptor: add unit test demonstrating sanity-checking behavior in <= 12.x (Andrew Poelstra) Pull request description: This PR has three changes which are mostly unrelated except that they were all found when fuzzing my "rewrite expression parser to be nonrecursive" branch against 12.x. * First is a unit test demonstrating #734. It doesn't fix anything, just tests the current behavior. * Second is a fix for #736 (backported in #735). * Third tweaks the new `Display` code from #722 to change how the ambiguous `l:0`/`u:0` is serialized, to match 12.x. ACKs for top commit: sanket1729: ACK 1259375 Tree-SHA512: 921d65a1efd49bda0f9db488a2854b004e14518f584d832497a9dbc13a845ceec99544375385570c6ac42d4985277e8dcbb3aa8654de93235cf9067ba601f91d
2 parents 734d34e + 1259375 commit b11cdc2

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

src/descriptor/mod.rs

+39
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,21 @@ mod tests {
10361036
);
10371037
}
10381038

1039+
#[test]
1040+
fn display_prefers_u() {
1041+
// The fragments u:0 and l:0 are identical in terms of Script and
1042+
// in terms of the in-memory representation -- OrI(False, False).
1043+
// Test that the way we display the ambiguous fragment doesn't
1044+
// change, in case somebody somehow is depending on it.
1045+
let desc = StdDescriptor::from_str("sh(u:0)").unwrap();
1046+
assert_eq!("sh(u:0)#ncq3yf9h", desc.to_string());
1047+
1048+
// This is a regression test for https://github.com/rust-bitcoin/rust-miniscript/pull/735
1049+
// which was found at the same time. It's just a bug plain and simple.
1050+
let desc = StdDescriptor::from_str("sh(and_n(u:0,1))").unwrap();
1051+
assert_eq!("sh(and_n(u:0,1))#5j5tw8nm", desc.to_string());
1052+
}
1053+
10391054
#[test]
10401055
fn desc_rtt_tests() {
10411056
roundtrip_descriptor("c:pk_k()");
@@ -2011,6 +2026,30 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
20112026
Descriptor::<DescriptorPublicKey>::from_str("wsh(andor(pk(tpubDEN9WSToTyy9ZQfaYqSKfmVqmq1VVLNtYfj3Vkqh67et57eJ5sTKZQBkHqSwPUsoSskJeaYnPttHe2VrkCsKA27kUaN9SDc5zhqeLzKa1rr/0'/<0;1;2;3>/*),older(10000),pk(tpubD8LYfn6njiA2inCoxwM7EuN3cuLVcaHAwLYeups13dpevd3nHLRdK9NdQksWXrhLQVxcUZRpnp5CkJ1FhE61WRAsHxDNAkvGkoQkAeWDYjV/8/<0;1;2>/*)))").unwrap_err();
20122027
}
20132028

2029+
#[test]
2030+
fn regression_736() {
2031+
Descriptor::<DescriptorPublicKey>::from_str(
2032+
"tr(0000000000000000000000000000000000000000000000000000000000000002,)",
2033+
)
2034+
.unwrap_err();
2035+
}
2036+
2037+
#[test]
2038+
fn regression_734() {
2039+
Descriptor::<DescriptorPublicKey>::from_str(
2040+
"wsh(or_i(pk(0202baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0a66a),1))",
2041+
)
2042+
.unwrap();
2043+
Descriptor::<DescriptorPublicKey>::from_str(
2044+
"sh(or_i(pk(0202baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0a66a),1))",
2045+
)
2046+
.unwrap();
2047+
Descriptor::<DescriptorPublicKey>::from_str(
2048+
"tr(02baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0a66a,1)",
2049+
)
2050+
.unwrap_err();
2051+
}
2052+
20142053
#[test]
20152054
fn test_context_pks() {
20162055
let comp_key = bitcoin::PublicKey::from_str(

src/descriptor/tr.rs

-3
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,6 @@ fn parse_tr_tree(s: &str) -> Result<expression::Tree, Error> {
603603
return Err(Error::Unexpected("invalid taproot internal key".to_string()));
604604
}
605605
let internal_key = expression::Tree { name: key.name, args: vec![] };
606-
if script.is_empty() {
607-
return Ok(expression::Tree { name: "tr", args: vec![internal_key] });
608-
}
609606
let (tree, rest) = expression::Tree::from_slice_delim(script, 1, '{')?;
610607
if rest.is_empty() {
611608
Ok(expression::Tree { name: "tr", args: vec![internal_key, tree] })

src/miniscript/display.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,14 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
260260
Terminal::ZeroNotEqual(..) => "n",
261261
Terminal::AndV(_, ref r) if matches!(r.as_inner(), Terminal::True) => "t",
262262
Terminal::AndV(..) => "and_v",
263-
Terminal::AndB(..) => "and_b",
264263
Terminal::AndOr(_, _, ref c) if matches!(c.as_inner(), Terminal::False) => "and_n",
264+
Terminal::AndB(..) => "and_b",
265265
Terminal::AndOr(..) => "andor",
266266
Terminal::OrB(..) => "or_b",
267267
Terminal::OrD(..) => "or_d",
268268
Terminal::OrC(..) => "or_c",
269-
Terminal::OrI(ref l, _) if matches!(l.as_inner(), Terminal::False) => "l",
270269
Terminal::OrI(_, ref r) if matches!(r.as_inner(), Terminal::False) => "u",
270+
Terminal::OrI(ref l, _) if matches!(l.as_inner(), Terminal::False) => "l",
271271
Terminal::OrI(..) => "or_i",
272272
Terminal::Thresh(..) => "thresh",
273273
Terminal::Multi(..) => "multi",

0 commit comments

Comments
 (0)