From ad2524b6edfc74b080617b27d347fbe6e7fc4e31 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 16 Oct 2023 15:15:37 +1100 Subject: [PATCH] Upgrade bitcoin dependency Upgrade to the latest versions the dependencies required to use `bitcoin v0.31.0-rc1`: - bitcoin: to v0.31.0-rc1 - secp256k1: to v0.28.0 - internals: to v0.2.0 - bitcoind: git branch with similar upgrade (includes bitcoincore-rpc) --- Cargo.toml | 8 +-- bitcoind-tests/Cargo.toml | 6 +- bitcoind-tests/tests/setup/test_util.rs | 6 +- bitcoind-tests/tests/test_cpp.rs | 23 ++++---- bitcoind-tests/tests/test_desc.rs | 18 +++--- examples/psbt_sign_finalize.rs | 26 ++++----- examples/sign_multisig.rs | 6 +- examples/taproot.rs | 7 +-- examples/verify_tx.rs | 2 +- src/descriptor/key.rs | 42 ++++++-------- src/descriptor/mod.rs | 19 +++---- src/descriptor/segwitv0.rs | 2 +- src/descriptor/sh.rs | 2 +- src/interpreter/error.rs | 6 +- src/interpreter/inner.rs | 20 +++---- src/interpreter/mod.rs | 22 +++----- src/lib.rs | 8 +-- src/miniscript/context.rs | 4 +- src/miniscript/decode.rs | 16 +++--- src/plan.rs | 11 ++-- src/policy/compiler.rs | 2 +- src/psbt/finalizer.rs | 16 +++--- src/psbt/mod.rs | 73 ++++++++++++------------- src/test_utils.rs | 2 +- src/util.rs | 2 +- 25 files changed, 166 insertions(+), 183 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ad9e89255..734c781f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,16 +23,16 @@ base64 = ["bitcoin/base64"] [dependencies] bech32 = { version = "0.10.0-beta", default-features = false } -bitcoin = { version = "0.30.0", default-features = false } -internals = { package = "bitcoin-private", version = "0.1.0", default_features = false } +bitcoin = { version = "0.31.0", default-features = false } +internals = { package = "bitcoin-internals", version = "0.2.0", 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.30.0", features = ["base64"] } -secp256k1 = {version = "0.27.0", features = ["rand-std"]} +bitcoin = { version = "0.31.0", features = ["base64"] } +secp256k1 = {version = "0.28.0", features = ["rand-std"]} [[example]] name = "htlc" diff --git a/bitcoind-tests/Cargo.toml b/bitcoind-tests/Cargo.toml index ebed07c62..3633778fb 100644 --- a/bitcoind-tests/Cargo.toml +++ b/bitcoind-tests/Cargo.toml @@ -9,7 +9,7 @@ publish = false [dependencies] miniscript = {path = "../"} -bitcoind = { version = "0.32.0" } +bitcoind = { git = "https://github.com/tcharding/bitcoind", branch = "10-16-upgrade-bitcoin" } actual-rand = { package = "rand", version = "0.8.4"} -secp256k1 = {version = "0.27.0", features = ["rand-std"]} -internals = { package = "bitcoin-private", version = "0.1.0", default_features = false } \ No newline at end of file +secp256k1 = {version = "0.28.0", features = ["rand-std"]} +internals = { package = "bitcoin-internals", version = "0.2.0", default_features = false } diff --git a/bitcoind-tests/tests/setup/test_util.rs b/bitcoind-tests/tests/setup/test_util.rs index c49b07741..63ec3fa63 100644 --- a/bitcoind-tests/tests/setup/test_util.rs +++ b/bitcoind-tests/tests/setup/test_util.rs @@ -44,7 +44,7 @@ pub struct PubData { #[derive(Debug, Clone)] pub struct SecretData { pub sks: Vec, - pub x_only_keypairs: Vec, + pub x_only_keypairs: Vec, pub sha256_pre: [u8; 32], pub hash256_pre: [u8; 32], pub ripemd160_pre: [u8; 32], @@ -62,7 +62,7 @@ fn setup_keys( ) -> ( Vec, Vec, - Vec, + Vec, Vec, ) { let secp_sign = secp256k1::Secp256k1::signing_only(); @@ -87,7 +87,7 @@ fn setup_keys( let mut x_only_pks = vec![]; for i in 0..n { - let keypair = bitcoin::secp256k1::KeyPair::from_secret_key(&secp_sign, &sks[i]); + let keypair = bitcoin::secp256k1::Keypair::from_secret_key(&secp_sign, &sks[i]); let (xpk, _parity) = XOnlyPublicKey::from_keypair(&keypair); x_only_keypairs.push(keypair); x_only_pks.push(xpk); diff --git a/bitcoind-tests/tests/test_cpp.rs b/bitcoind-tests/tests/test_cpp.rs index 6ac0e1610..031a5d673 100644 --- a/bitcoind-tests/tests/test_cpp.rs +++ b/bitcoind-tests/tests/test_cpp.rs @@ -11,7 +11,9 @@ use std::path::Path; use bitcoin::hashes::{sha256d, Hash}; use bitcoin::psbt::Psbt; -use bitcoin::{psbt, secp256k1, Amount, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid}; +use bitcoin::{ + psbt, secp256k1, transaction, Amount, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid, +}; use bitcoind::bitcoincore_rpc::{json, Client, RpcApi}; use miniscript::bitcoin::absolute; use miniscript::psbt::PsbtExt; @@ -49,7 +51,7 @@ fn btc>(btc: F) -> Amount { Amount::from_btc(btc.into()).unwrap() } // Find the Outpoint by value. // Ideally, we should find by scriptPubkey, but this // works for temp test case -fn get_vout(cl: &Client, txid: Txid, value: u64) -> (OutPoint, TxOut) { +fn get_vout(cl: &Client, txid: Txid, value: Amount) -> (OutPoint, TxOut) { let tx = cl .get_transaction(&txid, None) .unwrap() @@ -102,7 +104,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) { for (desc, txid) in desc_vec.iter().zip(txids) { let mut psbt = Psbt { unsigned_tx: Transaction { - version: 2, + version: transaction::Version::TWO, lock_time: absolute::LockTime::from_time(1_603_866_330) .expect("valid timestamp") .into(), // 10/28/2020 @ 6:25am (UTC) @@ -117,7 +119,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) { outputs: vec![], }; // figure out the outpoint from the txid - let (outpoint, witness_utxo) = get_vout(&cl, txid, btc(1.0).to_sat()); + let (outpoint, witness_utxo) = get_vout(&cl, txid, btc(1.0)); let mut txin = TxIn::default(); txin.previous_output = outpoint; // 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) { .get_new_address(None, Some(json::AddressType::Bech32)) .unwrap() .assume_checked(); - psbt.unsigned_tx - .output - .push(TxOut { value: 99_999_000, script_pubkey: addr.script_pubkey() }); + psbt.unsigned_tx.output.push(TxOut { + value: Amount::from_sat(99_999_000), + script_pubkey: addr.script_pubkey(), + }); let mut input = psbt::Input::default(); input.witness_utxo = Some(witness_utxo); input.witness_script = Some(desc.explicit_script().unwrap()); @@ -163,16 +166,16 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) { .map(|pk| sks[pks.iter().position(|&x| x == pk).unwrap()]) .collect(); // Get the required sighash message - let amt = btc(1).to_sat(); + 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 = sighash_cache - .segwit_signature_hash(0, &ms.encode(), amt, sighash_ty) + .p2wsh_signature_hash(0, &ms.encode(), amt, sighash_ty) .unwrap(); // requires both signing and verification because we check the tx // after we psbt extract it - let msg = secp256k1::Message::from_slice(&sighash[..]).unwrap(); + let msg = secp256k1::Message::from_digest(sighash.to_byte_array()); // Finally construct the signature and add to psbt for sk in sks_reqd { diff --git a/bitcoind-tests/tests/test_desc.rs b/bitcoind-tests/tests/test_desc.rs index bbb2b1bf2..92b9ea89c 100644 --- a/bitcoind-tests/tests/test_desc.rs +++ b/bitcoind-tests/tests/test_desc.rs @@ -14,7 +14,8 @@ use bitcoin::psbt::Psbt; use bitcoin::sighash::SighashCache; use bitcoin::taproot::{LeafVersion, TapLeafHash}; use bitcoin::{ - absolute, psbt, secp256k1, sighash, Amount, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid, + absolute, psbt, secp256k1, sighash, transaction, Amount, OutPoint, Sequence, Transaction, TxIn, + TxOut, Txid, }; use bitcoind::bitcoincore_rpc::{json, Client, RpcApi}; use miniscript::bitcoin::{self, ecdsa, taproot, ScriptBuf}; @@ -28,7 +29,7 @@ use setup::test_util::{self, TestData}; fn btc>(btc: F) -> Amount { Amount::from_btc(btc.into()).unwrap() } // Find the Outpoint by spk -fn get_vout(cl: &Client, txid: Txid, value: u64, spk: ScriptBuf) -> (OutPoint, TxOut) { +fn get_vout(cl: &Client, txid: Txid, value: Amount, spk: ScriptBuf) -> (OutPoint, TxOut) { let tx = cl .get_transaction(&txid, None) .unwrap() @@ -102,7 +103,7 @@ pub fn test_desc_satisfy( // Spend one input and spend one output for simplicity. let mut psbt = Psbt { unsigned_tx: Transaction { - version: 2, + version: transaction::Version::TWO, lock_time: absolute::LockTime::from_time(1_603_866_330) .expect("valid timestamp") .into(), // 10/28/2020 @ 6:25am (UTC) @@ -117,8 +118,7 @@ pub fn test_desc_satisfy( outputs: vec![], }; // figure out the outpoint from the txid - let (outpoint, witness_utxo) = - get_vout(&cl, txid, btc(1.0).to_sat(), derived_desc.script_pubkey()); + let (outpoint, witness_utxo) = get_vout(&cl, txid, btc(1.0), derived_desc.script_pubkey()); let mut txin = TxIn::default(); txin.previous_output = outpoint; // set the sequence to a non-final number for the locktime transactions to be @@ -137,7 +137,7 @@ pub fn test_desc_satisfy( // (Was getting insufficient fees error, for deep script trees) psbt.unsigned_tx .output - .push(TxOut { value: 99_997_000, script_pubkey: addr.script_pubkey() }); + .push(TxOut { value: Amount::from_sat(99_997_000), script_pubkey: addr.script_pubkey() }); let mut input = psbt::Input::default(); input .update_with_descriptor_unchecked(&definite_desc) @@ -172,7 +172,7 @@ pub fn test_desc_satisfy( let sighash_msg = sighash_cache .taproot_key_spend_signature_hash(0, &prevouts, hash_ty) .unwrap(); - let msg = secp256k1::Message::from_slice(&sighash_msg[..]).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 = @@ -183,7 +183,7 @@ pub fn test_desc_satisfy( // No internal key } // ------------------ script spend ------------- - let x_only_keypairs_reqd: Vec<(secp256k1::KeyPair, TapLeafHash)> = tr + let x_only_keypairs_reqd: Vec<(secp256k1::Keypair, TapLeafHash)> = tr .iter_scripts() .flat_map(|(_depth, ms)| { let leaf_hash = TapLeafHash::from_script(&ms.encode(), LeafVersion::TapScript); @@ -197,7 +197,7 @@ pub fn test_desc_satisfy( let sighash_msg = sighash_cache .taproot_script_spend_signature_hash(0, &prevouts, leaf_hash, hash_ty) .unwrap(); - let msg = secp256k1::Message::from_slice(&sighash_msg[..]).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); diff --git a/examples/psbt_sign_finalize.rs b/examples/psbt_sign_finalize.rs index 08abd5abe..c6974c50a 100644 --- a/examples/psbt_sign_finalize.rs +++ b/examples/psbt_sign_finalize.rs @@ -8,8 +8,8 @@ use miniscript::bitcoin::hashes::hex::FromHex; use miniscript::bitcoin::psbt::{self, Psbt}; use miniscript::bitcoin::sighash::SighashCache; use miniscript::bitcoin::{ - self, base64, secp256k1, Address, Network, OutPoint, PrivateKey, Script, Sequence, Transaction, - TxIn, TxOut, + self, secp256k1, transaction, Address, Amount, Network, OutPoint, PrivateKey, Script, Sequence, + Transaction, TxIn, TxOut, }; use miniscript::psbt::{PsbtExt, PsbtInputExt}; use miniscript::Descriptor; @@ -52,7 +52,7 @@ fn main() { println!("Backup3 public key: {}", _backup3_private.public_key(&secp256k1)); let spend_tx = Transaction { - version: 2, + version: transaction::Version::TWO, lock_time: bitcoin::absolute::LockTime::from_consensus(5000), input: vec![], output: vec![], @@ -86,13 +86,15 @@ fn main() { txin.sequence = Sequence::from_height(26); //Sequence::MAX; // psbt.unsigned_tx.input.push(txin); - psbt.unsigned_tx - .output - .push(TxOut { script_pubkey: receiver.script_pubkey(), value: amount / 5 - 500 }); + psbt.unsigned_tx.output.push(TxOut { + script_pubkey: receiver.script_pubkey(), + value: Amount::from_sat(amount / 5 - 500), + }); - psbt.unsigned_tx - .output - .push(TxOut { script_pubkey: bridge_descriptor.script_pubkey(), value: amount * 4 / 5 }); + psbt.unsigned_tx.output.push(TxOut { + script_pubkey: bridge_descriptor.script_pubkey(), + value: Amount::from_sat(amount * 4 / 5), + }); // Generating signatures & witness data @@ -133,14 +135,12 @@ fn main() { .insert(pk1, bitcoin::ecdsa::Signature { sig: sig1, hash_ty: hash_ty }); println!("{:#?}", psbt); - - let serialized = psbt.serialize(); - println!("{}", base64::encode(&serialized)); + println!("{}", psbt); psbt.finalize_mut(&secp256k1).unwrap(); println!("{:#?}", psbt); - let tx = psbt.extract_tx(); + let tx = psbt.extract_tx().expect("failed to extract tx"); println!("{}", bitcoin::consensus::encode::serialize_hex(&tx)); } diff --git a/examples/sign_multisig.rs b/examples/sign_multisig.rs index 1e913f609..2c49828c0 100644 --- a/examples/sign_multisig.rs +++ b/examples/sign_multisig.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use std::str::FromStr; use bitcoin::blockdata::witness::Witness; -use bitcoin::{absolute, ecdsa, secp256k1, Sequence}; +use bitcoin::{absolute, ecdsa, secp256k1, transaction, Amount, Sequence}; fn main() { let mut tx = spending_transaction(); @@ -78,7 +78,7 @@ fn main() { // Transaction which spends some output. fn spending_transaction() -> bitcoin::Transaction { bitcoin::Transaction { - version: 2, + version: transaction::Version::TWO, lock_time: absolute::LockTime::ZERO, input: vec![bitcoin::TxIn { previous_output: Default::default(), @@ -88,7 +88,7 @@ fn spending_transaction() -> bitcoin::Transaction { }], output: vec![bitcoin::TxOut { script_pubkey: bitcoin::ScriptBuf::new(), - value: 100_000_000, + value: Amount::from_sat(100_000_000), }], } } diff --git a/examples/taproot.rs b/examples/taproot.rs index 3482d3ddb..cb01539ac 100644 --- a/examples/taproot.rs +++ b/examples/taproot.rs @@ -3,10 +3,9 @@ use std::collections::HashMap; use std::str::FromStr; -use miniscript::bitcoin::address::WitnessVersion; -use miniscript::bitcoin::key::{KeyPair, XOnlyPublicKey}; +use miniscript::bitcoin::key::{Keypair, XOnlyPublicKey}; use miniscript::bitcoin::secp256k1::rand; -use miniscript::bitcoin::Network; +use miniscript::bitcoin::{Network, WitnessVersion}; use miniscript::descriptor::DescriptorType; use miniscript::policy::Concrete; use miniscript::{translate_hash_fail, Descriptor, Miniscript, Tap, TranslatePk, Translator}; @@ -83,7 +82,7 @@ fn main() { // We require secp for generating a random XOnlyPublicKey let secp = secp256k1::Secp256k1::new(); - let key_pair = KeyPair::new(&secp, &mut rand::thread_rng()); + let key_pair = Keypair::new(&secp, &mut rand::thread_rng()); // Random unspendable XOnlyPublicKey provided for compilation to Taproot Descriptor let (unspendable_pubkey, _parity) = XOnlyPublicKey::from_keypair(&key_pair); diff --git a/examples/verify_tx.rs b/examples/verify_tx.rs index bcac4fd3e..9a41fb309 100644 --- a/examples/verify_tx.rs +++ b/examples/verify_tx.rs @@ -85,7 +85,7 @@ fn main() { // Same, but with the wrong signature hash, to demonstrate what happens // given an apparently invalid script. let secp = Secp256k1::new(); - let message = secp256k1::Message::from_slice(&[0x01; 32][..]).expect("32-byte hash"); + let message = secp256k1::Message::from_digest([0x01; 32]); let iter = interpreter.iter_custom(Box::new(|key_sig: &KeySigPair| { let (pk, ecdsa_sig) = key_sig.as_ecdsa().expect("Ecdsa Sig"); diff --git a/src/descriptor/key.rs b/src/descriptor/key.rs index f18875cb5..b6461a21e 100644 --- a/src/descriptor/key.rs +++ b/src/descriptor/key.rs @@ -6,8 +6,7 @@ use core::str::FromStr; #[cfg(feature = "std")] use std::error; -use bitcoin::bip32; -use bitcoin::hash_types::XpubIdentifier; +use bitcoin::bip32::{self, XKeyIdentifier}; use bitcoin::hashes::hex::FromHex; use bitcoin::hashes::{hash160, ripemd160, sha256, Hash, HashEngine}; use bitcoin::key::XOnlyPublicKey; @@ -24,9 +23,9 @@ pub enum DescriptorPublicKey { /// Single public key. Single(SinglePub), /// Extended public key (xpub). - XPub(DescriptorXKey), + XPub(DescriptorXKey), /// Multiple extended public keys. - MultiXPub(DescriptorMultiXKey), + MultiXPub(DescriptorMultiXKey), } /// The descriptor secret key, either a single private key or an xprv. @@ -35,9 +34,9 @@ pub enum DescriptorSecretKey { /// Single private key. Single(SinglePriv), /// Extended private key (xpriv). - XPrv(DescriptorXKey), + XPrv(DescriptorXKey), /// Multiple extended private keys. - MultiXPrv(DescriptorMultiXKey), + MultiXPrv(DescriptorMultiXKey), } /// A descriptor [`SinglePubKey`] with optional origin information. @@ -153,18 +152,18 @@ impl fmt::Display for DescriptorSecretKey { } /// Trait for "extended key" types like `xpub` and `xprv`. Used internally to generalize parsing and -/// handling of `bip32::ExtendedPubKey` and `bip32::ExtendedPrivKey`. +/// handling of `bip32::Xpub` and `bip32::Xpriv`. pub trait InnerXKey: fmt::Display + FromStr { /// Returns the fingerprint of the key fn xkey_fingerprint(&self, secp: &Secp256k1) -> bip32::Fingerprint; /// Returns whether hardened steps can be derived on the key /// - /// `true` for `bip32::ExtendedPrivKey` and `false` for `bip32::ExtendedPubKey`. + /// `true` for `bip32::Xpriv` and `false` for `bip32::Xpub`. fn can_derive_hardened() -> bool; } -impl InnerXKey for bip32::ExtendedPubKey { +impl InnerXKey for bip32::Xpub { fn xkey_fingerprint(&self, _secp: &Secp256k1) -> bip32::Fingerprint { self.fingerprint() } @@ -172,7 +171,7 @@ impl InnerXKey for bip32::ExtendedPubKey { fn can_derive_hardened() -> bool { false } } -impl InnerXKey for bip32::ExtendedPrivKey { +impl InnerXKey for bip32::Xpriv { fn xkey_fingerprint(&self, secp: &Secp256k1) -> bip32::Fingerprint { self.fingerprint(secp) } @@ -200,7 +199,7 @@ impl SinglePriv { } } -impl DescriptorXKey { +impl DescriptorXKey { /// Returns the public version of this key, applying all the hardened derivation steps on the /// private key before turning it into a public key. /// @@ -210,7 +209,7 @@ impl DescriptorXKey { fn to_public( &self, secp: &Secp256k1, - ) -> Result, DescriptorKeyParseError> { + ) -> Result, DescriptorKeyParseError> { let unhardened = self .derivation_path .into_iter() @@ -226,7 +225,7 @@ impl DescriptorXKey { .xkey .derive_priv(secp, &hardened_path) .map_err(|_| DescriptorKeyParseError("Unable to derive the hardened steps"))?; - let xpub = bip32::ExtendedPubKey::from_priv(secp, &xprv); + let xpub = bip32::Xpub::from_priv(secp, &xprv); let origin = match &self.origin { Some((fingerprint, path)) => Some(( @@ -426,8 +425,7 @@ impl FromStr for DescriptorPublicKey { let (key_part, origin) = parse_key_origin(s)?; if key_part.contains("pub") { - let (xpub, derivation_paths, wildcard) = - parse_xkey_deriv::(key_part)?; + let (xpub, derivation_paths, wildcard) = parse_xkey_deriv::(key_part)?; if derivation_paths.len() > 1 { Ok(DescriptorPublicKey::MultiXPub(DescriptorMultiXKey { origin, @@ -527,7 +525,7 @@ impl DescriptorPublicKey { if let Some((fingerprint, _)) = single.origin { fingerprint } else { - let mut engine = XpubIdentifier::engine(); + let mut engine = XKeyIdentifier::engine(); match single.key { SinglePubKey::FullKey(pk) => { pk.write_into(&mut engine).expect("engines don't error") @@ -535,7 +533,7 @@ impl DescriptorPublicKey { SinglePubKey::XOnly(x_only_pk) => engine.input(&x_only_pk.serialize()), }; bip32::Fingerprint::from( - &XpubIdentifier::from_engine(engine)[..4] + &XKeyIdentifier::from_engine(engine)[..4] .try_into() .expect("4 byte slice"), ) @@ -707,8 +705,7 @@ impl FromStr for DescriptorSecretKey { .map_err(|_| DescriptorKeyParseError("Error while parsing a WIF private key"))?; Ok(DescriptorSecretKey::Single(SinglePriv { key: sk, origin: None })) } else { - let (xpriv, derivation_paths, wildcard) = - parse_xkey_deriv::(key_part)?; + let (xpriv, derivation_paths, wildcard) = parse_xkey_deriv::(key_part)?; if derivation_paths.len() > 1 { Ok(DescriptorSecretKey::MultiXPrv(DescriptorMultiXKey { origin, @@ -1300,10 +1297,7 @@ mod test { ); } - fn get_multipath_xpub( - key_str: &str, - num_paths: usize, - ) -> DescriptorMultiXKey { + fn get_multipath_xpub(key_str: &str, num_paths: usize) -> DescriptorMultiXKey { let desc_key = DescriptorPublicKey::from_str(key_str).unwrap(); assert_eq!(desc_key.num_der_paths(), num_paths); match desc_key { @@ -1312,7 +1306,7 @@ mod test { } } - fn get_multipath_xprv(key_str: &str) -> DescriptorMultiXKey { + fn get_multipath_xprv(key_str: &str) -> DescriptorMultiXKey { let desc_key = DescriptorSecretKey::from_str(key_str).unwrap(); match desc_key { DescriptorSecretKey::MultiXPrv(xprv) => xprv, diff --git a/src/descriptor/mod.rs b/src/descriptor/mod.rs index 5ceb512e4..a81a2786e 100644 --- a/src/descriptor/mod.rs +++ b/src/descriptor/mod.rs @@ -15,9 +15,8 @@ use core::fmt; use core::ops::Range; use core::str::{self, FromStr}; -use bitcoin::address::WitnessVersion; use bitcoin::hashes::{hash160, ripemd160, sha256}; -use bitcoin::{secp256k1, Address, Network, Script, ScriptBuf, TxIn, Witness}; +use bitcoin::{secp256k1, Address, Network, Script, ScriptBuf, TxIn, Witness, WitnessVersion}; use sync::Arc; use self::checksum::verify_checksum; @@ -1251,7 +1250,7 @@ mod tests { let sk = secp256k1::SecretKey::from_slice(&b"sally was a secret key, she said"[..]).unwrap(); let pk = bitcoin::PublicKey::new(secp256k1::PublicKey::from_secret_key(&secp, &sk)); - let msg = secp256k1::Message::from_slice(&b"michael was a message, amusingly"[..]) + let msg = secp256k1::Message::from_digest_slice(&b"michael was a message, amusingly"[..]) .expect("32 bytes"); let sig = secp.sign_ecdsa(&msg, &sk); let mut sigser = sig.serialize_der().to_vec(); @@ -1399,9 +1398,7 @@ mod tests { bitcoin::TxIn { previous_output: bitcoin::OutPoint::default(), script_sig: script::Builder::new() - .push_slice( - <&PushBytes>::try_from(ms.encode().to_v0_p2wsh().as_bytes()).unwrap() - ) + .push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().as_bytes()).unwrap()) .into_script(), sequence: Sequence::from_height(100), witness: Witness::from_slice(&vec![sigser.clone(), ms.encode().into_bytes(),]), @@ -1410,7 +1407,7 @@ mod tests { assert_eq!( shwsh.unsigned_script_sig(), script::Builder::new() - .push_slice(<&PushBytes>::try_from(ms.encode().to_v0_p2wsh().as_bytes()).unwrap()) + .push_slice(<&PushBytes>::try_from(ms.encode().to_p2wsh().as_bytes()).unwrap()) .into_script() ); } @@ -1626,7 +1623,7 @@ mod tests { ][..]) .into(), )), - xkey: bip32::ExtendedPubKey::from_str("xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL").unwrap(), + xkey: bip32::Xpub::from_str("xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL").unwrap(), derivation_path: (&[bip32::ChildNumber::from_normal_idx(1).unwrap()][..]).into(), wildcard: Wildcard::Unhardened, }); @@ -1637,7 +1634,7 @@ mod tests { let key = "xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL/1"; let expected = DescriptorPublicKey::XPub(DescriptorXKey { origin: None, - xkey: bip32::ExtendedPubKey::from_str("xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL").unwrap(), + xkey: bip32::Xpub::from_str("xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL").unwrap(), derivation_path: (&[bip32::ChildNumber::from_normal_idx(1).unwrap()][..]).into(), wildcard: Wildcard::None, }); @@ -1648,7 +1645,7 @@ mod tests { let key = "tpubD6NzVbkrYhZ4YqYr3amYH15zjxHvBkUUeadieW8AxTZC7aY2L8aPSk3tpW6yW1QnWzXAB7zoiaNMfwXPPz9S68ZCV4yWvkVXjdeksLskCed/1"; let expected = DescriptorPublicKey::XPub(DescriptorXKey { origin: None, - xkey: bip32::ExtendedPubKey::from_str("tpubD6NzVbkrYhZ4YqYr3amYH15zjxHvBkUUeadieW8AxTZC7aY2L8aPSk3tpW6yW1QnWzXAB7zoiaNMfwXPPz9S68ZCV4yWvkVXjdeksLskCed").unwrap(), + xkey: bip32::Xpub::from_str("tpubD6NzVbkrYhZ4YqYr3amYH15zjxHvBkUUeadieW8AxTZC7aY2L8aPSk3tpW6yW1QnWzXAB7zoiaNMfwXPPz9S68ZCV4yWvkVXjdeksLskCed").unwrap(), derivation_path: (&[bip32::ChildNumber::from_normal_idx(1).unwrap()][..]).into(), wildcard: Wildcard::None, }); @@ -1659,7 +1656,7 @@ mod tests { let key = "xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL"; let expected = DescriptorPublicKey::XPub(DescriptorXKey { origin: None, - xkey: bip32::ExtendedPubKey::from_str("xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL").unwrap(), + xkey: bip32::Xpub::from_str("xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL").unwrap(), derivation_path: bip32::DerivationPath::from(&[][..]), wildcard: Wildcard::None, }); diff --git a/src/descriptor/segwitv0.rs b/src/descriptor/segwitv0.rs index 241c19dc0..6b9cd8a2c 100644 --- a/src/descriptor/segwitv0.rs +++ b/src/descriptor/segwitv0.rs @@ -125,7 +125,7 @@ impl Wsh { impl Wsh { /// Obtains the corresponding script pubkey for this descriptor. - pub fn script_pubkey(&self) -> ScriptBuf { self.inner_script().to_v0_p2wsh() } + pub fn script_pubkey(&self) -> ScriptBuf { self.inner_script().to_p2wsh() } /// Obtains the corresponding script pubkey for this descriptor. pub fn address(&self, network: Network) -> Address { diff --git a/src/descriptor/sh.rs b/src/descriptor/sh.rs index b4fffd893..dfede59da 100644 --- a/src/descriptor/sh.rs +++ b/src/descriptor/sh.rs @@ -322,7 +322,7 @@ impl Sh { match self.inner { ShInner::Wsh(ref wsh) => { // wsh explicit must contain exactly 1 element - let witness_script = wsh.inner_script().to_v0_p2wsh(); + let witness_script = wsh.inner_script().to_p2wsh(); let push_bytes = <&PushBytes>::try_from(witness_script.as_bytes()) .expect("Witness script is not too large"); script::Builder::new().push_slice(push_bytes).into_script() diff --git a/src/interpreter/error.rs b/src/interpreter/error.rs index bc40f020a..730a2b303 100644 --- a/src/interpreter/error.rs +++ b/src/interpreter/error.rs @@ -89,7 +89,7 @@ pub enum Error { /// Miniscript requires the entire top level script to be satisfied. ScriptSatisfactionError, /// Schnorr Signature error - SchnorrSig(bitcoin::taproot::Error), + SchnorrSig(bitcoin::taproot::SigFromSliceError), /// Errors in signature hash calculations SighashError(bitcoin::sighash::Error), /// Taproot Annex Unsupported @@ -244,8 +244,8 @@ impl From for Error { } #[doc(hidden)] -impl From for Error { - fn from(e: bitcoin::taproot::Error) -> Error { Error::SchnorrSig(e) } +impl From for Error { + fn from(e: bitcoin::taproot::SigFromSliceError) -> Error { Error::SchnorrSig(e) } } #[doc(hidden)] diff --git a/src/interpreter/inner.rs b/src/interpreter/inner.rs index 88cf4ad4a..bae422b97 100644 --- a/src/interpreter/inner.rs +++ b/src/interpreter/inner.rs @@ -149,7 +149,7 @@ pub(super) fn from_txdata<'txin>( } } // ** pay to witness pubkeyhash ** - } else if spk.is_v0_p2wpkh() { + } else if spk.is_p2wpkh() { if !ssig_stack.is_empty() { Err(Error::NonEmptyScriptSig) } else { @@ -157,7 +157,7 @@ pub(super) fn from_txdata<'txin>( Some(elem) => { let pk = pk_from_stack_elem(&elem, true)?; let hash160 = pk.to_pubkeyhash(SigType::Ecdsa); - if *spk == bitcoin::ScriptBuf::new_v0_p2wpkh(&hash160.into()) { + if *spk == bitcoin::ScriptBuf::new_p2wpkh(&hash160.into()) { Ok(( Inner::PublicKey(pk.into(), PubkeyType::Wpkh), wit_stack, @@ -171,7 +171,7 @@ pub(super) fn from_txdata<'txin>( } } // ** pay to witness scripthash ** - } else if spk.is_v0_p2wsh() { + } else if spk.is_p2wsh() { if !ssig_stack.is_empty() { Err(Error::NonEmptyScriptSig) } else { @@ -181,7 +181,7 @@ pub(super) fn from_txdata<'txin>( let script = miniscript.encode(); let miniscript = miniscript.to_no_checks_ms(); let scripthash = sha256::Hash::hash(script.as_bytes()); - if *spk == bitcoin::ScriptBuf::new_v0_p2wsh(&scripthash.into()) { + if *spk == bitcoin::ScriptBuf::new_p2wsh(&scripthash.into()) { Ok((Inner::Script(miniscript, ScriptType::Wsh), wit_stack, Some(script))) } else { Err(Error::IncorrectWScriptHash) @@ -191,7 +191,7 @@ pub(super) fn from_txdata<'txin>( } } // ** pay to taproot **// - } else if spk.is_v1_p2tr() { + } else if spk.is_p2tr() { if !ssig_stack.is_empty() { Err(Error::NonEmptyScriptSig) } else { @@ -265,7 +265,7 @@ pub(super) fn from_txdata<'txin>( let pk = pk_from_stack_elem(&elem, true)?; let hash160 = pk.to_pubkeyhash(SigType::Ecdsa); if slice - == bitcoin::ScriptBuf::new_v0_p2wpkh(&hash160.into()) + == bitcoin::ScriptBuf::new_p2wpkh(&hash160.into()) .as_bytes() { Ok(( @@ -293,7 +293,7 @@ pub(super) fn from_txdata<'txin>( let miniscript = miniscript.to_no_checks_ms(); let scripthash = sha256::Hash::hash(script.as_bytes()); if slice - == bitcoin::ScriptBuf::new_v0_p2wsh(&scripthash.into()) + == bitcoin::ScriptBuf::new_p2wsh(&scripthash.into()) .as_bytes() { Ok(( @@ -435,7 +435,7 @@ mod tests { let pkhash = key.to_pubkeyhash(SigType::Ecdsa).into(); let wpkhash = key.to_pubkeyhash(SigType::Ecdsa).into(); - let wpkh_spk = bitcoin::ScriptBuf::new_v0_p2wpkh(&wpkhash); + let wpkh_spk = bitcoin::ScriptBuf::new_p2wpkh(&wpkhash); let wpkh_scripthash = hash160::Hash::hash(wpkh_spk.as_bytes()).into(); KeyTestData { @@ -755,7 +755,7 @@ mod tests { let wit_hash = sha256::Hash::hash(witness_script.as_bytes()).into(); let wit_stack = Witness::from_slice(&vec![witness_script.to_bytes()]); - let spk = ScriptBuf::new_v0_p2wsh(&wit_hash); + let spk = ScriptBuf::new_p2wsh(&wit_hash); let blank_script = bitcoin::ScriptBuf::new(); // wsh without witness @@ -790,7 +790,7 @@ mod tests { let wit_hash = sha256::Hash::hash(witness_script.as_bytes()).into(); let wit_stack = Witness::from_slice(&vec![witness_script.to_bytes()]); - let redeem_script = ScriptBuf::new_v0_p2wsh(&wit_hash); + let redeem_script = ScriptBuf::new_p2wsh(&wit_hash); let script_sig = script::Builder::new() .push_slice(<&PushBytes>::try_from(redeem_script.as_bytes()).unwrap()) .into_script(); diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 906989a04..446c7931b 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -181,6 +181,8 @@ impl<'txin> Interpreter<'txin> { /// - Insufficient sighash information is present /// - sighash single without corresponding output // TODO: Create a good first isse to change this to error + // TODO: Requires refactor to remove the script_code logic in order to use the new sighash API. + #[allow(deprecated)] // For segwit_signature_hash pub fn verify_sig>( &self, secp: &secp256k1::Secp256k1, @@ -212,9 +214,7 @@ impl<'txin> Interpreter<'txin> { let sighash_u32 = ecdsa_sig.hash_ty.to_u32(); let sighash = cache.legacy_signature_hash(input_idx, script_pubkey, sighash_u32); - sighash.map(|hash| { - secp256k1::Message::from_slice(hash.as_byte_array()).expect("32 byte") - }) + sighash.map(|hash| secp256k1::Message::from_digest(hash.to_byte_array())) } else if self.is_segwit_v0() { let amt = match get_prevout(prevouts, input_idx) { Some(txout) => txout.borrow().value, @@ -226,9 +226,7 @@ impl<'txin> Interpreter<'txin> { amt, ecdsa_sig.hash_ty, ); - sighash.map(|hash| { - secp256k1::Message::from_slice(hash.as_byte_array()).expect("32 byte") - }) + sighash.map(|hash| secp256k1::Message::from_digest(hash.to_byte_array())) } else { // taproot(or future) signatures in segwitv0 context return false; @@ -260,9 +258,8 @@ impl<'txin> Interpreter<'txin> { // schnorr sigs in ecdsa descriptors return false; }; - let msg = sighash_msg.map(|hash| { - secp256k1::Message::from_slice(hash.as_byte_array()).expect("32 byte") - }); + let msg = + sighash_msg.map(|hash| secp256k1::Message::from_digest(hash.to_byte_array())); let success = msg.map(|msg| secp.verify_schnorr(&schnorr_sig.sig, &msg, xpk).is_ok()); success.unwrap_or(false) // unwrap_or_default checks for errors, while success would have checksig results @@ -356,7 +353,7 @@ impl<'txin> Interpreter<'txin> { } } - /// Whether this is a segwit spend + /// Whether this is a segwit v0 spend (wrapped or native) pub fn is_segwit_v0(&self) -> bool { match self.inner { inner::Inner::PublicKey(_, inner::PubkeyType::Pk) => false, @@ -1049,8 +1046,7 @@ mod tests { Vec>, ) { let secp = secp256k1::Secp256k1::new(); - let msg = secp256k1::Message::from_slice(&b"Yoda: btc, I trust. HODL I must!"[..]) - .expect("32 bytes"); + let msg = secp256k1::Message::from_digest(*b"Yoda: btc, I trust. HODL I must!"); let mut pks = vec![]; let mut ecdsa_sigs = vec![]; let mut der_sigs = vec![]; @@ -1079,7 +1075,7 @@ mod tests { pks.push(pk); der_sigs.push(sigser); - let keypair = bitcoin::key::KeyPair::from_secret_key(&secp, &sk); + let keypair = bitcoin::key::Keypair::from_secret_key(&secp, &sk); let (x_only_pk, _parity) = bitcoin::key::XOnlyPublicKey::from_keypair(&keypair); x_only_pks.push(x_only_pk); let schnorr_sig = secp.sign_schnorr_with_aux_rand(&msg, &keypair, &[0u8; 32]); diff --git a/src/lib.rs b/src/lib.rs index 83119a764..f62406902 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -136,9 +136,9 @@ use core::{cmp, fmt, hash, str}; #[cfg(feature = "std")] use std::error; -use bitcoin::blockdata::{opcodes, script}; use bitcoin::hashes::{hash160, ripemd160, sha256, Hash}; use bitcoin::locktime::absolute; +use bitcoin::{script, Opcode}; pub use crate::descriptor::{DefiniteDescriptorKey, Descriptor, DescriptorPublicKey}; pub use crate::interpreter::Interpreter; @@ -415,7 +415,7 @@ pub trait ForEachKey { #[derive(Debug, PartialEq)] pub enum Error { /// Opcode appeared which is not part of the script subset - InvalidOpcode(opcodes::All), + InvalidOpcode(Opcode), /// Some opcode occurred followed by `OP_VERIFY` when it had /// a `VERIFY` version that should have been used instead NonMinimalVerify(String), @@ -427,8 +427,8 @@ pub enum Error { AddrError(bitcoin::address::Error), /// A `CHECKMULTISIG` opcode was preceded by a number > 20 CmsTooManyKeys(u32), - /// A tapscript multi_a cannot support more than MAX_BLOCK_WEIGHT/32 keys - MultiATooManyKeys(u32), + /// A tapscript multi_a cannot support more than Weight::MAX_BLOCK/32 keys + MultiATooManyKeys(u64), /// Encountered unprintable character in descriptor Unprintable(u8), /// expected character while parsing descriptor; didn't find one diff --git a/src/miniscript/context.rs b/src/miniscript/context.rs index 342760e6c..44da0bc6a 100644 --- a/src/miniscript/context.rs +++ b/src/miniscript/context.rs @@ -5,8 +5,8 @@ use core::{fmt, hash}; #[cfg(feature = "std")] use std::error; -use bitcoin::constants::MAX_BLOCK_WEIGHT; use bitcoin::hashes::{hash160, ripemd160, sha256}; +use bitcoin::Weight; use super::decode::ParseableKey; use crate::miniscript::limits::{ @@ -614,7 +614,7 @@ impl ScriptContext for Tap { // When the transaction sizes get close to block limits, // some guarantees are not easy to satisfy because of knapsack // constraints - if ms.ext.pk_cost > MAX_BLOCK_WEIGHT as usize { + if ms.ext.pk_cost as u64 > Weight::MAX_BLOCK.to_wu() { return Err(ScriptContextError::MaxWitnessScriptSizeExceeded); } diff --git a/src/miniscript/decode.rs b/src/miniscript/decode.rs index fa8b98ab7..409563b04 100644 --- a/src/miniscript/decode.rs +++ b/src/miniscript/decode.rs @@ -10,9 +10,8 @@ use core::marker::PhantomData; #[cfg(feature = "std")] use std::error; -use bitcoin::constants::MAX_BLOCK_WEIGHT; use bitcoin::hashes::{hash160, ripemd160, sha256, Hash}; -use bitcoin::Sequence; +use bitcoin::{Sequence, Weight}; use sync::Arc; use crate::miniscript::lex::{Token as Tk, TokenIter}; @@ -23,7 +22,7 @@ use crate::miniscript::ScriptContext; use crate::prelude::*; #[cfg(doc)] use crate::Descriptor; -use crate::{bitcoin, hash256, AbsLockTime, Error, Miniscript, MiniscriptKey, ToPublicKey}; +use crate::{hash256, AbsLockTime, Error, Miniscript, MiniscriptKey, ToPublicKey}; /// Trait for parsing keys from byte slices pub trait ParseableKey: Sized + ToPublicKey + private::Sealed { @@ -45,7 +44,7 @@ impl ParseableKey for bitcoin::secp256k1::XOnlyPublicKey { } /// Decoding error while parsing keys -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum KeyParseError { /// Bitcoin PublicKey parse error FullKeyParseError(bitcoin::key::Error), @@ -78,8 +77,8 @@ mod private { pub trait Sealed {} // Implement for those same types, but no others. - impl Sealed for super::bitcoin::PublicKey {} - impl Sealed for super::bitcoin::secp256k1::XOnlyPublicKey {} + impl Sealed for bitcoin::PublicKey {} + impl Sealed for bitcoin::secp256k1::XOnlyPublicKey {} } #[derive(Copy, Clone, Debug)] @@ -462,9 +461,10 @@ pub fn parse( }, // MultiA Tk::NumEqual, Tk::Num(k) => { + let max = Weight::MAX_BLOCK.to_wu() / 32; // Check size before allocating keys - if k > MAX_BLOCK_WEIGHT/32 { - return Err(Error::MultiATooManyKeys(MAX_BLOCK_WEIGHT/32)) + if k as u64 > max { + return Err(Error::MultiATooManyKeys(max)) } let mut keys = Vec::with_capacity(k as usize); // atleast k capacity while tokens.peek() == Some(&Tk::CheckSigAdd) { diff --git a/src/plan.rs b/src/plan.rs index 3383643ce..49b95c908 100644 --- a/src/plan.rs +++ b/src/plan.rs @@ -18,12 +18,11 @@ use core::cmp::Ordering; use core::iter::FromIterator; use bitcoin::absolute::LockTime; -use bitcoin::address::WitnessVersion; use bitcoin::hashes::{hash160, ripemd160, sha256}; use bitcoin::key::XOnlyPublicKey; use bitcoin::script::PushBytesBuf; use bitcoin::taproot::{ControlBlock, LeafVersion, TapLeafHash}; -use bitcoin::{bip32, psbt, ScriptBuf, Sequence}; +use bitcoin::{bip32, psbt, ScriptBuf, Sequence, WitnessVersion}; use crate::descriptor::{self, Descriptor, DescriptorType, KeyMap}; use crate::miniscript::hash256; @@ -413,7 +412,7 @@ impl Plan { Descriptor::Sh(sh) => match sh.as_inner() { descriptor::ShInner::Wsh(wsh) => { input.witness_script = Some(wsh.inner_script()); - input.redeem_script = Some(wsh.inner_script().to_v0_p2wsh()); + input.redeem_script = Some(wsh.inner_script().to_p2wsh()); } descriptor::ShInner::Wpkh(..) => input.redeem_script = Some(sh.inner_script()), descriptor::ShInner::SortedMulti(_) | descriptor::ShInner::Ms(_) => { @@ -737,7 +736,7 @@ mod test { use std::str::FromStr; use bitcoin::absolute::LockTime; - use bitcoin::bip32::ExtendedPubKey; + use bitcoin::bip32::Xpub; use bitcoin::Sequence; use super::*; @@ -1049,7 +1048,7 @@ mod test { #[test] fn test_plan_update_psbt_tr() { // keys taken from: https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki#Specifications - let root_xpub = ExtendedPubKey::from_str("xpub661MyMwAqRbcFkPHucMnrGNzDwb6teAX1RbKQmqtEF8kK3Z7LZ59qafCjB9eCRLiTVG3uxBxgKvRgbubRhqSKXnGGb1aoaqLrpMBDrVxga8").unwrap(); + let root_xpub = Xpub::from_str("xpub661MyMwAqRbcFkPHucMnrGNzDwb6teAX1RbKQmqtEF8kK3Z7LZ59qafCjB9eCRLiTVG3uxBxgKvRgbubRhqSKXnGGb1aoaqLrpMBDrVxga8").unwrap(); let fingerprint = root_xpub.fingerprint(); let xpub = format!("[{}/86'/0'/0']xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ", fingerprint); let desc = @@ -1097,7 +1096,7 @@ mod test { #[test] fn test_plan_update_psbt_segwit() { // keys taken from: https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki#Specifications - let root_xpub = ExtendedPubKey::from_str("xpub661MyMwAqRbcFkPHucMnrGNzDwb6teAX1RbKQmqtEF8kK3Z7LZ59qafCjB9eCRLiTVG3uxBxgKvRgbubRhqSKXnGGb1aoaqLrpMBDrVxga8").unwrap(); + let root_xpub = Xpub::from_str("xpub661MyMwAqRbcFkPHucMnrGNzDwb6teAX1RbKQmqtEF8kK3Z7LZ59qafCjB9eCRLiTVG3uxBxgKvRgbubRhqSKXnGGb1aoaqLrpMBDrVxga8").unwrap(); let fingerprint = root_xpub.fingerprint(); let xpub = format!("[{}/86'/0'/0']xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ", fingerprint); let desc = format!("wsh(multi(2,{}/1/0,{}/1/1))", xpub, xpub); diff --git a/src/policy/compiler.rs b/src/policy/compiler.rs index 66284f046..d00e8b4ad 100644 --- a/src/policy/compiler.rs +++ b/src/policy/compiler.rs @@ -1183,7 +1183,7 @@ mod tests { ret.push(pk); } let sig = secp.sign_ecdsa( - &secp256k1::Message::from_slice(&sk[..]).expect("secret key"), + &secp256k1::Message::from_digest(sk.clone()), // Not a digest but 32 bytes nonetheless. &secp256k1::SecretKey::from_slice(&sk[..]).expect("secret key"), ); (ret, sig) diff --git a/src/psbt/finalizer.rs b/src/psbt/finalizer.rs index a8457e167..3c304d72f 100644 --- a/src/psbt/finalizer.rs +++ b/src/psbt/finalizer.rs @@ -48,7 +48,7 @@ fn construct_tap_witness( map.insert(hash, bitcoin_key); } } - assert!(spk.is_v1_p2tr()); + assert!(spk.is_p2tr()); // try the key spend path first if let Some(sig) = @@ -179,7 +179,7 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result, In Some((pk, _sig)) => Descriptor::new_pkh(*pk).map_err(InputError::from), None => Err(InputError::MissingPubkey), } - } else if script_pubkey.is_v0_p2wpkh() { + } else if script_pubkey.is_p2wpkh() { // 3. `Wpkh`: creates a `wpkh` descriptor if the partial sig has corresponding pk. let partial_sig_contains_pk = inp.partial_sigs.iter().find(|&(&pk, _sig)| { // Indirect way to check the equivalence of pubkey-hashes. @@ -192,13 +192,13 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result, In Some((pk, _sig)) => Ok(Descriptor::new_wpkh(*pk)?), None => Err(InputError::MissingPubkey), } - } else if script_pubkey.is_v0_p2wsh() { + } else if script_pubkey.is_p2wsh() { // 4. `Wsh`: creates a `Wsh` descriptor if inp.redeem_script.is_some() { return Err(InputError::NonEmptyRedeemScript); } if let Some(ref witness_script) = inp.witness_script { - if witness_script.to_v0_p2wsh() != *script_pubkey { + if witness_script.to_p2wsh() != *script_pubkey { return Err(InputError::InvalidWitnessScript { witness_script: witness_script.clone(), p2wsh_expected: script_pubkey.clone(), @@ -222,10 +222,10 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result, In p2sh_expected: script_pubkey.clone(), }); } - if redeem_script.is_v0_p2wsh() { + if redeem_script.is_p2wsh() { // 5. `ShWsh` case if let Some(ref witness_script) = inp.witness_script { - if witness_script.to_v0_p2wsh() != *redeem_script { + if witness_script.to_p2wsh() != *redeem_script { return Err(InputError::InvalidWitnessScript { witness_script: witness_script.clone(), p2wsh_expected: redeem_script.clone(), @@ -239,7 +239,7 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result, In } else { Err(InputError::MissingWitnessScript) } - } else if redeem_script.is_v0_p2wpkh() { + } else if redeem_script.is_p2wpkh() { // 6. `ShWpkh` case let partial_sig_contains_pk = inp.partial_sigs.iter().find(|&(&pk, _sig)| { let addr = bitcoin::Address::p2wpkh(&pk, bitcoin::Network::Bitcoin) @@ -389,7 +389,7 @@ fn finalize_input_helper( let spk = get_scriptpubkey(psbt, index).map_err(|e| Error::InputError(e, index))?; let sat = PsbtInputSatisfier::new(psbt, index); - if spk.is_v1_p2tr() { + if spk.is_p2tr() { // Deal with tr case separately, unfortunately we cannot infer the full descriptor for Tr let wit = construct_tap_witness(&spk, &sat, allow_mall) .map_err(|e| Error::InputError(e, index))?; diff --git a/src/psbt/mod.rs b/src/psbt/mod.rs index a9eba63de..f2f45e575 100644 --- a/src/psbt/mod.rs +++ b/src/psbt/mod.rs @@ -17,7 +17,7 @@ use bitcoin::psbt::{self, Psbt}; use bitcoin::secp256k1::{self, Secp256k1, VerifyOnly}; use bitcoin::sighash::{self, SighashCache}; use bitcoin::taproot::{self, ControlBlock, LeafVersion, TapLeafHash}; -use bitcoin::{absolute, bip32, Script, ScriptBuf, Sequence}; +use bitcoin::{absolute, bip32, transaction, Script, ScriptBuf, Sequence}; use crate::miniscript::context::SigType; use crate::prelude::*; @@ -132,7 +132,7 @@ pub enum InputError { /// Non empty Redeem script NonEmptyRedeemScript, /// Non Standard sighash type - NonStandardSighashType(sighash::NonStandardSighashType), + NonStandardSighashType(sighash::NonStandardSighashTypeError), /// Sighash did not match WrongSighashFlag { /// required sighash type @@ -211,7 +211,9 @@ impl fmt::Display for InputError { pubkey, got, required ), InputError::CouldNotSatisfyTr => write!(f, "Could not satisfy Tr descriptor"), - InputError::NonStandardSighashType(e) => write!(f, "Non-standard sighash type {}", e), + InputError::NonStandardSighashType(ref e) => { + write!(f, "Non-standard sighash type {}", e) + } } } } @@ -329,7 +331,8 @@ impl<'psbt, Pk: MiniscriptKey + ToPublicKey> Satisfier for PsbtInputSatisfie return true; } - if self.psbt.unsigned_tx.version < 2 || !seq.is_relative_lock_time() { + if self.psbt.unsigned_tx.version < transaction::Version::TWO || !seq.is_relative_lock_time() + { return false; } @@ -828,7 +831,7 @@ impl PsbtExt for Psbt { let prevouts = bitcoin::sighash::Prevouts::All(&prevouts); let inp_spk = finalizer::get_scriptpubkey(self, idx).map_err(|_e| SighashError::MissingInputUtxo)?; - if inp_spk.is_v1_p2tr() { + if inp_spk.is_p2tr() { let hash_ty = inp .sighash_type .map(|sighash_type| sighash_type.taproot_hash_ty()) @@ -859,35 +862,29 @@ impl PsbtExt for Psbt { && inp .redeem_script .as_ref() - .map(|x| x.is_v0_p2wpkh()) + .map(|x| x.is_p2wpkh()) .unwrap_or(false); let is_nested_wsh = inp_spk.is_p2sh() && inp .redeem_script .as_ref() - .map(|x| x.is_v0_p2wsh()) + .map(|x| x.is_p2wsh()) .unwrap_or(false); - if inp_spk.is_v0_p2wpkh() || inp_spk.is_v0_p2wsh() || is_nested_wpkh || is_nested_wsh { - let msg = if inp_spk.is_v0_p2wpkh() { - let script_code = inp_spk - .p2wpkh_script_code() - .expect("checked is p2wpkh above"); - cache.segwit_signature_hash(idx, &script_code, amt, hash_ty)? + if inp_spk.is_p2wpkh() || inp_spk.is_p2wsh() || is_nested_wpkh || is_nested_wsh { + let msg = if inp_spk.is_p2wpkh() { + cache.p2wpkh_signature_hash(idx, &inp_spk, amt, hash_ty)? } else if is_nested_wpkh { let script_code = inp .redeem_script .as_ref() - .expect("redeem script non-empty checked earlier") - .p2wpkh_script_code() - .expect("checked is p2wpkh above"); - cache.segwit_signature_hash(idx, &script_code, amt, hash_ty)? + .expect("redeem script non-empty checked earlier"); + cache.p2wpkh_signature_hash(idx, &script_code, amt, hash_ty)? } else { - // wsh and nested wsh, script code is witness script - let script_code = inp + let witness_script = inp .witness_script .as_ref() .ok_or(SighashError::MissingWitnessScript)?; - cache.segwit_signature_hash(idx, script_code, amt, hash_ty)? + cache.p2wsh_signature_hash(idx, witness_script, amt, hash_ty)? }; Ok(PsbtSighashMsg::SegwitV0Sighash(msg)) } else { @@ -1197,7 +1194,7 @@ fn update_item_with_descriptor_helper( Descriptor::Sh(sh) => match sh.as_inner() { descriptor::ShInner::Wsh(wsh) => { *item.witness_script() = Some(wsh.inner_script()); - *item.redeem_script() = Some(wsh.inner_script().to_v0_p2wsh()); + *item.redeem_script() = Some(wsh.inner_script().to_p2wsh()); } descriptor::ShInner::Wpkh(..) => *item.redeem_script() = Some(sh.inner_script()), descriptor::ShInner::SortedMulti(_) | descriptor::ShInner::Ms(_) => { @@ -1306,7 +1303,7 @@ impl error::Error for OutputUpdateError { } /// Return error type for [`PsbtExt::sighash_msg`] -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum SighashError { /// Index out of bounds IndexOutOfBounds(usize, usize), @@ -1380,14 +1377,12 @@ impl PsbtSighashMsg { /// Convert the message to a [`secp256k1::Message`]. pub fn to_secp_msg(&self) -> secp256k1::Message { match *self { - PsbtSighashMsg::TapSighash(msg) => { - secp256k1::Message::from_slice(msg.as_ref()).expect("Sighashes are 32 bytes") - } + PsbtSighashMsg::TapSighash(msg) => secp256k1::Message::from_digest(msg.to_byte_array()), PsbtSighashMsg::LegacySighash(msg) => { - secp256k1::Message::from_slice(msg.as_ref()).expect("Sighashes are 32 bytes") + secp256k1::Message::from_digest(msg.to_byte_array()) } PsbtSighashMsg::SegwitV0Sighash(msg) => { - secp256k1::Message::from_slice(msg.as_ref()).expect("Sighashes are 32 bytes") + secp256k1::Message::from_digest(msg.to_byte_array()) } } } @@ -1397,19 +1392,19 @@ impl PsbtSighashMsg { mod tests { use std::str::FromStr; - use bitcoin::bip32::{DerivationPath, ExtendedPubKey}; + use bitcoin::bip32::{DerivationPath, Xpub}; use bitcoin::consensus::encode::deserialize; use bitcoin::hashes::hex::FromHex; use bitcoin::key::XOnlyPublicKey; use bitcoin::secp256k1::PublicKey; - use bitcoin::{absolute, OutPoint, TxIn, TxOut}; + use bitcoin::{absolute, Amount, OutPoint, TxIn, TxOut}; use super::*; use crate::Miniscript; #[test] fn test_extract_bip174() { - let psbt = bitcoin::psbt::PartiallySignedTransaction::deserialize(&Vec::::from_hex("70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000107da00473044022074018ad4180097b873323c0015720b3684cc8123891048e7dbcd9b55ad679c99022073d369b740e3eb53dcefa33823c8070514ca55a7dd9544f157c167913261118c01483045022100f61038b308dc1da865a34852746f015772934208c6d24454393cd99bdf2217770220056e675a675a6d0a02b85b14e5e29074d8a25a9b5760bea2816f661910a006ea01475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae0001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e8870107232200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b20289030108da0400473044022062eb7a556107a7c73f45ac4ab5a1dddf6f7075fb1275969a7f383efff784bcb202200c05dbb7470dbf2f08557dd356c7325c1ed30913e996cd3840945db12228da5f01473044022065f45ba5998b59a27ffe1a7bed016af1f1f90d54b3aa8f7450aa5f56a25103bd02207f724703ad1edb96680b284b56d4ffcb88f7fb759eabbe08aa30f29b851383d20147522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae00220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000").unwrap()).unwrap(); + let psbt = bitcoin::Psbt::deserialize(&Vec::::from_hex("70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000107da00473044022074018ad4180097b873323c0015720b3684cc8123891048e7dbcd9b55ad679c99022073d369b740e3eb53dcefa33823c8070514ca55a7dd9544f157c167913261118c01483045022100f61038b308dc1da865a34852746f015772934208c6d24454393cd99bdf2217770220056e675a675a6d0a02b85b14e5e29074d8a25a9b5760bea2816f661910a006ea01475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae0001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e8870107232200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b20289030108da0400473044022062eb7a556107a7c73f45ac4ab5a1dddf6f7075fb1275969a7f383efff784bcb202200c05dbb7470dbf2f08557dd356c7325c1ed30913e996cd3840945db12228da5f01473044022065f45ba5998b59a27ffe1a7bed016af1f1f90d54b3aa8f7450aa5f56a25103bd02207f724703ad1edb96680b284b56d4ffcb88f7fb759eabbe08aa30f29b851383d20147522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae00220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000").unwrap()).unwrap(); let secp = Secp256k1::verification_only(); let tx = psbt.extract(&secp).unwrap(); let expected: bitcoin::Transaction = deserialize(&Vec::::from_hex("0200000000010258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd7500000000da00473044022074018ad4180097b873323c0015720b3684cc8123891048e7dbcd9b55ad679c99022073d369b740e3eb53dcefa33823c8070514ca55a7dd9544f157c167913261118c01483045022100f61038b308dc1da865a34852746f015772934208c6d24454393cd99bdf2217770220056e675a675a6d0a02b85b14e5e29074d8a25a9b5760bea2816f661910a006ea01475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752aeffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d01000000232200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f000400473044022062eb7a556107a7c73f45ac4ab5a1dddf6f7075fb1275969a7f383efff784bcb202200c05dbb7470dbf2f08557dd356c7325c1ed30913e996cd3840945db12228da5f01473044022065f45ba5998b59a27ffe1a7bed016af1f1f90d54b3aa8f7450aa5f56a25103bd02207f724703ad1edb96680b284b56d4ffcb88f7fb759eabbe08aa30f29b851383d20147522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae00000000").unwrap()).unwrap(); @@ -1419,7 +1414,7 @@ mod tests { #[test] fn test_update_item_tr_no_script() { // keys taken from: https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki#Specifications - let root_xpub = ExtendedPubKey::from_str("xpub661MyMwAqRbcFkPHucMnrGNzDwb6teAX1RbKQmqtEF8kK3Z7LZ59qafCjB9eCRLiTVG3uxBxgKvRgbubRhqSKXnGGb1aoaqLrpMBDrVxga8").unwrap(); + let root_xpub = Xpub::from_str("xpub661MyMwAqRbcFkPHucMnrGNzDwb6teAX1RbKQmqtEF8kK3Z7LZ59qafCjB9eCRLiTVG3uxBxgKvRgbubRhqSKXnGGb1aoaqLrpMBDrVxga8").unwrap(); let fingerprint = root_xpub.fingerprint(); let desc = format!("tr([{}/86'/0'/0']xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/0/0)", fingerprint); let desc = Descriptor::from_str(&desc).unwrap(); @@ -1449,7 +1444,7 @@ mod tests { fn test_update_item_tr_with_tapscript() { use crate::Tap; // keys taken from: https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki#Specifications - let root_xpub = ExtendedPubKey::from_str("xpub661MyMwAqRbcFkPHucMnrGNzDwb6teAX1RbKQmqtEF8kK3Z7LZ59qafCjB9eCRLiTVG3uxBxgKvRgbubRhqSKXnGGb1aoaqLrpMBDrVxga8").unwrap(); + let root_xpub = Xpub::from_str("xpub661MyMwAqRbcFkPHucMnrGNzDwb6teAX1RbKQmqtEF8kK3Z7LZ59qafCjB9eCRLiTVG3uxBxgKvRgbubRhqSKXnGGb1aoaqLrpMBDrVxga8").unwrap(); let fingerprint = root_xpub.fingerprint(); let xpub = format!("[{}/86'/0'/0']xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ", fingerprint); let desc = @@ -1520,7 +1515,7 @@ mod tests { #[test] fn test_update_item_non_tr_multi() { // values taken from https://github.com/bitcoin/bips/blob/master/bip-0084.mediawiki (after removing zpub thingy) - let root_xpub = ExtendedPubKey::from_str("xpub661MyMwAqRbcFkPHucMnrGNzDwb6teAX1RbKQmqtEF8kK3Z7LZ59qafCjB9eCRLiTVG3uxBxgKvRgbubRhqSKXnGGb1aoaqLrpMBDrVxga8").unwrap(); + let root_xpub = Xpub::from_str("xpub661MyMwAqRbcFkPHucMnrGNzDwb6teAX1RbKQmqtEF8kK3Z7LZ59qafCjB9eCRLiTVG3uxBxgKvRgbubRhqSKXnGGb1aoaqLrpMBDrVxga8").unwrap(); let fingerprint = root_xpub.fingerprint(); let xpub = format!("[{}/84'/0'/0']xpub6CatWdiZiodmUeTDp8LT5or8nmbKNcuyvz7WyksVFkKB4RHwCD3XyuvPEbvqAQY3rAPshWcMLoP2fMFMKHPJ4ZeZXYVUhLv1VMrjPC7PW6V", fingerprint); let pubkeys = [ @@ -1592,11 +1587,11 @@ mod tests { let desc = Descriptor::::from_str(&desc).unwrap(); let mut non_witness_utxo = bitcoin::Transaction { - version: 1, + version: transaction::Version::ONE, lock_time: absolute::LockTime::ZERO, input: vec![], output: vec![TxOut { - value: 1_000, + value: Amount::from_sat(1_000), script_pubkey: ScriptBuf::from_hex( "5120a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c", ) @@ -1605,7 +1600,7 @@ mod tests { }; let tx = bitcoin::Transaction { - version: 1, + version: transaction::Version::ONE, lock_time: absolute::LockTime::ZERO, input: vec![TxIn { previous_output: OutPoint { txid: non_witness_utxo.txid(), vout: 0 }, @@ -1632,7 +1627,7 @@ mod tests { Ok(()), "matching non_witness_utxo" ); - non_witness_utxo.version = 0; + non_witness_utxo.version = transaction::Version::non_standard(0); psbt.inputs[0].non_witness_utxo = Some(non_witness_utxo); assert_eq!( psbt.update_input_with_descriptor(0, &desc), @@ -1654,11 +1649,11 @@ mod tests { let desc = Descriptor::::from_str(&desc).unwrap(); let tx = bitcoin::Transaction { - version: 1, + version: transaction::Version::ONE, lock_time: absolute::LockTime::ZERO, input: vec![], output: vec![TxOut { - value: 1_000, + value: Amount::from_sat(1_000), script_pubkey: ScriptBuf::from_hex( "5120a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c", ) diff --git a/src/test_utils.rs b/src/test_utils.rs index dea8aae58..086af7932 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -161,7 +161,7 @@ impl StrXOnlyKeyTranslator { let pks: Vec<_> = sks .iter() .map(|sk| { - let keypair = secp256k1::KeyPair::from_secret_key(&secp, sk); + let keypair = secp256k1::Keypair::from_secret_key(&secp, sk); let (pk, _parity) = XOnlyPublicKey::from_keypair(&keypair); pk }) diff --git a/src/util.rs b/src/util.rs index 11643b643..d73446db6 100644 --- a/src/util.rs +++ b/src/util.rs @@ -10,7 +10,7 @@ use crate::miniscript::context; use crate::miniscript::satisfy::Placeholder; use crate::prelude::*; use crate::{MiniscriptKey, ScriptContext, ToPublicKey}; -pub(crate) fn varint_len(n: usize) -> usize { bitcoin::VarInt(n as u64).len() } +pub(crate) fn varint_len(n: usize) -> usize { bitcoin::VarInt(n as u64).size() } pub(crate) trait ItemSize { fn size(&self) -> usize;