Skip to content

Commit 16d0830

Browse files
committed
Remove NoChecksSchnorr
This was a mistake. In the new API, we never decode/encode from NoChecks. We don't need a tag to know whether we want to parse 32/33 byte keys. We parse script with the correct context and then create another instance NoChecks
1 parent 6c9e436 commit 16d0830

File tree

3 files changed

+18
-118
lines changed

3 files changed

+18
-118
lines changed

src/interpreter/inner.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use bitcoin::util::taproot::{ControlBlock, TAPROOT_ANNEX_PREFIX};
2121
use {BareCtx, Legacy, Segwitv0, Tap};
2222

2323
use super::{stack, BitcoinKey, Error, Stack, TaggedHash160};
24-
use miniscript::context::{NoChecksEcdsa, ScriptContext};
24+
use miniscript::context::{NoChecks, ScriptContext};
2525
use {Miniscript, MiniscriptKey};
2626

2727
/// Attempts to parse a slice as a Bitcoin public key, checking compressedness
@@ -95,7 +95,7 @@ pub(super) enum Inner {
9595
// that only appropriate outputs are created
9696
PublicKey(super::BitcoinKey, PubkeyType),
9797
/// The script being evaluated is an actual script
98-
Script(Miniscript<super::BitcoinKey, NoChecksEcdsa>, ScriptType),
98+
Script(Miniscript<super::BitcoinKey, NoChecks>, ScriptType),
9999
}
100100

101101
// The `Script` returned by this method is always generated/cloned ... when
@@ -367,7 +367,7 @@ pub(super) fn from_txdata<'txin>(
367367
// we need to know whether to parse the public key provided in witness as x-only or full
368368
pub(super) fn pre_taproot_to_no_checks<Ctx: ScriptContext>(
369369
ms: &Miniscript<bitcoin::PublicKey, Ctx>,
370-
) -> Miniscript<BitcoinKey, NoChecksEcdsa> {
370+
) -> Miniscript<BitcoinKey, NoChecks> {
371371
// specify the () error type as this cannot error
372372
ms.real_translate_pk::<_, _, _, (), _>(&mut |pk| Ok(BitcoinKey::Fullkey(*pk)), &mut |pkh| {
373373
Ok(TaggedHash160::FullKey(*pkh))
@@ -379,7 +379,7 @@ pub(super) fn pre_taproot_to_no_checks<Ctx: ScriptContext>(
379379
#[allow(dead_code)]
380380
pub(super) fn taproot_to_no_checks<Ctx: ScriptContext>(
381381
ms: &Miniscript<bitcoin::XOnlyPublicKey, Ctx>,
382-
) -> Miniscript<BitcoinKey, NoChecksEcdsa> {
382+
) -> Miniscript<BitcoinKey, NoChecks> {
383383
// specify the () error type as this cannot error
384384
ms.real_translate_pk::<_, _, _, (), _>(
385385
&mut |xpk| Ok(BitcoinKey::XOnlyPublicKey(*xpk)),
@@ -734,7 +734,7 @@ mod tests {
734734
assert_eq!(script_code, Some(comp.pkh_spk.clone()));
735735
}
736736

737-
fn ms_inner_script(ms: &str) -> (Miniscript<BitcoinKey, NoChecksEcdsa>, bitcoin::Script) {
737+
fn ms_inner_script(ms: &str) -> (Miniscript<BitcoinKey, NoChecks>, bitcoin::Script) {
738738
let ms = Miniscript::<bitcoin::PublicKey, Segwitv0>::from_str_insane(ms).unwrap();
739739
let spk = ms.encode();
740740
let miniscript = pre_taproot_to_no_checks(&ms);

src/interpreter/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d};
2828
// use bitcoin::util::sighash;
2929
#[allow(unused_imports)]
3030
use bitcoin::{self, secp256k1};
31-
use miniscript::context::NoChecksEcdsa;
31+
use miniscript::context::NoChecks;
3232
use miniscript::ScriptContext;
3333
use Miniscript;
3434
use Terminal;
@@ -486,7 +486,7 @@ pub enum SatisfiedConstraint {
486486
///depending on evaluation of the children.
487487
struct NodeEvaluationState<'intp> {
488488
///The node which is being evaluated
489-
node: &'intp Miniscript<BitcoinKey, NoChecksEcdsa>,
489+
node: &'intp Miniscript<BitcoinKey, NoChecks>,
490490
///number of children evaluated
491491
n_evaluated: usize,
492492
///number of children satisfied
@@ -517,7 +517,7 @@ pub struct Iter<'intp, 'txin: 'intp> {
517517
///Iterator for Iter
518518
impl<'intp, 'txin: 'intp> Iterator for Iter<'intp, 'txin>
519519
where
520-
NoChecksEcdsa: ScriptContext,
520+
NoChecks: ScriptContext,
521521
{
522522
type Item = Result<SatisfiedConstraint, Error>;
523523

@@ -537,12 +537,12 @@ where
537537

538538
impl<'intp, 'txin: 'intp> Iter<'intp, 'txin>
539539
where
540-
NoChecksEcdsa: ScriptContext,
540+
NoChecks: ScriptContext,
541541
{
542542
/// Helper function to push a NodeEvaluationState on state stack
543543
fn push_evaluation_state(
544544
&mut self,
545-
node: &'intp Miniscript<BitcoinKey, NoChecksEcdsa>,
545+
node: &'intp Miniscript<BitcoinKey, NoChecks>,
546546
n_evaluated: usize,
547547
n_satisfied: usize,
548548
) -> () {
@@ -973,7 +973,7 @@ mod tests {
973973
use bitcoin;
974974
use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d, Hash};
975975
use bitcoin::secp256k1::{self, Secp256k1, VerifyOnly};
976-
use miniscript::context::NoChecksEcdsa;
976+
use miniscript::context::NoChecks;
977977
use Miniscript;
978978
use MiniscriptKey;
979979
use ToPublicKey;
@@ -1034,7 +1034,7 @@ mod tests {
10341034
fn from_stack<'txin, 'elem>(
10351035
verify_fn: Box<dyn FnMut(&KeySigPair) -> bool + 'elem>,
10361036
stack: Stack<'txin>,
1037-
ms: &'elem Miniscript<BitcoinKey, NoChecksEcdsa>,
1037+
ms: &'elem Miniscript<BitcoinKey, NoChecks>,
10381038
) -> Iter<'elem, 'txin> {
10391039
Iter {
10401040
verify_sig: verify_fn,
@@ -1438,8 +1438,8 @@ mod tests {
14381438

14391439
// By design there is no support for parse a miniscript with BitcoinKey
14401440
// because it does not implement FromStr
1441-
fn no_checks_ms(ms: &str) -> Miniscript<BitcoinKey, NoChecksEcdsa> {
1442-
let elem: Miniscript<bitcoin::PublicKey, NoChecksEcdsa> =
1441+
fn no_checks_ms(ms: &str) -> Miniscript<BitcoinKey, NoChecks> {
1442+
let elem: Miniscript<bitcoin::PublicKey, NoChecks> =
14431443
Miniscript::from_str_insane(ms).unwrap();
14441444
inner::pre_taproot_to_no_checks(&elem)
14451445
}

src/miniscript/context.rs

Lines changed: 4 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,8 @@ impl ScriptContext for BareCtx {
760760
/// scripts off of the blockchain without doing any sanity checks on them.
761761
/// This context should *NOT* be used unless you know what you are doing.
762762
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
763-
pub enum NoChecksEcdsa {}
764-
impl ScriptContext for NoChecksEcdsa {
763+
pub enum NoChecks {}
764+
impl ScriptContext for NoChecks {
765765
// todo: When adding support for interpreter, we need a enum with all supported keys here
766766
type Key = bitcoin::PublicKey;
767767
fn check_terminal_non_malleable<Pk: MiniscriptKey>(
@@ -853,108 +853,9 @@ impl ScriptContext for NoChecksEcdsa {
853853
}
854854
}
855855

856-
/// "No Checks Schnorr" Context
857-
///
858-
/// Used by the "satisified constraints" iterator, which is intended to read
859-
/// scripts off of the blockchain without doing any sanity checks on them.
860-
/// This context should *NOT* be used unless you know what you are doing.
861-
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
862-
pub enum NoChecksSchnorr {}
863-
impl ScriptContext for NoChecksSchnorr {
864-
// todo: When adding support for interpreter, we need a enum with all supported keys here
865-
type Key = bitcoin::secp256k1::XOnlyPublicKey;
866-
fn check_terminal_non_malleable<Pk: MiniscriptKey>(
867-
_frag: &Terminal<Pk, Self>,
868-
) -> Result<(), ScriptContextError> {
869-
Ok(())
870-
}
871-
872-
fn check_global_policy_validity<Pk: MiniscriptKey>(
873-
_ms: &Miniscript<Pk, Self>,
874-
) -> Result<(), ScriptContextError> {
875-
Ok(())
876-
}
877-
878-
fn check_global_consensus_validity<Pk: MiniscriptKey>(
879-
_ms: &Miniscript<Pk, Self>,
880-
) -> Result<(), ScriptContextError> {
881-
Ok(())
882-
}
883-
884-
fn check_local_policy_validity<Pk: MiniscriptKey>(
885-
_ms: &Miniscript<Pk, Self>,
886-
) -> Result<(), ScriptContextError> {
887-
Ok(())
888-
}
889-
890-
fn check_local_consensus_validity<Pk: MiniscriptKey>(
891-
_ms: &Miniscript<Pk, Self>,
892-
) -> Result<(), ScriptContextError> {
893-
Ok(())
894-
}
895-
896-
fn max_satisfaction_size<Pk: MiniscriptKey>(_ms: &Miniscript<Pk, Self>) -> Option<usize> {
897-
panic!("Tried to compute a satisfaction size bound on a no-checks schnorr miniscript")
898-
}
899-
900-
fn pk_len<Pk: MiniscriptKey>(_pk: &Pk) -> usize {
901-
panic!("Tried to compute a pk len bound on a no-checks schnorr miniscript")
902-
}
903-
904-
fn name_str() -> &'static str {
905-
// Internally used code
906-
"NochecksSchnorr"
907-
}
908-
909-
fn check_witness<Pk: MiniscriptKey>(_witness: &[Vec<u8>]) -> Result<(), ScriptContextError> {
910-
// Only really need to do this for segwitv0 and legacy
911-
// Bare is already restrcited by standardness rules
912-
// and would reach these limits.
913-
Ok(())
914-
}
915-
916-
fn check_global_validity<Pk: MiniscriptKey>(
917-
ms: &Miniscript<Pk, Self>,
918-
) -> Result<(), ScriptContextError> {
919-
Self::check_global_consensus_validity(ms)?;
920-
Self::check_global_policy_validity(ms)?;
921-
Ok(())
922-
}
923-
924-
fn check_local_validity<Pk: MiniscriptKey>(
925-
ms: &Miniscript<Pk, Self>,
926-
) -> Result<(), ScriptContextError> {
927-
Self::check_global_consensus_validity(ms)?;
928-
Self::check_global_policy_validity(ms)?;
929-
Self::check_local_consensus_validity(ms)?;
930-
Self::check_local_policy_validity(ms)?;
931-
Ok(())
932-
}
933-
934-
fn top_level_type_check<Pk: MiniscriptKey>(ms: &Miniscript<Pk, Self>) -> Result<(), Error> {
935-
if ms.ty.corr.base != types::Base::B {
936-
return Err(Error::NonTopLevel(format!("{:?}", ms)));
937-
}
938-
Ok(())
939-
}
940-
941-
fn other_top_level_checks<Pk: MiniscriptKey>(_ms: &Miniscript<Pk, Self>) -> Result<(), Error> {
942-
Ok(())
943-
}
944-
945-
fn top_level_checks<Pk: MiniscriptKey>(ms: &Miniscript<Pk, Self>) -> Result<(), Error> {
946-
Self::top_level_type_check(ms)?;
947-
Self::other_top_level_checks(ms)
948-
}
949-
950-
fn sig_type() -> SigType {
951-
SigType::Schnorr
952-
}
953-
}
954-
955856
/// Private Mod to prevent downstream from implementing this public trait
956857
mod private {
957-
use super::{BareCtx, Legacy, NoChecksEcdsa, NoChecksSchnorr, Segwitv0, Tap};
858+
use super::{BareCtx, Legacy, NoChecks, Segwitv0, Tap};
958859

959860
pub trait Sealed {}
960861

@@ -963,6 +864,5 @@ mod private {
963864
impl Sealed for Legacy {}
964865
impl Sealed for Segwitv0 {}
965866
impl Sealed for Tap {}
966-
impl Sealed for NoChecksEcdsa {}
967-
impl Sealed for NoChecksSchnorr {}
867+
impl Sealed for NoChecks {}
968868
}

0 commit comments

Comments
 (0)