Skip to content

Commit 1781af3

Browse files
committed
Merge #525: Update multi_a to not include n wrapper
7118c84 Add breaking tests (sanket1729) 0203377 Update multi_a to not include n wrapper (sanket1729) Pull request description: While we are at it, do not use the default impl. This makes these types of errors easy to make. I think this could have easily been prevented if I was forced to explicitly write AnyNonZero in front of multi_a. Reported by darosior. ACKs for top commit: apoelstra: There is some github weirdness going on. ACK 7118c84 darosior: utACK 7118c84 Tree-SHA512: 6acca28d5645b3cc3d66eae3544ede8647a923a798b2592f062d65c0aa05778e8593db7607521893e38af114f153351d55d1219394e0d720dfd61fdb775932e1
2 parents de54bff + 7118c84 commit 1781af3

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

src/miniscript/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,4 +1136,14 @@ mod tests {
11361136
SegwitMs::parse_insane(&script).unwrap_err();
11371137
SegwitMs::parse_with_ext(&script, &ExtParams::allow_all()).unwrap();
11381138
}
1139+
1140+
#[test]
1141+
fn tr_multi_a_j_wrapper() {
1142+
// Reported by darosior
1143+
// `multi_a` fragment may require the top stack element to be the empty vector.
1144+
// Previous version had incorrectly copied this code from multi.
1145+
type TapMs = Miniscript<String, Tap>;
1146+
let ms_str = TapMs::from_str_insane("j:multi_a(1,A,B,C)");
1147+
assert!(ms_str.is_err());
1148+
}
11391149
}

src/miniscript/types/correctness.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ impl Property for Correctness {
159159
}
160160
}
161161

162+
fn from_multi_a(_: usize, _: usize) -> Self {
163+
Correctness {
164+
base: Base::B,
165+
input: Input::Any,
166+
dissatisfiable: true,
167+
unit: true,
168+
}
169+
}
170+
162171
fn from_hash() -> Self {
163172
Correctness {
164173
base: Base::B,

src/miniscript/types/malleability.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ impl Property for Malleability {
108108
}
109109
}
110110

111+
fn from_multi_a(_: usize, _: usize) -> Self {
112+
Malleability {
113+
dissat: Dissat::Unique,
114+
safe: true,
115+
non_malleable: true,
116+
}
117+
}
118+
111119
fn from_hash() -> Self {
112120
Malleability {
113121
dissat: Dissat::Unknown,

src/miniscript/types/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,7 @@ pub trait Property: Sized {
256256
fn from_multi(k: usize, n: usize) -> Self;
257257

258258
/// Type property of a `MultiA` fragment
259-
fn from_multi_a(k: usize, n: usize) -> Self {
260-
// default impl same as multi
261-
Self::from_multi(k, n)
262-
}
259+
fn from_multi_a(k: usize, n: usize) -> Self;
263260

264261
/// Type property of a hash fragment
265262
fn from_hash() -> Self;
@@ -572,6 +569,13 @@ impl Property for Type {
572569
}
573570
}
574571

572+
fn from_multi_a(k: usize, n: usize) -> Self {
573+
Type {
574+
corr: Property::from_multi_a(k, n),
575+
mall: Property::from_multi_a(k, n),
576+
}
577+
}
578+
575579
fn from_hash() -> Self {
576580
Type {
577581
corr: Property::from_hash(),

tests/test_desc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ fn test_descs(cl: &Client, testdata: &TestData) {
395395
let result = test_desc_satisfy(cl, testdata, "tr(X!,{pk(X1!),pk(X2!)})");
396396
assert_eq!(result, Err(DescError::PsbtFinalizeError));
397397

398+
// Test 10: Test taproot desc with ZERO known keys
399+
let result = test_desc_satisfy(cl, testdata, "tr(X!,j:multi_a(3,X1!,X2,X3,X4))");
400+
assert_eq!(result, Err(DescError::DescParseError));
401+
398402
// Test 11: Test taproot with insufficient known keys
399403
let result = test_desc_satisfy(cl, testdata, "tr(X!,{pk(X1!),multi_a(3,X2!,X3,X4)})");
400404
assert_eq!(result, Err(DescError::PsbtFinalizeError));

0 commit comments

Comments
 (0)