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.
This commit is contained in:
Tobin C. Harding 2024-04-23 12:58:14 +10:00
parent 5ecc69cd28
commit 30e91cc766
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
3 changed files with 2 additions and 6 deletions

View File

@ -61,7 +61,6 @@ sha256t_hash_newtype! {
/// Taproot-tagged hash with tag \"TapSighash\". /// Taproot-tagged hash with tag \"TapSighash\".
/// ///
/// This hash type is used for computing taproot signature hash." /// This hash type is used for computing taproot signature hash."
#[hash_newtype(forward)]
pub struct TapSighash(_); pub struct TapSighash(_);
} }

View File

@ -36,7 +36,6 @@ sha256t_hash_newtype! {
/// Taproot-tagged hash with tag \"TapLeaf\". /// Taproot-tagged hash with tag \"TapLeaf\".
/// ///
/// This is used for computing tapscript script spend hash. /// This is used for computing tapscript script spend hash.
#[hash_newtype(forward)]
pub struct TapLeafHash(_); pub struct TapLeafHash(_);
pub struct TapBranchTag = hash_str("TapBranch"); pub struct TapBranchTag = hash_str("TapBranch");
@ -44,7 +43,6 @@ sha256t_hash_newtype! {
/// Tagged hash used in taproot trees. /// Tagged hash used in taproot trees.
/// ///
/// See BIP-340 for tagging rules. /// See BIP-340 for tagging rules.
#[hash_newtype(forward)]
pub struct TapNodeHash(_); pub struct TapNodeHash(_);
pub struct TapTweakTag = hash_str("TapTweak"); pub struct TapTweakTag = hash_str("TapTweak");
@ -52,7 +50,6 @@ sha256t_hash_newtype! {
/// Taproot-tagged hash with tag \"TapTweak\". /// Taproot-tagged hash with tag \"TapTweak\".
/// ///
/// This hash type is used while computing the tweaked public key. /// This hash type is used while computing the tweaked public key.
#[hash_newtype(forward)]
pub struct TapTweakHash(_); pub struct TapTweakHash(_);
} }

View File

@ -66,7 +66,7 @@ impl<T: Tag> core::hash::Hash for Hash<T> {
fn hash<H: core::hash::Hasher>(&self, h: &mut H) { self.0.hash(h) } fn hash<H: core::hash::Hasher>(&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<T: Tag>(e: sha256::HashEngine) -> Hash<T> { fn from_engine<T: Tag>(e: sha256::HashEngine) -> Hash<T> {
use crate::Hash as _; use crate::Hash as _;
@ -199,7 +199,7 @@ mod tests {
#[test] #[test]
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
fn manually_created_sha256t_hash_type() { 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. // We also provide a macro to create the tag and the hash type.