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 f06c4be commit c94f56c
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 90 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 <[email protected]>, Sanket Kanjalkar <[email protected]>"]
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.36.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"]}
8 changes: 4 additions & 4 deletions bitcoind-tests/tests/test_cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
// Get the required sighash message
let amt = btc(1);
let mut sighash_cache = bitcoin::sighash::SighashCache::new(&psbts[i].unsigned_tx);
let sighash_ty = bitcoin::sighash::EcdsaSighashType::All;
let sighash_type = bitcoin::sighash::EcdsaSighashType::All;
let sighash = sighash_cache
.p2wsh_signature_hash(0, &ms.encode(), amt, sighash_ty)
.p2wsh_signature_hash(0, &ms.encode(), amt, sighash_type)
.unwrap();

// requires both signing and verification because we check the tx
Expand All @@ -179,11 +179,11 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {

// Finally construct the signature and add to psbt
for sk in sks_reqd {
let sig = secp.sign_ecdsa(&msg, &sk);
let signature = secp.sign_ecdsa(&msg, &sk);
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
psbts[i].inputs[0]
.partial_sigs
.insert(pk, bitcoin::ecdsa::Signature { sig, hash_ty: sighash_ty });
.insert(pk, bitcoin::ecdsa::Signature { signature, sighash_type });
}
// Add the hash preimages to the psbt
psbts[i].inputs[0]
Expand Down
20 changes: 10 additions & 10 deletions bitcoind-tests/tests/test_desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub fn test_desc_satisfy(
match derived_desc {
Descriptor::Tr(ref tr) => {
// Fixme: take a parameter
let hash_ty = sighash::TapSighashType::Default;
let sighash_type = sighash::TapSighashType::Default;

let internal_key_present = x_only_pks
.iter()
Expand All @@ -170,15 +170,15 @@ pub fn test_desc_satisfy(
.add_xonly_tweak(&secp, &tr.spend_info().tap_tweak().to_scalar())
.expect("Tweaking failed");
let sighash_msg = sighash_cache
.taproot_key_spend_signature_hash(0, &prevouts, hash_ty)
.taproot_key_spend_signature_hash(0, &prevouts, sighash_type)
.unwrap();
let msg = secp256k1::Message::from_digest(sighash_msg.to_byte_array());
let mut aux_rand = [0u8; 32];
rand::thread_rng().fill_bytes(&mut aux_rand);
let schnorr_sig =
secp.sign_schnorr_with_aux_rand(&msg, &internal_keypair, &aux_rand);
psbt.inputs[0].tap_key_sig =
Some(taproot::Signature { sig: schnorr_sig, hash_ty: hash_ty });
Some(taproot::Signature { signature: schnorr_sig, sighash_type });
} else {
// No internal key
}
Expand All @@ -195,17 +195,17 @@ pub fn test_desc_satisfy(
.collect();
for (keypair, leaf_hash) in x_only_keypairs_reqd {
let sighash_msg = sighash_cache
.taproot_script_spend_signature_hash(0, &prevouts, leaf_hash, hash_ty)
.taproot_script_spend_signature_hash(0, &prevouts, leaf_hash, sighash_type)
.unwrap();
let msg = secp256k1::Message::from_digest(sighash_msg.to_byte_array());
let mut aux_rand = [0u8; 32];
rand::thread_rng().fill_bytes(&mut aux_rand);
let sig = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &aux_rand);
let signature = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &aux_rand);
let x_only_pk =
x_only_pks[xonly_keypairs.iter().position(|&x| x == keypair).unwrap()];
psbt.inputs[0]
.tap_script_sigs
.insert((x_only_pk, leaf_hash), taproot::Signature { sig, hash_ty: hash_ty });
.insert((x_only_pk, leaf_hash), taproot::Signature { signature, sighash_type });
}
}
_ => {
Expand Down Expand Up @@ -247,16 +247,16 @@ pub fn test_desc_satisfy(
.to_secp_msg();

// Fixme: Take a parameter
let hash_ty = sighash::EcdsaSighashType::All;
let sighash_type = sighash::EcdsaSighashType::All;

// Finally construct the signature and add to psbt
for sk in sks_reqd {
let sig = secp.sign_ecdsa(&msg, &sk);
let signature = secp.sign_ecdsa(&msg, &sk);
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
assert!(secp.verify_ecdsa(&msg, &sig, &pk.inner).is_ok());
assert!(secp.verify_ecdsa(&msg, &signature, &pk.inner).is_ok());
psbt.inputs[0]
.partial_sigs
.insert(pk, ecdsa::Signature { sig, hash_ty: hash_ty });
.insert(pk, ecdsa::Signature { signature, sighash_type });
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/psbt_sign_finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn main() {

psbt.inputs[0]
.partial_sigs
.insert(pk1, bitcoin::ecdsa::Signature { sig: sig1, hash_ty });
.insert(pk1, bitcoin::ecdsa::Signature { signature: sig1, sighash_type: hash_ty });

println!("{:#?}", psbt);
println!("{}", psbt);
Expand All @@ -150,7 +150,7 @@ fn main() {
fn get_vout(tx: &Transaction, spk: &Script) -> (OutPoint, TxOut) {
for (i, txout) in tx.clone().output.into_iter().enumerate() {
if spk == &txout.script_pubkey {
return (OutPoint::new(tx.txid(), i as u32), txout);
return (OutPoint::new(tx.compute_txid(), i as u32), txout);
}
}
panic!("Only call get vout on functions which have the expected outpoint");
Expand Down
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
16 changes: 12 additions & 4 deletions src/descriptor/segwitv0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,23 @@ 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
Loading

0 comments on commit c94f56c

Please sign in to comment.