From 2178c7367c863e623e3b4ceaef05291fa5002609 Mon Sep 17 00:00:00 2001 From: sanket1729 Date: Mon, 3 Jan 2022 08:22:44 +0530 Subject: [PATCH 1/2] Update to secp256k1 0.21.2 --- Cargo.toml | 4 ++-- src/util/address.rs | 4 ++-- src/util/ecdsa.rs | 4 ++-- src/util/misc.rs | 4 ++-- src/util/psbt/map/input.rs | 19 ++++++++++--------- src/util/psbt/map/output.rs | 10 +++++----- src/util/psbt/serialize.rs | 22 +++++++++++----------- src/util/schnorr.rs | 24 ++++++++++++------------ src/util/sighash.rs | 15 +++++++-------- src/util/taproot.rs | 20 +++++++++----------- 10 files changed, 62 insertions(+), 64 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b60b978e..03e29123 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] bech32 = { version = "0.8.1", default-features = false } bitcoin_hashes = { version = "0.10.0", default-features = false } -secp256k1 = { version = "0.20.3", default-features = false } +secp256k1 = { version = "0.21.2", default-features = false } core2 = { version = "0.3.0", optional = true, default-features = false } base64-compat = { version = "1.0.0", optional = true } @@ -46,7 +46,7 @@ hashbrown = { version = "0.8", optional = true } [dev-dependencies] serde_json = "<1.0.45" serde_test = "1" -secp256k1 = { version = "0.20.0", features = [ "recovery", "rand-std" ] } +secp256k1 = { version = "0.21.2", features = [ "recovery", "rand-std" ] } bincode = "1.3.1" # We need to pin ryu (transitive dep from serde_json) to stay compatible with Rust 1.22.0 ryu = "<1.0.5" diff --git a/src/util/address.rs b/src/util/address.rs index 892f9f10..def02a4f 100644 --- a/src/util/address.rs +++ b/src/util/address.rs @@ -879,7 +879,7 @@ mod tests { use blockdata::script::Script; use network::constants::Network::{Bitcoin, Testnet}; use util::ecdsa::PublicKey; - use secp256k1::schnorrsig; + use secp256k1::XOnlyPublicKey; use super::*; @@ -1266,7 +1266,7 @@ mod tests { #[test] fn p2tr_from_untweaked(){ //Test case from BIP-086 - let internal_key = schnorrsig::PublicKey::from_str("cc8a4bc64d897bddc5fbc2f670f7a8ba0b386779106cf1223c6fc5d7cd6fc115").unwrap(); + let internal_key = XOnlyPublicKey::from_str("cc8a4bc64d897bddc5fbc2f670f7a8ba0b386779106cf1223c6fc5d7cd6fc115").unwrap(); let secp = Secp256k1::verification_only(); let address = Address::p2tr(&secp, internal_key, None, Network::Bitcoin); assert_eq!(address.to_string(), "bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr"); diff --git a/src/util/ecdsa.rs b/src/util/ecdsa.rs index f5163913..9cd4bb2c 100644 --- a/src/util/ecdsa.rs +++ b/src/util/ecdsa.rs @@ -419,7 +419,7 @@ impl<'de> ::serde::Deserialize<'de> for PublicKey { #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct EcdsaSig { /// The underlying ECDSA Signature - pub sig: secp256k1::Signature, + pub sig: secp256k1::ecdsa::Signature, /// The corresponding hash type pub hash_ty: EcdsaSigHashType, } @@ -432,7 +432,7 @@ impl EcdsaSig { .ok_or(EcdsaSigError::EmptySignature)?; let hash_ty = EcdsaSigHashType::from_u32_standard(*hash_ty as u32) .map_err(|_| EcdsaSigError::NonStandardSigHashType(*hash_ty))?; - let sig = secp256k1::Signature::from_der(sig) + let sig = secp256k1::ecdsa::Signature::from_der(sig) .map_err(EcdsaSigError::Secp256k1)?; Ok(EcdsaSig { sig, hash_ty }) } diff --git a/src/util/misc.rs b/src/util/misc.rs index add253ea..9cf39561 100644 --- a/src/util/misc.rs +++ b/src/util/misc.rs @@ -40,7 +40,7 @@ mod message_signing { use hashes::sha256d; use secp256k1; - use secp256k1::recovery::{RecoveryId, RecoverableSignature}; + use secp256k1::ecdsa::{RecoveryId, RecoverableSignature}; use util::ecdsa::PublicKey; use util::address::{Address, AddressType}; @@ -146,7 +146,7 @@ mod message_signing { msg_hash: sha256d::Hash ) -> Result { let msg = secp256k1::Message::from_slice(&msg_hash[..])?; - let pubkey = secp_ctx.recover(&msg, &self.signature)?; + let pubkey = secp_ctx.recover_ecdsa(&msg, &self.signature)?; Ok(PublicKey { key: pubkey, compressed: self.compressed, diff --git a/src/util/psbt/map/input.rs b/src/util/psbt/map/input.rs index a443f402..4a593b21 100644 --- a/src/util/psbt/map/input.rs +++ b/src/util/psbt/map/input.rs @@ -19,6 +19,7 @@ use io; use blockdata::script::Script; use blockdata::transaction::{EcdsaSigHashType, Transaction, TxOut}; use consensus::encode; +use secp256k1::XOnlyPublicKey; use util::bip32::KeySource; use hashes::{self, hash160, ripemd160, sha256, sha256d}; use util::ecdsa::PublicKey; @@ -123,15 +124,15 @@ pub struct Input { pub tap_key_sig: Option, /// Map of | with signature #[cfg_attr(feature = "serde", serde(with = "::serde_utils::btreemap_as_seq"))] - pub tap_script_sigs: BTreeMap<(schnorr::PublicKey, TapLeafHash), schnorr::SchnorrSig>, + pub tap_script_sigs: BTreeMap<(XOnlyPublicKey, TapLeafHash), schnorr::SchnorrSig>, /// Map of Control blocks to Script version pair #[cfg_attr(feature = "serde", serde(with = "::serde_utils::btreemap_as_seq"))] pub tap_scripts: BTreeMap, /// Map of tap root x only keys to origin info and leaf hashes contained in it #[cfg_attr(feature = "serde", serde(with = "::serde_utils::btreemap_as_seq"))] - pub tap_key_origins: BTreeMap, KeySource)>, + pub tap_key_origins: BTreeMap, KeySource)>, /// Taproot Internal key - pub tap_internal_key : Option, + pub tap_internal_key : Option, /// Taproot Merkle root pub tap_merkle_root : Option, /// Proprietary key-value pairs for this input. @@ -214,7 +215,7 @@ impl Map for Input { } PSBT_IN_TAP_SCRIPT_SIG => { impl_psbt_insert_pair! { - self.tap_script_sigs <= | + self.tap_script_sigs <= | } } PSBT_IN_TAP_LEAF_SCRIPT=> { @@ -224,12 +225,12 @@ impl Map for Input { } PSBT_IN_TAP_BIP32_DERIVATION => { impl_psbt_insert_pair! { - self.tap_key_origins <= |< raw_value: (Vec, KeySource)> + self.tap_key_origins <= |< raw_value: (Vec, KeySource)> } } PSBT_IN_TAP_INTERNAL_KEY => { impl_psbt_insert_pair! { - self.tap_internal_key <= |< raw_value: schnorr::PublicKey> + self.tap_internal_key <= |< raw_value: XOnlyPublicKey> } } PSBT_IN_TAP_MERKLE_ROOT => { @@ -314,7 +315,7 @@ impl Map for Input { } impl_psbt_get_pair! { - rv.push(self.tap_script_sigs as |>) + rv.push(self.tap_script_sigs as |>) } impl_psbt_get_pair! { @@ -323,11 +324,11 @@ impl Map for Input { impl_psbt_get_pair! { rv.push(self.tap_key_origins as |<(Vec, KeySource)>) + XOnlyPublicKey>|<(Vec, KeySource)>) } impl_psbt_get_pair! { - rv.push(self.tap_internal_key as |) + rv.push(self.tap_internal_key as |) } impl_psbt_get_pair! { diff --git a/src/util/psbt/map/output.rs b/src/util/psbt/map/output.rs index 75e764c6..6aed3438 100644 --- a/src/util/psbt/map/output.rs +++ b/src/util/psbt/map/output.rs @@ -18,6 +18,7 @@ use io; use blockdata::script::Script; use consensus::encode; +use secp256k1::XOnlyPublicKey; use util::bip32::KeySource; use util::ecdsa::PublicKey; use util::psbt; @@ -25,7 +26,6 @@ use util::psbt::map::Map; use util::psbt::raw; use util::psbt::Error; -use schnorr; use util::taproot::TapLeafHash; use util::taproot::{NodeInfo, TaprootBuilder}; @@ -59,12 +59,12 @@ pub struct Output { #[cfg_attr(feature = "serde", serde(with = "::serde_utils::btreemap_as_seq"))] pub bip32_derivation: BTreeMap, /// The internal pubkey - pub tap_internal_key: Option, + pub tap_internal_key: Option, /// Taproot Output tree pub tap_tree: Option, /// Map of tap root x only keys to origin info and leaf hashes contained in it #[cfg_attr(feature = "serde", serde(with = "::serde_utils::btreemap_as_seq"))] - pub tap_key_origins: BTreeMap, KeySource)>, + pub tap_key_origins: BTreeMap, KeySource)>, /// Proprietary key-value pairs for this output. #[cfg_attr( feature = "serde", @@ -148,7 +148,7 @@ impl Map for Output { } PSBT_OUT_TAP_INTERNAL_KEY => { impl_psbt_insert_pair! { - self.tap_internal_key <= | + self.tap_internal_key <= | } } PSBT_OUT_TAP_TREE => { @@ -158,7 +158,7 @@ impl Map for Output { } PSBT_OUT_TAP_BIP32_DERIVATION => { impl_psbt_insert_pair! { - self.tap_key_origins <= |< raw_value: (Vec, KeySource)> + self.tap_key_origins <= |< raw_value: (Vec, KeySource)> } } _ => match self.unknown.entry(raw_key) { diff --git a/src/util/psbt/serialize.rs b/src/util/psbt/serialize.rs index 7c9e7687..e1a5cfed 100644 --- a/src/util/psbt/serialize.rs +++ b/src/util/psbt/serialize.rs @@ -25,7 +25,7 @@ use io; use blockdata::script::Script; use blockdata::transaction::{EcdsaSigHashType, Transaction, TxOut}; use consensus::encode::{self, serialize, Decodable, Encodable, deserialize_partial}; -use secp256k1::schnorrsig; +use secp256k1::{self, XOnlyPublicKey}; use util::bip32::{ChildNumber, Fingerprint, KeySource}; use hashes::{hash160, ripemd160, sha256, sha256d, Hash}; use util::ecdsa::PublicKey; @@ -157,15 +157,15 @@ impl Deserialize for EcdsaSigHashType { } // Taproot related ser/deser -impl Serialize for schnorr::PublicKey { +impl Serialize for XOnlyPublicKey { fn serialize(&self) -> Vec { - schnorr::PublicKey::serialize(&self).to_vec() + XOnlyPublicKey::serialize(&self).to_vec() } } -impl Deserialize for schnorr::PublicKey { +impl Deserialize for XOnlyPublicKey { fn deserialize(bytes: &[u8]) -> Result { - schnorr::PublicKey::from_slice(bytes) + XOnlyPublicKey::from_slice(bytes) .map_err(|_| encode::Error::ParseFailed("Invalid xonly public key")) } } @@ -182,12 +182,12 @@ impl Deserialize for schnorr::SchnorrSig { 65 => { let hash_ty = SchnorrSigHashType::from_u8(bytes[64]) .map_err(|_| encode::Error::ParseFailed("Invalid Sighash type"))?; - let sig = schnorrsig::Signature::from_slice(&bytes[..64]) + let sig = secp256k1::schnorr::Signature::from_slice(&bytes[..64]) .map_err(|_| encode::Error::ParseFailed("Invalid Schnorr signature"))?; Ok(schnorr::SchnorrSig{ sig, hash_ty }) } 64 => { - let sig = schnorrsig::Signature::from_slice(&bytes[..64]) + let sig = secp256k1::schnorr::Signature::from_slice(&bytes[..64]) .map_err(|_| encode::Error::ParseFailed("Invalid Schnorr signature"))?; Ok(schnorr::SchnorrSig{ sig, hash_ty: SchnorrSigHashType::Default }) } @@ -196,7 +196,7 @@ impl Deserialize for schnorr::SchnorrSig { } } -impl Serialize for (schnorr::PublicKey, TapLeafHash) { +impl Serialize for (XOnlyPublicKey, TapLeafHash) { fn serialize(&self) -> Vec { let ser_pk = self.0.serialize(); let mut buf = Vec::with_capacity(ser_pk.len() + self.1.as_ref().len()); @@ -206,12 +206,12 @@ impl Serialize for (schnorr::PublicKey, TapLeafHash) { } } -impl Deserialize for (schnorr::PublicKey, TapLeafHash) { +impl Deserialize for (XOnlyPublicKey, TapLeafHash) { fn deserialize(bytes: &[u8]) -> Result { if bytes.len() < 32 { return Err(io::Error::from(io::ErrorKind::UnexpectedEof).into()) } - let a: schnorr::PublicKey = Deserialize::deserialize(&bytes[..32])?; + let a: XOnlyPublicKey = Deserialize::deserialize(&bytes[..32])?; let b: TapLeafHash = Deserialize::deserialize(&bytes[32..])?; Ok((a, b)) } @@ -266,7 +266,7 @@ impl Serialize for (Vec, KeySource) { impl Deserialize for (Vec, KeySource) { fn deserialize(bytes: &[u8]) -> Result { - let (leafhash_vec, consumed) = deserialize_partial::>(&bytes)?; + let (leafhash_vec, consumed) = deserialize_partial::>(&bytes)?; let key_source = KeySource::deserialize(&bytes[consumed..])?; Ok((leafhash_vec, key_source)) } diff --git a/src/util/schnorr.rs b/src/util/schnorr.rs index 38c40e6a..d8d6820e 100644 --- a/src/util/schnorr.rs +++ b/src/util/schnorr.rs @@ -20,18 +20,18 @@ use core::fmt; use prelude::*; -pub use secp256k1::schnorrsig::{PublicKey, KeyPair}; +pub use secp256k1::{XOnlyPublicKey, KeyPair}; use secp256k1::{self, Secp256k1, Verification, constants}; use hashes::Hash; use util::taproot::{TapBranchHash, TapTweakHash}; use SchnorrSigHashType; /// Untweaked Schnorr public key -pub type UntweakedPublicKey = PublicKey; +pub type UntweakedPublicKey = XOnlyPublicKey; /// Tweaked Schnorr public key #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct TweakedPublicKey(PublicKey); +pub struct TweakedPublicKey(XOnlyPublicKey); impl fmt::LowerHex for TweakedPublicKey { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -58,7 +58,7 @@ pub trait TapTweak { /// /// # Returns /// The tweaked key and its parity. - fn tap_tweak(self, secp: &Secp256k1, merkle_root: Option) -> (TweakedPublicKey, bool); + fn tap_tweak(self, secp: &Secp256k1, merkle_root: Option) -> (TweakedPublicKey, secp256k1::Parity); /// Directly converts an [`UntweakedPublicKey`] to a [`TweakedPublicKey`] /// @@ -68,7 +68,7 @@ pub trait TapTweak { } impl TapTweak for UntweakedPublicKey { - fn tap_tweak(self, secp: &Secp256k1, merkle_root: Option) -> (TweakedPublicKey, bool) { + fn tap_tweak(self, secp: &Secp256k1, merkle_root: Option) -> (TweakedPublicKey, secp256k1::Parity) { let tweak_value = TapTweakHash::from_key_and_tweak(self, merkle_root).into_inner(); let mut output_key = self.clone(); let parity = output_key.tweak_add_assign(&secp, &tweak_value).expect("Tap tweak failed"); @@ -83,19 +83,19 @@ impl TapTweak for UntweakedPublicKey { } impl TweakedPublicKey { - /// Creates a new [`TweakedPublicKey`] from a [`PublicKey`]. No tweak is applied, consider + /// Creates a new [`TweakedPublicKey`] from a [`XOnlyPublicKey`]. No tweak is applied, consider /// calling `tap_tweak` on an [`UntweakedPublicKey`] instead of using this constructor. - pub fn dangerous_assume_tweaked(key: PublicKey) -> TweakedPublicKey { + pub fn dangerous_assume_tweaked(key: XOnlyPublicKey) -> TweakedPublicKey { TweakedPublicKey(key) } /// Returns the underlying public key. - pub fn into_inner(self) -> PublicKey { + pub fn into_inner(self) -> XOnlyPublicKey { self.0 } /// Returns a reference to underlying public key. - pub fn as_inner(&self) -> &PublicKey { + pub fn as_inner(&self) -> &XOnlyPublicKey { &self.0 } @@ -113,7 +113,7 @@ impl TweakedPublicKey { #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct SchnorrSig { /// The underlying schnorr signature - pub sig: secp256k1::schnorrsig::Signature, + pub sig: secp256k1::schnorr::Signature, /// The corresponding hash type pub hash_ty: SchnorrSigHashType, } @@ -125,7 +125,7 @@ impl SchnorrSig { match sl.len() { 64 => { // default type - let sig = secp256k1::schnorrsig::Signature::from_slice(sl) + let sig = secp256k1::schnorr::Signature::from_slice(sl) .map_err(SchnorrSigError::Secp256k1)?; return Ok( SchnorrSig { sig, hash_ty : SchnorrSigHashType::Default }); }, @@ -133,7 +133,7 @@ impl SchnorrSig { let (hash_ty, sig) = sl.split_last().expect("Slice len checked == 65"); let hash_ty = SchnorrSigHashType::from_u8(*hash_ty) .map_err(|_| SchnorrSigError::InvalidSighashType(*hash_ty))?; - let sig = secp256k1::schnorrsig::Signature::from_slice(sig) + let sig = secp256k1::schnorr::Signature::from_slice(sig) .map_err(SchnorrSigError::Secp256k1)?; Ok(SchnorrSig { sig, hash_ty }) } diff --git a/src/util/sighash.rs b/src/util/sighash.rs index af73abf4..5a23c1e9 100644 --- a/src/util/sighash.rs +++ b/src/util/sighash.rs @@ -754,7 +754,7 @@ mod tests { use std::str::FromStr; use hashes::hex::ToHex; use util::taproot::{TapTweakHash, TapSighashHash, TapBranchHash, TapLeafHash}; - use secp256k1::{self, SecretKey}; + use secp256k1::{self, SecretKey, XOnlyPublicKey}; extern crate serde_json; use {Script, Transaction, TxIn, TxOut}; @@ -1043,23 +1043,22 @@ mod tests { }; let hash_ty = SchnorrSigHashType::from_u8(inp["given"]["hashType"].as_u64().unwrap() as u8).unwrap(); - use schnorr::PublicKey as XOnlyPubKey; - let expected_internal_pk = hex_hash!(XOnlyPubKey, inp["intermediary"]["internalPubkey"].as_str().unwrap()); + let expected_internal_pk = hex_hash!(XOnlyPublicKey, inp["intermediary"]["internalPubkey"].as_str().unwrap()); let expected_tweak = hex_hash!(TapTweakHash, inp["intermediary"]["tweak"].as_str().unwrap()); let _expected_tweaked_priv_key = hex_hash!(SecretKey, inp["intermediary"]["tweakedPrivkey"].as_str().unwrap()); let expected_sig_msg = Vec::::from_hex(inp["intermediary"]["sigMsg"].as_str().unwrap()).unwrap(); let expected_sig_hash = hex_hash!(TapSighashHash, inp["intermediary"]["sigHash"].as_str().unwrap()); let sig_str = inp["expected"]["witness"][0].as_str().unwrap(); let (expected_key_spend_sig, expected_hash_ty) = if sig_str.len() == 128 { - (secp256k1::schnorrsig::Signature::from_str(sig_str).unwrap(), SchnorrSigHashType::Default) + (secp256k1::schnorr::Signature::from_str(sig_str).unwrap(), SchnorrSigHashType::Default) } else { let hash_ty = SchnorrSigHashType::from_u8(Vec::::from_hex(&sig_str[128..]).unwrap()[0]).unwrap(); - (secp256k1::schnorrsig::Signature::from_str(&sig_str[..128]).unwrap(), hash_ty) + (secp256k1::schnorr::Signature::from_str(&sig_str[..128]).unwrap(), hash_ty) }; // tests - let keypair = secp256k1::schnorrsig::KeyPair::from_secret_key(&secp, internal_priv_key); - let internal_key = XOnlyPubKey::from_keypair(secp, &keypair); + let keypair = secp256k1::KeyPair::from_secret_key(&secp, internal_priv_key); + let internal_key = XOnlyPublicKey::from_keypair(&keypair); let tweak = TapTweakHash::from_key_and_tweak(internal_key, merkle_root); let mut tweaked_keypair = keypair; tweaked_keypair.tweak_add_assign(&secp, &tweak).unwrap(); @@ -1081,7 +1080,7 @@ mod tests { ).unwrap(); let msg = secp256k1::Message::from_slice(&sig_hash).unwrap(); - let key_spend_sig = secp.schnorrsig_sign_with_aux_rand(&msg, &tweaked_keypair, &[0u8; 32]); + let key_spend_sig = secp.sign_schnorr_with_aux_rand(&msg, &tweaked_keypair, &[0u8; 32]); assert_eq!(expected_internal_pk, internal_key); assert_eq!(expected_tweak, tweak); diff --git a/src/util/taproot.rs b/src/util/taproot.rs index 2dcff7ee..ca29905c 100644 --- a/src/util/taproot.rs +++ b/src/util/taproot.rs @@ -175,7 +175,7 @@ pub struct TaprootSpendInfo { /// The Merkle root of the script tree (None if there are no scripts) merkle_root: Option, /// The sign final output pubkey as per BIP 341 - output_key_parity: bool, + output_key_parity: secp256k1::Parity, /// The tweaked output key output_key: TweakedPublicKey, /// Map from (script, leaf_version) to (sets of) [`TaprootMerkleBranch`]. @@ -288,7 +288,7 @@ impl TaprootSpendInfo { } /// Parity of the output key. See also [`TaprootSpendInfo::output_key`] - pub fn output_key_parity(&self) -> bool { + pub fn output_key_parity(&self) -> secp256k1::Parity { self.output_key_parity } @@ -657,7 +657,7 @@ pub struct ControlBlock { /// The tapleaf version, pub leaf_version: LeafVersion, /// The parity of the output key (NOT THE INTERNAL KEY WHICH IS ALWAYS XONLY) - pub output_key_parity: bool, + pub output_key_parity: secp256k1::Parity, /// The internal key pub internal_key: UntweakedPublicKey, /// The merkle proof of a script associated with this leaf @@ -679,7 +679,7 @@ impl ControlBlock { { return Err(TaprootError::InvalidControlBlockSize(sl.len())); } - let output_key_parity = (sl[0] & 1) == 1; + let output_key_parity = secp256k1::Parity::from((sl[0] & 1) as i32); let leaf_version = LeafVersion::from_u8(sl[0] & TAPROOT_LEAF_MASK)?; let internal_key = UntweakedPublicKey::from_slice(&sl[1..TAPROOT_CONTROL_BASE_SIZE]) .map_err(TaprootError::InvalidInternalKey)?; @@ -700,8 +700,7 @@ impl ControlBlock { /// Serialize to a writer. Returns the number of bytes written pub fn encode(&self, mut writer: Write) -> io::Result { - let first_byte: u8 = - (if self.output_key_parity { 1 } else { 0 }) | self.leaf_version.as_u8(); + let first_byte: u8 = i32::from(self.output_key_parity) as u8 | self.leaf_version.as_u8(); let mut bytes_written = 0; bytes_written += writer.write(&[first_byte])?; bytes_written += writer.write(&self.internal_key.serialize())?; @@ -909,9 +908,8 @@ mod test { use hashes::hex::{FromHex, ToHex}; use hashes::sha256t::Tag; use hashes::{sha256, Hash, HashEngine}; - use secp256k1::VerifyOnly; + use secp256k1::{VerifyOnly, XOnlyPublicKey}; use core::str::FromStr; - use schnorr; extern crate serde_json; fn tag_engine(tag_name: &str) -> sha256::HashEngine { @@ -996,7 +994,7 @@ mod test { } fn _verify_tap_commitments(secp: &Secp256k1, out_spk_hex: &str, script_hex : &str, control_block_hex: &str) { - let out_pk = schnorr::PublicKey::from_str(&out_spk_hex[4..]).unwrap(); + let out_pk = XOnlyPublicKey::from_str(&out_spk_hex[4..]).unwrap(); let out_pk = TweakedPublicKey::dangerous_assume_tweaked(out_pk); let script = Script::from_hex(script_hex).unwrap(); let control_block = ControlBlock::from_slice(&Vec::::from_hex(control_block_hex).unwrap()).unwrap(); @@ -1152,7 +1150,7 @@ mod test { let secp = &secp256k1::Secp256k1::verification_only(); for arr in data["scriptPubKey"].as_array().unwrap() { - let internal_key = schnorr::PublicKey::from_str(arr["given"]["internalPubkey"].as_str().unwrap()).unwrap(); + let internal_key = XOnlyPublicKey::from_str(arr["given"]["internalPubkey"].as_str().unwrap()).unwrap(); // process the tree let script_tree = &arr["given"]["scriptTree"]; let mut merkle_root = None; @@ -1176,7 +1174,7 @@ mod test { assert_eq!(ctrl_blk, expected_ctrl_blk); } } - let expected_output_key = schnorr::PublicKey::from_str(arr["intermediary"]["tweakedPubkey"].as_str().unwrap()).unwrap(); + let expected_output_key = XOnlyPublicKey::from_str(arr["intermediary"]["tweakedPubkey"].as_str().unwrap()).unwrap(); let expected_tweak = TapTweakHash::from_str(arr["intermediary"]["tweak"].as_str().unwrap()).unwrap(); let expected_spk = Script::from_str(arr["expected"]["scriptPubKey"].as_str().unwrap()).unwrap(); let expected_addr = Address::from_str(arr["expected"]["bip350Address"].as_str().unwrap()).unwrap(); From 91470f56c8f655454fdaa68826cdb886eac8a244 Mon Sep 17 00:00:00 2001 From: sanket1729 Date: Fri, 7 Jan 2022 04:29:58 +0530 Subject: [PATCH 2/2] Uncomment sighash test We can check tweak add priv key with latest secp --- src/util/sighash.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/sighash.rs b/src/util/sighash.rs index 5a23c1e9..112a4cc2 100644 --- a/src/util/sighash.rs +++ b/src/util/sighash.rs @@ -1045,7 +1045,7 @@ mod tests { let expected_internal_pk = hex_hash!(XOnlyPublicKey, inp["intermediary"]["internalPubkey"].as_str().unwrap()); let expected_tweak = hex_hash!(TapTweakHash, inp["intermediary"]["tweak"].as_str().unwrap()); - let _expected_tweaked_priv_key = hex_hash!(SecretKey, inp["intermediary"]["tweakedPrivkey"].as_str().unwrap()); + let expected_tweaked_priv_key = hex_hash!(SecretKey, inp["intermediary"]["tweakedPrivkey"].as_str().unwrap()); let expected_sig_msg = Vec::::from_hex(inp["intermediary"]["sigMsg"].as_str().unwrap()).unwrap(); let expected_sig_hash = hex_hash!(TapSighashHash, inp["intermediary"]["sigHash"].as_str().unwrap()); let sig_str = inp["expected"]["witness"][0].as_str().unwrap(); @@ -1088,9 +1088,9 @@ mod tests { assert_eq!(expected_sig_hash, sig_hash); assert_eq!(expected_hash_ty, hash_ty); assert_eq!(expected_key_spend_sig, key_spend_sig); - // TODO: Uncomment these after a rust-secp release - // let tweaked_priv_key = SecretKey::from_keypair(&tweaked_keypair); - // assert_eq!(expected_tweaked_priv_key, tweaked_priv_key); + + let tweaked_priv_key = SecretKey::from_keypair(&tweaked_keypair); + assert_eq!(expected_tweaked_priv_key, tweaked_priv_key); } }