From 30e91cc766b6b1523bb8e4c93dbe74a45c097053 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 23 Apr 2024 12:58:14 +1000 Subject: [PATCH] Default to forward for tagged hashes Displaying backward is an anomaly of Bitcoin Core's early days and the double SHA256 hash type. We should not let this unfortunate beast leak out into other places. Default to displaying forward when creating a new tagged hash and remove all the explicit attributes from `bitcoin` that just clutter the code. --- bitcoin/src/crypto/sighash.rs | 1 - bitcoin/src/taproot/mod.rs | 3 --- hashes/src/sha256t.rs | 4 ++-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/bitcoin/src/crypto/sighash.rs b/bitcoin/src/crypto/sighash.rs index b786c9836..56d07e69b 100644 --- a/bitcoin/src/crypto/sighash.rs +++ b/bitcoin/src/crypto/sighash.rs @@ -61,7 +61,6 @@ sha256t_hash_newtype! { /// Taproot-tagged hash with tag \"TapSighash\". /// /// This hash type is used for computing taproot signature hash." - #[hash_newtype(forward)] pub struct TapSighash(_); } diff --git a/bitcoin/src/taproot/mod.rs b/bitcoin/src/taproot/mod.rs index 60ce28ee0..87318ada4 100644 --- a/bitcoin/src/taproot/mod.rs +++ b/bitcoin/src/taproot/mod.rs @@ -36,7 +36,6 @@ sha256t_hash_newtype! { /// Taproot-tagged hash with tag \"TapLeaf\". /// /// This is used for computing tapscript script spend hash. - #[hash_newtype(forward)] pub struct TapLeafHash(_); pub struct TapBranchTag = hash_str("TapBranch"); @@ -44,7 +43,6 @@ sha256t_hash_newtype! { /// Tagged hash used in taproot trees. /// /// See BIP-340 for tagging rules. - #[hash_newtype(forward)] pub struct TapNodeHash(_); pub struct TapTweakTag = hash_str("TapTweak"); @@ -52,7 +50,6 @@ sha256t_hash_newtype! { /// Taproot-tagged hash with tag \"TapTweak\". /// /// This hash type is used while computing the tweaked public key. - #[hash_newtype(forward)] pub struct TapTweakHash(_); } diff --git a/hashes/src/sha256t.rs b/hashes/src/sha256t.rs index 6a32831c1..6627048cc 100644 --- a/hashes/src/sha256t.rs +++ b/hashes/src/sha256t.rs @@ -66,7 +66,7 @@ impl core::hash::Hash for Hash { fn hash(&self, h: &mut H) { self.0.hash(h) } } -crate::internal_macros::hash_trait_impls!(256, true, T: Tag); +crate::internal_macros::hash_trait_impls!(256, false, T: Tag); fn from_engine(e: sha256::HashEngine) -> Hash { use crate::Hash as _; @@ -199,7 +199,7 @@ mod tests { #[test] #[cfg(feature = "alloc")] fn manually_created_sha256t_hash_type() { - assert_eq!(TestHash::hash(&[0]).to_string(), HASH_ZERO_BACKWARD); + assert_eq!(TestHash::hash(&[0]).to_string(), HASH_ZERO_FORWARD); } // We also provide a macro to create the tag and the hash type.