Skip to content

Commit b7d8465

Browse files
committed
Update satisfy API for taproot support
1 parent 329d145 commit b7d8465

File tree

2 files changed

+313
-83
lines changed

2 files changed

+313
-83
lines changed

src/miniscript/mod.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use std::marker::PhantomData;
2828
use std::{fmt, str};
2929

3030
use bitcoin::blockdata::script;
31+
use bitcoin::util::taproot::{LeafVersion, TapLeafHash};
3132

3233
pub use self::context::{BareCtx, Legacy, Segwitv0, Tap};
3334

@@ -358,7 +359,12 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
358359
where
359360
Pk: ToPublicKey,
360361
{
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+
{
362368
satisfy::Witness::Stack(stack) => {
363369
Ctx::check_witness::<Pk>(&stack)?;
364370
Ok(stack)
@@ -378,7 +384,16 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
378384
where
379385
Pk: ToPublicKey,
380386
{
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+
{
382397
satisfy::Witness::Stack(stack) => {
383398
Ctx::check_witness::<Pk>(&stack)?;
384399
Ok(stack)
@@ -449,6 +464,7 @@ serde_string_impl_pk!(Miniscript, "a miniscript", Ctx; ScriptContext);
449464
#[cfg(test)]
450465
mod tests {
451466

467+
use bitcoin::util::taproot::TapLeafHash;
452468
use miniscript::satisfy::BitcoinSchnorrSig;
453469
use {Satisfier, ToPublicKey};
454470

@@ -1038,7 +1054,11 @@ mod tests {
10381054

10391055
// a simple satisfier that always outputs the same signature
10401056
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> {
10421062
Some(BitcoinSchnorrSig {
10431063
sig: self.0,
10441064
hash_ty: bitcoin::util::sighash::SigHashType::Default,

0 commit comments

Comments
 (0)