Skip to content

Commit 507469c

Browse files
committed
Test bitcoin v0.32.0-rc1
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. Introduces a new TODO because are currently manually handling the script code but there is a new API in `rust-bitcoin` that expects to handle the script code for us. The fix is quite invasive so for now just use `SighashCache::p2wsh_signature_hash`.
1 parent a74a581 commit 507469c

19 files changed

+180
-97
lines changed

Cargo.toml

+37-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "miniscript"
3-
version = "11.0.0"
3+
version = "12.0.0"
44
authors = ["Andrew Poelstra <[email protected]>, Sanket Kanjalkar <[email protected]>"]
55
license = "CC0-1.0"
66
homepage = "https://github.com/rust-bitcoin/rust-miniscript/"
@@ -13,7 +13,7 @@ edition = "2018"
1313
[features]
1414
default = ["std"]
1515
std = ["bitcoin/std", "bitcoin/secp-recovery", "bech32/std"]
16-
no-std = ["bitcoin/no-std", "bech32/alloc"]
16+
no-std = ["bech32/alloc"]
1717
compiler = []
1818
trace = []
1919

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

2424
[dependencies]
2525
bech32 = { version = "0.11.0", default-features = false }
26-
bitcoin = { version = "0.31.0", default-features = false }
26+
bitcoin = { version = "0.32.0-rc1", default-features = false }
2727

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

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

3636
[[example]]
3737
name = "htlc"
@@ -68,3 +68,35 @@ required-features = ["std", "base64", "compiler"]
6868
[workspace]
6969
members = ["bitcoind-tests", "fuzz"]
7070
exclude = ["embedded"]
71+
72+
[patch.crates-io.bitcoind]
73+
git = "https://github.com/tcharding/bitcoind/"
74+
branch = "test-bitcoin"
75+
76+
[patch.crates-io.bitcoincore-rpc]
77+
git = "https://github.com/tcharding/rust-bitcoincore-rpc"
78+
branch = "test-bitcoin"
79+
80+
[patch.crates-io.base58ck]
81+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
82+
branch = "rc1-fixes"
83+
84+
[patch.crates-io.bitcoin]
85+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
86+
branch = "rc1-fixes"
87+
88+
[patch.crates-io.bitcoin_hashes]
89+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
90+
branch = "rc1-fixes"
91+
92+
[patch.crates-io.bitcoin-internals]
93+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
94+
branch = "rc1-fixes"
95+
96+
[patch.crates-io.bitcoin-io]
97+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
98+
branch = "rc1-fixes"
99+
100+
[patch.crates-io.bitcoin-units]
101+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
102+
branch = "rc1-fixes"

bitcoind-tests/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ publish = false
99

1010
[dependencies]
1111
miniscript = {path = "../"}
12-
bitcoind = { version = "0.34.0" }
12+
bitcoind = { version = "0.36.0" }
1313
actual-rand = { package = "rand", version = "0.8.4"}
14-
secp256k1 = {version = "0.28.0", features = ["rand-std"]}
14+
secp256k1 = {version = "0.29.0", features = ["rand-std"]}

bitcoind-tests/tests/test_cpp.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
168168
// Get the required sighash message
169169
let amt = btc(1);
170170
let mut sighash_cache = bitcoin::sighash::SighashCache::new(&psbts[i].unsigned_tx);
171-
let sighash_ty = bitcoin::sighash::EcdsaSighashType::All;
171+
let sighash_type = bitcoin::sighash::EcdsaSighashType::All;
172172
let sighash = sighash_cache
173-
.p2wsh_signature_hash(0, &ms.encode(), amt, sighash_ty)
173+
.p2wsh_signature_hash(0, &ms.encode(), amt, sighash_type)
174174
.unwrap();
175175

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

180180
// Finally construct the signature and add to psbt
181181
for sk in sks_reqd {
182-
let sig = secp.sign_ecdsa(&msg, &sk);
182+
let signature = secp.sign_ecdsa(&msg, &sk);
183183
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
184184
psbts[i].inputs[0]
185185
.partial_sigs
186-
.insert(pk, bitcoin::ecdsa::Signature { sig, hash_ty: sighash_ty });
186+
.insert(pk, bitcoin::ecdsa::Signature { signature, sighash_type });
187187
}
188188
// Add the hash preimages to the psbt
189189
psbts[i].inputs[0]

bitcoind-tests/tests/test_desc.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub fn test_desc_satisfy(
155155
match derived_desc {
156156
Descriptor::Tr(ref tr) => {
157157
// Fixme: take a parameter
158-
let hash_ty = sighash::TapSighashType::Default;
158+
let sighash_type = sighash::TapSighashType::Default;
159159

160160
let internal_key_present = x_only_pks
161161
.iter()
@@ -170,15 +170,15 @@ pub fn test_desc_satisfy(
170170
.add_xonly_tweak(&secp, &tr.spend_info().tap_tweak().to_scalar())
171171
.expect("Tweaking failed");
172172
let sighash_msg = sighash_cache
173-
.taproot_key_spend_signature_hash(0, &prevouts, hash_ty)
173+
.taproot_key_spend_signature_hash(0, &prevouts, sighash_type)
174174
.unwrap();
175175
let msg = secp256k1::Message::from_digest(sighash_msg.to_byte_array());
176176
let mut aux_rand = [0u8; 32];
177177
rand::thread_rng().fill_bytes(&mut aux_rand);
178178
let schnorr_sig =
179179
secp.sign_schnorr_with_aux_rand(&msg, &internal_keypair, &aux_rand);
180180
psbt.inputs[0].tap_key_sig =
181-
Some(taproot::Signature { sig: schnorr_sig, hash_ty: hash_ty });
181+
Some(taproot::Signature { signature: schnorr_sig, sighash_type });
182182
} else {
183183
// No internal key
184184
}
@@ -195,17 +195,17 @@ pub fn test_desc_satisfy(
195195
.collect();
196196
for (keypair, leaf_hash) in x_only_keypairs_reqd {
197197
let sighash_msg = sighash_cache
198-
.taproot_script_spend_signature_hash(0, &prevouts, leaf_hash, hash_ty)
198+
.taproot_script_spend_signature_hash(0, &prevouts, leaf_hash, sighash_type)
199199
.unwrap();
200200
let msg = secp256k1::Message::from_digest(sighash_msg.to_byte_array());
201201
let mut aux_rand = [0u8; 32];
202202
rand::thread_rng().fill_bytes(&mut aux_rand);
203-
let sig = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &aux_rand);
203+
let signature = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &aux_rand);
204204
let x_only_pk =
205205
x_only_pks[xonly_keypairs.iter().position(|&x| x == keypair).unwrap()];
206206
psbt.inputs[0]
207207
.tap_script_sigs
208-
.insert((x_only_pk, leaf_hash), taproot::Signature { sig, hash_ty: hash_ty });
208+
.insert((x_only_pk, leaf_hash), taproot::Signature { signature, sighash_type });
209209
}
210210
}
211211
_ => {
@@ -247,16 +247,16 @@ pub fn test_desc_satisfy(
247247
.to_secp_msg();
248248

249249
// Fixme: Take a parameter
250-
let hash_ty = sighash::EcdsaSighashType::All;
250+
let sighash_type = sighash::EcdsaSighashType::All;
251251

252252
// Finally construct the signature and add to psbt
253253
for sk in sks_reqd {
254-
let sig = secp.sign_ecdsa(&msg, &sk);
254+
let signature = secp.sign_ecdsa(&msg, &sk);
255255
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
256-
assert!(secp.verify_ecdsa(&msg, &sig, &pk.inner).is_ok());
256+
assert!(secp.verify_ecdsa(&msg, &signature, &pk.inner).is_ok());
257257
psbt.inputs[0]
258258
.partial_sigs
259-
.insert(pk, ecdsa::Signature { sig, hash_ty: hash_ty });
259+
.insert(pk, ecdsa::Signature { signature, sighash_type });
260260
}
261261
}
262262
}

examples/psbt_sign_finalize.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ fn main() {
134134

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

139139
println!("{:#?}", psbt);
140140
println!("{}", psbt);
@@ -150,7 +150,7 @@ fn main() {
150150
fn get_vout(tx: &Transaction, spk: &Script) -> (OutPoint, TxOut) {
151151
for (i, txout) in tx.clone().output.into_iter().enumerate() {
152152
if spk == &txout.script_pubkey {
153-
return (OutPoint::new(tx.txid(), i as u32), txout);
153+
return (OutPoint::new(tx.compute_txid(), i as u32), txout);
154154
}
155155
}
156156
panic!("Only call get vout on functions which have the expected outpoint");

examples/sign_multisig.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ fn list_of_three_arbitrary_public_keys() -> Vec<bitcoin::PublicKey> {
118118
// a valid signature for this transaction; Miniscript does not verify the validity.
119119
fn random_signature_from_the_blockchain() -> ecdsa::Signature {
120120
ecdsa::Signature {
121-
sig: secp256k1::ecdsa::Signature::from_str(
121+
signature: secp256k1::ecdsa::Signature::from_str(
122122
"3045\
123123
0221\
124124
00f7c3648c390d87578cd79c8016940aa8e3511c4104cb78daa8fb8e429375efc1\
125125
0220\
126126
531d75c136272f127a5dc14acc0722301cbddc222262934151f140da345af177",
127127
)
128128
.unwrap(),
129-
hash_ty: bitcoin::sighash::EcdsaSighashType::All,
129+
sighash_type: bitcoin::sighash::EcdsaSighashType::All,
130130
}
131131
}

examples/verify_tx.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ fn main() {
8787

8888
let iter = interpreter.iter_custom(Box::new(|key_sig: &KeySigPair| {
8989
let (pk, ecdsa_sig) = key_sig.as_ecdsa().expect("Ecdsa Sig");
90-
ecdsa_sig.hash_ty == bitcoin::sighash::EcdsaSighashType::All
90+
ecdsa_sig.sighash_type == bitcoin::sighash::EcdsaSighashType::All
9191
&& secp
92-
.verify_ecdsa(&message, &ecdsa_sig.sig, &pk.inner)
92+
.verify_ecdsa(&message, &ecdsa_sig.signature, &pk.inner)
9393
.is_ok()
9494
}));
9595

src/descriptor/bare.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Pkh<Pk> {
273273

274274
/// Obtains the corresponding script pubkey for this descriptor.
275275
pub fn address(&self, network: Network) -> Address {
276-
Address::p2pkh(&self.pk.to_public_key(), network)
276+
Address::p2pkh(self.pk.to_public_key(), network)
277277
}
278278

279279
/// Obtains the underlying miniscript for this descriptor.

src/descriptor/key.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use core::str::FromStr;
77
use std::error;
88

99
use bitcoin::bip32::{self, XKeyIdentifier};
10-
use bitcoin::hashes::hex::FromHex;
1110
use bitcoin::hashes::{hash160, ripemd160, sha256, Hash, HashEngine};
1211
use bitcoin::key::XOnlyPublicKey;
1312
use bitcoin::secp256k1::{Secp256k1, Signing, Verification};

src/descriptor/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1267,8 +1267,8 @@ mod tests {
12671267
) -> Option<bitcoin::ecdsa::Signature> {
12681268
if *pk == self.pk {
12691269
Some(bitcoin::ecdsa::Signature {
1270-
sig: self.sig,
1271-
hash_ty: bitcoin::sighash::EcdsaSighashType::All,
1270+
signature: self.sig,
1271+
sighash_type: bitcoin::sighash::EcdsaSighashType::All,
12721272
})
12731273
} else {
12741274
None
@@ -1534,11 +1534,11 @@ mod tests {
15341534

15351535
satisfier.insert(
15361536
a,
1537-
bitcoin::ecdsa::Signature { sig: sig_a, hash_ty: EcdsaSighashType::All },
1537+
bitcoin::ecdsa::Signature { signature: sig_a, sighash_type: EcdsaSighashType::All },
15381538
);
15391539
satisfier.insert(
15401540
b,
1541-
bitcoin::ecdsa::Signature { sig: sig_b, hash_ty: EcdsaSighashType::All },
1541+
bitcoin::ecdsa::Signature { signature: sig_b, sighash_type: EcdsaSighashType::All },
15421542
);
15431543

15441544
satisfier

src/descriptor/segwitv0.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -374,15 +374,23 @@ impl<Pk: MiniscriptKey> Wpkh<Pk> {
374374
impl<Pk: MiniscriptKey + ToPublicKey> Wpkh<Pk> {
375375
/// Obtains the corresponding script pubkey for this descriptor.
376376
pub fn script_pubkey(&self) -> ScriptBuf {
377-
let addr = Address::p2wpkh(&self.pk.to_public_key(), Network::Bitcoin)
378-
.expect("wpkh descriptors have compressed keys");
377+
use core::convert::TryFrom;
378+
let pk = self.pk.to_public_key();
379+
let compressed = bitcoin::key::CompressedPublicKey::try_from(pk)
380+
.expect("TODO: do we guarantee this is uncompressed");
381+
382+
let addr = Address::p2wpkh(&compressed, Network::Bitcoin);
379383
addr.script_pubkey()
380384
}
381385

382386
/// Obtains the corresponding script pubkey for this descriptor.
383387
pub fn address(&self, network: Network) -> Address {
384-
Address::p2wpkh(&self.pk.to_public_key(), network)
385-
.expect("Rust Miniscript types don't allow uncompressed pks in segwit descriptors")
388+
use core::convert::TryFrom;
389+
let pk = self.pk.to_public_key();
390+
let compressed = bitcoin::key::CompressedPublicKey::try_from(pk)
391+
.expect("TODO: do we guarantee this is uncompressed");
392+
393+
Address::p2wpkh(&compressed, network)
386394
}
387395

388396
/// Obtains the underlying miniscript for this descriptor.
@@ -394,7 +402,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wpkh<Pk> {
394402
// the previous txo's scriptPubKey.
395403
// The item 5:
396404
// - For P2WPKH witness program, the scriptCode is `0x1976a914{20-byte-pubkey-hash}88ac`.
397-
let addr = Address::p2pkh(&self.pk.to_public_key(), Network::Bitcoin);
405+
let addr = Address::p2pkh(self.pk.to_public_key(), Network::Bitcoin);
398406
addr.script_pubkey()
399407
}
400408

src/interpreter/error.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub enum Error {
9595
/// Schnorr Signature error
9696
SchnorrSig(bitcoin::taproot::SigFromSliceError),
9797
/// Errors in signature hash calculations
98-
SighashError(bitcoin::sighash::Error),
98+
SighashError(bitcoin::sighash::InvalidSighashTypeError),
9999
/// Taproot Annex Unsupported
100100
TapAnnexUnsupported,
101101
/// An uncompressed public key was encountered in a context where it is
@@ -242,8 +242,8 @@ impl From<secp256k1::Error> for Error {
242242
}
243243

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

249249
#[doc(hidden)]

0 commit comments

Comments
 (0)