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 @@ -237,15 +237,24 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
237
237
// TODO: We might require other compile errors for Taproot. Will discuss and update.
238
238
#[ cfg( feature = "compiler" ) ]
239
239
pub fn compile_tr ( & self , unspendable_key : Option < Pk > ) -> Result < Descriptor < Pk > , Error > {
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)
240
+ self . is_valid ( ) ?; // Check for validity
241
+ match self . is_safe_nonmalleable ( ) {
242
+ ( false , _) => Err ( Error :: from ( CompilerError :: TopLevelNonSafe ) ) ,
243
+ ( _, false ) => Err ( Error :: from (
244
+ CompilerError :: ImpossibleNonMalleableCompilation ,
245
+ ) ) ,
246
+ _ => {
247
+ let ( internal_key, policy) = self . clone ( ) . extract_key ( unspendable_key) ?;
248
+ let tree = Descriptor :: new_tr (
249
+ internal_key,
250
+ match policy {
251
+ Policy :: Trivial => None ,
252
+ policy => Some ( policy. compile_tr_policy ( ) ?) ,
253
+ } ,
254
+ ) ?;
255
+ Ok ( tree)
256
+ }
257
+ }
249
258
}
250
259
251
260
/// Compile the descriptor into an optimized `Miniscript` representation
Original file line number Diff line number Diff line change @@ -407,5 +407,16 @@ mod tests {
407
407
Descriptor :: new_tr ( unspendable_key. clone ( ) , Some ( tree) ) . unwrap ( ) ;
408
408
assert_eq ! ( descriptor, expected_descriptor) ;
409
409
}
410
+
411
+ {
412
+ // Invalid policy compilation (Duplicate PubKeys)
413
+ let policy: Concrete < String > = policy_str ! ( "or(and(pk(A),pk(B)),and(pk(A),pk(D)))" ) ;
414
+ let descriptor = policy. compile_tr ( Some ( unspendable_key. clone ( ) ) ) ;
415
+
416
+ assert_eq ! (
417
+ descriptor. unwrap_err( ) . to_string( ) ,
418
+ "Policy contains duplicate keys"
419
+ ) ;
420
+ }
410
421
}
411
422
}
You can’t perform that action at this time.
0 commit comments