Skip to content

Commit b8ceef7

Browse files
committed
update rust-bitcoin to 0.31
1 parent 2f58314 commit b8ceef7

File tree

26 files changed

+143
-130
lines changed

26 files changed

+143
-130
lines changed

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ rand = ["bitcoin/rand"]
1919
base64 = ["bitcoin/base64"]
2020

2121
[dependencies]
22-
bitcoin = "0.30.0"
23-
elements = "0.23.0"
24-
bitcoin-miniscript = { package = "miniscript", version = "10.0" }
25-
simplicity = { git = "https://github.com/BlockstreamResearch/rust-simplicity", rev = "d5c0d65320816bfdf36411feed4bdff0708b5b12", optional = true }
22+
bitcoin = "0.31.0"
23+
elements = "0.24.0"
24+
bitcoin-miniscript = { package = "miniscript", version = "11.0" }
25+
simplicity = { git = "https://github.com/BlockstreamResearch/rust-simplicity", rev = "39fe6d7533b06001e9954fa08df34a1052702caf", optional = true }
2626

2727
# Do NOT use this as a feature! Use the `serde` feature instead.
2828
actual-serde = { package = "serde", version = "1.0", optional = true }
@@ -31,8 +31,8 @@ actual-serde = { package = "serde", version = "1.0", optional = true }
3131
serde_json = "1.0"
3232
actual-rand = { package = "rand", version = "0.8.4"}
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
actual-base64 = { package = "base64", version = "0.13.0" }
3737

3838

bitcoind-tests/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ edition = "2018"
88

99
[dependencies]
1010
elements-miniscript = { path = "../" }
11-
elementsd = { version = "0.8.0" }
11+
elementsd = { version = "0.9.0" }
1212
actual-rand = { package = "rand", version = "0.8.4" }
13-
secp256k1 = { version = "0.27.0", features = ["rand-std"] }
13+
secp256k1 = { version = "0.28.1", features = ["rand-std"] }

bitcoind-tests/tests/setup/test_util.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct PubData {
5757
#[derive(Debug, Clone)]
5858
pub struct SecretData {
5959
pub sks: Vec<bitcoin::secp256k1::SecretKey>,
60-
pub x_only_keypairs: Vec<bitcoin::key::KeyPair>,
60+
pub x_only_keypairs: Vec<bitcoin::key::Keypair>,
6161
pub sha256_pre: [u8; 32],
6262
pub hash256_pre: [u8; 32],
6363
pub ripemd160_pre: [u8; 32],
@@ -75,7 +75,7 @@ fn setup_keys(
7575
) -> (
7676
Vec<bitcoin::secp256k1::SecretKey>,
7777
Vec<miniscript::bitcoin::PublicKey>,
78-
Vec<bitcoin::key::KeyPair>,
78+
Vec<bitcoin::key::Keypair>,
7979
Vec<bitcoin::key::XOnlyPublicKey>,
8080
) {
8181
let secp_sign = secp256k1::Secp256k1::signing_only();
@@ -100,7 +100,7 @@ fn setup_keys(
100100
let mut x_only_pks = vec![];
101101

102102
for sk in &sks {
103-
let keypair = bitcoin::key::KeyPair::from_secret_key(&secp_sign, sk);
103+
let keypair = bitcoin::key::Keypair::from_secret_key(&secp_sign, sk);
104104
let (xpk, _parity) = bitcoin::key::XOnlyPublicKey::from_keypair(&keypair);
105105
x_only_keypairs.push(keypair);
106106
x_only_pks.push(xpk);

bitcoind-tests/tests/test_arith.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec
105105
let prevouts = [witness_utxo];
106106
let prevouts = sighash::Prevouts::All(&prevouts);
107107
// ------------------ script spend -------------
108-
let x_only_keypairs_reqd: Vec<(secp256k1::KeyPair, TapLeafHash)> = tr
108+
let x_only_keypairs_reqd: Vec<(secp256k1::Keypair, TapLeafHash)> = tr
109109
.iter_scripts()
110110
.flat_map(|(_depth, script)| {
111111
let leaf_hash = TapLeafHash::from_script(&script.encode(), script.version());

bitcoind-tests/tests/test_cpp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub fn test_from_cpp_ms(cl: &ElementsD, testdata: &TestData) {
148148

149149
// requires both signing and verification because we check the tx
150150
// after we psbt extract it
151-
let msg = secp256k1_zkp::Message::from_slice(&sighash[..]).unwrap();
151+
let msg = secp256k1_zkp::Message::from_digest_slice(&sighash[..]).unwrap();
152152

153153
// Finally construct the signature and add to psbt
154154
for sk in sks_reqd {

bitcoind-tests/tests/test_csfs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec
106106
let prevouts = [witness_utxo];
107107
let prevouts = sighash::Prevouts::All(&prevouts);
108108
// ------------------ script spend -------------
109-
let x_only_keypairs_reqd: Vec<(secp256k1::KeyPair, TapLeafHash)> = tr
109+
let x_only_keypairs_reqd: Vec<(secp256k1::Keypair, TapLeafHash)> = tr
110110
.iter_scripts()
111111
.flat_map(|(_depth, script)| {
112112
let leaf_hash = TapLeafHash::from_script(&script.encode(), script.version());
@@ -126,7 +126,7 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec
126126
testdata.pubdata.genesis_hash,
127127
)
128128
.unwrap();
129-
let msg = secp256k1::Message::from_slice(&sighash_msg[..]).unwrap();
129+
let msg = secp256k1::Message::from_digest_slice(&sighash_msg[..]).unwrap();
130130
let mut aux_rand = [0u8; 32];
131131
rand::thread_rng().fill_bytes(&mut aux_rand);
132132
let sig = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &aux_rand);
@@ -167,7 +167,7 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec
167167

168168
// Create a signature
169169
let keypair = &self.0.secretdata.x_only_keypairs[i];
170-
let msg = secp256k1::Message::from_slice(msg.as_inner()).unwrap();
170+
let msg = secp256k1::Message::from_digest_slice(msg.as_inner()).unwrap();
171171
let mut aux_rand = [0u8; 32];
172172
rand::thread_rng().fill_bytes(&mut aux_rand);
173173

bitcoind-tests/tests/test_desc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub fn test_desc_satisfy(
163163
testdata.pubdata.genesis_hash,
164164
)
165165
.unwrap();
166-
let msg = secp256k1::Message::from_slice(&sighash_msg[..]).unwrap();
166+
let msg = secp256k1::Message::from_digest_slice(&sighash_msg[..]).unwrap();
167167
let mut aux_rand = [0u8; 32];
168168
rand::thread_rng().fill_bytes(&mut aux_rand);
169169
let schnorr_sig =
@@ -176,7 +176,7 @@ pub fn test_desc_satisfy(
176176
// No internal key
177177
}
178178
// ------------------ script spend -------------
179-
let x_only_keypairs_reqd: Vec<(secp256k1::KeyPair, TapLeafHash)> = tr
179+
let x_only_keypairs_reqd: Vec<(secp256k1::Keypair, TapLeafHash)> = tr
180180
.iter_scripts()
181181
.flat_map(|(_depth, script)| {
182182
let leaf_hash = TapLeafHash::from_script(&script.encode(), script.version());
@@ -196,7 +196,7 @@ pub fn test_desc_satisfy(
196196
testdata.pubdata.genesis_hash,
197197
)
198198
.unwrap();
199-
let msg = secp256k1::Message::from_slice(&sighash_msg[..]).unwrap();
199+
let msg = secp256k1::Message::from_digest_slice(&sighash_msg[..]).unwrap();
200200
let mut aux_rand = [0u8; 32];
201201
rand::thread_rng().fill_bytes(&mut aux_rand);
202202
let sig = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &aux_rand);

bitcoind-tests/tests/test_introspect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec
105105
let prevouts = [witness_utxo];
106106
let prevouts = sighash::Prevouts::All(&prevouts);
107107
// ------------------ script spend -------------
108-
let x_only_keypairs_reqd: Vec<(secp256k1::KeyPair, TapLeafHash)> = tr
108+
let x_only_keypairs_reqd: Vec<(secp256k1::Keypair, TapLeafHash)> = tr
109109
.iter_scripts()
110110
.flat_map(|(_depth, script)| {
111111
let leaf_hash = TapLeafHash::from_script(&script.encode(), script.version());
@@ -125,7 +125,7 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec
125125
testdata.pubdata.genesis_hash,
126126
)
127127
.unwrap();
128-
let msg = secp256k1::Message::from_slice(&sighash_msg[..]).unwrap();
128+
let msg = secp256k1::Message::from_digest_slice(&sighash_msg[..]).unwrap();
129129
let mut aux_rand = [0u8; 32];
130130
rand::thread_rng().fill_bytes(&mut aux_rand);
131131
let sig = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &aux_rand);

examples/taproot.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ extern crate elements_miniscript as miniscript;
33
use std::collections::HashMap;
44
use std::str::FromStr;
55

6-
use bitcoin::address::WitnessVersion;
6+
use bitcoin::WitnessVersion;
77
use miniscript::descriptor::DescriptorType;
8+
use miniscript::descriptor::TapLeafScript;
89
use miniscript::policy::Concrete;
910
use miniscript::{
1011
translate_hash_fail, Descriptor, Miniscript, NoExt, Tap, TranslatePk, Translator,
1112
};
12-
use miniscript::descriptor::TapLeafScript;
13-
use secp256k1::{rand, KeyPair};
13+
use secp256k1::{rand, Keypair};
1414

1515
// Refer to https://github.com/sanket1729/adv_btc_workshop/blob/master/workshop.md#creating-a-taproot-descriptor
1616
// for a detailed explanation of the policy and it's compilation
@@ -71,14 +71,19 @@ fn main() {
7171
iter.next().unwrap(),
7272
(
7373
1,
74-
TapLeafScript::Miniscript(&Miniscript::<String, Tap, NoExt>::from_str("and_v(vc:pk_k(In),older(9))").unwrap())
74+
TapLeafScript::Miniscript(
75+
&Miniscript::<String, Tap, NoExt>::from_str("and_v(vc:pk_k(In),older(9))")
76+
.unwrap()
77+
)
7578
)
7679
);
7780
assert_eq!(
7881
iter.next().unwrap(),
7982
(
8083
1,
81-
TapLeafScript::Miniscript(&Miniscript::<String, Tap, NoExt>::from_str("multi_a(2,hA,S)").unwrap())
84+
TapLeafScript::Miniscript(
85+
&Miniscript::<String, Tap, NoExt>::from_str("multi_a(2,hA,S)").unwrap()
86+
)
8287
)
8388
);
8489
assert_eq!(iter.next(), None);
@@ -88,7 +93,7 @@ fn main() {
8893

8994
// We require secp for generating a random XOnlyPublicKey
9095
let secp = secp256k1::Secp256k1::new();
91-
let key_pair = KeyPair::new(&secp, &mut rand::thread_rng());
96+
let key_pair = Keypair::new(&secp, &mut rand::thread_rng());
9297
// Random unspendable XOnlyPublicKey provided for compilation to Taproot Descriptor
9398
let (unspendable_pubkey, _parity) = bitcoin::key::XOnlyPublicKey::from_keypair(&key_pair);
9499

examples/verify_tx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn main() {
120120
// 3. Example three: same, but with the wrong signature hash, to demonstrate
121121
// what happens given an apparently invalid script
122122
let secp = secp256k1_zkp::Secp256k1::new();
123-
let message = secp256k1_zkp::Message::from_slice(&[0x01; 32][..]).expect("32-byte hash");
123+
let message = secp256k1_zkp::Message::from_digest_slice(&[0x01; 32][..]).expect("32-byte hash");
124124
let interpreter = miniscript::Interpreter::from_txdata(
125125
&spk_input_1,
126126
&transaction.input[0].script_sig,

src/confidential/bare.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,12 @@ use elements::secp256k1_zkp;
2020

2121
use crate::ToPublicKey;
2222

23-
/// The SHA-256 initial midstate value for the [`TweakHash`].
24-
const MIDSTATE_HASH_TO_PRIVATE_HASH: [u8; 32] = [
25-
0x2f, 0x85, 0x61, 0xec, 0x30, 0x88, 0xad, 0xa9, 0x5a, 0xe7, 0x43, 0xcd, 0x3c, 0x5f, 0x59, 0x7d,
26-
0xc0, 0x4b, 0xd0, 0x7f, 0x06, 0x5f, 0x1c, 0x06, 0x47, 0x89, 0x36, 0x63, 0xf3, 0x92, 0x6e, 0x65,
27-
];
28-
29-
sha256t_hash_newtype!(
30-
TweakHash,
31-
TweakTag,
32-
MIDSTATE_HASH_TO_PRIVATE_HASH,
33-
64,
34-
doc = "BIP-340 Tagged hash for tweaking blinding keys",
35-
forward
36-
);
23+
sha256t_hash_newtype! {
24+
pub struct TapTweakTag = hash_str("CT-Blinding-Key/1.0");
25+
/// Taproot-tagged hash for elements tapscript Merkle tree leafs
26+
#[hash_newtype(forward)]
27+
pub struct TapTweakHash(_);
28+
}
3729

3830
/// Tweaks a bare key using the scriptPubKey of a descriptor
3931
pub fn tweak_key<'a, Pk, V>(
@@ -45,12 +37,12 @@ where
4537
Pk: ToPublicKey + 'a,
4638
V: secp256k1_zkp::Verification,
4739
{
48-
let mut eng = TweakHash::engine();
40+
let mut eng = TapTweakHash::engine();
4941
pk.to_public_key()
5042
.write_into(&mut eng)
5143
.expect("engines don't error");
5244
spk.consensus_encode(&mut eng).expect("engines don't error");
53-
let hash_bytes = TweakHash::from_engine(eng).to_byte_array();
45+
let hash_bytes = TapTweakHash::from_engine(eng).to_byte_array();
5446
let hash_scalar = secp256k1_zkp::Scalar::from_be_bytes(hash_bytes).expect("bytes from hash");
5547
pk.to_public_key()
5648
.inner
@@ -67,12 +59,12 @@ pub fn tweak_private_key<V>(
6759
where
6860
V: secp256k1_zkp::Signing,
6961
{
70-
let mut eng = TweakHash::engine();
62+
let mut eng = TapTweakHash::engine();
7163
bitcoin::PublicKey::new(sk.public_key(secp))
7264
.write_into(&mut eng)
7365
.expect("engines don't error");
7466
spk.consensus_encode(&mut eng).expect("engines don't error");
75-
let hash_bytes = TweakHash::from_engine(eng).to_byte_array();
67+
let hash_bytes = TapTweakHash::from_engine(eng).to_byte_array();
7668
let hash_scalar = secp256k1_zkp::Scalar::from_be_bytes(hash_bytes).expect("bytes from hash");
7769
sk.add_tweak(&hash_scalar).unwrap()
7870
}
@@ -84,6 +76,12 @@ mod tests {
8476

8577
use super::*;
8678

79+
const MIDSTATE_HASH_TO_PRIVATE_HASH: [u8; 32] = [
80+
0x2f, 0x85, 0x61, 0xec, 0x30, 0x88, 0xad, 0xa9, 0x5a, 0xe7, 0x43, 0xcd, 0x3c, 0x5f, 0x59,
81+
0x7d, 0xc0, 0x4b, 0xd0, 0x7f, 0x06, 0x5f, 0x1c, 0x06, 0x47, 0x89, 0x36, 0x63, 0xf3, 0x92,
82+
0x6e, 0x65,
83+
];
84+
8785
#[test]
8886
fn tagged_hash() {
8987
// Check that cached midstate is computed correctly
@@ -100,18 +98,18 @@ mod tests {
10098

10199
// Test empty hash
102100
assert_eq!(
103-
TweakHash::from_engine(TweakTag::engine()).to_string(),
101+
TapTweakHash::from_engine(TapTweakTag::engine()).to_string(),
104102
"d12a140aca856fbb917b931f263c42f064608985e2ce17ae5157daa17c55e8d9",
105103
);
106104
assert_eq!(
107-
TweakHash::hash(&[]).to_string(),
105+
TapTweakHash::hash(&[]).to_string(),
108106
"d12a140aca856fbb917b931f263c42f064608985e2ce17ae5157daa17c55e8d9",
109107
);
110108

111109
// And hash of 100 bytes
112110
let data: Vec<u8> = (0..80).collect();
113111
assert_eq!(
114-
TweakHash::hash(&data).to_string(),
112+
TapTweakHash::hash(&data).to_string(),
115113
"e1e52419a2934d278c50e29608969d2f23c1bd1243a09bfc8026d4ed4b085e39",
116114
);
117115
}

src/confidential/elip151.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,12 @@ use crate::descriptor::{DescriptorSecretKey, SinglePriv};
2929
use crate::extensions::{Extension, ParseableExt};
3030
use crate::{Descriptor as OrdinaryDescriptor, DescriptorPublicKey, Error};
3131

32-
/// The SHA-256 initial midstate value for the [`Elip151Hash`].
33-
const MIDSTATE_ELIP151: [u8; 32] = [
34-
0x49, 0x81, 0x61, 0xd8, 0x52, 0x45, 0xf7, 0xaa, 0xd8, 0x24, 0x27, 0xb5, 0x64, 0x69, 0xe7, 0xd6,
35-
0x98, 0x17, 0xeb, 0x0f, 0x27, 0x14, 0x6f, 0x4e, 0x7b, 0x95, 0xb3, 0x6e, 0x46, 0xc1, 0xb5, 0x61,
36-
];
37-
38-
sha256t_hash_newtype!(
39-
Elip151Hash,
40-
Elip151Tag,
41-
MIDSTATE_ELIP151,
42-
64,
43-
doc = "ELIP-151 Deterministic descriptor blinding keys",
44-
forward
45-
);
32+
sha256t_hash_newtype! {
33+
pub struct Elip151Tag = hash_str("ELIP-151 Deterministic descriptor blinding keys");
34+
/// ELIP-151 Deterministic descriptor blinding keys
35+
#[hash_newtype(forward)]
36+
pub struct Elip151Hash(_);
37+
}
4638

4739
impl Key {
4840
pub fn from_elip151<T: Extension + ParseableExt>(
@@ -114,6 +106,13 @@ mod test {
114106
use bitcoin::hashes::{sha256, HashEngine};
115107
use std::str::FromStr;
116108

109+
/// The SHA-256 initial midstate value for the [`Elip151Hash`].
110+
const MIDSTATE_ELIP151: [u8; 32] = [
111+
0x49, 0x81, 0x61, 0xd8, 0x52, 0x45, 0xf7, 0xaa, 0xd8, 0x24, 0x27, 0xb5, 0x64, 0x69, 0xe7,
112+
0xd6, 0x98, 0x17, 0xeb, 0x0f, 0x27, 0x14, 0x6f, 0x4e, 0x7b, 0x95, 0xb3, 0x6e, 0x46, 0xc1,
113+
0xb5, 0x61,
114+
];
115+
117116
#[test]
118117
fn tagged_hash_elip151() {
119118
// Check that cached midstate is computed correctly, code from rust-bitcoin
@@ -175,7 +174,8 @@ mod test {
175174
] {
176175
let conf_desc = confidential_descriptor(desc).unwrap();
177176
let elip151_desc = add_checksum(&format!("ct(elip151,{})", desc));
178-
let conf_desc_elip151 = ConfidentialDescriptor::<DescriptorPublicKey>::from_str(&elip151_desc).unwrap();
177+
let conf_desc_elip151 =
178+
ConfidentialDescriptor::<DescriptorPublicKey>::from_str(&elip151_desc).unwrap();
179179
assert_eq!(conf_desc, conf_desc_elip151);
180180

181181
// Uncomment this and below to regenerate test vectors; to see the output, run

0 commit comments

Comments
 (0)