@@ -28,6 +28,7 @@ use std::marker::PhantomData;
28
28
use std:: { fmt, str} ;
29
29
30
30
use bitcoin:: blockdata:: script;
31
+ use bitcoin:: util:: taproot:: { LeafVersion , TapLeafHash } ;
31
32
32
33
pub use self :: context:: { BareCtx , Legacy , Segwitv0 , Tap } ;
33
34
@@ -358,7 +359,12 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
358
359
where
359
360
Pk : ToPublicKey ,
360
361
{
361
- match satisfy:: Satisfaction :: satisfy ( & self . node , & satisfier, self . ty . mall . safe ) . stack {
362
+ // Only satisfactions for default versions (0xc0) are allowed.
363
+ let ver = LeafVersion :: default ( ) ;
364
+ let leaf_hash = TapLeafHash :: from_script ( & self . encode ( ) , ver) ;
365
+ match satisfy:: Satisfaction :: satisfy ( & self . node , & satisfier, self . ty . mall . safe , & leaf_hash)
366
+ . stack
367
+ {
362
368
satisfy:: Witness :: Stack ( stack) => {
363
369
Ctx :: check_witness :: < Pk > ( & stack) ?;
364
370
Ok ( stack)
@@ -378,7 +384,16 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
378
384
where
379
385
Pk : ToPublicKey ,
380
386
{
381
- match satisfy:: Satisfaction :: satisfy_mall ( & self . node , & satisfier, self . ty . mall . safe ) . stack {
387
+ let ver = LeafVersion :: default ( ) ;
388
+ let leaf_hash = TapLeafHash :: from_script ( & self . encode ( ) , ver) ;
389
+ match satisfy:: Satisfaction :: satisfy_mall (
390
+ & self . node ,
391
+ & satisfier,
392
+ self . ty . mall . safe ,
393
+ & leaf_hash,
394
+ )
395
+ . stack
396
+ {
382
397
satisfy:: Witness :: Stack ( stack) => {
383
398
Ctx :: check_witness :: < Pk > ( & stack) ?;
384
399
Ok ( stack)
@@ -449,6 +464,7 @@ serde_string_impl_pk!(Miniscript, "a miniscript", Ctx; ScriptContext);
449
464
#[ cfg( test) ]
450
465
mod tests {
451
466
467
+ use bitcoin:: util:: taproot:: TapLeafHash ;
452
468
use miniscript:: satisfy:: BitcoinSchnorrSig ;
453
469
use { Satisfier , ToPublicKey } ;
454
470
@@ -1038,7 +1054,11 @@ mod tests {
1038
1054
1039
1055
// a simple satisfier that always outputs the same signature
1040
1056
impl < Pk : ToPublicKey > Satisfier < Pk > for SimpleSatisfier {
1041
- fn lookup_schnorr_sig ( & self , _pk : & Pk ) -> Option < BitcoinSchnorrSig > {
1057
+ fn lookup_tap_leaf_script_sig (
1058
+ & self ,
1059
+ _pk : & Pk ,
1060
+ _h : & TapLeafHash ,
1061
+ ) -> Option < BitcoinSchnorrSig > {
1042
1062
Some ( BitcoinSchnorrSig {
1043
1063
sig : self . 0 ,
1044
1064
hash_ty : bitcoin:: util:: sighash:: SigHashType :: Default ,
0 commit comments