commit 2e9ba1d345d5016372267545af561800806b52f1
parent 9ceca3857e0d7ad4dfdf9535d3e0b3e3791cb667
Author: Jared Tobin <jared@jtobin.io>
Date: Wed, 4 Nov 2026 20:19:04 +0400
lib: rename hash_node to hash_node_split
Diffstat:
3 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/lib/Data/MSSMT/Internal.hs b/lib/Data/MSSMT/Internal.hs
@@ -24,9 +24,9 @@ module Data.MSSMT.Internal (
-- * Hashing
, native
, hash_leaf
- , hash_node
- , hash_node_native
- , hash_node_pure
+ , hash_node_split
+ , hash_node_split_native
+ , hash_node_split_pure
, hash_node_aggregate
, hash_node_aggregate_native
, hash_node_aggregate_pure
@@ -157,11 +157,11 @@ hash_leaf v s = unsafe_hash . SHA256.hash $
-- first 24 bytes of right, then the last 8 bytes of right || right
-- sum || 0x80 || 0^39 || 640 (the message length in bits, as a
-- big-endian 64-bit word).
-hash_node :: Hash -> Word64 -> Hash -> Word64 -> Hash
-hash_node l sl r sr
- | native = hash_node_native l sl r sr
- | otherwise = hash_node_pure l sl r sr
-{-# INLINE hash_node #-}
+hash_node_split :: Hash -> Word64 -> Hash -> Word64 -> Hash
+hash_node_split l sl r sr
+ | native = hash_node_split_native l sl r sr
+ | otherwise = hash_node_split_pure l sl r sr
+{-# INLINE hash_node_split #-}
-- | sha256(left || right || sum), the Taproot Assets branch hash.
--
@@ -197,9 +197,9 @@ iv = Hash
0x6a09e667bb67ae85 0x3c6ef372a54ff53a
0x510e527f9b05688c 0x1f83d9ab5be0cd19
--- | 'hash_node', via hardware SHA-256. Callers check 'native'.
-hash_node_native :: Hash -> Word64 -> Hash -> Word64 -> Hash
-hash_node_native l sl (Hash b0 b1 b2 b3) sr = case Exts.runRW# go of
+-- | 'hash_node_split', via hardware SHA-256. Callers check 'native'.
+hash_node_split_native :: Hash -> Word64 -> Hash -> Word64 -> Hash
+hash_node_split_native l sl (Hash b0 b1 b2 b3) sr = case Exts.runRW# go of
(# _, h #) -> h
where
go s0 =
@@ -220,9 +220,9 @@ hash_node_native l sl (Hash b0 b1 b2 b3) sr = case Exts.runRW# go of
case unIO (c_sha256_block st bk) s14 of { (# s15, () #) ->
get_hash st s15 }}}}}}}}}}}}}}}
--- | 'hash_node', in pure Haskell.
-hash_node_pure :: Hash -> Word64 -> Hash -> Word64 -> Hash
-hash_node_pure (Hash a0 a1 a2 a3) sl (Hash b0 b1 b2 b3) sr =
+-- | 'hash_node_split', in pure Haskell.
+hash_node_split_pure :: Hash -> Word64 -> Hash -> Word64 -> Hash
+hash_node_split_pure (Hash a0 a1 a2 a3) sl (Hash b0 b1 b2 b3) sr =
let !r0 = SHA256I.iv ()
!r1 = SHA256I.update r0 $ SHA256I.B
(hi a0) (lo a0) (hi a1) (lo a1) (hi a2) (lo a2) (hi a3) (lo a3)
@@ -321,7 +321,7 @@ get_hash a s0 =
-- | A branch hashing scheme.
data Scheme =
- -- | Branches commit to each child's hash and sum, via 'hash_node'.
+ -- | Branches commit to each child's hash and sum, via 'hash_node_split'.
Split
-- | Branches commit to their children's hashes and the sum of their
-- sums, via 'hash_node_aggregate', as in Taproot Assets.
@@ -330,7 +330,7 @@ data Scheme =
-- branch hash under a scheme; callers rule out sum overflow
hash_branch :: Scheme -> Hash -> Word64 -> Hash -> Word64 -> Hash
-hash_branch Split l sl r sr = hash_node l sl r sr
+hash_branch Split l sl r sr = hash_node_split l sl r sr
hash_branch Aggregate l sl r sr = hash_node_aggregate l r (sl + sr)
{-# INLINE hash_branch #-}
diff --git a/test/Main.hs b/test/Main.hs
@@ -84,10 +84,10 @@ hashing = testGroup "hashing" $ [
Q.testProperty "hash_leaf ~ reference" $ \v -> Q.forAll big $ \s ->
serialize_hash (I.hash_leaf (BS.pack v) s)
Q.=== R.hash_leaf (BS.pack v) s
- , split "hash_node_pure" I.hash_node_pure
+ , split "hash_node_split_pure" I.hash_node_split_pure
, aggregate "hash_node_aggregate_pure" I.hash_node_aggregate_pure
]
- <> [ split "hash_node_native" I.hash_node_native | I.native ]
+ <> [ split "hash_node_split_native" I.hash_node_split_native | I.native ]
<> [ aggregate "hash_node_aggregate_native" I.hash_node_aggregate_native
| I.native
]
@@ -96,7 +96,7 @@ hashing = testGroup "hashing" $ [
Q.forAll gen_hash $ \l -> Q.forAll big $ \sl ->
Q.forAll gen_hash $ \r -> Q.forAll big $ \sr ->
serialize_hash (f l sl r sr)
- Q.=== R.hash_node (serialize_hash l) sl (serialize_hash r) sr
+ Q.=== R.hash_node_split (serialize_hash l) sl (serialize_hash r) sr
aggregate name f = Q.testProperty (name <> " ~ reference") $
Q.forAll gen_hash $ \l -> Q.forAll gen_hash $ \r ->
Q.forAll big $ \s ->
diff --git a/test/Reference.hs b/test/Reference.hs
@@ -2,7 +2,7 @@
module Reference (
hash_leaf
- , hash_node
+ , hash_node_split
, hash_node_aggregate
, root
, root_aggregate
@@ -28,8 +28,8 @@ hash_leaf :: BS.ByteString -> Word64 -> BS.ByteString
hash_leaf v s = sha256 (BSB.byteString v <> BSB.word64BE s)
-- sha256(left || left sum || right || right sum)
-hash_node :: Branch
-hash_node l sl r sr = sha256 $
+hash_node_split :: Branch
+hash_node_split l sl r sr = sha256 $
BSB.byteString l <> BSB.word64BE sl <> BSB.byteString r <> BSB.word64BE sr
-- sha256(left || right || sum)
@@ -41,7 +41,7 @@ hash_node_aggregate l r s = sha256 $
-- the root hash and sum of the tree holding the given leaves, keyed
-- by 32-byte keys
root :: M.Map BS.ByteString (BS.ByteString, Word64) -> (BS.ByteString, Word64)
-root = root_by hash_node
+root = root_by hash_node_split
root_aggregate
:: M.Map BS.ByteString (BS.ByteString, Word64) -> (BS.ByteString, Word64)