Skip to content

Commit

Permalink
Merge #645: remove sketchy LikelyFalse error
Browse files Browse the repository at this point in the history
50db03c cargo fmt (Andrew Poelstra)
220f101 ci: screw up imports for rust-lang/rust#121684 (Andrew Poelstra)
df069af ci: remove unnecessary imports of `bitcoin` (Andrew Poelstra)
3725549 ci: tighten import of `Vec` (Andrew Poelstra)
d441ccd ci: remove imports that are redundant with super::* (Andrew Poelstra)
b87b4fb remove sketchy `LikelyFalse` error (Andrew Poelstra)

Pull request description:

  This error would trigger on `l:0` on the basis that this is equivalent to `u:0` but always less efficient. There are no other "linting" errors like this in this library, and the C++ implementation doesn't have it, so we should drop it.

  Fixes #633

ACKs for top commit:
  tcharding:
    ACK 50db03c
  sanket1729:
    ACK 50db03c

Tree-SHA512: 30681e6abe7957b9fbe059e808d8057fd174ea156d1853960370d2fd63b032a500f85965a5c7424764df76ed804c62d9a781ae38cdc2b123e9b4b53308dd89f5
  • Loading branch information
apoelstra committed Feb 28, 2024
2 parents ef3abb6 + 50db03c commit d3f638d
Show file tree
Hide file tree
Showing 21 changed files with 31 additions and 46 deletions.
5 changes: 3 additions & 2 deletions examples/psbt_sign_finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use miniscript::bitcoin::consensus::encode::deserialize;
use miniscript::bitcoin::hashes::hex::FromHex;
use miniscript::bitcoin::psbt::{self, Psbt};
use miniscript::bitcoin::sighash::SighashCache;
//use miniscript::bitcoin::secp256k1; // https://github.com/rust-lang/rust/issues/121684
use miniscript::bitcoin::{
self, secp256k1, transaction, Address, Amount, Network, OutPoint, PrivateKey, Script, Sequence,
Transaction, TxIn, TxOut,
transaction, Address, Amount, Network, OutPoint, PrivateKey, Script, Sequence, Transaction,
TxIn, TxOut,
};
use miniscript::psbt::{PsbtExt, PsbtInputExt};
use miniscript::Descriptor;
Expand Down
2 changes: 1 addition & 1 deletion examples/sign_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::HashMap;
use std::str::FromStr;

use bitcoin::blockdata::witness::Witness;
use bitcoin::{absolute, ecdsa, secp256k1, transaction, Amount, Sequence};
use bitcoin::{absolute, ecdsa, transaction, Amount, Sequence};

fn main() {
let mut tx = spending_transaction();
Expand Down
2 changes: 1 addition & 1 deletion examples/verify_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::str::FromStr;

use miniscript::bitcoin::consensus::Decodable;
use miniscript::bitcoin::secp256k1::{self, Secp256k1};
use miniscript::bitcoin::secp256k1::Secp256k1;
use miniscript::bitcoin::{absolute, sighash, Sequence};
use miniscript::interpreter::KeySigPair;

Expand Down
2 changes: 1 addition & 1 deletion src/descriptor/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ impl Serialize for DescriptorPublicKey {
mod test {
use core::str::FromStr;

use bitcoin::{bip32, secp256k1};
use bitcoin::bip32;
#[cfg(feature = "serde")]
use serde_test::{assert_tokens, Token};

Expand Down
10 changes: 3 additions & 7 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,25 +997,21 @@ pub(crate) use write_descriptor;
#[cfg(test)]
mod tests {
use core::convert::TryFrom;
use core::str::FromStr;

use bitcoin::blockdata::opcodes::all::{OP_CLTV, OP_CSV};
use bitcoin::blockdata::script::Instruction;
use bitcoin::blockdata::{opcodes, script};
use bitcoin::hashes::hex::FromHex;
use bitcoin::hashes::{hash160, sha256, Hash};
use bitcoin::hashes::Hash;
use bitcoin::script::PushBytes;
use bitcoin::sighash::EcdsaSighashType;
use bitcoin::{self, bip32, secp256k1, PublicKey, Sequence};
use bitcoin::{bip32, PublicKey, Sequence};

use super::checksum::desc_checksum;
use super::tr::Tr;
use super::*;
use crate::descriptor::key::Wildcard;
use crate::descriptor::{DescriptorPublicKey, DescriptorXKey, SinglePub};
use crate::hex_script;
#[cfg(feature = "compiler")]
use crate::policy;
use crate::{hex_script, Descriptor, Error, Miniscript, Satisfier};

type StdDescriptor = Descriptor<PublicKey>;
const TEST_PK: &str = "pk(020000000000000000000000000000000000000000000000000000000000000002)";
Expand Down
4 changes: 3 additions & 1 deletion src/descriptor/tr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
use core::str::FromStr;
use core::{cmp, fmt, hash};

#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/121684
use bitcoin::secp256k1;
use bitcoin::taproot::{
LeafVersion, TaprootBuilder, TaprootSpendInfo, TAPROOT_CONTROL_BASE_SIZE,
TAPROOT_CONTROL_MAX_NODE_COUNT, TAPROOT_CONTROL_NODE_SIZE,
};
use bitcoin::{opcodes, secp256k1, Address, Network, ScriptBuf};
use bitcoin::{opcodes, Address, Network, ScriptBuf};
use sync::Arc;

use super::checksum::{self, verify_checksum};
Expand Down
4 changes: 3 additions & 1 deletion src/interpreter/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use std::error;

use bitcoin::hashes::hash160;
use bitcoin::hex::DisplayHex;
use bitcoin::{secp256k1, taproot};
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/121684
use bitcoin::secp256k1;
use bitcoin::taproot;

use super::BitcoinKey;
use crate::prelude::*;
Expand Down
4 changes: 1 addition & 3 deletions src/interpreter/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,10 @@ mod tests {

use bitcoin::blockdata::script;
use bitcoin::hashes::hex::FromHex;
use bitcoin::hashes::{hash160, sha256, Hash};
use bitcoin::script::PushBytes;
use bitcoin::{self, ScriptBuf};
use bitcoin::ScriptBuf;

use super::*;
use crate::miniscript::analyzable::ExtParams;

struct KeyTestData {
pk_spk: bitcoin::ScriptBuf,
Expand Down
6 changes: 1 addition & 5 deletions src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,15 +1023,11 @@ fn verify_sersig<'txin>(
#[cfg(test)]
mod tests {

use bitcoin;
use bitcoin::hashes::{hash160, ripemd160, sha256, Hash};
use bitcoin::secp256k1::{self, Secp256k1};
use bitcoin::secp256k1::Secp256k1;

use super::inner::ToNoChecks;
use super::*;
use crate::miniscript::analyzable::ExtParams;
use crate::miniscript::context::NoChecks;
use crate::{Miniscript, ToPublicKey};

#[allow(clippy::type_complexity)]
fn setup_keys_sigs(
Expand Down
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,6 @@ pub enum Error {
MultiAt(String),
/// Name of a fragment contained `@` but we were not parsing an OR
AtOutsideOr(String),
/// Encountered a `l:0` which is syntactically equal to `u:0` except stupid
LikelyFalse,
/// Encountered a wrapping character that we don't recognize
UnknownWrapper(char),
/// Parsed a miniscript and the result was not of type T
Expand Down Expand Up @@ -526,7 +524,6 @@ impl fmt::Display for Error {
Error::MultiColon(ref s) => write!(f, "«{}» has multiple instances of «:»", s),
Error::MultiAt(ref s) => write!(f, "«{}» has multiple instances of «@»", s),
Error::AtOutsideOr(ref s) => write!(f, "«{}» contains «@» in non-or() context", s),
Error::LikelyFalse => write!(f, "0 is not very likely (use «u:0»)"),
Error::UnknownWrapper(ch) => write!(f, "unknown wrapper «{}:»", ch),
Error::NonTopLevel(ref s) => write!(f, "non-T miniscript: {}", s),
Error::Trailing(ref s) => write!(f, "trailing tokens: {}", s),
Expand Down Expand Up @@ -599,7 +596,6 @@ impl error::Error for Error {
| MultiColon(_)
| MultiAt(_)
| AtOutsideOr(_)
| LikelyFalse
| UnknownWrapper(_)
| NonTopLevel(_)
| Trailing(_)
Expand Down
3 changes: 0 additions & 3 deletions src/miniscript/astelem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,6 @@ impl_from_tree!(
)
}
'l' => {
if ms.node == Terminal::False {
return Err(Error::LikelyFalse);
}
unwrapped = Terminal::OrI(
Arc::new(Miniscript::from_ast(Terminal::False)?),
Arc::new(ms),
Expand Down
2 changes: 0 additions & 2 deletions src/miniscript/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> Iterator for PkIter<'a, Pk, Ctx>
// dependent libraries for their own tasts based on Miniscript AST
#[cfg(test)]
pub mod test {
use bitcoin;
use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d, Hash};
use bitcoin::secp256k1;

use super::Miniscript;
use crate::miniscript::context::Segwitv0;
Expand Down
2 changes: 1 addition & 1 deletion src/miniscript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ mod tests {
use bitcoin::hashes::{hash160, sha256, Hash};
use bitcoin::secp256k1::XOnlyPublicKey;
use bitcoin::taproot::TapLeafHash;
use bitcoin::{self, secp256k1, Sequence};
use bitcoin::Sequence;
use sync::Arc;

use super::{Miniscript, ScriptContext, Segwitv0, Tap};
Expand Down
2 changes: 0 additions & 2 deletions src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,9 +735,7 @@ impl Assets {
mod test {
use std::str::FromStr;

use bitcoin::absolute::LockTime;
use bitcoin::bip32::Xpub;
use bitcoin::Sequence;

use super::*;
use crate::*;
Expand Down
3 changes: 1 addition & 2 deletions src/policy/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//! Optimizing compiler from concrete policies to Miniscript
//!
use core::convert::From;
use core::{cmp, f64, fmt, hash, mem};
#[cfg(feature = "std")]
use std::error;
Expand Down Expand Up @@ -1152,7 +1151,7 @@ mod tests {
use core::str::FromStr;

use bitcoin::blockdata::{opcodes, script};
use bitcoin::{self, hashes, secp256k1, Sequence};
use bitcoin::{hashes, Sequence};

use super::*;
use crate::miniscript::{Legacy, Segwitv0, Tap};
Expand Down
2 changes: 0 additions & 2 deletions src/policy/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,8 +1146,6 @@ impl<Pk: MiniscriptKey> TreeLike for Arc<Policy<Pk>> {
mod compiler_tests {
use core::str::FromStr;

use sync::Arc;

use super::*;

#[test]
Expand Down
7 changes: 4 additions & 3 deletions src/policy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ pub use self::semantic::Policy as Semantic;
use crate::descriptor::Descriptor;
use crate::miniscript::{Miniscript, ScriptContext};
use crate::sync::Arc;
use crate::{Error, MiniscriptKey, Terminal, Vec};
#[cfg(all(not(feature = "std"), not(test)))]
use crate::Vec;
use crate::{Error, MiniscriptKey, Terminal};

/// Policy entailment algorithm maximum number of terminals allowed.
const ENTAILMENT_MAX_TERMINALS: usize = 20;
Expand Down Expand Up @@ -245,10 +247,9 @@ mod tests {
#[cfg(feature = "compiler")]
use crate::descriptor::Tr;
use crate::miniscript::context::Segwitv0;
use crate::miniscript::Miniscript;
use crate::prelude::*;
#[cfg(feature = "compiler")]
use crate::{descriptor::TapTree, Descriptor, Tap};
use crate::{descriptor::TapTree, Tap};

type ConcretePol = Concrete<String>;
type SemanticPol = Semantic<String>;
Expand Down
2 changes: 0 additions & 2 deletions src/policy/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,6 @@ impl<Pk: MiniscriptKey> TreeLike for Arc<Policy<Pk>> {

#[cfg(test)]
mod tests {
use core::str::FromStr;

use bitcoin::PublicKey;

use super::*;
Expand Down
4 changes: 3 additions & 1 deletion src/psbt/finalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use core::mem;

use bitcoin::hashes::hash160;
use bitcoin::key::XOnlyPublicKey;
use bitcoin::secp256k1::{self, Secp256k1};
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/121684
use bitcoin::secp256k1;
use bitcoin::secp256k1::Secp256k1;
use bitcoin::sighash::Prevouts;
use bitcoin::taproot::LeafVersion;
use bitcoin::{PublicKey, Script, ScriptBuf, TxOut, Witness};
Expand Down
6 changes: 4 additions & 2 deletions src/psbt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use std::error;

use bitcoin::hashes::{hash160, sha256d, Hash};
use bitcoin::psbt::{self, Psbt};
use bitcoin::secp256k1::{self, Secp256k1, VerifyOnly};
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/121684
use bitcoin::secp256k1;
use bitcoin::secp256k1::{Secp256k1, VerifyOnly};
use bitcoin::sighash::{self, SighashCache};
use bitcoin::taproot::{self, ControlBlock, LeafVersion, TapLeafHash};
use bitcoin::{absolute, bip32, transaction, Script, ScriptBuf, Sequence};
Expand Down Expand Up @@ -1403,7 +1405,7 @@ mod tests {
use bitcoin::hashes::hex::FromHex;
use bitcoin::key::XOnlyPublicKey;
use bitcoin::secp256k1::PublicKey;
use bitcoin::{absolute, Amount, OutPoint, TxIn, TxOut};
use bitcoin::{Amount, OutPoint, TxIn, TxOut};

use super::*;
use crate::Miniscript;
Expand Down
1 change: 1 addition & 0 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::str::FromStr;

use bitcoin::hashes::{hash160, ripemd160, sha256};
use bitcoin::key::XOnlyPublicKey;
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/121684
use bitcoin::secp256k1;

use crate::miniscript::context::SigType;
Expand Down

0 comments on commit d3f638d

Please sign in to comment.