Skip to content

Commit f9cfa37

Browse files
committed
Merge #618: Upgrade bitcoin dependency
e7b5db2 Upgrade bitcoin dependency (Tobin C. Harding) Pull request description: Upgrade `rust-bitcoin` to version 0.31.0 and also other required dependencies from our stack: - secp256k1: to v0.28.0 - internals: to v0.2.0 - bitcoind: to v0.34.0 ACKs for top commit: apoelstra: ACK e7b5db2 Tree-SHA512: ee172b59c6e4d4fcb24a1d1ca3f4bcaaebe5afe6fba0efc8cab587b8677d5a8cf68bc05c968105e151e810b0e20f146a69dc806667422ddd711793030ccee40c
2 parents c94deab + e7b5db2 commit f9cfa37

25 files changed

+166
-183
lines changed

Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ base64 = ["bitcoin/base64"]
2323

2424
[dependencies]
2525
bech32 = { version = "0.10.0-beta", default-features = false }
26-
bitcoin = { version = "0.30.0", default-features = false }
27-
internals = { package = "bitcoin-private", version = "0.1.0", default_features = false }
26+
bitcoin = { version = "0.31.0", default-features = false }
27+
internals = { package = "bitcoin-internals", version = "0.2.0", default_features = false }
2828

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

3232
[dev-dependencies]
3333
serde_test = "1.0.147"
34-
bitcoin = { version = "0.30.0", features = ["base64"] }
35-
secp256k1 = {version = "0.27.0", features = ["rand-std"]}
34+
bitcoin = { version = "0.31.0", features = ["base64"] }
35+
secp256k1 = {version = "0.28.0", features = ["rand-std"]}
3636

3737
[[example]]
3838
name = "htlc"

bitcoind-tests/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ publish = false
99

1010
[dependencies]
1111
miniscript = {path = "../"}
12-
bitcoind = { version = "0.32.0" }
12+
bitcoind = { version = "0.34.0" }
1313
actual-rand = { package = "rand", version = "0.8.4"}
14-
secp256k1 = {version = "0.27.0", features = ["rand-std"]}
15-
internals = { package = "bitcoin-private", version = "0.1.0", default_features = false }
14+
secp256k1 = {version = "0.28.0", features = ["rand-std"]}
15+
internals = { package = "bitcoin-internals", version = "0.2.0", default_features = false }

bitcoind-tests/tests/setup/test_util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub struct PubData {
4444
#[derive(Debug, Clone)]
4545
pub struct SecretData {
4646
pub sks: Vec<bitcoin::secp256k1::SecretKey>,
47-
pub x_only_keypairs: Vec<bitcoin::secp256k1::KeyPair>,
47+
pub x_only_keypairs: Vec<bitcoin::secp256k1::Keypair>,
4848
pub sha256_pre: [u8; 32],
4949
pub hash256_pre: [u8; 32],
5050
pub ripemd160_pre: [u8; 32],
@@ -62,7 +62,7 @@ fn setup_keys(
6262
) -> (
6363
Vec<bitcoin::secp256k1::SecretKey>,
6464
Vec<miniscript::bitcoin::PublicKey>,
65-
Vec<bitcoin::secp256k1::KeyPair>,
65+
Vec<bitcoin::secp256k1::Keypair>,
6666
Vec<XOnlyPublicKey>,
6767
) {
6868
let secp_sign = secp256k1::Secp256k1::signing_only();
@@ -87,7 +87,7 @@ fn setup_keys(
8787
let mut x_only_pks = vec![];
8888

8989
for i in 0..n {
90-
let keypair = bitcoin::secp256k1::KeyPair::from_secret_key(&secp_sign, &sks[i]);
90+
let keypair = bitcoin::secp256k1::Keypair::from_secret_key(&secp_sign, &sks[i]);
9191
let (xpk, _parity) = XOnlyPublicKey::from_keypair(&keypair);
9292
x_only_keypairs.push(keypair);
9393
x_only_pks.push(xpk);

bitcoind-tests/tests/test_cpp.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use std::path::Path;
1111

1212
use bitcoin::hashes::{sha256d, Hash};
1313
use bitcoin::psbt::Psbt;
14-
use bitcoin::{psbt, secp256k1, Amount, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid};
14+
use bitcoin::{
15+
psbt, secp256k1, transaction, Amount, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid,
16+
};
1517
use bitcoind::bitcoincore_rpc::{json, Client, RpcApi};
1618
use miniscript::bitcoin::absolute;
1719
use miniscript::psbt::PsbtExt;
@@ -49,7 +51,7 @@ fn btc<F: Into<f64>>(btc: F) -> Amount { Amount::from_btc(btc.into()).unwrap() }
4951
// Find the Outpoint by value.
5052
// Ideally, we should find by scriptPubkey, but this
5153
// works for temp test case
52-
fn get_vout(cl: &Client, txid: Txid, value: u64) -> (OutPoint, TxOut) {
54+
fn get_vout(cl: &Client, txid: Txid, value: Amount) -> (OutPoint, TxOut) {
5355
let tx = cl
5456
.get_transaction(&txid, None)
5557
.unwrap()
@@ -102,7 +104,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
102104
for (desc, txid) in desc_vec.iter().zip(txids) {
103105
let mut psbt = Psbt {
104106
unsigned_tx: Transaction {
105-
version: 2,
107+
version: transaction::Version::TWO,
106108
lock_time: absolute::LockTime::from_time(1_603_866_330)
107109
.expect("valid timestamp")
108110
.into(), // 10/28/2020 @ 6:25am (UTC)
@@ -117,7 +119,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
117119
outputs: vec![],
118120
};
119121
// figure out the outpoint from the txid
120-
let (outpoint, witness_utxo) = get_vout(&cl, txid, btc(1.0).to_sat());
122+
let (outpoint, witness_utxo) = get_vout(&cl, txid, btc(1.0));
121123
let mut txin = TxIn::default();
122124
txin.previous_output = outpoint;
123125
// set the sequence to a non-final number for the locktime transactions to be
@@ -132,9 +134,10 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
132134
.get_new_address(None, Some(json::AddressType::Bech32))
133135
.unwrap()
134136
.assume_checked();
135-
psbt.unsigned_tx
136-
.output
137-
.push(TxOut { value: 99_999_000, script_pubkey: addr.script_pubkey() });
137+
psbt.unsigned_tx.output.push(TxOut {
138+
value: Amount::from_sat(99_999_000),
139+
script_pubkey: addr.script_pubkey(),
140+
});
138141
let mut input = psbt::Input::default();
139142
input.witness_utxo = Some(witness_utxo);
140143
input.witness_script = Some(desc.explicit_script().unwrap());
@@ -163,16 +166,16 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
163166
.map(|pk| sks[pks.iter().position(|&x| x == pk).unwrap()])
164167
.collect();
165168
// Get the required sighash message
166-
let amt = btc(1).to_sat();
169+
let amt = btc(1);
167170
let mut sighash_cache = bitcoin::sighash::SighashCache::new(&psbts[i].unsigned_tx);
168171
let sighash_ty = bitcoin::sighash::EcdsaSighashType::All;
169172
let sighash = sighash_cache
170-
.segwit_signature_hash(0, &ms.encode(), amt, sighash_ty)
173+
.p2wsh_signature_hash(0, &ms.encode(), amt, sighash_ty)
171174
.unwrap();
172175

173176
// requires both signing and verification because we check the tx
174177
// after we psbt extract it
175-
let msg = secp256k1::Message::from_slice(&sighash[..]).unwrap();
178+
let msg = secp256k1::Message::from_digest(sighash.to_byte_array());
176179

177180
// Finally construct the signature and add to psbt
178181
for sk in sks_reqd {

bitcoind-tests/tests/test_desc.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use bitcoin::psbt::Psbt;
1414
use bitcoin::sighash::SighashCache;
1515
use bitcoin::taproot::{LeafVersion, TapLeafHash};
1616
use bitcoin::{
17-
absolute, psbt, secp256k1, sighash, Amount, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid,
17+
absolute, psbt, secp256k1, sighash, transaction, Amount, OutPoint, Sequence, Transaction, TxIn,
18+
TxOut, Txid,
1819
};
1920
use bitcoind::bitcoincore_rpc::{json, Client, RpcApi};
2021
use miniscript::bitcoin::{self, ecdsa, taproot, ScriptBuf};
@@ -28,7 +29,7 @@ use setup::test_util::{self, TestData};
2829
fn btc<F: Into<f64>>(btc: F) -> Amount { Amount::from_btc(btc.into()).unwrap() }
2930

3031
// Find the Outpoint by spk
31-
fn get_vout(cl: &Client, txid: Txid, value: u64, spk: ScriptBuf) -> (OutPoint, TxOut) {
32+
fn get_vout(cl: &Client, txid: Txid, value: Amount, spk: ScriptBuf) -> (OutPoint, TxOut) {
3233
let tx = cl
3334
.get_transaction(&txid, None)
3435
.unwrap()
@@ -102,7 +103,7 @@ pub fn test_desc_satisfy(
102103
// Spend one input and spend one output for simplicity.
103104
let mut psbt = Psbt {
104105
unsigned_tx: Transaction {
105-
version: 2,
106+
version: transaction::Version::TWO,
106107
lock_time: absolute::LockTime::from_time(1_603_866_330)
107108
.expect("valid timestamp")
108109
.into(), // 10/28/2020 @ 6:25am (UTC)
@@ -117,8 +118,7 @@ pub fn test_desc_satisfy(
117118
outputs: vec![],
118119
};
119120
// figure out the outpoint from the txid
120-
let (outpoint, witness_utxo) =
121-
get_vout(&cl, txid, btc(1.0).to_sat(), derived_desc.script_pubkey());
121+
let (outpoint, witness_utxo) = get_vout(&cl, txid, btc(1.0), derived_desc.script_pubkey());
122122
let mut txin = TxIn::default();
123123
txin.previous_output = outpoint;
124124
// set the sequence to a non-final number for the locktime transactions to be
@@ -137,7 +137,7 @@ pub fn test_desc_satisfy(
137137
// (Was getting insufficient fees error, for deep script trees)
138138
psbt.unsigned_tx
139139
.output
140-
.push(TxOut { value: 99_997_000, script_pubkey: addr.script_pubkey() });
140+
.push(TxOut { value: Amount::from_sat(99_997_000), script_pubkey: addr.script_pubkey() });
141141
let mut input = psbt::Input::default();
142142
input
143143
.update_with_descriptor_unchecked(&definite_desc)
@@ -172,7 +172,7 @@ pub fn test_desc_satisfy(
172172
let sighash_msg = sighash_cache
173173
.taproot_key_spend_signature_hash(0, &prevouts, hash_ty)
174174
.unwrap();
175-
let msg = secp256k1::Message::from_slice(&sighash_msg[..]).unwrap();
175+
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 =
@@ -183,7 +183,7 @@ pub fn test_desc_satisfy(
183183
// No internal key
184184
}
185185
// ------------------ script spend -------------
186-
let x_only_keypairs_reqd: Vec<(secp256k1::KeyPair, TapLeafHash)> = tr
186+
let x_only_keypairs_reqd: Vec<(secp256k1::Keypair, TapLeafHash)> = tr
187187
.iter_scripts()
188188
.flat_map(|(_depth, ms)| {
189189
let leaf_hash = TapLeafHash::from_script(&ms.encode(), LeafVersion::TapScript);
@@ -197,7 +197,7 @@ pub fn test_desc_satisfy(
197197
let sighash_msg = sighash_cache
198198
.taproot_script_spend_signature_hash(0, &prevouts, leaf_hash, hash_ty)
199199
.unwrap();
200-
let msg = secp256k1::Message::from_slice(&sighash_msg[..]).unwrap();
200+
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);
203203
let sig = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &aux_rand);

examples/psbt_sign_finalize.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use miniscript::bitcoin::hashes::hex::FromHex;
88
use miniscript::bitcoin::psbt::{self, Psbt};
99
use miniscript::bitcoin::sighash::SighashCache;
1010
use miniscript::bitcoin::{
11-
self, base64, secp256k1, Address, Network, OutPoint, PrivateKey, Script, Sequence, Transaction,
12-
TxIn, TxOut,
11+
self, secp256k1, transaction, Address, Amount, Network, OutPoint, PrivateKey, Script, Sequence,
12+
Transaction, TxIn, TxOut,
1313
};
1414
use miniscript::psbt::{PsbtExt, PsbtInputExt};
1515
use miniscript::Descriptor;
@@ -52,7 +52,7 @@ fn main() {
5252
println!("Backup3 public key: {}", _backup3_private.public_key(&secp256k1));
5353

5454
let spend_tx = Transaction {
55-
version: 2,
55+
version: transaction::Version::TWO,
5656
lock_time: bitcoin::absolute::LockTime::from_consensus(5000),
5757
input: vec![],
5858
output: vec![],
@@ -86,13 +86,15 @@ fn main() {
8686
txin.sequence = Sequence::from_height(26); //Sequence::MAX; //
8787
psbt.unsigned_tx.input.push(txin);
8888

89-
psbt.unsigned_tx
90-
.output
91-
.push(TxOut { script_pubkey: receiver.script_pubkey(), value: amount / 5 - 500 });
89+
psbt.unsigned_tx.output.push(TxOut {
90+
script_pubkey: receiver.script_pubkey(),
91+
value: Amount::from_sat(amount / 5 - 500),
92+
});
9293

93-
psbt.unsigned_tx
94-
.output
95-
.push(TxOut { script_pubkey: bridge_descriptor.script_pubkey(), value: amount * 4 / 5 });
94+
psbt.unsigned_tx.output.push(TxOut {
95+
script_pubkey: bridge_descriptor.script_pubkey(),
96+
value: Amount::from_sat(amount * 4 / 5),
97+
});
9698

9799
// Generating signatures & witness data
98100

@@ -133,14 +135,12 @@ fn main() {
133135
.insert(pk1, bitcoin::ecdsa::Signature { sig: sig1, hash_ty: hash_ty });
134136

135137
println!("{:#?}", psbt);
136-
137-
let serialized = psbt.serialize();
138-
println!("{}", base64::encode(&serialized));
138+
println!("{}", psbt);
139139

140140
psbt.finalize_mut(&secp256k1).unwrap();
141141
println!("{:#?}", psbt);
142142

143-
let tx = psbt.extract_tx();
143+
let tx = psbt.extract_tx().expect("failed to extract tx");
144144
println!("{}", bitcoin::consensus::encode::serialize_hex(&tx));
145145
}
146146

examples/sign_multisig.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::collections::HashMap;
66
use std::str::FromStr;
77

88
use bitcoin::blockdata::witness::Witness;
9-
use bitcoin::{absolute, ecdsa, secp256k1, Sequence};
9+
use bitcoin::{absolute, ecdsa, secp256k1, transaction, Amount, Sequence};
1010

1111
fn main() {
1212
let mut tx = spending_transaction();
@@ -78,7 +78,7 @@ fn main() {
7878
// Transaction which spends some output.
7979
fn spending_transaction() -> bitcoin::Transaction {
8080
bitcoin::Transaction {
81-
version: 2,
81+
version: transaction::Version::TWO,
8282
lock_time: absolute::LockTime::ZERO,
8383
input: vec![bitcoin::TxIn {
8484
previous_output: Default::default(),
@@ -88,7 +88,7 @@ fn spending_transaction() -> bitcoin::Transaction {
8888
}],
8989
output: vec![bitcoin::TxOut {
9090
script_pubkey: bitcoin::ScriptBuf::new(),
91-
value: 100_000_000,
91+
value: Amount::from_sat(100_000_000),
9292
}],
9393
}
9494
}

examples/taproot.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
use std::collections::HashMap;
44
use std::str::FromStr;
55

6-
use miniscript::bitcoin::address::WitnessVersion;
7-
use miniscript::bitcoin::key::{KeyPair, XOnlyPublicKey};
6+
use miniscript::bitcoin::key::{Keypair, XOnlyPublicKey};
87
use miniscript::bitcoin::secp256k1::rand;
9-
use miniscript::bitcoin::Network;
8+
use miniscript::bitcoin::{Network, WitnessVersion};
109
use miniscript::descriptor::DescriptorType;
1110
use miniscript::policy::Concrete;
1211
use miniscript::{translate_hash_fail, Descriptor, Miniscript, Tap, TranslatePk, Translator};
@@ -83,7 +82,7 @@ fn main() {
8382

8483
// We require secp for generating a random XOnlyPublicKey
8584
let secp = secp256k1::Secp256k1::new();
86-
let key_pair = KeyPair::new(&secp, &mut rand::thread_rng());
85+
let key_pair = Keypair::new(&secp, &mut rand::thread_rng());
8786
// Random unspendable XOnlyPublicKey provided for compilation to Taproot Descriptor
8887
let (unspendable_pubkey, _parity) = XOnlyPublicKey::from_keypair(&key_pair);
8988

examples/verify_tx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn main() {
8585
// Same, but with the wrong signature hash, to demonstrate what happens
8686
// given an apparently invalid script.
8787
let secp = Secp256k1::new();
88-
let message = secp256k1::Message::from_slice(&[0x01; 32][..]).expect("32-byte hash");
88+
let message = secp256k1::Message::from_digest([0x01; 32]);
8989

9090
let iter = interpreter.iter_custom(Box::new(|key_sig: &KeySigPair| {
9191
let (pk, ecdsa_sig) = key_sig.as_ecdsa().expect("Ecdsa Sig");

0 commit comments

Comments
 (0)