Skip to content

Commit

Permalink
Test bitcoin v0.32.0-rc1
Browse files Browse the repository at this point in the history
Test the latest bitcoin release candidate. Includes bumping the version numbers so we can use this branch to test crates further up the stack.

Requires the `rc-fixes` branch.
  • Loading branch information
tcharding committed Apr 8, 2024
1 parent 9eb4375 commit 8bcd517
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 68 deletions.
42 changes: 37 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "miniscript"
version = "11.0.0"
version = "12.0.0"
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>, Sanket Kanjalkar <sanket1729@gmail.com>"]
license = "CC0-1.0"
homepage = "https://github.com/rust-bitcoin/rust-miniscript/"
Expand All @@ -13,7 +13,7 @@ edition = "2018"
[features]
default = ["std"]
std = ["bitcoin/std", "bitcoin/secp-recovery", "bech32/std"]
no-std = ["bitcoin/no-std", "bech32/alloc"]
no-std = ["bech32/alloc"]
compiler = []
trace = []

Expand All @@ -23,15 +23,15 @@ base64 = ["bitcoin/base64"]

[dependencies]
bech32 = { version = "0.11.0", default-features = false }
bitcoin = { version = "0.31.0", default-features = false }
bitcoin = { version = "0.32.0-rc1", default-features = false }

# Do NOT use this as a feature! Use the `serde` feature instead.
actual-serde = { package = "serde", version = "1.0.103", optional = true }

[dev-dependencies]
serde_test = "1.0.147"
bitcoin = { version = "0.31.0", features = ["base64"] }
secp256k1 = {version = "0.28.0", features = ["rand-std"]}
bitcoin = { version = "0.32.0-rc1", features = ["base64"] }
secp256k1 = {version = "0.29.0", features = ["rand-std"]}

[[example]]
name = "htlc"
Expand Down Expand Up @@ -68,3 +68,35 @@ required-features = ["std", "base64", "compiler"]
[workspace]
members = ["bitcoind-tests", "fuzz"]
exclude = ["embedded"]

[patch.crates-io.bitcoind]
git = "https://github.com/tcharding/bitcoind/"
branch = "test-bitcoin"

[patch.crates-io.bitcoincore-rpc]
git = "https://github.com/tcharding/rust-bitcoincore-rpc"
branch = "test-bitcoin"

[patch.crates-io.base58ck]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "rc1-fixes"

[patch.crates-io.bitcoin]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "rc1-fixes"

[patch.crates-io.bitcoin_hashes]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "rc1-fixes"

[patch.crates-io.bitcoin-internals]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "rc1-fixes"

[patch.crates-io.bitcoin-io]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "rc1-fixes"

[patch.crates-io.bitcoin-units]
git = "https://github.com/rust-bitcoin/rust-bitcoin"
branch = "rc1-fixes"
4 changes: 2 additions & 2 deletions bitcoind-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ publish = false

[dependencies]
miniscript = {path = "../"}
bitcoind = { version = "0.34.0" }
bitcoind = { version = "0.35.0" }
actual-rand = { package = "rand", version = "0.8.4"}
secp256k1 = {version = "0.28.0", features = ["rand-std"]}
secp256k1 = {version = "0.29.0", features = ["rand-std"]}
4 changes: 2 additions & 2 deletions examples/sign_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ fn list_of_three_arbitrary_public_keys() -> Vec<bitcoin::PublicKey> {
// a valid signature for this transaction; Miniscript does not verify the validity.
fn random_signature_from_the_blockchain() -> ecdsa::Signature {
ecdsa::Signature {
sig: secp256k1::ecdsa::Signature::from_str(
signature: secp256k1::ecdsa::Signature::from_str(
"3045\
0221\
00f7c3648c390d87578cd79c8016940aa8e3511c4104cb78daa8fb8e429375efc1\
0220\
531d75c136272f127a5dc14acc0722301cbddc222262934151f140da345af177",
)
.unwrap(),
hash_ty: bitcoin::sighash::EcdsaSighashType::All,
sighash_type: bitcoin::sighash::EcdsaSighashType::All,
}
}
4 changes: 2 additions & 2 deletions examples/verify_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ fn main() {

let iter = interpreter.iter_custom(Box::new(|key_sig: &KeySigPair| {
let (pk, ecdsa_sig) = key_sig.as_ecdsa().expect("Ecdsa Sig");
ecdsa_sig.hash_ty == bitcoin::sighash::EcdsaSighashType::All
ecdsa_sig.sighash_type == bitcoin::sighash::EcdsaSighashType::All
&& secp
.verify_ecdsa(&message, &ecdsa_sig.sig, &pk.inner)
.verify_ecdsa(&message, &ecdsa_sig.signature, &pk.inner)
.is_ok()
}));

Expand Down
1 change: 0 additions & 1 deletion src/descriptor/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use core::str::FromStr;
use std::error;

use bitcoin::bip32::{self, XKeyIdentifier};
use bitcoin::hashes::hex::FromHex;
use bitcoin::hashes::{hash160, ripemd160, sha256, Hash, HashEngine};
use bitcoin::key::XOnlyPublicKey;
use bitcoin::secp256k1::{Secp256k1, Signing, Verification};
Expand Down
8 changes: 4 additions & 4 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,8 +1267,8 @@ mod tests {
) -> Option<bitcoin::ecdsa::Signature> {
if *pk == self.pk {
Some(bitcoin::ecdsa::Signature {
sig: self.sig,
hash_ty: bitcoin::sighash::EcdsaSighashType::All,
signature: self.sig,
sighash_type: bitcoin::sighash::EcdsaSighashType::All,
})
} else {
None
Expand Down Expand Up @@ -1534,11 +1534,11 @@ mod tests {

satisfier.insert(
a,
bitcoin::ecdsa::Signature { sig: sig_a, hash_ty: EcdsaSighashType::All },
bitcoin::ecdsa::Signature { signature: sig_a, sighash_type: EcdsaSighashType::All },
);
satisfier.insert(
b,
bitcoin::ecdsa::Signature { sig: sig_b, hash_ty: EcdsaSighashType::All },
bitcoin::ecdsa::Signature { signature: sig_b, sighash_type: EcdsaSighashType::All },
);

satisfier
Expand Down
14 changes: 10 additions & 4 deletions src/descriptor/segwitv0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,21 @@ impl<Pk: MiniscriptKey> Wpkh<Pk> {
impl<Pk: MiniscriptKey + ToPublicKey> Wpkh<Pk> {
/// Obtains the corresponding script pubkey for this descriptor.
pub fn script_pubkey(&self) -> ScriptBuf {
let addr = Address::p2wpkh(&self.pk.to_public_key(), Network::Bitcoin)
.expect("wpkh descriptors have compressed keys");
use core::convert::TryFrom;
let pk = self.pk.to_public_key();
let compressed = bitcoin::key::CompressedPublicKey::try_from(pk).expect("TODO: Handle compressed key");

let addr = Address::p2wpkh(&compressed, Network::Bitcoin);
addr.script_pubkey()
}

/// Obtains the corresponding script pubkey for this descriptor.
pub fn address(&self, network: Network) -> Address {
Address::p2wpkh(&self.pk.to_public_key(), network)
.expect("Rust Miniscript types don't allow uncompressed pks in segwit descriptors")
use core::convert::TryFrom;
let pk = self.pk.to_public_key();
let compressed = bitcoin::key::CompressedPublicKey::try_from(pk).expect("TODO: Handle compressed key");

Address::p2wpkh(&compressed, network)
}

/// Obtains the underlying miniscript for this descriptor.
Expand Down
6 changes: 3 additions & 3 deletions src/interpreter/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub enum Error {
/// Schnorr Signature error
SchnorrSig(bitcoin::taproot::SigFromSliceError),
/// Errors in signature hash calculations
SighashError(bitcoin::sighash::Error),
SighashError(bitcoin::sighash::InvalidSighashTypeError),
/// Taproot Annex Unsupported
TapAnnexUnsupported,
/// An uncompressed public key was encountered in a context where it is
Expand Down Expand Up @@ -242,8 +242,8 @@ impl From<secp256k1::Error> for Error {
}

#[doc(hidden)]
impl From<bitcoin::sighash::Error> for Error {
fn from(e: bitcoin::sighash::Error) -> Error { Error::SighashError(e) }
impl From<bitcoin::sighash::InvalidSighashTypeError> for Error {
fn from(e: bitcoin::sighash::InvalidSighashTypeError) -> Error { Error::SighashError(e) }
}

#[doc(hidden)]
Expand Down
31 changes: 16 additions & 15 deletions src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl<'txin> Interpreter<'txin> {
KeySigPair::Ecdsa(key, ecdsa_sig) => {
let script_pubkey = self.script_code.as_ref().expect("Legacy have script code");
let msg = if self.is_legacy() {
let sighash_u32 = ecdsa_sig.hash_ty.to_u32();
let sighash_u32 = ecdsa_sig.sighash_type.to_u32();
let sighash =
cache.legacy_signature_hash(input_idx, script_pubkey, sighash_u32);
sighash.map(|hash| secp256k1::Message::from_digest(hash.to_byte_array()))
Expand All @@ -227,11 +227,12 @@ impl<'txin> Interpreter<'txin> {
Some(txout) => txout.borrow().value,
None => return false,
};
let sighash = cache.segwit_signature_hash(
// TODO: Don't manually handle the script code.
let sighash = cache.p2wsh_signature_hash(
input_idx,
script_pubkey,
amt,
ecdsa_sig.hash_ty,
ecdsa_sig.sighash_type,
);
sighash.map(|hash| secp256k1::Message::from_digest(hash.to_byte_array()))
} else {
Expand All @@ -240,12 +241,12 @@ impl<'txin> Interpreter<'txin> {
};

let success =
msg.map(|msg| secp.verify_ecdsa(&msg, &ecdsa_sig.sig, &key.inner).is_ok());
msg.map(|msg| secp.verify_ecdsa(&msg, &ecdsa_sig.signature, &key.inner).is_ok());
success.unwrap_or(false) // unwrap_or checks for errors, while success would have checksig results
}
KeySigPair::Schnorr(xpk, schnorr_sig) => {
let sighash_msg = if self.is_taproot_v1_key_spend() {
cache.taproot_key_spend_signature_hash(input_idx, prevouts, schnorr_sig.hash_ty)
cache.taproot_key_spend_signature_hash(input_idx, prevouts, schnorr_sig.sighash_type)
} else if self.is_taproot_v1_script_spend() {
let tap_script = self.script_code.as_ref().expect(
"Internal Hack: Saving leaf script instead\
Expand All @@ -259,7 +260,7 @@ impl<'txin> Interpreter<'txin> {
input_idx,
prevouts,
leaf_hash,
schnorr_sig.hash_ty,
schnorr_sig.sighash_type,
)
} else {
// schnorr sigs in ecdsa descriptors
Expand All @@ -268,7 +269,7 @@ impl<'txin> Interpreter<'txin> {
let msg =
sighash_msg.map(|hash| secp256k1::Message::from_digest(hash.to_byte_array()));
let success =
msg.map(|msg| secp.verify_schnorr(&schnorr_sig.sig, &msg, xpk).is_ok());
msg.map(|msg| secp.verify_schnorr(&schnorr_sig.signature, &msg, xpk).is_ok());
success.unwrap_or(false) // unwrap_or_default checks for errors, while success would have checksig results
}
}
Expand Down Expand Up @@ -1069,12 +1070,12 @@ mod tests {
inner: secp256k1::PublicKey::from_secret_key(&secp, &sk),
compressed: true,
};
let sig = secp.sign_ecdsa(&msg, &sk);
let signature = secp.sign_ecdsa(&msg, &sk);
ecdsa_sigs.push(bitcoin::ecdsa::Signature {
sig,
hash_ty: bitcoin::sighash::EcdsaSighashType::All,
signature,
sighash_type: bitcoin::sighash::EcdsaSighashType::All,
});
let mut sigser = sig.serialize_der().to_vec();
let mut sigser = signature.serialize_der().to_vec();
sigser.push(0x01); // sighash_all
pks.push(pk);
der_sigs.push(sigser);
Expand All @@ -1084,8 +1085,8 @@ mod tests {
x_only_pks.push(x_only_pk);
let schnorr_sig = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &[0u8; 32]);
let schnorr_sig = bitcoin::taproot::Signature {
sig: schnorr_sig,
hash_ty: bitcoin::sighash::TapSighashType::Default,
signature: schnorr_sig,
sighash_type: bitcoin::sighash::TapSighashType::Default,
};
ser_schnorr_sigs.push(schnorr_sig.to_vec());
schnorr_sigs.push(schnorr_sig);
Expand All @@ -1100,10 +1101,10 @@ mod tests {
let secp_ref = &secp;
let vfyfn = |pksig: &KeySigPair| match pksig {
KeySigPair::Ecdsa(pk, ecdsa_sig) => secp_ref
.verify_ecdsa(&sighash, &ecdsa_sig.sig, &pk.inner)
.verify_ecdsa(&sighash, &ecdsa_sig.signature, &pk.inner)
.is_ok(),
KeySigPair::Schnorr(xpk, schnorr_sig) => secp_ref
.verify_schnorr(&schnorr_sig.sig, &sighash, xpk)
.verify_schnorr(&schnorr_sig.signature, &sighash, xpk)
.is_ok(),
};

Expand Down
15 changes: 12 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ pub enum Error {
/// rust-bitcoin script error
Script(script::Error),
/// rust-bitcoin address error
AddrError(bitcoin::address::Error),
AddrError(bitcoin::address::ParseError),
/// rust-bitcoin p2sh address error
AddrP2shError(bitcoin::address::P2shError),
/// A `CHECKMULTISIG` opcode was preceded by a number > 20
CmsTooManyKeys(u32),
/// A tapscript multi_a cannot support more than Weight::MAX_BLOCK/32 keys
Expand Down Expand Up @@ -513,6 +515,7 @@ impl fmt::Display for Error {
},
Error::Script(ref e) => fmt::Display::fmt(e, f),
Error::AddrError(ref e) => fmt::Display::fmt(e, f),
Error::AddrP2shError(ref e) => fmt::Display::fmt(e, f),
Error::CmsTooManyKeys(n) => write!(f, "checkmultisig with {} keys", n),
Error::Unprintable(x) => write!(f, "unprintable character 0x{:02x}", x),
Error::ExpectedChar(c) => write!(f, "expected {}", c),
Expand Down Expand Up @@ -593,6 +596,7 @@ impl error::Error for Error {
| MultipathDescLenMismatch => None,
Script(e) => Some(e),
AddrError(e) => Some(e),
AddrP2shError(e) => Some(e),
Secp(e) => Some(e),
#[cfg(feature = "compiler")]
CompilerError(e) => Some(e),
Expand Down Expand Up @@ -635,8 +639,13 @@ impl From<bitcoin::secp256k1::Error> for Error {
}

#[doc(hidden)]
impl From<bitcoin::address::Error> for Error {
fn from(e: bitcoin::address::Error) -> Error { Error::AddrError(e) }
impl From<bitcoin::address::ParseError> for Error {
fn from(e: bitcoin::address::ParseError) -> Error { Error::AddrError(e) }
}

#[doc(hidden)]
impl From<bitcoin::address::P2shError> for Error {
fn from(e: bitcoin::address::P2shError) -> Error { Error::AddrP2shError(e) }
}

#[doc(hidden)]
Expand Down
2 changes: 1 addition & 1 deletion src/miniscript/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl ParseableKey for bitcoin::secp256k1::XOnlyPublicKey {
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum KeyParseError {
/// Bitcoin PublicKey parse error
FullKeyParseError(bitcoin::key::Error),
FullKeyParseError(bitcoin::key::FromSliceError),
/// Xonly key parse Error
XonlyKeyParseError(bitcoin::secp256k1::Error),
}
Expand Down
8 changes: 4 additions & 4 deletions src/miniscript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1289,8 +1289,8 @@ mod tests {
_h: &TapLeafHash,
) -> Option<bitcoin::taproot::Signature> {
Some(bitcoin::taproot::Signature {
sig: self.0,
hash_ty: bitcoin::sighash::TapSighashType::Default,
signature: self.0,
sighash_type: bitcoin::sighash::TapSighashType::Default,
})
}
}
Expand Down Expand Up @@ -1420,8 +1420,8 @@ mod tests {
) -> Option<bitcoin::taproot::Signature> {
if pk == &self.1 {
Some(bitcoin::taproot::Signature {
sig: self.0,
hash_ty: bitcoin::sighash::TapSighashType::Default,
signature: self.0,
sighash_type: bitcoin::sighash::TapSighashType::Default,
})
} else {
None
Expand Down
4 changes: 2 additions & 2 deletions src/policy/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ mod tests {
#[test]
#[allow(clippy::needless_range_loop)]
fn compile_misc() {
let (keys, sig) = pubkeys_and_a_sig(10);
let (keys, signature) = pubkeys_and_a_sig(10);
let key_pol: Vec<BPolicy> = keys.iter().map(|k| Concrete::Key(*k)).collect();

let policy: BPolicy = Concrete::Key(keys[0]);
Expand Down Expand Up @@ -1424,7 +1424,7 @@ mod tests {
assert_eq!(abs.minimum_n_keys(), Some(3));

let bitcoinsig =
bitcoin::ecdsa::Signature { sig, hash_ty: bitcoin::sighash::EcdsaSighashType::All };
bitcoin::ecdsa::Signature { signature, sighash_type: bitcoin::sighash::EcdsaSighashType::All };
let sigvec = bitcoinsig.to_vec();

let no_sat = BTreeMap::<bitcoin::PublicKey, bitcoin::ecdsa::Signature>::new();
Expand Down
Loading

0 comments on commit 8bcd517

Please sign in to comment.