File tree 2 files changed +29
-9
lines changed
2 files changed +29
-9
lines changed Original file line number Diff line number Diff line change @@ -230,15 +230,24 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
230
230
// TODO: We might require other compile errors for Taproot.
231
231
#[ cfg( feature = "compiler" ) ]
232
232
pub fn compile_tr ( & self , unspendable_key : Option < Pk > ) -> Result < Descriptor < Pk > , Error > {
233
- let ( internal_key, policy) = self . clone ( ) . extract_key ( unspendable_key) ?;
234
- let tree = Descriptor :: new_tr (
235
- internal_key,
236
- match policy {
237
- Policy :: Trivial => None ,
238
- policy => Some ( policy. compile_tr_policy ( ) ?) ,
239
- } ,
240
- ) ?;
241
- Ok ( tree)
233
+ self . is_valid ( ) ?; // Check for validity
234
+ match self . is_safe_nonmalleable ( ) {
235
+ ( false , _) => Err ( Error :: from ( CompilerError :: TopLevelNonSafe ) ) ,
236
+ ( _, false ) => Err ( Error :: from (
237
+ CompilerError :: ImpossibleNonMalleableCompilation ,
238
+ ) ) ,
239
+ _ => {
240
+ let ( internal_key, policy) = self . clone ( ) . extract_key ( unspendable_key) ?;
241
+ let tree = Descriptor :: new_tr (
242
+ internal_key,
243
+ match policy {
244
+ Policy :: Trivial => None ,
245
+ policy => Some ( policy. compile_tr_policy ( ) ?) ,
246
+ } ,
247
+ ) ?;
248
+ Ok ( tree)
249
+ }
250
+ }
242
251
}
243
252
244
253
/// Compile the descriptor into an optimized `Miniscript` representation
Original file line number Diff line number Diff line change @@ -401,5 +401,16 @@ mod tests {
401
401
Descriptor :: new_tr ( unspendable_key. clone ( ) , Some ( tree) ) . unwrap ( ) ;
402
402
assert_eq ! ( descriptor, expected_descriptor) ;
403
403
}
404
+
405
+ {
406
+ // Invalid policy compilation (Duplicate PubKeys)
407
+ let policy: Concrete < String > = policy_str ! ( "or(and(pk(A),pk(B)),and(pk(A),pk(D)))" ) ;
408
+ let descriptor = policy. compile_tr ( Some ( unspendable_key. clone ( ) ) ) ;
409
+
410
+ assert_eq ! (
411
+ descriptor. unwrap_err( ) . to_string( ) ,
412
+ "Policy contains duplicate keys"
413
+ ) ;
414
+ }
404
415
}
405
416
}
You can’t perform that action at this time.
0 commit comments