Skip to content

Commit fbb393e

Browse files
committed
Policy normalize bug
Normalization bug in then special case when both is_and and is_or is true for thresh(1,frag). Added an example test case that failed because of it.
1 parent 8bbcc83 commit fbb393e

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/policy/compiler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,7 @@ mod tests {
12461246
assert!(policy_compile_lift_check("and(pk(A),pk(B))").is_ok());
12471247
assert!(policy_compile_lift_check("or(pk(A),pk(B))").is_ok());
12481248
assert!(policy_compile_lift_check("thresh(2,pk(A),pk(B),pk(C))").is_ok());
1249+
assert!(policy_compile_lift_check("or(thresh(1,pk(A),pk(B)),pk(C))").is_ok());
12491250

12501251
assert_eq!(
12511252
policy_compile_lift_check("thresh(2,after(9),after(9),pk(A))"),

src/policy/semantic.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -413,18 +413,15 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
413413
for sub in subs {
414414
match sub {
415415
Policy::Trivial | Policy::Unsatisfiable => {}
416-
Policy::Threshold(1, or_subs) => {
417-
if is_or {
418-
ret_subs.extend(or_subs);
419-
} else {
420-
ret_subs.push(Policy::Threshold(1, or_subs));
421-
}
422-
}
423-
Policy::Threshold(k, and_subs) => {
424-
if k == and_subs.len() && is_and {
425-
ret_subs.extend(and_subs)
426-
} else {
427-
ret_subs.push(Policy::Threshold(k, and_subs));
416+
Policy::Threshold(k, subs) => {
417+
match (is_and, is_or) {
418+
(true, true) => {
419+
// means m = n = 1, thresh(1,X) type thing.
420+
ret_subs.push(Policy::Threshold(k, subs));
421+
}
422+
(true, false) if k == subs.len() => ret_subs.extend(subs), // and case
423+
(false, true) if k == 1 => ret_subs.extend(subs), // or case
424+
_ => ret_subs.push(Policy::Threshold(k, subs)),
428425
}
429426
}
430427
x => ret_subs.push(x),

0 commit comments

Comments
 (0)