From 9bf8dfcbb939066c5d919d5f06c33fe1bebfc784 Mon Sep 17 00:00:00 2001 From: jlest01 <174762002+jlest01@users.noreply.github.com> Date: Tue, 20 Aug 2024 20:22:23 -0300 Subject: [PATCH] Update secp256k1 dependency to use PR https://github.com/rust-bitcoin/rust-secp256k1/pull/721 --- bitcoin/Cargo.toml | 4 ++-- bitcoin/examples/sign-tx-taproot.rs | 4 ++-- bitcoin/examples/taproot-psbt.rs | 2 +- bitcoin/src/psbt/mod.rs | 10 +++++++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/bitcoin/Cargo.toml b/bitcoin/Cargo.toml index 9553756a9..44a1baadf 100644 --- a/bitcoin/Cargo.toml +++ b/bitcoin/Cargo.toml @@ -17,7 +17,7 @@ exclude = ["tests", "contrib"] [features] default = [ "std", "secp-recovery" ] std = ["base58/std", "bech32/std", "hashes/std", "hex/std", "internals/std", "io/std", "primitives/std", "secp256k1/std", "units/std", "bitcoinconsensus?/std"] -rand-std = ["secp256k1/rand-std", "std"] +rand-std = ["secp256k1/std", "secp256k1/rand", "std"] rand = ["secp256k1/rand"] serde = ["dep:serde", "hashes/serde", "internals/serde", "primitives/serde", "secp256k1/serde", "units/serde"] secp-lowmemory = ["secp256k1/lowmemory"] @@ -31,7 +31,7 @@ hex = { package = "hex-conservative", version = "0.2.0", default-features = fals internals = { package = "bitcoin-internals", version = "0.3.0", features = ["alloc"] } io = { package = "bitcoin-io", version = "0.1.1", default-features = false, features = ["alloc"] } primitives = { package = "bitcoin-primitives", version = "0.100.0", default-features = false, features = ["alloc"] } -secp256k1 = { version = "0.29.0", default-features = false, features = ["hashes", "alloc"] } +secp256k1 = { git = "https://github.com/rust-bitcoin/rust-secp256k1.git", rev = "refs/pull/721/head", default-features = false, features = ["alloc", "hashes", "rand", "std"] } units = { package = "bitcoin-units", version = "0.1.0", default-features = false, features = ["alloc"] } base64 = { version = "0.22.0", optional = true } diff --git a/bitcoin/examples/sign-tx-taproot.rs b/bitcoin/examples/sign-tx-taproot.rs index adfcec3ae..6e715ba35 100644 --- a/bitcoin/examples/sign-tx-taproot.rs +++ b/bitcoin/examples/sign-tx-taproot.rs @@ -7,7 +7,7 @@ use std::str::FromStr; use bitcoin::address::script_pubkey::ScriptBufExt as _; use bitcoin::key::{Keypair, TapTweak, TweakedKeypair, UntweakedPublicKey}; use bitcoin::locktime::absolute; -use bitcoin::secp256k1::{rand, Message, Secp256k1, SecretKey, Signing, Verification}; +use bitcoin::secp256k1::{rand, Secp256k1, SecretKey, Signing, Verification}; use bitcoin::sighash::{Prevouts, SighashCache, TapSighashType}; use bitcoin::{ transaction, Address, Amount, Network, OutPoint, ScriptBuf, Sequence, Transaction, TxIn, TxOut, @@ -71,7 +71,7 @@ fn main() { // Sign the sighash using the secp256k1 library (exported by rust-bitcoin). let tweaked: TweakedKeypair = keypair.tap_tweak(&secp, None); - let msg = Message::from(sighash); + let msg = sighash.to_byte_array(); let signature = secp.sign_schnorr(&msg, &tweaked.to_inner()); // Update the witness stack. diff --git a/bitcoin/examples/taproot-psbt.rs b/bitcoin/examples/taproot-psbt.rs index be43816c6..a2666af65 100644 --- a/bitcoin/examples/taproot-psbt.rs +++ b/bitcoin/examples/taproot-psbt.rs @@ -740,7 +740,7 @@ fn sign_psbt_taproot( Some(_) => keypair, // no tweak for script spend }; - let msg = secp256k1::Message::from(hash); + let msg = hash.to_byte_array(); let signature = secp.sign_schnorr(&msg, &keypair); let final_signature = taproot::Signature { signature, sighash_type }; diff --git a/bitcoin/src/psbt/mod.rs b/bitcoin/src/psbt/mod.rs index d64f94852..089040bb4 100644 --- a/bitcoin/src/psbt/mod.rs +++ b/bitcoin/src/psbt/mod.rs @@ -28,7 +28,7 @@ use crate::prelude::{btree_map, BTreeMap, BTreeSet, Borrow, Box, Vec}; use crate::script::ScriptExt as _; use crate::sighash::{self, EcdsaSighashType, Prevouts, SighashCache}; use crate::transaction::{self, Transaction, TxOut}; -use crate::{Amount, FeeRate, TapLeafHash, TapSighashType}; +use crate::{Amount, FeeRate, TapLeafHash, TapSighash, TapSighashType}; #[rustfmt::skip] // Keep public re-exports separate. #[doc(inline)] @@ -443,6 +443,8 @@ impl Psbt { .tap_tweak(secp, input.tap_merkle_root) .to_inner(); + let msg = msg.to_byte_array(); + #[cfg(feature = "rand-std")] let signature = secp.sign_schnorr(&msg, &key_pair); #[cfg(not(feature = "rand-std"))] @@ -470,6 +472,8 @@ impl Psbt { let (msg, sighash_type) = self.sighash_taproot(input_index, cache, Some(lh))?; + let msg = msg.to_byte_array(); + #[cfg(feature = "rand-std")] let signature = secp.sign_schnorr(&msg, &key_pair); #[cfg(not(feature = "rand-std"))] @@ -560,7 +564,7 @@ impl Psbt { input_index: usize, cache: &mut SighashCache, leaf_hash: Option, - ) -> Result<(Message, TapSighashType), SignError> { + ) -> Result<(TapSighash, TapSighashType), SignError> { use OutputType::*; if self.signing_algorithm(input_index)? != SigningAlgorithm::Schnorr { @@ -605,7 +609,7 @@ impl Psbt { } else { cache.taproot_key_spend_signature_hash(input_index, &prev_outs, hash_ty)? }; - Ok((Message::from(sighash), hash_ty)) + Ok((sighash, hash_ty)) } _ => Err(SignError::Unsupported), }