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 @@ -246,15 +246,24 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
246
246
// TODO: We might require other compile errors for Taproot.
247
247
#[ cfg( feature = "compiler" ) ]
248
248
pub fn compile_tr ( & self , unspendable_key : Option < Pk > ) -> Result < Descriptor < Pk > , Error > {
249
- let ( internal_key, policy) = self . clone ( ) . extract_key ( unspendable_key) ?;
250
- let tree = Descriptor :: new_tr (
251
- internal_key,
252
- match policy {
253
- Policy :: Trivial => None ,
254
- policy => Some ( policy. compile_tr_policy ( ) ?) ,
255
- } ,
256
- ) ?;
257
- Ok ( tree)
249
+ self . is_valid ( ) ?; // Check for validity
250
+ match self . is_safe_nonmalleable ( ) {
251
+ ( false , _) => Err ( Error :: from ( CompilerError :: TopLevelNonSafe ) ) ,
252
+ ( _, false ) => Err ( Error :: from (
253
+ CompilerError :: ImpossibleNonMalleableCompilation ,
254
+ ) ) ,
255
+ _ => {
256
+ let ( internal_key, policy) = self . clone ( ) . extract_key ( unspendable_key) ?;
257
+ let tree = Descriptor :: new_tr (
258
+ internal_key,
259
+ match policy {
260
+ Policy :: Trivial => None ,
261
+ policy => Some ( policy. compile_tr_policy ( ) ?) ,
262
+ } ,
263
+ ) ?;
264
+ Ok ( tree)
265
+ }
266
+ }
258
267
}
259
268
260
269
/// 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