From 34c31fed3a6ac13881e46178b48e3d23528151b2 Mon Sep 17 00:00:00 2001 From: Smaug Date: Wed, 27 Apr 2022 13:07:28 +0200 Subject: [PATCH] fix(primitives): Fix native scripts policy id (add missing tag) (#94) --- pallas-crypto/src/hash/hasher.rs | 8 ++++++++ pallas-primitives/src/alonzo/crypto.rs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pallas-crypto/src/hash/hasher.rs b/pallas-crypto/src/hash/hasher.rs index eaf55907..525349da 100644 --- a/pallas-crypto/src/hash/hasher.rs +++ b/pallas-crypto/src/hash/hasher.rs @@ -78,6 +78,14 @@ macro_rules! common_hasher { hasher.finalize() } + #[inline] + pub fn hash_tagged_cbor(data: &impl minicbor::Encode, tag: u8) -> Hash<{ $size / 8 }> { + let mut hasher = Self::new(); + hasher.input(&[tag]); + let () = minicbor::encode(data, &mut hasher).expect("Infallible"); + hasher.finalize() + } + /// consume the [`Hasher`] and returns the computed digest pub fn finalize(mut self) -> Hash<{ $size / 8 }> { use cryptoxide::digest::Digest as _; diff --git a/pallas-primitives/src/alonzo/crypto.rs b/pallas-primitives/src/alonzo/crypto.rs index bf1c548a..05dca73b 100644 --- a/pallas-primitives/src/alonzo/crypto.rs +++ b/pallas-primitives/src/alonzo/crypto.rs @@ -21,7 +21,7 @@ pub fn hash_plutus_data(data: &PlutusData) -> Hash<32> { impl NativeScript { pub fn to_hash(&self) -> Hash<28> { - Hasher::<224>::hash_cbor(self) + Hasher::<224>::hash_tagged_cbor(self, 0) } }