Skip to content

Commit 284bbd5

Browse files
committed
Update satisfy API for taproot support
1 parent c4bf098 commit 284bbd5

File tree

2 files changed

+303
-84
lines changed

2 files changed

+303
-84
lines changed

src/miniscript/mod.rs

+21-3
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,11 @@ 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 leaf_hash = TapLeafHash::from_script(&self.encode(), LeafVersion::TapScript);
364+
match satisfy::Satisfaction::satisfy(&self.node, &satisfier, self.ty.mall.safe, &leaf_hash)
365+
.stack
366+
{
362367
satisfy::Witness::Stack(stack) => {
363368
Ctx::check_witness::<Pk>(&stack)?;
364369
Ok(stack)
@@ -378,7 +383,15 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
378383
where
379384
Pk: ToPublicKey,
380385
{
381-
match satisfy::Satisfaction::satisfy_mall(&self.node, &satisfier, self.ty.mall.safe).stack {
386+
let leaf_hash = TapLeafHash::from_script(&self.encode(), LeafVersion::TapScript);
387+
match satisfy::Satisfaction::satisfy_mall(
388+
&self.node,
389+
&satisfier,
390+
self.ty.mall.safe,
391+
&leaf_hash,
392+
)
393+
.stack
394+
{
382395
satisfy::Witness::Stack(stack) => {
383396
Ctx::check_witness::<Pk>(&stack)?;
384397
Ok(stack)
@@ -449,6 +462,7 @@ serde_string_impl_pk!(Miniscript, "a miniscript", Ctx; ScriptContext);
449462
#[cfg(test)]
450463
mod tests {
451464

465+
use bitcoin::util::taproot::TapLeafHash;
452466
use {Satisfier, ToPublicKey};
453467

454468
use super::{Miniscript, ScriptContext};
@@ -1039,7 +1053,11 @@ mod tests {
10391053

10401054
// a simple satisfier that always outputs the same signature
10411055
impl<Pk: ToPublicKey> Satisfier<Pk> for SimpleSatisfier {
1042-
fn lookup_schnorr_sig(&self, _pk: &Pk) -> Option<bitcoin::SchnorrSig> {
1056+
fn lookup_tap_leaf_script_sig(
1057+
&self,
1058+
_pk: &Pk,
1059+
_h: &TapLeafHash,
1060+
) -> Option<bitcoin::SchnorrSig> {
10431061
Some(bitcoin::SchnorrSig {
10441062
sig: self.0,
10451063
hash_ty: bitcoin::SchnorrSigHashType::Default,

0 commit comments

Comments
 (0)