Upgrade secp dependency

Upgrade `rust-secp256k1` to the latest version `v0.29.0`. This removes
the duplicate deps as well.
This commit is contained in:
Tobin C. Harding 2024-03-27 14:15:50 +11:00
parent 69716f17b9
commit e1869340be
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
9 changed files with 45 additions and 93 deletions

View File

@ -18,9 +18,9 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
name = "base58ck"
version = "0.1.0"
dependencies = [
"bitcoin-internals 0.3.0",
"bitcoin_hashes 0.14.0",
"hex-conservative 0.2.0",
"bitcoin-internals",
"bitcoin_hashes",
"hex-conservative",
]
[[package]]
@ -53,12 +53,12 @@ dependencies = [
"base64",
"bech32",
"bincode",
"bitcoin-internals 0.3.0",
"bitcoin-internals",
"bitcoin-io",
"bitcoin-units",
"bitcoin_hashes 0.14.0",
"bitcoin_hashes",
"bitcoinconsensus",
"hex-conservative 0.2.0",
"hex-conservative",
"hex_lit",
"mutagen",
"ordered",
@ -79,12 +79,6 @@ dependencies = [
"serde_json",
]
[[package]]
name = "bitcoin-internals"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9425c3bf7089c983facbae04de54513cce73b41c7f9ff8c845b54e7bc64ebbfb"
[[package]]
name = "bitcoin-internals"
version = "0.3.0"
@ -100,28 +94,18 @@ version = "0.1.2"
name = "bitcoin-units"
version = "0.1.0"
dependencies = [
"bitcoin-internals 0.3.0",
"bitcoin-internals",
"serde",
"serde_json",
"serde_test",
]
[[package]]
name = "bitcoin_hashes"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b"
dependencies = [
"bitcoin-internals 0.2.0",
"hex-conservative 0.1.1",
]
[[package]]
name = "bitcoin_hashes"
version = "0.14.0"
dependencies = [
"bitcoin-io",
"hex-conservative 0.2.0",
"hex-conservative",
"schemars",
"serde",
"serde_json",
@ -178,12 +162,6 @@ version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3"
[[package]]
name = "hex-conservative"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2"
[[package]]
name = "hex-conservative"
version = "0.2.0"
@ -374,11 +352,11 @@ dependencies = [
[[package]]
name = "secp256k1"
version = "0.28.0"
version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2acea373acb8c21ecb5a23741452acd2593ed44ee3d343e72baaa143bc89d0d5"
checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3"
dependencies = [
"bitcoin_hashes 0.13.0",
"bitcoin_hashes",
"rand",
"secp256k1-sys",
"serde",
@ -386,9 +364,9 @@ dependencies = [
[[package]]
name = "secp256k1-sys"
version = "0.9.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09e67c467c38fd24bd5499dc9a18183b31575c12ee549197e3e20d57aa4fe3b7"
checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b"
dependencies = [
"cc",
]

View File

@ -18,9 +18,9 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
name = "base58ck"
version = "0.1.0"
dependencies = [
"bitcoin-internals 0.3.0",
"bitcoin_hashes 0.14.0",
"hex-conservative 0.2.0",
"bitcoin-internals",
"bitcoin_hashes",
"hex-conservative",
]
[[package]]
@ -52,12 +52,12 @@ dependencies = [
"base64",
"bech32",
"bincode",
"bitcoin-internals 0.3.0",
"bitcoin-internals",
"bitcoin-io",
"bitcoin-units",
"bitcoin_hashes 0.14.0",
"bitcoin_hashes",
"bitcoinconsensus",
"hex-conservative 0.2.0",
"hex-conservative",
"hex_lit",
"mutagen",
"ordered",
@ -78,12 +78,6 @@ dependencies = [
"serde_json",
]
[[package]]
name = "bitcoin-internals"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9425c3bf7089c983facbae04de54513cce73b41c7f9ff8c845b54e7bc64ebbfb"
[[package]]
name = "bitcoin-internals"
version = "0.3.0"
@ -99,28 +93,18 @@ version = "0.1.2"
name = "bitcoin-units"
version = "0.1.0"
dependencies = [
"bitcoin-internals 0.3.0",
"bitcoin-internals",
"serde",
"serde_json",
"serde_test",
]
[[package]]
name = "bitcoin_hashes"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b"
dependencies = [
"bitcoin-internals 0.2.0",
"hex-conservative 0.1.1",
]
[[package]]
name = "bitcoin_hashes"
version = "0.14.0"
dependencies = [
"bitcoin-io",
"hex-conservative 0.2.0",
"hex-conservative",
"schemars",
"serde",
"serde_json",
@ -177,12 +161,6 @@ version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3"
[[package]]
name = "hex-conservative"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2"
[[package]]
name = "hex-conservative"
version = "0.2.0"
@ -363,11 +341,11 @@ dependencies = [
[[package]]
name = "secp256k1"
version = "0.28.0"
version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2acea373acb8c21ecb5a23741452acd2593ed44ee3d343e72baaa143bc89d0d5"
checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3"
dependencies = [
"bitcoin_hashes 0.13.0",
"bitcoin_hashes",
"rand",
"secp256k1-sys",
"serde",
@ -375,9 +353,9 @@ dependencies = [
[[package]]
name = "secp256k1-sys"
version = "0.9.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09e67c467c38fd24bd5499dc9a18183b31575c12ee549197e3e20d57aa4fe3b7"
checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b"
dependencies = [
"cc",
]

View File

@ -35,7 +35,7 @@ hex = { package = "hex-conservative", version = "0.2.0", default-features = fals
hex_lit = "0.1.1"
internals = { package = "bitcoin-internals", version = "0.3.0" }
io = { package = "bitcoin-io", version = "0.1.1", default-features = false, features = ["alloc"] }
secp256k1 = { version = "0.28.0", default-features = false, features = ["hashes", "alloc"] }
secp256k1 = { version = "0.29.0", default-features = false, features = ["hashes", "alloc"] }
units = { package = "bitcoin-units", version = "0.1.0", default-features = false, features = ["alloc"] }
base64 = { version = "0.21.3", optional = true }

View File

@ -1,4 +1,3 @@
use bitcoin::hashes::Hash;
use bitcoin::{
consensus, ecdsa, sighash, Amount, CompressedPublicKey, Script, ScriptBuf, Transaction,
};
@ -45,7 +44,7 @@ fn compute_sighash_p2wpkh(raw_tx: &[u8], inp_idx: usize, value: u64) {
.p2wpkh_signature_hash(inp_idx, &spk, Amount::from_sat(value), sig.sighash_type)
.expect("failed to compute sighash");
println!("Segwit p2wpkh sighash: {:x}", sighash);
let msg = secp256k1::Message::from_digest(sighash.to_byte_array());
let msg = secp256k1::Message::from(sighash);
println!("Message is {:x}", msg);
let secp = secp256k1::Secp256k1::verification_only();
pk.verify(&secp, &msg, &sig).unwrap()

View File

@ -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_digest(sighash.to_byte_array());
let msg = Message::from(sighash);
let signature = secp.sign_schnorr(&msg, &tweaked.to_inner());
// Update the witness stack.

View File

@ -80,7 +80,6 @@ use std::str::FromStr;
use bitcoin::bip32::{ChildNumber, DerivationPath, Fingerprint, Xpriv, Xpub};
use bitcoin::consensus::encode;
use bitcoin::hashes::Hash;
use bitcoin::key::{TapTweak, XOnlyPublicKey};
use bitcoin::opcodes::all::{OP_CHECKSIG, OP_CLTV, OP_DROP};
use bitcoin::psbt::{self, Input, Output, Psbt, PsbtSighashType};
@ -739,7 +738,7 @@ fn sign_psbt_taproot(
Some(_) => keypair, // no tweak for script spend
};
let msg = secp256k1::Message::from_digest(hash.to_byte_array());
let msg = secp256k1::Message::from(hash);
let signature = secp.sign_schnorr(&msg, &keypair);
let final_signature = taproot::Signature { signature, sighash_type };

View File

@ -32,10 +32,12 @@ pub(crate) const UINT256_ONE: [u8; 32] = [
0, 0, 0, 0, 0, 0, 0, 0
];
macro_rules! impl_thirty_two_byte_hash {
macro_rules! impl_message_from_hash {
($ty:ident) => {
impl secp256k1::ThirtyTwoByteHash for $ty {
fn into_32(self) -> [u8; 32] { self.to_byte_array() }
impl From<$ty> for secp256k1::Message {
fn from(hash: $ty) -> secp256k1::Message {
secp256k1::Message::from_digest(hash.to_byte_array())
}
}
};
}
@ -50,8 +52,8 @@ hash_newtype! {
pub struct SegwitV0Sighash(sha256d::Hash);
}
impl_thirty_two_byte_hash!(LegacySighash);
impl_thirty_two_byte_hash!(SegwitV0Sighash);
impl_message_from_hash!(LegacySighash);
impl_message_from_hash!(SegwitV0Sighash);
sha256t_hash_newtype! {
pub struct TapSighashTag = hash_str("TapSighash");
@ -63,7 +65,7 @@ sha256t_hash_newtype! {
pub struct TapSighash(_);
}
impl_thirty_two_byte_hash!(TapSighash);
impl_message_from_hash!(TapSighash);
/// Efficiently calculates signature hash message for legacy, segwit and taproot inputs.
#[derive(Debug)]
@ -1935,7 +1937,7 @@ mod tests {
.taproot_signature_hash(tx_ind, &Prevouts::All(&utxos), None, None, hash_ty)
.unwrap();
let msg = secp256k1::Message::from_digest(sighash.to_byte_array());
let msg = secp256k1::Message::from(sighash);
let key_spend_sig = secp.sign_schnorr_with_aux_rand(&msg, &tweaked_keypair, &[0u8; 32]);
assert_eq!(expected.internal_pubkey, internal_key);

View File

@ -18,7 +18,6 @@ use core::{cmp, fmt};
#[cfg(feature = "std")]
use std::collections::{HashMap, HashSet};
use hashes::Hash;
use internals::write_err;
use secp256k1::{Keypair, Message, Secp256k1, Signing, Verification};
@ -523,7 +522,7 @@ impl Psbt {
let sighash = cache
.legacy_signature_hash(input_index, spk, hash_ty.to_u32())
.expect("input checked above");
Ok((Message::from_digest(sighash.to_byte_array()), hash_ty))
Ok((Message::from(sighash), hash_ty))
}
Sh => {
let script_code =
@ -531,17 +530,17 @@ impl Psbt {
let sighash = cache
.legacy_signature_hash(input_index, script_code, hash_ty.to_u32())
.expect("input checked above");
Ok((Message::from_digest(sighash.to_byte_array()), hash_ty))
Ok((Message::from(sighash), hash_ty))
}
Wpkh => {
let sighash = cache.p2wpkh_signature_hash(input_index, spk, utxo.value, hash_ty)?;
Ok((Message::from_digest(sighash.to_byte_array()), hash_ty))
Ok((Message::from(sighash), hash_ty))
}
ShWpkh => {
let redeem_script = input.redeem_script.as_ref().expect("checked above");
let sighash =
cache.p2wpkh_signature_hash(input_index, redeem_script, utxo.value, hash_ty)?;
Ok((Message::from_digest(sighash.to_byte_array()), hash_ty))
Ok((Message::from(sighash), hash_ty))
}
Wsh | ShWsh => {
let witness_script =
@ -549,7 +548,7 @@ impl Psbt {
let sighash = cache
.p2wsh_signature_hash(input_index, witness_script, utxo.value, hash_ty)
.map_err(SignError::SegwitV0Sighash)?;
Ok((Message::from_digest(sighash.to_byte_array()), hash_ty))
Ok((Message::from(sighash), hash_ty))
}
Tr => {
// This PSBT signing API is WIP, taproot to come shortly.
@ -1199,7 +1198,7 @@ pub use self::display_from_str::PsbtParseError;
#[cfg(test)]
mod tests {
use hashes::{hash160, ripemd160, sha256};
use hashes::{hash160, ripemd160, sha256, Hash};
use hex::{test_hex_unwrap as hex, FromHex};
#[cfg(feature = "rand-std")]
use secp256k1::{All, SecretKey};

View File

@ -177,9 +177,6 @@ do_dup_deps() {
cargo tree --target=all --all-features --duplicates \
| grep '^[0-9A-Za-z]' \
| grep -v 'syn' \
| grep -v 'bitcoin_hashes' \
| grep -v 'bitcoin-internals' \
| grep -v 'hex-conservative' \
| wc -l
)
if [ "$duplicate_dependencies" -ne 0 ]; then