File tree Expand file tree Collapse file tree 2 files changed +29
-9
lines changed Expand file tree Collapse file tree 2 files changed +29
-9
lines changed Original file line number Diff line number Diff line change @@ -256,15 +256,24 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
256
256
// TODO: We might require other compile errors for Taproot. Will discuss and update.
257
257
#[ cfg( feature = "compiler" ) ]
258
258
pub fn compile_tr ( & self , unspendable_key : Option < Pk > ) -> Result < Descriptor < Pk > , Error > {
259
- let ( internal_key, policy) = self . clone ( ) . extract_key ( unspendable_key) ?;
260
- let tree = Descriptor :: new_tr (
261
- internal_key,
262
- match policy {
263
- Policy :: Trivial => None ,
264
- policy => Some ( policy. compile_tr_policy ( ) ?) ,
265
- } ,
266
- ) ?;
267
- Ok ( tree)
259
+ self . is_valid ( ) ?; // Check for validity
260
+ match self . is_safe_nonmalleable ( ) {
261
+ ( false , _) => Err ( Error :: from ( CompilerError :: TopLevelNonSafe ) ) ,
262
+ ( _, false ) => Err ( Error :: from (
263
+ CompilerError :: ImpossibleNonMalleableCompilation ,
264
+ ) ) ,
265
+ _ => {
266
+ let ( internal_key, policy) = self . clone ( ) . extract_key ( unspendable_key) ?;
267
+ let tree = Descriptor :: new_tr (
268
+ internal_key,
269
+ match policy {
270
+ Policy :: Trivial => None ,
271
+ policy => Some ( policy. compile_tr_policy ( ) ?) ,
272
+ } ,
273
+ ) ?;
274
+ Ok ( tree)
275
+ }
276
+ }
268
277
}
269
278
270
279
/// 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