Skip to content

Commit e67d92f

Browse files
committed
WIP: Upgrade rust-bitcoin to current tip of master
1 parent d946871 commit e67d92f

21 files changed

+119
-92
lines changed

Cargo.toml

+17-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ base64 = ["bitcoin/base64"]
2323

2424
[dependencies]
2525
bech32 = { version = "0.11.0", default-features = false }
26-
bitcoin = { version = "0.32.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.32.0", features = ["base64"] }
33+
bitcoin = { version = "0.32.0-rc1", features = ["base64"] }
3434
secp256k1 = {version = "0.29.0", features = ["rand-std"]}
3535

3636
[[example]]
@@ -68,3 +68,18 @@ required-features = ["std", "base64", "compiler"]
6868
[workspace]
6969
members = ["fuzz"]
7070
exclude = ["embedded"]
71+
72+
[patch.crates-io.bitcoin]
73+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
74+
75+
[patch.crates-io.bitcoin_hashes]
76+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
77+
78+
[patch.crates-io.bitcoin-internals]
79+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
80+
81+
[patch.crates-io.bitcoin-io]
82+
git = "https://github.com/rust-bitcoin/rust-bitcoin"
83+
84+
[patch.crates-io.bitcoin-units]
85+
git = "https://github.com/rust-bitcoin/rust-bitcoin"

src/descriptor/bare.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Pkh<Pk> {
295295
// serialize() does not allocate here
296296
sig.serialize().as_ref(),
297297
)
298-
.push_key(&self.pk.to_public_key())
298+
.push_key(self.pk.to_public_key())
299299
.into_script();
300300
let witness = vec![];
301301
Ok((witness, script_sig))

src/descriptor/key.rs

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

99
use bitcoin::bip32::{self, XKeyIdentifier};
10-
use bitcoin::hashes::{hash160, ripemd160, sha256, Hash, HashEngine};
10+
use bitcoin::hashes::{hash160, ripemd160, sha256, HashEngine};
1111
use bitcoin::key::XOnlyPublicKey;
1212
use bitcoin::secp256k1::{Secp256k1, Signing, Verification};
1313

@@ -220,10 +220,7 @@ impl DescriptorXKey<bip32::Xpriv> {
220220
let hardened_path = &self.derivation_path[..last_hardened_idx];
221221
let unhardened_path = &self.derivation_path[last_hardened_idx..];
222222

223-
let xprv = self
224-
.xkey
225-
.derive_priv(secp, &hardened_path)
226-
.map_err(|_| DescriptorKeyParseError("Unable to derive the hardened steps"))?;
223+
let xprv = self.xkey.derive_priv(secp, &hardened_path);
227224
let xpub = bip32::Xpub::from_priv(secp, &xprv);
228225

229226
let origin = match &self.origin {

src/descriptor/mod.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,6 @@ mod tests {
10041004
use bitcoin::blockdata::script::Instruction;
10051005
use bitcoin::blockdata::{opcodes, script};
10061006
use bitcoin::hashes::hex::FromHex;
1007-
use bitcoin::hashes::Hash;
10081007
use bitcoin::script::PushBytes;
10091008
use bitcoin::sighash::EcdsaSighashType;
10101009
use bitcoin::{bip32, PublicKey, Sequence};
@@ -1309,7 +1308,7 @@ mod tests {
13091308
previous_output: bitcoin::OutPoint::default(),
13101309
script_sig: script::Builder::new()
13111310
.push_slice(<&PushBytes>::try_from(sigser.as_slice()).unwrap())
1312-
.push_key(&pk)
1311+
.push_key(pk)
13131312
.into_script(),
13141313
sequence: Sequence::from_height(100),
13151314
witness: Witness::default(),
@@ -1397,7 +1396,15 @@ mod tests {
13971396
bitcoin::TxIn {
13981397
previous_output: bitcoin::OutPoint::default(),
13991398
script_sig: script::Builder::new()
1400-
.push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().as_bytes()).unwrap())
1399+
.push_slice(
1400+
<&PushBytes>::try_from(
1401+
ms.encode()
1402+
.to_p2wsh()
1403+
.expect("TODO: Do we need to propagate this error")
1404+
.as_bytes()
1405+
)
1406+
.unwrap()
1407+
)
14011408
.into_script(),
14021409
sequence: Sequence::from_height(100),
14031410
witness: Witness::from_slice(&[sigser.clone(), ms.encode().into_bytes()]),
@@ -1406,7 +1413,15 @@ mod tests {
14061413
assert_eq!(
14071414
shwsh.unsigned_script_sig(),
14081415
script::Builder::new()
1409-
.push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().as_bytes()).unwrap())
1416+
.push_slice(
1417+
<&PushBytes>::try_from(
1418+
ms.encode()
1419+
.to_p2wsh()
1420+
.expect("TODO: Do we need to propagate this error")
1421+
.as_bytes()
1422+
)
1423+
.unwrap()
1424+
)
14101425
.into_script()
14111426
);
14121427
}

src/descriptor/segwitv0.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use core::convert::TryFrom;
99
use core::fmt;
1010

11+
use bitcoin::key::CompressedPublicKey;
1112
use bitcoin::{Address, Network, ScriptBuf, Weight};
1213

1314
use super::checksum::verify_checksum;
@@ -132,14 +133,19 @@ impl<Pk: MiniscriptKey> Wsh<Pk> {
132133

133134
impl<Pk: MiniscriptKey + ToPublicKey> Wsh<Pk> {
134135
/// Obtains the corresponding script pubkey for this descriptor.
135-
pub fn script_pubkey(&self) -> ScriptBuf { self.inner_script().to_p2wsh() }
136+
pub fn script_pubkey(&self) -> ScriptBuf {
137+
self.inner_script()
138+
.to_p2wsh()
139+
.expect("TODO: Do we need to propagate this error")
140+
}
136141

137142
/// Obtains the corresponding script pubkey for this descriptor.
138143
pub fn address(&self, network: Network) -> Address {
139-
match self.inner {
144+
let res = match self.inner {
140145
WshInner::SortedMulti(ref smv) => Address::p2wsh(&smv.encode(), network),
141146
WshInner::Ms(ref ms) => Address::p2wsh(&ms.encode(), network),
142-
}
147+
};
148+
res.expect("TODO: Do we need to propagate this error")
143149
}
144150

145151
/// Obtains the underlying miniscript for this descriptor.
@@ -375,21 +381,19 @@ impl<Pk: MiniscriptKey> Wpkh<Pk> {
375381
impl<Pk: MiniscriptKey + ToPublicKey> Wpkh<Pk> {
376382
/// Obtains the corresponding script pubkey for this descriptor.
377383
pub fn script_pubkey(&self) -> ScriptBuf {
378-
let pk = self.pk.to_public_key();
379-
let compressed = bitcoin::key::CompressedPublicKey::try_from(pk)
384+
let pk = CompressedPublicKey::try_from(self.pk.to_public_key())
380385
.expect("wpkh descriptors have compressed keys");
386+
let addr = Address::p2wpkh(pk, Network::Bitcoin);
381387

382-
let addr = Address::p2wpkh(&compressed, Network::Bitcoin);
383388
addr.script_pubkey()
384389
}
385390

386391
/// Obtains the corresponding script pubkey for this descriptor.
387392
pub fn address(&self, network: Network) -> Address {
388-
let pk = self.pk.to_public_key();
389-
let compressed = bitcoin::key::CompressedPublicKey::try_from(pk)
390-
.expect("Rust Miniscript types don't allow uncompressed pks in segwit descriptors");
393+
let pk = CompressedPublicKey::try_from(self.pk.to_public_key())
394+
.expect("wpkh descriptors have compressed keys");
391395

392-
Address::p2wpkh(&compressed, network)
396+
Address::p2wpkh(pk, network)
393397
}
394398

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

src/descriptor/sh.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,13 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
264264
impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
265265
/// Obtains the corresponding script pubkey for this descriptor.
266266
pub fn script_pubkey(&self) -> ScriptBuf {
267-
match self.inner {
267+
let res = match self.inner {
268268
ShInner::Wsh(ref wsh) => wsh.script_pubkey().to_p2sh(),
269269
ShInner::Wpkh(ref wpkh) => wpkh.script_pubkey().to_p2sh(),
270270
ShInner::SortedMulti(ref smv) => smv.encode().to_p2sh(),
271271
ShInner::Ms(ref ms) => ms.encode().to_p2sh(),
272-
}
272+
};
273+
res.expect("TODO: Do we need to propagate this error")
273274
}
274275

275276
/// Obtains the corresponding address for this descriptor.
@@ -288,7 +289,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
288289
ShInner::SortedMulti(ref smv) => smv.encode(),
289290
ShInner::Ms(ref ms) => ms.encode(),
290291
};
291-
let address = Address::p2sh(&script, network)?;
292+
let address = Address::p2sh(&script, network).expect("TODO: handle this error");
292293

293294
Ok(address)
294295
}
@@ -327,7 +328,10 @@ impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
327328
match self.inner {
328329
ShInner::Wsh(ref wsh) => {
329330
// wsh explicit must contain exactly 1 element
330-
let witness_script = wsh.inner_script().to_p2wsh();
331+
let witness_script = wsh
332+
.inner_script()
333+
.to_p2wsh()
334+
.expect("TODO: Do we need to propagate this error");
331335
let push_bytes = <&PushBytes>::try_from(witness_script.as_bytes())
332336
.expect("Witness script is not too large");
333337
script::Builder::new().push_slice(push_bytes).into_script()

src/interpreter/error.rs

-9
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ pub enum Error {
9494
ScriptSatisfactionError,
9595
/// Schnorr Signature error
9696
SchnorrSig(bitcoin::taproot::SigFromSliceError),
97-
/// Errors in signature hash calculations
98-
SighashError(bitcoin::sighash::InvalidSighashTypeError),
9997
/// Taproot Annex Unsupported
10098
TapAnnexUnsupported,
10199
/// An uncompressed public key was encountered in a context where it is
@@ -170,7 +168,6 @@ impl fmt::Display for Error {
170168
Error::ScriptSatisfactionError => f.write_str("Top level script must be satisfied"),
171169
Error::Secp(ref e) => fmt::Display::fmt(e, f),
172170
Error::SchnorrSig(ref s) => write!(f, "Schnorr sig error: {}", s),
173-
Error::SighashError(ref e) => fmt::Display::fmt(e, f),
174171
Error::TapAnnexUnsupported => f.write_str("Encountered annex element"),
175172
Error::UncompressedPubkey => {
176173
f.write_str("uncompressed pubkey in non-legacy descriptor")
@@ -231,7 +228,6 @@ impl error::Error for Error {
231228
Miniscript(e) => Some(e),
232229
Secp(e) => Some(e),
233230
SchnorrSig(e) => Some(e),
234-
SighashError(e) => Some(e),
235231
}
236232
}
237233
}
@@ -241,11 +237,6 @@ impl From<secp256k1::Error> for Error {
241237
fn from(e: secp256k1::Error) -> Error { Error::Secp(e) }
242238
}
243239

244-
#[doc(hidden)]
245-
impl From<bitcoin::sighash::InvalidSighashTypeError> for Error {
246-
fn from(e: bitcoin::sighash::InvalidSighashTypeError) -> Error { Error::SighashError(e) }
247-
}
248-
249240
#[doc(hidden)]
250241
impl From<bitcoin::ecdsa::Error> for Error {
251242
fn from(e: bitcoin::ecdsa::Error) -> Error { Error::EcdsaSig(e) }

src/interpreter/inner.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Written in 2019 by Sanket Kanjular and Andrew Poelstra
22
// SPDX-License-Identifier: CC0-1.0
33

4-
use bitcoin::hashes::{hash160, sha256, Hash};
4+
use bitcoin::hashes::{hash160, sha256};
55
use bitcoin::taproot::{ControlBlock, TAPROOT_ANNEX_PREFIX};
66
use bitcoin::Witness;
77

@@ -433,14 +433,14 @@ mod tests {
433433
let wpkh_scripthash = hash160::Hash::hash(wpkh_spk.as_bytes()).into();
434434

435435
KeyTestData {
436-
pk_spk: bitcoin::ScriptBuf::new_p2pk(&key),
436+
pk_spk: bitcoin::ScriptBuf::new_p2pk(key),
437437
pkh_spk: bitcoin::ScriptBuf::new_p2pkh(&pkhash),
438438
pk_sig: script::Builder::new().push_slice(dummy_sig).into_script(),
439439
pkh_sig: script::Builder::new()
440440
.push_slice(dummy_sig)
441-
.push_key(&key)
441+
.push_key(key)
442442
.into_script(),
443-
pkh_sig_justkey: script::Builder::new().push_key(&key).into_script(),
443+
pkh_sig_justkey: script::Builder::new().push_key(key).into_script(),
444444
wpkh_spk: wpkh_spk.clone(),
445445
wpkh_stack: Witness::from_slice(&[dummy_sig_vec.clone(), key.to_bytes()]),
446446
wpkh_stack_justkey: Witness::from_slice(&[key.to_bytes()]),

src/interpreter/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use core::fmt;
1212
use core::str::FromStr;
1313

14-
use bitcoin::hashes::{hash160, ripemd160, sha256, Hash};
14+
use bitcoin::hashes::{hash160, ripemd160, sha256};
1515
use bitcoin::{absolute, relative, secp256k1, sighash, taproot, Sequence, TxOut, Witness};
1616

1717
use crate::miniscript::context::{NoChecks, SigType};

src/interpreter/stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! Interpreter stack
55
66
use bitcoin::blockdata::{opcodes, script};
7-
use bitcoin::hashes::{hash160, ripemd160, sha256, Hash};
7+
use bitcoin::hashes::{hash160, ripemd160, sha256};
88
use bitcoin::{absolute, relative, Sequence};
99

1010
use super::error::PkEvalErrInner;

src/lib.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ use core::{fmt, hash, str};
138138
#[cfg(feature = "std")]
139139
use std::error;
140140

141-
use bitcoin::hashes::{hash160, ripemd160, sha256, Hash};
141+
use bitcoin::hashes::{hash160, ripemd160, sha256};
142142
use bitcoin::hex::DisplayHex;
143143
use bitcoin::{script, Opcode};
144144

@@ -432,8 +432,6 @@ pub enum Error {
432432
Script(script::Error),
433433
/// rust-bitcoin address error
434434
AddrError(bitcoin::address::ParseError),
435-
/// rust-bitcoin p2sh address error
436-
AddrP2shError(bitcoin::address::P2shError),
437435
/// A `CHECKMULTISIG` opcode was preceded by a number > 20
438436
CmsTooManyKeys(u32),
439437
/// A tapscript multi_a cannot support more than Weight::MAX_BLOCK/32 keys
@@ -516,7 +514,6 @@ impl fmt::Display for Error {
516514
},
517515
Error::Script(ref e) => fmt::Display::fmt(e, f),
518516
Error::AddrError(ref e) => fmt::Display::fmt(e, f),
519-
Error::AddrP2shError(ref e) => fmt::Display::fmt(e, f),
520517
Error::CmsTooManyKeys(n) => write!(f, "checkmultisig with {} keys", n),
521518
Error::Unprintable(x) => write!(f, "unprintable character 0x{:02x}", x),
522519
Error::ExpectedChar(c) => write!(f, "expected {}", c),
@@ -597,7 +594,6 @@ impl error::Error for Error {
597594
| MultipathDescLenMismatch => None,
598595
Script(e) => Some(e),
599596
AddrError(e) => Some(e),
600-
AddrP2shError(e) => Some(e),
601597
Secp(e) => Some(e),
602598
#[cfg(feature = "compiler")]
603599
CompilerError(e) => Some(e),
@@ -644,11 +640,6 @@ impl From<bitcoin::address::ParseError> for Error {
644640
fn from(e: bitcoin::address::ParseError) -> Error { Error::AddrError(e) }
645641
}
646642

647-
#[doc(hidden)]
648-
impl From<bitcoin::address::P2shError> for Error {
649-
fn from(e: bitcoin::address::P2shError) -> Error { Error::AddrP2shError(e) }
650-
}
651-
652643
#[doc(hidden)]
653644
#[cfg(feature = "compiler")]
654645
impl From<crate::policy::compiler::CompilerError> for Error {

src/miniscript/astelem.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use core::fmt;
1111
use core::str::FromStr;
1212

13-
use bitcoin::hashes::{hash160, Hash};
13+
use bitcoin::hashes::hash160;
1414
use bitcoin::{absolute, opcodes, script};
1515
use sync::Arc;
1616

@@ -465,7 +465,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
465465
debug_assert!(Ctx::sig_type() == SigType::Ecdsa);
466466
builder = builder.push_int(thresh.k() as i64);
467467
for pk in thresh.data() {
468-
builder = builder.push_key(&pk.to_public_key());
468+
builder = builder.push_key(pk.to_public_key());
469469
}
470470
builder
471471
.push_int(thresh.n() as i64)

src/miniscript/decode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use core::marker::PhantomData;
1010
#[cfg(feature = "std")]
1111
use std::error;
1212

13-
use bitcoin::hashes::{hash160, ripemd160, sha256, Hash};
13+
use bitcoin::hashes::{hash160, ripemd160, sha256};
1414
use sync::Arc;
1515

1616
use crate::miniscript::lex::{Token as Tk, TokenIter};

src/miniscript/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> Iterator for PkIter<'a, Pk, Ctx>
203203
// dependent libraries for their own tasts based on Miniscript AST
204204
#[cfg(test)]
205205
pub mod test {
206-
use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d, Hash};
206+
use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d};
207207

208208
use super::Miniscript;
209209
use crate::miniscript::context::Segwitv0;

src/miniscript/lex.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ pub fn lex(script: &'_ script::Script) -> Result<Vec<Token<'_>>, Error> {
213213
33 => ret.push(Token::Bytes33(bytes.as_bytes())),
214214
65 => ret.push(Token::Bytes65(bytes.as_bytes())),
215215
_ => {
216-
match script::read_scriptint(bytes.as_bytes()) {
216+
match bytes.read_scriptint() {
217217
Ok(v) if v >= 0 => {
218218
// check minimality of the number
219219
if script::Builder::new().push_int(v).into_script()[1..].as_bytes()

src/miniscript/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ mod tests {
697697
use core::str;
698698
use core::str::FromStr;
699699

700-
use bitcoin::hashes::{hash160, sha256, Hash};
700+
use bitcoin::hashes::{hash160, sha256};
701701
use bitcoin::secp256k1::XOnlyPublicKey;
702702
use bitcoin::taproot::TapLeafHash;
703703
use sync::Arc;

0 commit comments

Comments
 (0)