mssmt (empty) → 0.1.0
raw patch · 19 files changed
+4121/−0 lines, 19 filesdep +aesondep +basedep +bytestring
Dependencies added: aeson, base, bytestring, containers, criterion, deepseq, mssmt, ppad-base16, ppad-sha256, primitive, tasty, tasty-hunit, tasty-quickcheck, weigh
Files
- CHANGELOG +10/−0
- LICENSE +20/−0
- bench/Alloc.hs +47/−0
- bench/Fixtures.hs +102/−0
- bench/Main.hs +74/−0
- bench/Weight.hs +52/−0
- etc/mssmt_tree_deletion.json +45/−0
- etc/mssmt_tree_error_cases.json +42/−0
- etc/mssmt_tree_proofs.json too large to diff
- etc/mssmt_tree_replacement.json +1519/−0
- lib/Data/MSSMT.hs +27/−0
- lib/Data/MSSMT/Aggregate.hs +110/−0
- lib/Data/MSSMT/Hash.hs +359/−0
- lib/Data/MSSMT/Internal.hs +640/−0
- lib/Data/MSSMT/Split.hs +118/−0
- mssmt.cabal +131/−0
- test/Main.hs +517/−0
- test/Reference.hs +103/−0
- test/Vectors.hs +205/−0
+ CHANGELOG view
@@ -0,0 +1,10 @@+# Changelog++- 0.1.0 (2026-11-05)+ * Initial release, supporting in-memory Merkle-Sum Sparse Merkle Trees+ whose branches commit to the hash and sum of each of their children+ ("Data.MSSMT.Split"), or to their children's hashes and the sum of+ their sums ("Data.MSSMT.Aggregate"), with insertion (one at a time or+ batched), deletion, lookup, and inclusion and exclusion proofs.+ * Trees may be held partly elsewhere, as in a store, with operations+ loading only the paths they touch ("Data.MSSMT.Internal").
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2026 Jared Tobin++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ bench/Alloc.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}++-- Bytes allocated per operation, measured over distinct inputs so that+-- no result can be shared between runs. Run with +RTS -s for the+-- process's totals as well.++module Main where++import Control.DeepSeq (NFData, force)+import Control.Exception (evaluate)+import Control.Monad (forM_)+import Data.MSSMT+import Fixtures+import GHC.Stats (allocated_bytes, getRTSStats)+import Prelude hiding (lookup)+import System.Mem (performMajorGC)+import Text.Printf (printf)++-- mean bytes allocated by evaluating f on each input to normal form+per :: NFData b => (a -> b) -> [a] -> IO Double+per f xs = do+ performMajorGC+ a <- allocated_bytes <$> getRTSStats+ forM_ xs $ \x -> evaluate (force (f x))+ performMajorGC+ b <- allocated_bytes <$> getRTSStats+ pure (fromIntegral (b - a) / fromIntegral (length xs))++main :: IO ()+main = do+ Fixtures {..} <- evaluate (force fixtures)+ -- the keys in the 1024-leaf fixture tree, and as many not in it+ ins <- evaluate (force [k | (k, _, _) <- leaves 1024])+ outs <- evaluate (force [k | (k, _, _) <- drop 1024 (leaves 2048)])+ proofs <- evaluate $+ force [(k, v, s, prove k f_tree) | (k, v, s) <- leaves 1024]+ let run name m = m >>= printf "%-24s %8.0f bytes\n" (name :: String)+ run "baseline" (per (const ()) ins)+ run "insert, fresh key" (per (\k -> insert k "v" 1 f_tree) outs)+ run "insert, replace" (per (\k -> insert k "v" 1 f_tree) ins)+ run "delete, present" (per (`delete` f_tree) ins)+ run "lookup, present" (per (`lookup` f_tree) ins)+ run "prove, inclusion" (per (`prove` f_tree) ins)+ run "prove, exclusion" (per (`prove` f_tree) outs)+ run "verify, inclusion" $+ per (\(k, v, s, p) -> verify k v s p f_root) proofs
+ bench/Fixtures.hs view
@@ -0,0 +1,102 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# LANGUAGE BangPatterns #-}++module Fixtures (+ Fixtures(..)+ , fixtures+ , leaves+ , build+ ) where++import Control.DeepSeq+import Control.Monad (foldM)+import qualified Crypto.Hash.SHA256 as SHA256+import Data.Bits (bit, testBit, xor)+import qualified Data.ByteString as BS+import qualified Data.ByteString.Char8 as B8+import Data.MSSMT+import qualified Data.MSSMT.Internal as I+import Data.Void (Void)+import Data.Word (Word64)++-- all fields are strict, so WHNF is NF+instance NFData Key where+ rnf = rwhnf++instance NFData Commitment where+ rnf = rwhnf++instance NFData Tree where+ rnf = rwhnf++instance NFData Neighbor where+ rnf = rwhnf++instance NFData Proof where+ rnf (Proof nb ps) = rnf nb `seq` rnf ps++-- | A tree of 1024 leaves, its root, a leaf in it, a key not in it+-- whose slot is empty, their proofs, and a key not in it whose slot+-- the leaf occupies.+data Fixtures = Fixtures {+ f_tree :: !Tree+ , f_root :: !Commitment+ , f_key :: !Key+ , f_value :: !BS.ByteString+ , f_sum :: !Word64+ , f_proof :: !Proof+ , f_out :: !Key+ , f_xproof :: !Proof+ , f_near :: !Key+ }++instance NFData Fixtures where+ rnf (Fixtures t r k v s p o x n) =+ rnf t `seq` rnf r `seq` rnf k `seq` rnf v `seq` rnf s+ `seq` rnf p `seq` rnf o `seq` rnf x `seq` rnf n++fixtures :: Fixtures+fixtures = Fixtures t (root t) k v s (prove k t) o (prove o t) n where+ t = build (leaves 1024)+ (k, v, s) = leaf_of 1+ o = key_of 0+ n = near k raw+ raw = case foldM ins I.empty (leaves 1024) of+ Just r -> r+ Nothing -> error "bang"+ ins r (k', v', s') = I.complete (I.insert_with I.Split k' v' s' r)++-- a key whose path ends at the given key's leaf, diverging from it just+-- beneath: the given key, with the bit beneath its leaf flipped+near :: Key -> I.Tree Void -> Key+near (I.Key h) = flip_at . go 0 where+ bs = I.serialize_hash h+ go :: Int -> I.Tree Void -> Int+ go !d t = case t of+ I.Node l _ r -> go (d + 1) (if kbit d then r else l)+ I.Leaf {} -> d+ I.Empty -> d+ kbit d = testBit (BS.index bs (d `quot` 8)) (d `rem` 8)+ flip_at d = case BS.splitAt (d `quot` 8) bs of+ (a, b) | Just (w, c) <- BS.uncons b+ , Just n <- key (a <> BS.cons (w `xor` bit (d `rem` 8)) c) -> n+ _ -> error "bang"++-- | n distinct leaves.+leaves :: Int -> [(Key, BS.ByteString, Word64)]+leaves n = fmap leaf_of [1 .. n]++leaf_of :: Int -> (Key, BS.ByteString, Word64)+leaf_of i =+ (key_of i, SHA256.hash (B8.pack ('v' : show i)), fromIntegral i)++key_of :: Int -> Key+key_of i = case key (SHA256.hash (B8.pack (show i))) of+ Just k -> k+ Nothing -> error "bang"++-- | Build a tree from leaves.+build :: [(Key, BS.ByteString, Word64)] -> Tree+build ls = case foldM (\t (k, v, s) -> insert k v s t) empty ls of+ Just t -> t+ Nothing -> error "bang"
+ bench/Main.hs view
@@ -0,0 +1,74 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}++module Main where++import Control.Monad (foldM)+import Criterion.Main+import Data.MSSMT+import Fixtures+import Prelude hiding (lookup)++main :: IO ()+main = defaultMain [+ env (pure fixtures) $ \ ~f -> bgroup "mssmt" [+ bench_insert f+ , bench_delete f+ , bench_lookup f+ , bench_prove f+ , bench_verify f+ , bench_build+ , bench_insert_many f+ ]+ ]++bench_insert :: Fixtures -> Benchmark+bench_insert ~Fixtures {..} = bgroup "insert" [+ bench "empty tree" $ nf (insert f_out "v" 1) empty+ , bench "1024 leaves, fresh key" $ nf (insert f_out "v" 1) f_tree+ , bench "1024 leaves, fresh key in a leaf's slot" $+ nf (insert f_near "v" 1) f_tree+ , bench "1024 leaves, replace" $ nf (insert f_key "v" 1) f_tree+ ]++bench_delete :: Fixtures -> Benchmark+bench_delete ~Fixtures {..} = bgroup "delete" [+ bench "1024 leaves, present" $ nf (delete f_key) f_tree+ , bench "1024 leaves, absent" $ nf (delete f_out) f_tree+ ]++bench_lookup :: Fixtures -> Benchmark+bench_lookup ~Fixtures {..} = bgroup "lookup" [+ bench "1024 leaves, present" $ nf (lookup f_key) f_tree+ , bench "1024 leaves, absent" $ nf (lookup f_out) f_tree+ ]++bench_prove :: Fixtures -> Benchmark+bench_prove ~Fixtures {..} = bgroup "prove" [+ bench "1024 leaves, inclusion" $ nf (prove f_key) f_tree+ , bench "1024 leaves, exclusion" $ nf (prove f_out) f_tree+ , bench "1024 leaves, exclusion in a leaf's slot" $+ nf (prove f_near) f_tree+ ]++bench_verify :: Fixtures -> Benchmark+bench_verify ~Fixtures {..} = bgroup "verify" [+ bench "inclusion" $ nf (verify f_key f_value f_sum f_proof) f_root+ , bench "exclusion" $ nf (verify f_out mempty 0 f_xproof) f_root+ ]++bench_build :: Benchmark+bench_build = env (pure (leaves 64)) $ \ls -> bgroup "build (64 leaves)" [+ bench "one at a time" $ nf build ls+ , bench "batched" $ nf (insert_many ls) empty+ ]++bench_insert_many :: Fixtures -> Benchmark+bench_insert_many ~Fixtures {..} =+ env (pure (drop 1024 (leaves 1088))) $ \ls ->+ bgroup "insert 64 leaves into 1024" [+ bench "one at a time" $ nf (\t -> foldM ins t ls) f_tree+ , bench "batched" $ nf (insert_many ls) f_tree+ ]+ where+ ins t (k, v, s) = insert k v s t
+ bench/Weight.hs view
@@ -0,0 +1,52 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}++module Main where++import Control.DeepSeq+import Data.MSSMT+import Fixtures+import Prelude hiding (lookup)+import Weigh++-- note that 'weigh' doesn't work properly in a repl+main :: IO ()+main = do+ let !f = force fixtures+ !ls = force (leaves 64)+ mainWith $ do+ insert_ f+ delete_ f+ lookup_ f+ prove_ f+ verify_ f+ func "build (64 leaves)" build ls++insert_ :: Fixtures -> Weigh ()+insert_ Fixtures {..} = wgroup "insert" $ do+ func "empty tree" (insert f_out "v" 1) empty+ func "1024 leaves, fresh key" (insert f_out "v" 1) f_tree+ func "1024 leaves, fresh key in a leaf's slot" (insert f_near "v" 1) f_tree+ func "1024 leaves, replace" (insert f_key "v" 1) f_tree++delete_ :: Fixtures -> Weigh ()+delete_ Fixtures {..} = wgroup "delete" $ do+ func "1024 leaves, present" (delete f_key) f_tree+ func "1024 leaves, absent" (delete f_out) f_tree++lookup_ :: Fixtures -> Weigh ()+lookup_ Fixtures {..} = wgroup "lookup" $ do+ func "1024 leaves, present" (lookup f_key) f_tree+ func "1024 leaves, absent" (lookup f_out) f_tree++prove_ :: Fixtures -> Weigh ()+prove_ Fixtures {..} = wgroup "prove" $ do+ func "1024 leaves, inclusion" (prove f_key) f_tree+ func "1024 leaves, exclusion" (prove f_out) f_tree+ func "1024 leaves, exclusion in a leaf's slot" (prove f_near) f_tree++verify_ :: Fixtures -> Weigh ()+verify_ Fixtures {..} = wgroup "verify" $ do+ func "inclusion" (verify f_key f_value f_sum f_proof) f_root+ func "exclusion" (verify f_out mempty 0 f_xproof) f_root
+ etc/mssmt_tree_deletion.json view
@@ -0,0 +1,45 @@+{+ "all_tree_leaves": [+ {+ "key": "0100000000000000000000000000000000000000000000000000000000000000",+ "node": {+ "value": "4f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2c64981855ad8681d0d86d1e91e00167939cb6694d2c422acd208a0072939487f6999eb9d18a44784045d87f3c67cf22746e995af5a25367951baa2ff6cd471c4",+ "sum": "2775174756"+ }+ },+ {+ "key": "0200000000000000000000000000000000000000000000000000000000000000",+ "node": {+ "value": "83f15fb9680b4e7c8b763a1b1d49d4955c8486216325253fec738dd7a9e28bf921119c160f0702448615bbda08313f6a8eb668d20bf5059875921e668a5bdf2c7fc4844592d2572bcd0668d2d6c52f5054e2d0836bf84c7174cb7476364cc3dbd968b0f7172ed85794bb358b0c3b525da1786f9fff094279db1944ebd7a19d0f7bbacbe0255aa5b7d44bec40f84c892b9bffd43629b0223beea5f4f74391f445d15afd4294040374f6924b98cbf8713f8d962d7c8d019192c24224e2cafccae3a61fb586b14323a6bc8f9e7df1d929333ff993933bea6f5b3af6de0374366c4719e43a1b067d89bc7f01f1f573981659",+ "sum": "3808566791"+ }+ },+ {+ "key": "0400000000000000000000000000000000000000000000000000000000000000",+ "node": {+ "value": "a44f7dbb5722f5717a289a266f97647981998ebea89c0b4b373970115e82ed6f4125c8fa7311e4d7defa922daae7786667f7e936cd4f24abf7df866baa56",+ "sum": "1027230157"+ }+ }+ ],+ "valid_test_cases": [+ {+ "root_hash": "c290ff98be50aa38892c07d61b41ff20e19b76d46cbe993d0c3e87411d0d1af6",+ "root_sum": "2775174756",+ "inserted_leaves": [+ "0100000000000000000000000000000000000000000000000000000000000000",+ "0200000000000000000000000000000000000000000000000000000000000000",+ "0400000000000000000000000000000000000000000000000000000000000000"+ ],+ "deleted_leaves": [+ "0200000000000000000000000000000000000000000000000000000000000000",+ "0400000000000000000000000000000000000000000000000000000000000000"+ ],+ "replaced_leaves": null,+ "inclusion_proofs": null,+ "exclusion_proofs": null,+ "comment": "sub tree deletion"+ }+ ],+ "error_test_cases": null+}
+ etc/mssmt_tree_error_cases.json view
@@ -0,0 +1,42 @@+{+ "all_tree_leaves": [+ {+ "key": "5f0f9a621d729566c74d10037c4d7bbb0407d1e2c64981855ad8681d0d86d1e9",+ "node": {+ "value": "52fdfc072182654f163f",+ "sum": "1"+ }+ },+ {+ "key": "1e00167939cb6694d2c422acd208a0072939487f6999eb9d18a44784045d87f3",+ "node": {+ "value": "52fdfc072182654f163f",+ "sum": "18446744073709551615"+ }+ }+ ],+ "valid_test_cases": [+ {+ "root_hash": "3aef57ab466f3b8eebd90dc155816684553fc5f8888ffa95fe9944ee5a71c8ea",+ "root_sum": "1",+ "inserted_leaves": [+ "5f0f9a621d729566c74d10037c4d7bbb0407d1e2c64981855ad8681d0d86d1e9"+ ],+ "deleted_leaves": null,+ "replaced_leaves": null,+ "inclusion_proofs": null,+ "exclusion_proofs": null,+ "comment": "non overflowing leaf"+ }+ ],+ "error_test_cases": [+ {+ "inserted_leaves": [+ "5f0f9a621d729566c74d10037c4d7bbb0407d1e2c64981855ad8681d0d86d1e9",+ "1e00167939cb6694d2c422acd208a0072939487f6999eb9d18a44784045d87f3"+ ],+ "error": "integer overflow",+ "comment": "overflowing leaf"+ }+ ]+}
+ etc/mssmt_tree_proofs.json view
file too large to diff
+ etc/mssmt_tree_replacement.json view
@@ -0,0 +1,1519 @@+{+ "all_tree_leaves": [+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000000",+ "node": {+ "value": "4f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2c64981855ad8681d0d86d1e91e00167939cb6694d2c422acd208a0072939487f6999eb9d18a44784045d87f3c67cf22746e995af5a25367951baa2ff6cd471c4",+ "sum": "2775174756"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000001",+ "node": {+ "value": "83f15fb9680b4e7c8b763a1b1d49d4955c8486216325253fec738dd7a9e28bf921119c160f0702448615bbda08313f6a8eb668d20bf5059875921e668a5bdf2c7fc4844592d2572bcd0668d2d6c52f5054e2d0836bf84c7174cb7476364cc3dbd968b0f7172ed85794bb358b0c3b525da1786f9fff094279db1944ebd7a19d0f7bbacbe0255aa5b7d44bec40f84c892b9bffd43629b0223beea5f4f74391f445d15afd4294040374f6924b98cbf8713f8d962d7c8d019192c24224e2cafccae3a61fb586b14323a6bc8f9e7df1d929333ff993933bea6f5b3af6de0374366c4719e43a1b067d89bc7f01f1f573981659",+ "sum": "3808566791"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000002",+ "node": {+ "value": "a44f7dbb5722f5717a289a266f97647981998ebea89c0b4b373970115e82ed6f4125c8fa7311e4d7defa922daae7786667f7e936cd4f24abf7df866baa56",+ "sum": "1027230157"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000003",+ "node": {+ "value": "0383673a0ad8be9c3978b04883e56a156a8de563afa467d49dec6a40e9a1d007f033c2823061bdd0eaa59f8e4da6430105220d0b29688b734b8ea0f3ca9936e8461f10d77c96ea80a7a665f606f6a63b7f3dfd2567c18979e4d60f26686d9bf2fb26c901ff354cde1607ee294b39f32b7c7822ba64f84ab43ca0c6e6b91c1fd3be8990434179d3af4491a369012db92d184fc39d1734ff5716428953bb6865fcf92b0c3a17c9",+ "sum": "3206327371"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000004",+ "node": {+ "value": "028be9914ea54c3deab2a4b4475d63afbe8fb56987c77f5818526f1814be823350eab13935f31d84484517e924aef78ae151c00755925836b7075885650c30ec29a3703934bf50a28da102975deda77e758579ea3dfe41",+ "sum": "146173984"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000005",+ "node": {+ "value": "36ab75045f8efd69d22ae5411947cb553d7694267aef4ebcea406b32d6108bd68584f57e37caac6e33feaa3263a399437024ba9c9b14678a274f01a910ae295f6efbfe5f5abf44ccde263b5606633e2bf0006f28295d7d39069f01a239c4365854c3af7f6b41d631f92b9a8d12f41257325fff332f7576b0620556304a3e3eae14c28d0cea39d2901a52720da85ca1e4b38eaf3f44c6c6ef8362f2f54fc00e09d6fc25640854c15dfcacaa8a2cecce5a3aba53ab705b18db94b4d338a5143e63408d8724",+ "sum": "2801355319"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000006",+ "node": {+ "value": "b0cf2c4160f38ee9e2a9f3fb4ffb0019b454d522b5ffa17604193fb8966710a7960732ca52cf53c3f520c889b79bf504cfb57c7601232d589baccea9d6e263e25c27741d3f6c62cbbb15d9afbcbf7f7da41ab0408e39",+ "sum": "1500730"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000007",+ "node": {+ "value": "9a4f091e9a83fdeae0ec55eb233a9b5394cb3c7856b546d313c8a3b4c1c0e05447f4ba370eb36dbcfdec90b302dcdc3b9ef522e2a6f1ed0afec1f8e20faabedf6b162e717d3a748a58677a0c56348f8921",+ "sum": "1686506880"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000008",+ "node": {+ "value": "a266b1948b6570ffa0b773963c130ad797ddeafe4e3ad29b5125210f0ef1c314090f07c79a6f",+ "sum": "2028254870"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000009",+ "node": {+ "value": "b00ce73bff706f7ff4b6f44090a32711f3208e4e4b89cb5165ce64002cbd9c2887aa113df2468928d5a23b9ca740f80c9382d9c6034ad2960c796503e1ce221725f50caf1fbfe831b10b7bf5b15c47",+ "sum": "356729937"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000000a",+ "node": {+ "value": "a53dbf8e7d47f74aa594468ced323cb76f0d3fac476c9fb03fc9228fbae88fd580663a0454b68312207f0a3b584c62316492b49753b5d5027ce15a4f0a58250d",+ "sum": "1109697861"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000000b",+ "node": {+ "value": "8fb50e77be6fb77970466a5626fe33408cf9e88e2c797408a32d29416baf206a329cfffd4a75e498320982c85aad70384859c05a4b13a1d5b2f5bfef5a6ed92da482caa9568e5b6fe9d8a9ddd9eb09277b92cef9046efa18500944cbe800a0b1527ea64729a861d2f6497a3235c37f4192779ec1d96b3b1c5424fce0b727b03072e6415a761f03abaa40abc9448fddeb2191d945c047",+ "sum": "1004036031"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000000c",+ "node": {+ "value": "674affabe3037ffe7fa68aa8af5e39cc416e734d373c5ebebc9cdcc595bcce3c7bd3d8df93fab7e125ddebafe65a31bd5d41e2d2ce9c2b17892f0fea1931a290220777a93143dfdcbfa68406e877073ff08834e197a4034aa48afa3f85b8a62708caebbac880b5b89b93da53810164402104e648b6226a1b78021851f5d9ac0f313a89ddfc454c5f8f72ac89b38b19f53784c19e9beac03c875a27db029de37ae37a42318813487685929359ca8c5eb94e152dc1af42ea3d1676c1bdd19ab8e2925c6daee4de5ef9f9dcf08dfcbd02b80809398585928a0f7de50be1a6dc1d5768e8537988fddce562e9b948c918bba3e933e5c400cde5",+ "sum": "1892881108"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000000d",+ "node": {+ "value": "e60c5ead6fc7d728b45347eada650af24c56d0800a8691332088a805bd55c446e25eb07590bafcccbec6177536401d9a2b7f512b54bfc9d00532adf5aaa7c3a96bc59b489f77d9042c5bce26b163defde5ee6a0fbb3e9346cef81f0ae9515ef30fa47a364e75aea9e111d596e685a591121966e031650d510354aa845580ff560760fd36514ca197c875f1d02d9216eba7627e2398322eb5cf43d72bd2e5b887d4630fb8d4747ead6eb82acd1c5b078143ee26a586ad23139d5041723470bf24a865837c9123461c41f5ff99aa99",+ "sum": "2549328945"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000000e",+ "node": {+ "value": "ce24eb297b9fa007864bafd7cd4ca1b2fb5766ab431a032b72b9a7e937ed648d0801f29055d3090d2463718254f94424",+ "sum": "1065949414"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000000f",+ "node": {+ "value": "83c7b98b1a493f321f0966603022c1dfc579b99ed9d20d573ad53171c8fef7f1f4e4613bb365b2ebb44f0ffb6907136385cdc838f0bdd4c812f042577410aca008c2afbc4c79c62572e20f8ed94ee62b4de7aa1cc84c887e1f7c31e927dfe52a5f8f46627eb5d3a4fe16",+ "sum": "316736257"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000010",+ "node": {+ "value": "fafce2589733e563e19d3045aad3e226488ac02cca4291aed169dce5039d6ab00e40f67aab29332de1448b35507c7c8a09c4db07105dc31003620405da3b2169f5a910c9d0096e5e3ef1b570680746acd0cc7760331b663138d6d342b051b5df410637cf7aee9b0c8c10a8f9980630f34ce001c0ab7ac65e502d39b216cbc50e73a32eaf936401e2506bd8b82c30d346bc4b2fa319f245a8657ec122eaf4ad5425c249ee160e17b95541c2aee5df820ac85de3f8e784870fd87a36cc0d163833df636613a9cc947437b6592835b9f6f4f8c0e70dbeebae7b14cdb9bc4103",+ "sum": "2951784240"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000011",+ "node": {+ "value": "3aa5baf40db8409a7cbf05ae21f97425254543d94d115900b90ae703b97d98",+ "sum": "3263939470"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000012",+ "node": {+ "value": "56d2ddd9daa7ccbb7500dae4e2e5df8cf3859ebddada6745fba6a04c5c37c7ca35036f11732ce8bc27b48868611fc73c82a491bfabd7a19df50fdc78a55dbbc2fd37f9296566557fab885b03",+ "sum": "3630813544"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000013",+ "node": {+ "value": "9f30e797b8ad99408fe1e037c68bf7c5e5de1d2c68192348ec1189fb2e36973cef09ff14be23922801f6eaee41409158b45f2dec82d17caaba160cd640ff73495fe4a05ce1202ca7287ed3235b95e69f571fa5e656aaa51fae1ebdd7aa6269c2ec7f4057b33593bc84888c970fd528d4a99a1eab9d2420134537cd6d02282e0981e140232a4a87383a21d1845c408ad757043813032a0bd5a30dcca6e3aa2df04715d879279a96879a4f3690ac2025a60c7db15e0501ebc34b734355fe4a059bd3899d920e95f1c46d432f9b08e64d7f9b38965d5a77a7ac183c3833e1a3425ead69d4f975012fd1a49ed832f69e6e9c63b453ec049c",+ "sum": "2709129610"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000014",+ "node": {+ "value": "9e7af6506ad3fdb1f4415b0af9ce8c208bc20ee526741539fa3203c77ecba410fd6718f227e0b430f9bcb0",+ "sum": "2494494336"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000015",+ "node": {+ "value": "49cd42a708a721aa29987b45d4e428811984ecad349cc35dd93515cefe0b002cee5e71c47935e281ebfc4b8b652b69ccb092e55a20f1b9f97d046296124621928739a86671cc180152b953e3bf9d19f825c3dd54ae1688e49efb5efe65dcdad34bc860010e7c8c997c",+ "sum": "452271480"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000016",+ "node": {+ "value": "d5f057832f3f36d7d893e216e4c7",+ "sum": "920050048"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000017",+ "node": {+ "value": "bbc69776b4591532da1c5be68ef4eebe",+ "sum": "1648433865"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000018",+ "node": {+ "value": "8cb8fa7dc548fa086197ff5dfd02f2ba3884c53dd718c8560da743a8e9d4aeae20ccef002d82ca352592b8d8f2a8df3b0c35f15b9b370dca80d4ca8e9a133eb520",+ "sum": "2745290810"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000019",+ "node": {+ "value": "94f2dd5c0658b480f2ac84233633957e688e924ffe3713b52c76fd8a56da8bb07daa8eb4eb8f7334f99256e2766a4109150eed424f0f743543cdea66e5baaa03edc918e8305bb19fc0c6b4ddb4aa3886cb5090940fc6d4cabe2153809e4ed60a0e2af07f1b2a6bb5a6017a578a27cbdc20a1759f76b0889a",+ "sum": "1852568093"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000001a",+ "node": {+ "value": "83",+ "sum": "1055175982"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000001b",+ "node": {+ "value": "ce257873db7635516e87b33e4b412ba3df68544920f5ea27ec097710954f42158bdba66d4814c064b4112538676095467c89ba98e6a543758d7093a494df5cc36d09c7a6472a41f29c380a987b1ecdcf84765f",+ "sum": "1383341063"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000001c",+ "node": {+ "value": "4e5d3cc1ef53c9ae0d8869fe67fdc7a2c67b425f13c5be8d9f630c1d063c02fd75cf64c1aec9d2e2ef6e6431d5f5ad0489078dc61f46494dccf403dad7f094170d2c3e29c198b0f341e284c4be8fa60c1a478d6bd55dd2c04dad86d2053d5d25b014e3d8b64322cdcb5004faa46cfa2d6ad2ff933bc3bd9a5a74660af3d048a9a43634c0250427d9a6219197a3f3633f841753ba7c27f3619f387b6b1a6cb9c1dc227674aa020724d137da2cb87b1615d512974fa4747dd1e17d02c9462a44fec150ca3a8f99cc1e4953365e4299565e10",+ "sum": "3035641021"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000001d",+ "node": {+ "value": "8535b1f63f7fb3a126c860830a87293d9271da736e4398c1e37fb75c4bf02786e1faf4b610cd1377fbb9ae180655a0abefbad700c09473469f1eca5a66d53fa3dc7cd3e7c3b0411d7e145f96eb9654ab94913dda503a50f9e773842f4d2a5faa60869bf365830511f2ededd03e0a73000edb60c9a29a5f5e194cf3b5667a694690384599d116f8d2fd93b2aed55b7d44b5b054f3f38e788e4fdf36e591568c41d1052cad0fcb68ca4c4bf509",+ "sum": "45696965"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000001e",+ "node": {+ "value": "1adb7efb087a5604",+ "sum": "2981227368"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000001f",+ "node": {+ "value": "e9e22b4d54db59f0554c58251342134a8daaef1498069ba581ef1da2510be92843487a4eb8111c79a6f0195fc38ad6aee93c1df2b5897eaa38ad8f47ab2fe0e3aa3e6accbfd4c16d468433185fc61c861b96ca65e34d31f24d6f56ee85092314a4d7656205c15322f1c97613c079eae292ba966e10d1e700164e518b243f424c46f9",+ "sum": "1693462417"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000020",+ "node": {+ "value": "ea636226517b805a072512a5e4cd274b7fd1fa23f830058208ff1a063b41039c74036b5b3da8b1a0b93135a710352da0f6c31203a09d1f2329651bb3ab3984ab591f2247e71cd44835e7a1a1b66d8595f7aef9bf39d1417d2d31ea3599d405ff4b5999a86f52f3259b452909b57937d85364d6c23deb4f14e0d9fcee9184df5994fdc11f045c025c8d561adb0e7d",+ "sum": "557869130"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000021",+ "node": {+ "value": "cdb3fd88e48b2e7eb7ae5dae994cb5eae3eaf21cf9005db560d6d22e4d9b97d7e9e488751afcd72aa176c0fcde9316f676fd527d9c42105b851639f09ea70533d26fc60cbeb4b76ed554fc99177620b28ca6f56a716f8cb384811c3e356e7c",+ "sum": "2167453402"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000022",+ "node": {+ "value": "793acfb2a6c20723c1b9f003e115b304c023792448794546a2474f04294d7a616215e5dd6c40a65bb6edb508c3680b14c176c327fdfb1ee21962c0006b7deb4e5de87db21989d13c3ab0462d5d2a52ef4ca0d366ae06a314f50e3a21d9247f814037798cc5e10a63de027477decdeb8a8e0c279299272490106ddf8683126f60d35772c6dfc744b0adbf",+ "sum": "1643456740"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000023",+ "node": {+ "value": "d5dcf118c446976647d1c1d3f8f6237c6218fa86fb47080b1f7966137667bd6661660c43b75b63390b514bbe491aa46b524bde1c5b7456255fb214c3f74907b7ce1cba94210b78b5e68f049fcb002b96a5d38d59df6e977d587abb42d0972d5f3f",+ "sum": "2922392294"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000024",+ "node": {+ "value": "fc898b3cbec2dd276ee1f43c8cd7e92a993eb15107d02f59ba75f8dd1442ee37786ddb902deb88dd0ebdbf229fb25a9dca86d0ce46a278a45f5517bff2c049cc959a227dcdd3aca677e96ce84390e9b9a28e09887773",+ "sum": "840730988"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000025",+ "node": {+ "value": "31847a591af95e16f248ab03da494112449ce7bdace6c988292f95699bb5e4d9c8d250aa28a6df44c0c265156deb27e9476a0a4af44f34bdf631b4af1146afe34ea988fc953e71fc21ce60b3962313000fe46d75",+ "sum": "2894878065"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000026",+ "node": {+ "value": "7109281ffd12576f3fbb9a8e05883ccc51c9a1269b6d8e",+ "sum": "1722422046"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000027",+ "node": {+ "value": "9d27e9dea8d2d17709dc50ae8aa38231fd409e9580e255fe2bf59e6e1b6e310610ea4881206262be76120d6c97db969e003947f08bad8fa731f149397c47d2c964e84f090e77e19046277e18cd8917c48a776c9de627b6656203b522c60e97cc61914621c564243913ae643f1c9c9e0ad00a14f66eaa45844229ecc35abb2637317ae5d5e338c68691bea8fa1fd469b7b54d0fccd730c1284ec7e6fccdec800b8fa67e6e55ac574f1e53a65ab9764c218a404184793cc9892308e296b334c85f7097edc16927c2451c4cd7e53f239aa4f4c83241bde178f692898b1ece2dbcb19a97e64c4710326528f24b099d0b674bd614fa",+ "sum": "650781031"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000028",+ "node": {+ "value": "d307d9b9eb366e0260fca84c1d27e50a1116d2ce16c8f5eb212c77c1a84425744ea3195edbb54c970b77e090b644942d43fe8c4546a158bad7620217a40e34b9bb84d189eff32b20ef3f015714dbb1f150015d6eeb84cbccbd3fffa63bde89f33691f5db2dea41e1e608af3ff39f3a6988dba204ce1b09214475ae0ea864b8439bc9ea10db4d2b08c7fcf2e8bd89fa9844f8061d462e28f174489e75140f84e842040141cc59ce38f9551850cfbdfac2d75337d155090d70d0d93004340bdfe60062f17c53f3c9005b9995a0feb49f6bef8eaff80f4feb7ef3f2181733a4b43b6ac43a5130a73a9b3c2cbc93bd",+ "sum": "3805944934"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000029",+ "node": {+ "value": "296cd5f48ce31328aa32edc11efc8a4b4b3f",+ "sum": "2531659996"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000002a",+ "node": {+ "value": "37303bc48696a3bd574ee34738de4c4c29910f8feb7557bfffcfe7428b4703144bd6d7fe5b3f5de748918553df5453b3c6001696f3de0137e454aadf30cedfb6be36b0b908a38409f1a2dc202fc285610765e4c86414692bf4bde20ed899e97727b7ea1d95d7c621717c560f1d260ab3624ed6168d77c483dd5ce0d234049017795f2e5a7569d7ad323c50a5",+ "sum": "1238281356"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000002b",+ "node": {+ "value": "b1b72f14e0569a684a3dcf2ccbc148fd3db506e28d24f6c55544cb3980a36e86747adc89ebad78d1630618",+ "sum": "2468321841"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000002c",+ "node": {+ "value": "c30c419d047cf3baf40fd05219a1fcec717b87a65fa0221a3aa8143062d77588168019454240ae3d37640996f2967810459bc658dfe556de4d07263dc3d9158ec2420082",+ "sum": "1656364364"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000002d",+ "node": {+ "value": "26d12343264ec9451ec23aaaa367d640faad4af3d4",+ "sum": "1098915260"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000002e",+ "node": {+ "value": "4d6d34996778affa9ee962e7dfef5e70d933d4309f0f343e96061b91b11ac380a9675e17a96099fe411bedc28a298cd78d5496e28fbbd4f5b0a27735d1144348e22be5b75724d8f125e99c4cb4e9c3a1f0b4e9da5146e6afaa33d02fda74bf58a8badee2b634b989c01755afa6ab20ee494c6ae4c2c6f17af6",+ "sum": "4192516426"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000002f",+ "node": {+ "value": "ad5d3ea7e8e35f325c9168ac490f22cb713ddb61fbd96011c5849ac8e2fcd42db820349bdf9157dcc00d9f9ed9c099b10c7194d48b623b0df43759734b2a2e5f8a35e7192bf9a003dcb9d16a54bd84d922f85b6021b28aacc5264fe9e83deb48f18f864cbd367eb163d39c45b0eb907311a2a4b09fb26109088df782ce031b02f3caffd2dbe25b1cbde9f35b",+ "sum": "2545730124"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000030",+ "node": {+ "value": "dfda259a86c3de59257c255c712686ee47d128a55c7b9e8c546035eab7e2da420f32ed5c94bc12a34dc68eb99257a7ea03b69d6c760b0681fa24e4ca97b7c377182ab5fee30a278b08c44c988a8f925af2997883111c750d176b432735868208f40de7137331b544f2d28040a3581d195e82811c945c3f9fde68fc21b36a44e1cfa2d8eb625f3102461539b3f13c660936a5ddb29a0ae791fbf52c2f697bd334653f3605b362d91cd78569b41dbd09b2a5892440b5097fa08d0b4b291fc5b934585dd8d5adc80d573fdd194b2eae26dfc49f5e51c1f1607d7e87740702f244bf39ca1d52423e0ae84891dfdf4f43ef984c7a5f",+ "sum": "4033364015"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000031",+ "node": {+ "value": "293a5621f955986f63d115b6ac998a65b48b3dae5977abaf985258d3d1cfe1616c",+ "sum": "2852922998"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000032",+ "node": {+ "value": "ec3d6a777b1fb7144817904342a9bd34167051162941a6b1b85db5e587f76e4a53211755d5ab29c11822d7711a97b3f1ff5b21f2485d9c86241fb56cdd6796245d3112df11ad9a7344db44d09934c4efb280ed6580cfcafb5c97a32993cbbf491718",+ "sum": "3150140716"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000033",+ "node": {+ "value": "3e0b7bb3010448dfd39a4e7f406c8bd2d804f993bb410fffa4eb57518a531ecf259a8af068230acb826d9ffc20ee0fc43885221a321e3928971bb28615f0d9f099f5b68a80503a910fdba0bc643c60b64837900be38770b6b30c362c4580722b5dbb1b9c8cd02a18fd7b5661d2c4d28aa941c50a",+ "sum": "2475947613"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000034",+ "node": {+ "value": "b0b9400532755011b40e8252bd0e3c7a22efb0ef91221e04b4aa8316d4a4ffeaa11909d38cc264650e7ca416835ded0953f39e29b01d3a33bba454760fb0a96d9fe50b3e42c95271e57840380d1fd39a375b3e5513a31a4b80a2dad8731d4fd1ced5ff61e1fbe8ff3ff90a277e6b5631f99f046c4c3c66158554f61af2ede73aede97e94b1d1f129aaadf9b53548553cc2304103e245b77701f134d94d2a3658f2b41108c5a519c2c8f450db027824f1c0ab94010589a4139ff521938b4f0c7bf0986585f535b6e292e5b3ded23bf81c",+ "sum": "1605207876"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000035",+ "node": {+ "value": "ec17f335975668f013e9da70b33bd52a72094a8f03762ea7440ce9fcd10e251837cfc9ccc1a8cc470c67379f6a32f16cf70ea8c19d1a67779a9b2d2b379665e0e908a88b26e78c9f94f17acefa6d5feb70a7095e0297c53e091cf98df132a23a5ce5aa7259f1154b92e079f0b6f95d2a38aa5d62a2fd97c12ee7b085e57cc46528638defacc1e70c3aceab82a9fa04e6aa70f5fbfd19de075bee4e3aac4a87d0ad0226a463a554816f1ebac08f30f4c3a93fa85d79b92f0da06348b4f008880fac2df0f768d8f9d082f5a747afb0f62eb29c89d926de9fc4919214741d8647c67d57ac55f9",+ "sum": "668214579"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000036",+ "node": {+ "value": "4751389e425613e9b6a6",+ "sum": "3384706894"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000037",+ "node": {+ "value": "4e610a7e2dcdb10b5d78423285506b42a99b00a4fb7b619b4526bb4ec78299dd01ad894fde2f053e18c55b6047f86333f2690c2cb8e87d9834ab8a5e339aa346e4d9952ed62dc083e3b11a823a67f23fec099a033f127ebe8626a89fa1a5a6b3520aa0d215a8e7dea3af37907686c16521739a95d6c532cc259c497bf397fceaea49cd46b9ad5c1b39a36fdd2f0d2225fef1b6ca2bb73fe604646c10ba4c572ab13a26559ededc98f5a34c874cc25621e65ba4852529b5a4e9c1b2bf8e1a8f8ff05a31095b84696c6381eb9ad37a",+ "sum": "1707730146"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000038",+ "node": {+ "value": "c0db184fe57b549d28ad1cc4642dac96e0215ee1596481600d3619e8f45e2c9ae1da834d44aca216bba0efef6254503ca90339f2d7ca508b2722d50c08def8a736",+ "sum": "3815369986"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000039",+ "node": {+ "value": "590fa4696739f2ae25ff7b72ceb24dff4455b85bbd675c8cb71ad18386dc58c371bdf37b4b3875b98a9423ff3becfc0d0ba2aacab3ee7683cb3b345095fefcaca5751ca793da63c89428f3717306b9729be998cdb2c9d856306c5ae3d89da2cdcef12f86f6110c98d873079572187d4559f24d8e48dc366441acf226a4db79e214ec3ee288acc349887e2e377419bcafa377d0151497b52e4d9cf2a02b0fc91ad9516482bdf6eccd1497",+ "sum": "1038704455"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000003a",+ "node": {+ "value": "951f23a510060fee32721872bbc95cd8d400dff00bcac2ecce6229c7d73d8f85ed5a87afdccf6dedd2992d5c7b5b8090c47c737ded036ff0e9aedf02a2242fd9820b",+ "sum": "2426662403"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000003b",+ "node": {+ "value": "e618b9601e04bc74e3546997f109f1dfae20c03ff31f17564769aa49f01233c9c4b79f90fa3d1433d18cdc497914046ad77d27922588a7d0e61d4258d7d80cdab8503e3111ddca22cf7f39c1f80f1e16a68d9e21db8b53dd316dfa4233cb453a39a90101c60efc08514a3057db007e96507745bd4a0764ed8717a250bffb5fd1ea58474bdfb5b86968193969392640d832a3387ed4ac9cdab0d2af8fcb51b86e4d927097f1e79b5af96574ecd59d0dd150a0208978c41de28ad6cadf72a49279cffd",+ "sum": "241480879"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000003c",+ "node": {+ "value": "90da1dd92e3011ce0f4a0863375a9db3f67fca1e3b8288a078611161d7cb668ecdb932e1ff3733982c8c460eeeff2bca",+ "sum": "434644121"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000003d",+ "node": {+ "value": "46a4dd676e3a0dd66f1280c8cb77a85136b3f003fab4887dad548de7bfe6488ae55e7a71da4097db03900d4b94e776a93953032883492da900b2a6c3e73d7a6f12ee30c9dd06cc34e5a3893976eb1de5864d32e792ac02e68d052d9d0cfc7cfb40b77728422f6c26cf68987c6b40fcfe9d660abc65",+ "sum": "2362877930"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000003e",+ "node": {+ "value": "7360eba6ece2cdf81b94c80e68e8c51106497cfa5171236efe2d71d76b5dff3352af9b407dc5aab60f46b5683646f5b28732b7c750d351a08a507243d8e437cc4bef13a3edaa205fc4e9968b4e563fa0dc965ba20b8e48bc188a321b16d3213bed696475127a20afc1a3680ef261df6d",+ "sum": "1212228378"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000003f",+ "node": {+ "value": "37b01715c4e638d7d615c50bef576eeb19b3b15b2c2b454dfcef2b18161a143ddf52fc8e88fa71cbe34c92cd4b5a0adc81e5c33e11d2721bc1b95a9e693ac3cabc490889a8a42bf7e22375b679e8598c8faef22a006ed2da8ab1c08aaed2f56d6f26649036335c0881bfec1e3a5346335c3b3707ee92173f1a7a3305c2933f78e995da8f1df64daf12b8",+ "sum": "2142274260"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000040",+ "node": {+ "value": "1ce23c8813b6770fa03498fd359a104884699d628020173edbcc4398b977e456e4885964840466176a490e7c513ba5d66090277c1ab1632a995a54f555a4521170a000507865b6650730aa6d6050a55959102836fff3d37e4773340e592e56951ff9652519de4421d9c5b63edbeb30a3852a1ea110a9a29721aee323d5a306de1624cecc87badc47aa87f489635d2fb60bff62ba",+ "sum": "166465932"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000041",+ "node": {+ "value": "67f52579cc289a6db6a4170a2cae31a1d30744b7022536d1526d41659c2dcc8b39c26aecfc0f8a707136d81b2827a158fd7386a537514471c213a8c859016748e0264cf3fbde10f40c620840ec4df99432e2b9e1e368e33f126ec40c572e841c2618d49d4eb098b9533b1f4ae00b468d15de8c8ab6d0b650e599576f2bd90a124c9c6a0f911fd1bd8253bac272942cbdf8864f3747ff7f09d8a5a9d8599be7ee1744e5f1faf3e526cd2a06b157527272af9d38565957c9ce663c295766c0e0e464971c6282b70d4c0c1fb3b69856b34c089ad2b2c745f5a033cee1429c5b855581ee285278893c43a5968d9c28384b7abe8d",+ "sum": "3990811793"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000042",+ "node": {+ "value": "5314ad6d06eaa58512f8738bde35b7b15ef359dd",+ "sum": "2369645406"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000043",+ "node": {+ "value": "2e6e5df04369b35f1fdca390565872251bc6844bc81bda88e115cc2f33e367cb85c01a914b3a512404ad6a98b5b0c3a211d4bffd5802ee43b3fb07451c74524ec8b4eddbb41ca33dd6e49791875d716a44bec97b7c2d4546616939ffa3b1ab9b8ba1d1a637e7c985cc922606caa0453085e35f2fe0bd2de129d1d1856ade975a3281a62965927d8bb695e54514e6955889361a2a00a1b24e62bda78d0b71a0d40147016fcdaf1a702331dda8e678d8f476dcc91698da1688c610ec0cb1d9b8fbcd45dfde6d1503ba60a01337ae5b2f5c854a82c3087779ba",+ "sum": "2678474138"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000044",+ "node": {+ "value": "bd2e5ca2fa1696442764758f67cd926369578ae87612790dc56ed9cda935281a490e5c984950ec7a4e930520d273a69da4ed3a330e532508e26f942961fed0e3efeed52a7b96250d723155aa39a8ae85131c255c32bf406b647de1a37fbadc61e302bb5b70adec4505ee66b3a1d1b7bfe9c58b11e53ad556d56e5807017bb30b71be94e8f86aaf1496e8b8d6db75ec0afbe1cd336c23963c745d7b4ba1787ceb30728f1762b46f6eaad5064c8029d29b86266b87f93142a274f519f3281d",+ "sum": "2542193928"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000045",+ "node": {+ "value": "8cb05a48d73cd7783fdf14954a03ec1a930e9a954424eff030e3f15357de4c19983f484619a0e9e2b67221cf965e9aa8d8926595c793adfe0181050df8b845ce648a66df532f78b10c83ecc86374a4f8abf8edcc303654bafd3dcc7de9c77a0a9d1d98fb121534b47d16f75b55fdc2a5e2e6799f8a2f8000d4292282e56863ae422a5779900ad6881b78946e750d7777f33f2f013a75c19615632c0e40b983381e9b8d35a26abe30242c45662eebb157e6d7a8a5519de60268ac289b82955d4feb47b9eef6da65031c6f52c2c4f5baa36fce3618b6a331f1e8bdd62148954fcf0846afeeb0a6cadb",+ "sum": "4009902793"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000046",+ "node": {+ "value": "61052187d01b67d44218471bfb04c1a3d82bf7b776208013fc8adabaefb11719f7a7e6cb0b92d4cc39b403ceb56bd806cbdcc9ee75362ab4aaeb760e170fdc6a23c038d45f465d8ec8519af8b0aad2eb5fae2972c603ed35ff8e46644803fc042ff8044540280766e35d8aaddcaa81e7c0c7eba28674f710492924c61743da4d241e12b0c519910d4e31de332c2672ea77c9a3d5c60cd78a35d7924fda105b6f0a7cc11523157982418405be0bacf554b6398aeb9a1a3b12fe411c09e9bfb66416a47dd51cbd29abf8fbbd264dd57ba21a388c7e19e812e66768b2584ad8471bef36245881fc04a22d9900a246668592ca",+ "sum": "518248336"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000047",+ "node": {+ "value": "35cfc3a8c98cef57e0826dee394eb927b3d6b3a3c42fa2576dcc6efd1259b6819da9544c82728276b324a36121a519aee5ae850738a44349cdec1220a6a933808aee44ba48ce46ec8fb7d897bd9e6bc4c325a27d1b457eb6be5c1806cd301c5d874d2e863fb0a01cbd3e1f5b0f8e0c771fca0c0b14042a7b0f3ae6264294a82212119b73821dcfbbfd85bb625b6f75e4dc0ee0292ab4f17daf1d507e6c97364260480d406bd43b7d8e8c2f26672a916321b482d5fa7166e282bfeed9b3598c8f8c19d2f8c8b98df24c2500c8ad41cd6ed3f2835737916d846f1a6406cda1125ed7740fe301d1144559b7c95fa407599ae40a795226513153f86c9b8abe7d8a",+ "sum": "2465343709"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000048",+ "node": {+ "value": "a6c0681b7bd333402d00fa8e15cb32300b5a24ea316c5e1df67de78891846cb9183a4b112c3bcc17bcaa5fecd6c1dbbf6ef8272d9269e7f0ba9f17050a6aa5f11cb28874360396ab647941f2c9a85cb06a969919b16997b0827af8f909c614545f1ad638ebb23109f6bab6b49b22",+ "sum": "3750614762"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000049",+ "node": {+ "value": "b2285cb224e5a1d63169ec85fe1c7dd246dbafa6138448420f463d547a41c2b26026d4621b854bc7786ab3a0a93ae5390dd840f2454028b7c3bb87680f04",+ "sum": "1233999616"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000004a",+ "node": {+ "value": "f084089bd2fae141599e2babe71abfbe7644fb25ec8a8a44a8928ff77a59a3e235de6bd7c7b803cf3cf60435e473e3315f02d7292b1c3f5a19c93646",+ "sum": "170790384"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000004b",+ "node": {+ "value": "7322c5c7dd8d2e4ca0466f6725e8a35b574f0439f34ca52a393b2f017d2503ba2018fb4a0991fddc1949832d370a27c42ed18a328b63a1d0f34e987682fe6ca3d48b4834b4312a17e99b3d88827b8d2238bc2b0baf92580ee6c5efe640f2a029a791a3c77bec459be74cbc30931508d9f312c3a0944212831cbe4fc92e8f107f2f750c91bcc09f7624fa9a09b49b7712cf5d619ea9da100fc23068ae2f4e353047e3956b215884bdb122353f06b8ee98f36c3212493d61ae9ce151cd0453f3075b18a12d7d73da3de7dc2d98376cfb420069ca8148c511ca6bbae5757239",+ "sum": "1557030678"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000004c",+ "node": {+ "value": "4a3cc9ee252bdd2bcae3e70162fe0e8069974e073f0a093d45be52d7de16a8f5f65c548aa6525822ffb00dc642530fedf355f7188ef01756384760c80afb61ad903d10119a7d615ec4fbdc79c490160bdeaf200915e405f2a921a2380c0ab9d2ac1e4fdc8ec4b907368c004458598efac13dc72751e7faded538e3dc8b16590cac9b7ec294da",+ "sum": "251282547"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000004d",+ "node": {+ "value": "0ac843c867fbe3cf1b4eb146d65339b0b03392259f12627a8e98e80f4896c30b8ecd210acb2365539a872541921dcd8e1e54caf4936dfc7e1f68f3bbce61d325b447a8cce7f0fcad28494f2e47dae46b136594b5dfca7abdafd6856f91496c05b21079aa55aa8c41628220a2cf0cdd755893375b7bb13d914c9a1d1db4a18f8fa36c55e52d0342352052032fb62d32fcd51cb1ac46f44b06e682db5d96d583cda03b966c650c03ae53542e8da1066b68844a7e2280c664415e413f270b1fdcfbb40b9daa6131d071ee7eb1553dc5b1a50677971223dc316d2d326d57cbd529c88698facdca425e2d5c6b10d7aecae28b",+ "sum": "415709000"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000004e",+ "node": {+ "value": "8890aa44ede97eadcbefc96dd8bfccbe3b855a96f1fd4913035f817b75954ef1827c7718aab24d353e41cba73748e14e0c2750d5b6a9752125708cc7ee7a498c7fbadf4186e7f8fa93bfdf281a49400f877621651b8ba87edda5231e80",+ "sum": "3023748391"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000004f",+ "node": {+ "value": "b758564ef47c6c4287bd4182d1b2be053380616e98da",+ "sum": "3636605497"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000050",+ "node": {+ "value": "06f3ef638ebde30d99bf4f91d0e01557c7dcd8f79e5120143c935fc699eb5616ccd3cac56b5f8a53ed9e6c47ba896bfefe712004ad908c12cf6d954b83bec8fb0e641cc261ff8f542b86e62d90e227f2a5bd59c9d390c0dd857f6da2b7624787a0bb31908bae84896890b283da61d8ec4f56eea38b22b438d6374b42243f9c1d94288874e53ab90c554cc1f1d736acde67aff55007fd4b3becc4d0f3ddd96f10dc75255cb0",+ "sum": "2330002030"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000051",+ "node": {+ "value": "327aa470762ba75d9c0462803c9bbffa51441501a03a2fbb2344aa13d27ffb9e98704ea6720b6a9992e534",+ "sum": "296402671"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000052",+ "node": {+ "value": "49688cd74d341e5948cab0af015328b284ae7bd89a5f763ceaf5ca3e647a9f5bff7197e4d357e4359fa5fe30709545453149be510e3bff86beeba5110c79c0215fbe9ac9339a8ac7d41f7488588ab14ac657aaf7d5c03a353932bbb2b261f0e83f3526c5e8e0c2348a10ab4eed6ecdcf90147550abcb0a722f257e01d38bad47cdd5a64eef43ef4e741bf50da275720a0aee47adfc5cd2534b911dc269197c3c396820b303f6941e3fd85b5ed21d6d8136745c3eeb9f36b1f226434e334dc94be8a560",+ "sum": "277144840"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000053",+ "node": {+ "value": "6079cb7643132003767bf0c87d00a3c2fcee48bbbcdd949af33455128216709df25879b0ce894ac4f121dfca6b8c7865002b828696641d14ffc59924fbda50866fded0afaea545c8008c564a3a0b023f519a9980ead541d91d1c07a739fd02286ea5660e473f80494236a68e84ea31aad71348e45055ded69c39941e31d51df257a4d0b0d8f025dbedee093f2b91795bc1533dc472020769a157a187abd6d8d52e1693e2ef56b2212759d0c0120e54c425d0084fdb3925e296dd6cdd8e677043a90674904057d88ebdea5998aa03562a790adecc4399352df4",+ "sum": "2568539289"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000054",+ "node": {+ "value": "3e5179cf8c58b3b7b98869184e42ea8b304fe1059f180ff83d14a0861ca7c0682c34b48a70df8653bd8d9a26f9489e1271fa44e41b392e648d0e619ecdad2c53952094802eeb70ade4ffe096e3049867de93a824217e31364b18204e9681dd8e84ae2678aad155b238f59dd9bf9ce07e97183a690b2a46a8f36248435b2f713e7d8dcda4dea1e3c4cf9692dda082322c51f7bb1f63d92aa987eccf1355a043e21a7b8d60a2b97f18487f6fff4c77df92dbfdc9",+ "sum": "3245350426"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000055",+ "node": {+ "value": "837521154b0499522c9d1016953dd0fa2eb6a92b6d14d6e3da5c12fabe92bd639e253983fc9104109179164346e8eb27acfdc8f4be622d8741c7bc414464c149e21da97ab4afbf3e07b98b0eced52b76c057872a60107194b432cf04b7be05e65209045d2952ea0284d83e2ed5a15cfdc58071204573c18ab03765b4d5e63a601419e039c42075b27ebb2827de9c6233d6632e6d3db9140bdb4a9291d53f33734c2dc8e24df907",+ "sum": "25670385"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000056",+ "node": {+ "value": "64dc10fd0f83448143276647c08bfadcfe3bc23898eda655c9353693ed7b022f43eefa23c21db7660c5029ca64a6085d93029ea6c43197356f56b7624d4819f5008d053357d981ffbe7f4096d6c55d8417002d36189b04bbb2c637339d90f4910a400833a8d422d88dc816c1636e8d9f7f926c244a28d9e0a956cec11e81d0fd81d4b2b5d4904ad1a5f55b5ec078dcb5c2bc1112bbfd5efc8c2577fe6d9872a985ee129e5b953e9cebf28cf23c",+ "sum": "2314957880"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000057",+ "node": {+ "value": "6f9c6a5e09591d7f0608a3fd95b99f6ba03984fb0e13c6bbbde3668c59f2f2b69d7caadffa946f67e725d56280e59e66dca025a18d4616e81abd9801835bd94485bb2025dee81fba440005b181ee81dc1d7796cbec92e4ec1c9016c8e8073cf281cef749993f09a618a4671d58b476feffa454600f82955c591882715148a826586f68bb50059914dce1c1c85e5e3951647c9964ec9316005209a58b",+ "sum": "3651565360"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000058",+ "node": {+ "value": "aeb52c3e433b050a700b556d4314e5c041d193ee47f47adc971aed1b63259dd5cd4f95854a71a947eae3d3d12d0d7b52c6cd2fef2d2e892607a9681d73ac3236fad21ee30a4f857010bc95c00d5f6f0c6b3fe50cd6452be6eec4f5f01542dc2cb5e2db1f52224f11348fe2a0",+ "sum": "2748797007"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000059",+ "node": {+ "value": "723008e836a2ee95d0aac66855fe4c3b1b2e02ba0700be759b1ef1c2a3123ee4ccf9200d8d4de5e0d503f04c205366393d1e91b648392ca28389d976aa618b4796acbfe8aa356ecdce1f7786bf09af226bb9402317b6fa319bbb9248d8ce00b1f49f066c69d4df",+ "sum": "2354582329"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000005a",+ "node": {+ "value": "932672d8a57c21d0c6d6d493f7ca94d01b9852e4fca6a9291e9060154bc38af6c86932645f53914709fc90e11db56ec4716d600ee6452041248ea8244f79534f793bfc1f2020855d817cb4ca3c48ea7f6441ce9af9bda61936c226d810086c04a35e8654fdc30d4b35701adccc016d58",+ "sum": "1400528769"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000005b",+ "node": {+ "value": "95b286edb73dc3020ba186a01fee3dd6036c0e205a8d05979bad228fd12c0fd2fded6c7f1e4c11354d266ed9c2f706269c43cd90504997d93a17b39b10dab0ff083ab3bd06540ce612d08f46ce75a16ef330525737410a0d98fb3d484968f9c12edcaf50103fdcc14128ea4ad6c30b56",+ "sum": "2466136210"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000005c",+ "node": {+ "value": "247e63d423647ad3042626fafd2084a0582ff1b1efdb5baa162662048019546234e2f6b6a1d8bb971114aae41df7795b4f3598f2af9e8921a9aadc7fab6c780aaa32a384865a4ccb02351dbc55ec92a3152d1e66ec9d478be5dca17b4a131b4a0d3d4420fc6123fef80fd5",+ "sum": "1494088426"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000005d",+ "node": {+ "value": "bdc9a37210717feec573d83c83a2e3f7d4023f2f68e785cde728fdbf5054060e4c89faa61c9dd10524a08811d15c627b3b4ada549a3fa1d8dd77c005daaf2addeb100abf694da8dd692f113965cd6366a5a7b0c17e1f2a320243e2c90b01418e22426d0401a2c8fd02cb3129a14fdfa6cbcaa1f1c2f17706e9ac374a3458777761e986ee4c358d26f8e420d33230d198fd86704e77298dd4c40c52057566ac0cd92993b21937c3a3b4a8b89110a97cf38c781ad758bdc28f356560cf3acbedfa8e05b396d226ef619746e8e4fa84c8e00a7f0e6d652808c89c9b123d9bd802624cfa949eb68af85ca459b9aa85b81dbc0b630856cb9d7e18cd",+ "sum": "3189199324"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000005e",+ "node": {+ "value": "c96b3ce3e3ccf0083017607902a7967a02d0a439e7c54b3b7ca4cc9d94a7754efba0bb5e192e8d1a6e7c794aa59e410869b21009d9443204213f7bceb880ccf1f61edb6a67c395a361ff14144262b4d90c0e715dbefce92339ff704cc4065d56118624a7e429e4cadf0b9d2e7ffc4eb31c6078474a5265beba0774209c79bf81a930b302bd0f142534a6ae402da6d355a010d8c82dc379ea16d49b9d",+ "sum": "3894730761"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000005f",+ "node": {+ "value": "8583b327df7ec88f5bd68f713b5d53796e72e28c29e8436c64cd411d335623ff4f5d167f3c7b8cba411e82f03714662425c8e1bc1efbf435d28df541a914a55317de0ded8c744a1c3a6e047590244b207bcdcbf4bd1f9f81210deddd629192c58e6fd73e83812f084ef52f21c67bea98ee17554437d9642e2eb41210e5ef845bd5a81284",+ "sum": "2993465125"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000060",+ "node": {+ "value": "55c428c234d6a07eeca180bb20d99635e36b9208221b2b8ef073fbf5a57f5190e19cb86c4989b0e8150d22ec3aaf56f6ed9cb6720284d13a4b0a34cd3d7f7fc70893266d1893fa4185269fb806677ff490aec8f889896fca50d6c80d295875b1d54a779b6d49305360b31011b48537157d0f323ff4e865d46fba6bd23a06c146878cf9404360d325432312ff08ce495edca63a3c93c44d79c050e3f1de4b6ca5fedbbd43dbdef9ceb26d440a59c7e0be3a8e461c4f15b6b1e1dc36a71fc723ad593fb903e83d0804ce497fc49bfc6b6a602b9dc6e9891010b14ca066cb1c68044c1ad837c638076dd3708078509c",+ "sum": "2686565323"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000061",+ "node": {+ "value": "ba4942cb8950eade143577bc9dcedde58d51deddc70075e452bbceab1e95b5d003eb96bea69687faa6d50d9c605769cb4287b5d9924dd68881c699abaa6f93e41dac7639cdbbbd0259099a3ed096f482a1fa322b15ffc379812c74e09e95f1bd3706347eac421fe56895e738a47fcd3e118773c3a7e7e264cc7ff5a53a80e436df058265dab9756fdf6913786a47e98bbc411052d58ffec9ee948e28cbaadaae471c5d828eaf3b3c87d3bfd495477b403da54f1418a15ace0d4d0df68f6a8f2b0457b127d5eae1f45ae055",+ "sum": "2184377447"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000062",+ "node": {+ "value": "afa13f7d6dc9a9465ea1f945295f16ee04047fc9dd3deda8ee32631d7af70c20edc1e12c5f8abd2e78f43dbd4cd6407f038efab144a24ea8a090a7ba3e6499345a60106220c2959a388e1a73d0701d854bfaaa86165a5aee934b615ac7f45da7c43a1e8f74613917ed10dcd227e4b070414412e77851db5bc053e5f502bb4e2b2645bca074c18643e8144caeccb58be49ea9a552913c0616382c899635eea79a166988c206b9aaa0977c7ced89c4c7aaeaa8fb89b38030c44530a97187fda592b088198b63a52dfad59a0a4c1aad",+ "sum": "1888599220"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000063",+ "node": {+ "value": "f812bdf18819b484171e9d0cbb08be40ae60de8818bd7f400191b42c7b3200c27643f06720a7e0a17441f34131629388ac43955b78c31ea6602a70dd665f872e7669e865f6f40e634e8772d747608cd3a570e1726eb1ddca64f08582b022bb026eda6a913dc83f174ce3c18b9fc0503d3ac74e2fe45691d6dfb4af8c86d752a16d6664fab4de08afe8858392fcc35cb9ea82fc42c42d48c0c0556267ea0dcc19b10f05e0",+ "sum": "424739646"+ }+ }+ ],+ "valid_test_cases": [+ {+ "root_hash": "a255e5abffd35359d700f9c7563eebfc04be3dd270f6047e700a6b206b298c62",+ "root_sum": "180374280256",+ "inserted_leaves": [+ "0000000000000000000000000000000000000000000000000000000000000000",+ "0000000000000000000000000000000000000000000000000000000000000001",+ "0000000000000000000000000000000000000000000000000000000000000002",+ "0000000000000000000000000000000000000000000000000000000000000003",+ "0000000000000000000000000000000000000000000000000000000000000004",+ "0000000000000000000000000000000000000000000000000000000000000005",+ "0000000000000000000000000000000000000000000000000000000000000006",+ "0000000000000000000000000000000000000000000000000000000000000007",+ "0000000000000000000000000000000000000000000000000000000000000008",+ "0000000000000000000000000000000000000000000000000000000000000009",+ "000000000000000000000000000000000000000000000000000000000000000a",+ "000000000000000000000000000000000000000000000000000000000000000b",+ "000000000000000000000000000000000000000000000000000000000000000c",+ "000000000000000000000000000000000000000000000000000000000000000d",+ "000000000000000000000000000000000000000000000000000000000000000e",+ "000000000000000000000000000000000000000000000000000000000000000f",+ "0000000000000000000000000000000000000000000000000000000000000010",+ "0000000000000000000000000000000000000000000000000000000000000011",+ "0000000000000000000000000000000000000000000000000000000000000012",+ "0000000000000000000000000000000000000000000000000000000000000013",+ "0000000000000000000000000000000000000000000000000000000000000014",+ "0000000000000000000000000000000000000000000000000000000000000015",+ "0000000000000000000000000000000000000000000000000000000000000016",+ "0000000000000000000000000000000000000000000000000000000000000017",+ "0000000000000000000000000000000000000000000000000000000000000018",+ "0000000000000000000000000000000000000000000000000000000000000019",+ "000000000000000000000000000000000000000000000000000000000000001a",+ "000000000000000000000000000000000000000000000000000000000000001b",+ "000000000000000000000000000000000000000000000000000000000000001c",+ "000000000000000000000000000000000000000000000000000000000000001d",+ "000000000000000000000000000000000000000000000000000000000000001e",+ "000000000000000000000000000000000000000000000000000000000000001f",+ "0000000000000000000000000000000000000000000000000000000000000020",+ "0000000000000000000000000000000000000000000000000000000000000021",+ "0000000000000000000000000000000000000000000000000000000000000022",+ "0000000000000000000000000000000000000000000000000000000000000023",+ "0000000000000000000000000000000000000000000000000000000000000024",+ "0000000000000000000000000000000000000000000000000000000000000025",+ "0000000000000000000000000000000000000000000000000000000000000026",+ "0000000000000000000000000000000000000000000000000000000000000027",+ "0000000000000000000000000000000000000000000000000000000000000028",+ "0000000000000000000000000000000000000000000000000000000000000029",+ "000000000000000000000000000000000000000000000000000000000000002a",+ "000000000000000000000000000000000000000000000000000000000000002b",+ "000000000000000000000000000000000000000000000000000000000000002c",+ "000000000000000000000000000000000000000000000000000000000000002d",+ "000000000000000000000000000000000000000000000000000000000000002e",+ "000000000000000000000000000000000000000000000000000000000000002f",+ "0000000000000000000000000000000000000000000000000000000000000030",+ "0000000000000000000000000000000000000000000000000000000000000031",+ "0000000000000000000000000000000000000000000000000000000000000032",+ "0000000000000000000000000000000000000000000000000000000000000033",+ "0000000000000000000000000000000000000000000000000000000000000034",+ "0000000000000000000000000000000000000000000000000000000000000035",+ "0000000000000000000000000000000000000000000000000000000000000036",+ "0000000000000000000000000000000000000000000000000000000000000037",+ "0000000000000000000000000000000000000000000000000000000000000038",+ "0000000000000000000000000000000000000000000000000000000000000039",+ "000000000000000000000000000000000000000000000000000000000000003a",+ "000000000000000000000000000000000000000000000000000000000000003b",+ "000000000000000000000000000000000000000000000000000000000000003c",+ "000000000000000000000000000000000000000000000000000000000000003d",+ "000000000000000000000000000000000000000000000000000000000000003e",+ "000000000000000000000000000000000000000000000000000000000000003f",+ "0000000000000000000000000000000000000000000000000000000000000040",+ "0000000000000000000000000000000000000000000000000000000000000041",+ "0000000000000000000000000000000000000000000000000000000000000042",+ "0000000000000000000000000000000000000000000000000000000000000043",+ "0000000000000000000000000000000000000000000000000000000000000044",+ "0000000000000000000000000000000000000000000000000000000000000045",+ "0000000000000000000000000000000000000000000000000000000000000046",+ "0000000000000000000000000000000000000000000000000000000000000047",+ "0000000000000000000000000000000000000000000000000000000000000048",+ "0000000000000000000000000000000000000000000000000000000000000049",+ "000000000000000000000000000000000000000000000000000000000000004a",+ "000000000000000000000000000000000000000000000000000000000000004b",+ "000000000000000000000000000000000000000000000000000000000000004c",+ "000000000000000000000000000000000000000000000000000000000000004d",+ "000000000000000000000000000000000000000000000000000000000000004e",+ "000000000000000000000000000000000000000000000000000000000000004f",+ "0000000000000000000000000000000000000000000000000000000000000050",+ "0000000000000000000000000000000000000000000000000000000000000051",+ "0000000000000000000000000000000000000000000000000000000000000052",+ "0000000000000000000000000000000000000000000000000000000000000053",+ "0000000000000000000000000000000000000000000000000000000000000054",+ "0000000000000000000000000000000000000000000000000000000000000055",+ "0000000000000000000000000000000000000000000000000000000000000056",+ "0000000000000000000000000000000000000000000000000000000000000057",+ "0000000000000000000000000000000000000000000000000000000000000058",+ "0000000000000000000000000000000000000000000000000000000000000059",+ "000000000000000000000000000000000000000000000000000000000000005a",+ "000000000000000000000000000000000000000000000000000000000000005b",+ "000000000000000000000000000000000000000000000000000000000000005c",+ "000000000000000000000000000000000000000000000000000000000000005d",+ "000000000000000000000000000000000000000000000000000000000000005e",+ "000000000000000000000000000000000000000000000000000000000000005f",+ "0000000000000000000000000000000000000000000000000000000000000060",+ "0000000000000000000000000000000000000000000000000000000000000061",+ "0000000000000000000000000000000000000000000000000000000000000062",+ "0000000000000000000000000000000000000000000000000000000000000063"+ ],+ "deleted_leaves": null,+ "replaced_leaves": [+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000000",+ "node": {+ "value": "318c44163503acaa874f592d945448fbeb93a877a26a72306a36e181745ba300afdc30cb7986919f3dbdc5c47ef1fa052a9e4aeeda3955f61ce2f30a0593a81dbaffebac5a49e5a8d1308352701d1ca9e620a67a89abdf5f0f8b1a0acfde5819981d4b7758799c0fe41030b86754837712af821c315301aa8dd50d1387b9fb92ee6310",+ "sum": "4149173577"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000001",+ "node": {+ "value": "777e08229e46ce298a6211aaa3aa4f6e55b5a4641220ec94cca73087760da1b1ac3e0da3f438214e691aa184b0535950b715a64d11485940dcaa3f72e0aa521002b1443f5e7880e2a85b8340d32db0fc4c4702e10f0fa24a35da9307850e945f608ad34d6cfdf6f2b9ff4f6b8e9eb5a883546578e2ff3cc5787322e4384640f42dc5bd05f432d9610dcf7c06cdf34762dd2a5e805e24aee8cebb3b4db9e4d1471da995bba9a72cf59ea8a040671b1d8ce24a3dce4fc86d2df85c8ab5e1eb2b0567c1864fb464f48c3ca72c7df2749542ed4d4be51b63769012ce3d06356856b2a424995a2429a156ad93",+ "sum": "360913452"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000002",+ "node": {+ "value": "bc790dfe4fd0f7fce38c30dffe9da9bc941d131f435c1398f828",+ "sum": "2622860655"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000003",+ "node": {+ "value": "4a230e9ddd0fde7a39c33f6455dfcc5ae3fa20ea0e0d6549a43536b4cd8a2991a135b7d7a4265fb840318813091274414108f13fe191db77746a5f4270f6d51a29ff523954f84cb76131d4abee79161dcbd97dc1ef24cfdb1fade057dddee00a1e0de0db1afaeed1b535f7bb402afa3b297551fd148c8f3e05f1351d3a8ee2948daaf14e7fc448c4670c906ae076eac5a7c656fd5f9cd937b91e26c9e5adb43c138f8d65e447b0022a524e059f879c6e274ff7e671f75717233aae70853d5bd7bbb41b43c47bb08d6dc2f5",+ "sum": "1464100111"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000004",+ "node": {+ "value": "4f9ec6068abab9ca8a0d2dc32439759aa5695f701a17d28dfb85850fdb55fddadcdde4d220e4b05821e5736d346e7dc9c94572743366488b1de8975184771361894b6520e3407c5c2e38473430969e35b106024da8618665d58c9d084824a28991a33658d6ec702139e01b65b7d0cc537a644caeee880657803d95f5f67816948d5ab362922f8ffbd531473eb0ff8fde2afc",+ "sum": "1559872144"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000005",+ "node": {+ "value": "37a4abfa283905d33b123066e7a9fe2491ee9eb24fc9de7dbd322c8ddbc5ebcd0d92cd102ebac96b90e2fd784fd6d4b699304df23b17d963080a013794322690456be525c071b78fcd2d1148026e44ff14c4d0f942cd44d2b3263f4a93b79ec7a618b4b0d77ae7a1f6e6c7c7e2f498b825bf1954df348bae45ae1d7c87b6787f121260c9a724429a4a2491ef989f65acfdc72fa717486dcf1984905218e11cc3970a09d71061e6df751f100abfbfd9b0dc303188756312c12d08",+ "sum": "1887179007"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000006",+ "node": {+ "value": "481d9d3e20c1dbde1820035997dc8a8ff3015b4e0674e7ce7bf0c2d994b7977f2d91b49bf200995040daeb1218a0f4307b6b8211913992b070d321bdb947b4ba5017a0885e7e5502710a75cbbcb56d49e1bdc2bc2afa5a0e83851162dec41340bafc41c5e11fcbf4ea2ac45bc57def4742281bbf734777f83c9ae1ea3d5ed42380230570f59c40d5dd9a2d89b75fa3c92664f12a",+ "sum": "1829776384"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000007",+ "node": {+ "value": "d21d1703ad794f617c8b32b20cc4dd7c1b7f969a65e1bafaf6c43f30c9eba256f10201910e2cc31a9b13a46ad29257024ef8f2ee29b2ee63cc5b6230ab9f87cd5cb534f4b0bb08a790466e0d57b849fffa1ed21bfb0b27804e3ff9df7bebf14e100cf91691a493e53870abfad6321f6711c50fbcf1f0b2c1e5231d6c0a08e710525176355f6f82bedc1f787f0d3cb41fa11e91ebf9f4cbae46035a371232d63ef0d8bda0355af8cd0a2f7d1327d80ab769ea0f1da0f76ec99cc737b5ce84675fa8a9ac0c98342bb82b5848bf656d35327ea01a1b09d84ab974c307511af68a",+ "sum": "3077444087"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000008",+ "node": {+ "value": "30ace8897ec0d1a90d5d167e29ebaa6f46d93d697760c8771417ce94c0f3698985a98702833d1b68641b811840ca3d935386dbd4600fbc81c8728c4fd0e4588be739a048f03bd4ac651ceecd7e2fb120fe7190011f957fcbbfdc025f1ca0b356208db8cad87fcd53c5d3a30a7c2a48140ccd4cdb49f3961cef742caedd1e848bf3ca",+ "sum": "937605449"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000009",+ "node": {+ "value": "cafb0da0fafcb829d5e3ace9394028683d712552579e024084a6b855830a",+ "sum": "1645952454"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000000a",+ "node": {+ "value": "d9f5378f167e8dabbeaf7d0a9e65c71660314d6c8d54beeca2711113fbc32a2ff8c0daa8373278d10085d2a0660ad53f4e",+ "sum": "100902286"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000000b",+ "node": {+ "value": "1aded9162ccd69599163a451c6837d5ea5e115bd9a560f395128ea002ee739009a44fa46078b18959933fb6e866feb4612a56ce93b1affcb95fccaa18d71a148582ba1412a5daa07404fcb39c3cb4a2519cc506c1172c6c326016ae2e5410f6a438569f35a50d45cbf3cc46188651aa22c257858f60649cee8c05c75953ce49358dfe5980445fce9614ccd16d333ad236e29d204691ca0bf46f29da954bcaae52e41016556d2f4cae1d37565bcbe84de1b49f344d0200478a38187da29c155cc9818",+ "sum": "232024309"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000000c",+ "node": {+ "value": "4d9d33dc4963d0ace2b4e7a24b21c14a5e671994fe1f7d22d1135d4df9268dd18d323fde3603288735626a5449582d3530e2c2225414e05a8c7b987c873a82e272a5d83e59b90f3d7264631d6ad04a0cf3b5e96596a66ed5bfbc24ab6e4870aeec0acbad2cc5affaee06de32dca06f175bf763cf8e7fdf95941a177e934f0078be7dbaa4c9b6f5c16b4a5607bab5d56144a6ba3c7d9a084b8d1f4b24b6f9754ed207b230d3a2cc26259ccc725e1f8a44c4df8143e13edb5ebf073e2c9d2da5f1562df4feece2f6480987f093f642eb7afa3aa92dce2a8b60bb925cd2d11cf6c2ae7d21531a9c8f068d71d0e682023932fe64e956a49347aed22b21084c4a",+ "sum": "1918649547"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000000d",+ "node": {+ "value": "844884766c68bacca62bdcafab6603c81bdbd8e680d9d8b3825eaea4df023142e840f98ee251466a0422d810a54726a9f03a7e0afeb0043e60e2ba4908f951d2e87fcbc372096f2a9f4f2a95ad5faede3796b11ecf4401c3ee3d268bd8c46476c61e0ffc5c43c0f3c58c79e20f75520c102aa3c260972a870fc50f8841fa0553a9e30bf37ad282fb51b34adc7a933ca1691a8a706605ce0b906fdccbe954f8e5f2f63c42599a483c4be73a041ef90ad930fe60e7e6d44bab29eebde5abb111e433447825c8a46e",+ "sum": "2634073129"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000000e",+ "node": {+ "value": "f7070d1f658654a2ff1fc11c383e7bc5559e7546b8bf8d44358b1ce8cb63978dd194260e00a88a8fd17df06373aa8004a89172a6051bd5b8cea41bdaf3f23fc0612197f5573f3f72bce39c9f89fa",+ "sum": "4096668816"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000000f",+ "node": {+ "value": "f3fb48d8ca096a081af462ea5318cc898a9cc09e8258a837559570cbd5eb901e8c0e04ee88ba31c81a76b000b80e544feba576b3eb5272b53e46e96a0b35b9c759caadcec61444f8ec",+ "sum": "2245707924"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000010",+ "node": {+ "value": "47c3ab3493889047d690e84431d445407fdd99560c0bdd287e0944116f8ac62ab992ed3f1e2b415aea784b03c6904795f4326ff60bc839615f2894570dc9c27cf928ef192047528a1a19ec9909783b0d1a13dd4baf4a19e49bf798975abe2ad167dd574b32b3d0c22aa4d9b52761e8f56cf2100fe5a39fceae3d865f3724d4f299d07ff899fed6baf7fceb7189357bf56cf94a6493e61301b43e3ed158cb9c7a0e615fd9888c2db07f7689762f62ef6b3ad4125e06b07a422f5040c3aa8b8f205d68356c922556fc4c976165fed9599daeb297498ecf744bf6c7dc5e30604c461ad994022eea0fb6fe33f82a97b5c272fd24162a94",+ "sum": "1879505451"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000011",+ "node": {+ "value": "b7612c141ed04a86b8d00fd9c25bf77a8dc3e63f5543331405be6bf4216a891089b316aa4f887cb4aff0dfb4e80c2ccd65ddd9daa74b17b4411c0fc849dc748d9b138279dcd9ebfc6e6759a53f5c28a41bb82107d71cc161fa81291a8290fb70ae7ec12264ff9f51124da1",+ "sum": "528234824"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000012",+ "node": {+ "value": "575b1ddcc1c62edf20b1d53962b42386eb570b10378f9764421ecbd7c480285333274719ff4c89c06005050fa9ba6579a844060eb7ece6c43bab520e683e0f36ba49cba259edc6ae35d41e0d7812a7d5edbe4d90cd5e0504d16f4c3f70d01f",+ "sum": "3396629061"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000013",+ "node": {+ "value": "5a031360f45c66cded8c10565a1ca6d23a84bf182df2fcb05956ed4d46b49fc0fe3bd23961d9466fde070341ce41bc6e148449360a31634fe10e91082d82def90d9da2c250ea72c58add2058d046b4392b78bc3af5b3936ed568733e8ad5672dabbfa3130a6a535ec73bda8e7223535f49f96cd35d56ed4792c5cb7076720d5461d96a2692b2ada52be08fb7bad15d15a01081437900",+ "sum": "2333723775"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000014",+ "node": {+ "value": "4061e30952a040e4cb9650f2a010417812790105d8f58bd25d99b0db3cb162293f6322e86cd5b0bb1505a7b998fb0f81d1e1915faca3c2c8ddea3911550780339430a7955521839deff5b301f3fad54edd5ebd2ac4ec9b1795cb4dc0e2eb62ebca8e886c3f1e507d10a0228c3027b472a7104b815f5ec8dae55e0783ff7ae9a3e6b99e381ad788206b135520cb870ba0cdbe876feea843b85a82adc95a6d71c5",+ "sum": "176801457"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000015",+ "node": {+ "value": "55b1f12d78490b067315735017a94ac150b44dfaace151896f873923310ffcd41e91bac04de6d70ea71565948c907ab21c4a23703fbbd2a8de6d3095f3d8f901538968e360e7bfddb9d22036b1c23f4f5f1b2ee22623426a2d5de68c1e1a38e38e08e2b5670aac1edff69e9c73c2ca56cb69c709009ef1d541aff1fdb2b40c929b87f162f394b76cdbba1f5605993e4dd9c312321d59b0aa5c6e33be1b10bfd00b92d4c02db064d0e4a98f2913c89051b0f0ea",+ "sum": "2656698338"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000016",+ "node": {+ "value": "d163deb5aa142e072fd91802eb9f0d2eb7318dd620555e6ce186706b866d41cf6ba81f100342faa14d801dc6f3d522db38fab17a879fcbb6acfe922163505bd23a6842f6ef6397ae5f",+ "sum": "1966640512"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000017",+ "node": {+ "value": "b66d6ccb7a47891c75c687d791a930b26aaa2e3412e7aa16e2cf15017bf6df6d2e1c289af0d7ce03954a60c1dfcee5e4b3da51eb43ddd14faf59082005d0c8b104561f66c002ff426be60be769282fc5685cfd1968df194173667e48e9ad681d35757f1199f1d93377bbad093c8cc3efa2bcb6ecb703694422772d15aaa58cab9e9ab277ed510f684114cc4a44ccadb3eb1c9a76d8619a9b7743106df6fb6f927ac49b22ae5bb9a9a4d231e340a2cd0e328253",+ "sum": "3176609401"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000018",+ "node": {+ "value": "f6d75df6f5d4b56cd1471e16400f404a947e9737f4f874fe09a29ad799f4525156e3abbf0585c3c3c0a3744c865d56db3d2ecba6bcbb1adcc8bf5f3b2a2d46d3eba18cda55201598a8112fd8f14e205f0e615f",+ "sum": "6672931"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000019",+ "node": {+ "value": "081b8ff6c5d0d819f6aacc53cf3c6653138b9a962acee9d6ea01d280c35bb1f05d1509238ccf004c5013167f804d1780d9f4ef9d45742fccac346b0472bde24ff5db9ae016455a3c02256358fcd8e6a9aae94f8a37a1a3da58a889bbe3d295e165442e580f59bdd31c92ffcab40c49c1cdbb4db1dd4882b66edc10fcb1704203c518c1d8d4c268588ce13fc38e0210aeb47d11d2603d4b3de5c6ff5e969b9d5904abb282b699bd04a6e9f1cb3236",+ "sum": "428221918"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000001a",+ "node": {+ "value": "79e30400d7254b93bff02523cd8498c021fc35a488f164a70ef1ceb873d914a681d3a3a34cc76bfd5a547e2630d774",+ "sum": "630116111"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000001b",+ "node": {+ "value": "1af5c6cd7e1a93d3388c7a990b5feacd7749cf39fdecdc20adfdd540c69d330195db7cc0d4555ea5f5356a3647e2265399f153c34ed1e217c5dafdc2c5dd3d566c332c7ddacb0d76ecd3a0ad505a4165443aa81b0f43cabfb462942fe74a77c22b8f68a8b1a6d712d1e9b86e6a750005a3796ba154539613170906d228dabf572ab969c762f8b296054f23d5d4a37bff64bf9cc46f43b491b41101256018376d487fe8097f1653a7a9e99e1ef2492600598fb0bbb7df8270be",+ "sum": "2511696804"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000001c",+ "node": {+ "value": "8b9106126dd3db4c6a99402aeb58d371263a32dcf76d33c8904395b9cf0016fdfc15608eb43e20b099cbe7455f7a76f69bba058ef96f83ae752587485657f89c7f26fde7fbeba82ede581ee92821dc13b8202930aa58bd4f1c86f68926baca0d06fee642ea8c652d226af91a9638a0244f1a03c7ce56969b87cd5c1f86110d192e0b98dd979d74acca6c1956b1127d9a1f456053d17974081ed8ced0faa4293a319e5b25ba285c1151214f52c283e39c35af51c4572c8e395b7856697bfedfc4145ab4ed0bdb",+ "sum": "2183833204"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000001d",+ "node": {+ "value": "e43ba56c63b51833cb0dfff7196d83f6a1c6d6d712cce2ec1989fd9ff5a0a22ac5022b49d56658f196703e4809e7624fe7cfa6c13b378f5aac7e66e657ed7eaa942d1a00544a947199f24d736b8976ec2cfb563433c49ba131bd08b63636854219d4c45100c98e3092773ef492dd9210bfd8f54cfe2cddafcf5c05468d90e6200c2ef99d17fa6992cc45eff3072b7cfd51cabb07ea3019582c245b3ff7580302e88edc2c13fc43646ba34de37338568baa66ecff3accfebad88d143afd1c3b09ae39c501e3f116af33b0",+ "sum": "667748527"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000001e",+ "node": {+ "value": "b720d6c2a51f400054e174d3b692273fcab263eb87bc38b1f486e707d399fe8d5a3f0a7ed4f5e443d477d1ab30bc0b312b7d85754cb886e9f7e7affceb80a0127d9ce2f27693f447be80efc695d2e3ee9ca37c3f1b4120f45a3607fb98eaea",+ "sum": "2960813884"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000001f",+ "node": {+ "value": "02950995f4a87c3dc6ad6238aadc71b7884318c2b93cd24139eed13d68773f901307a90189e2726471e4bf9e786b2e4cf144764f33c3ac3e66521f845f6f0688f09eaa227fe71033b0f74295f6ddb91fe741323f2b54f420cb9b774d4291b062",+ "sum": "3042067797"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000020",+ "node": {+ "value": "19f15c2424d637a1641db6f0f6cad564a36a910f49894bfd598e91f38ceea65e8253c1284f210cf7b50a96e664e562f3cc01c4fc490fa6d4679fd63fbb3ed8995a8a05166b573e92d22ef4370c6aac74ae94c94177e5f711",+ "sum": "2957694825"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000021",+ "node": {+ "value": "43c6f340efa8de8c40894316efbb06400f9695b18ba279e8947c032a84a40ca647d9ace4576dd0082494d6bd7be4e7928e749c78110af8774a5d43e9c9479964e2fddcee51146460eac734311225d08c60706e40f298a7cb97f369ef599be097ac3bf1c275497bbd68968a235fdf8a61bc7cfeef0fe451bb04e662ca39f34ea8e3acdd0befe9762f9eeb275c0cdd43c80fc91131d1e0e790",+ "sum": "456374377"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000022",+ "node": {+ "value": "0821efb4cad7cc01fd6d6fd194ac5ffe7703d890d0169e21b444cdbaf691fc741a5d99bd",+ "sum": "1961401986"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000023",+ "node": {+ "value": "47357c37785739aa6d9eb3f38801077e6d17e3cee3fb57ae83f30c79c3cf290e2739c6b7323612cec3a561ebeadb4faa642f150323aaa9d270658c907c4c1610a5e1834730c08be3379cf1abc50c30e2bf01ce903927c27d85e1353db9e216dda8860c45925e2bb791abe5c8281ee6d16607bdca87f60662dcbd6e20224e7f009a86db66fadd8e37e0a59559328385090c6953cd20bb61f28a734fb056714f5159977f18e5c5f11de75f7a00ba807e47a2",+ "sum": "3026695467"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000024",+ "node": {+ "value": "9e4da32df7c673dd8a7c87fce665cda8adb9547d1dccbdbe7be44846b4b121b0bfa65e4ed530789510d79bc4477e50178060f2668ac8956f39ef422ecb0e4cf90b8ce508552eedeeefa6c7d1bccc077e8088bd7e0e6aaf0bda9f11c412c270ee2ad6912f9808f9344a4bb137bdacb5b9372b00b0de026a8f5d1fb13972e1290b5005689f7636c43aee2fd44393d390371ae573f0e064b2d7df552b9adf04bf173d71c621795b9fb503dc5e918536c6ad25ce4a76f70e6b752b6d44be321187269a19bcf33ec899ca40e88b4eb23217095a85057bf95d8a54812cae4a7d32e0c2966a2137611074c6c8c3dd45",+ "sum": "1600605213"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000025",+ "node": {+ "value": "a553c43c675de1ce08f9c6b45ceb5b47bcd7d7b2d4380bcdbd6eced452d93e6d8cbe18123277889c7f86b15fb991364a501fbf5d8244f2e3332ea0ab49e833c6f765017a4006cc7cd1a0365945a8d8873cb21832b210c83e451c01ac949de2fb0f7a420e405bf64eb251c6f022181595d68174b91e503187d3b3f49b60c23e44ea40ca20311305b413047bb22e89672758b74d6bd1a06decf09e9556421087a40c1d2c44c5fb13d4d9625581ac4ccef1a1b5eeb5689aac5c0291aebda27650daf9d4396a64d02c6d58bcbd609d9a0017880ae0cbaf02ad0f1fc8d1b3ec987ffe13102d77352690c9b761bf",+ "sum": "4212185824"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000026",+ "node": {+ "value": "13ea0bf03486620761dc77a6ba007ba07153b17425c4026597473e78863cbf430c0e5e9b04a83ad11506b61b8d9be3aeb06b5114e0d53d4724863eba124f3b974bdb0d02743520409910621cd730c97ca984fe2921c38055f83ee8c4611db92e52d8ea51d89203e89df7586c574df15f3a96ed5a10bf04cb27f9656b5b11cf35fd21360b029ab26e9a741c6b3e6357",+ "sum": "3728390669"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000027",+ "node": {+ "value": "aa1a41de2cac1b8cd4454b11962e5507ebf904e9d6c52a7d9722300517c434758fbd6191f4550108b143eb16c0b60094fdc29327492c",+ "sum": "2237987465"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000028",+ "node": {+ "value": "1833f525acfffb619d356bf8347a8bbb4babdc2ac866e497f192e65a694d620687cfb4f631fbd6ae5d20ac2e3a124d85f9391a",+ "sum": "1158980028"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000029",+ "node": {+ "value": "240b616d829a13c622ef8c48a181fc7598eacb419fa438d4046aa971942c86b36eb8e16eab67105783d27fc56f5b66f35451b2a407d4648a87ae70807e45bccf14983b3abcb198d661d562dfcb00ffc569ca967171746e4e36f839946bc7d2ea9a0eda85b5a5594f6a9c1b179f7230eaa7797a6aaf8628d67fd538050cf47aa654778c11dbdc149458c1ec2233c7ca5cb172356424eb79479b6a3eed1deb9f327852",+ "sum": "1633973910"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000002a",+ "node": {+ "value": "82a1034ba10f2616b05d521dc407a2ae7dfcf46fbae30547b56f14dbb0ead11b3666666c45d345cd5dbfa2",+ "sum": "3947255187"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000002b",+ "node": {+ "value": "00ae24d5205c0b78b56d5e18613b3169bd441b3c31513528fe102f9bac588c400f29c515d59bbcb0725a62c2e5bfb32b5cf291d737e67f923080f52d8a79f2324e45a3bd051bd51bac2816c501af873b27f253ef9b92ba4d7a422e2fb26a35c1e99eca605a",+ "sum": "1455858298"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000002c",+ "node": {+ "value": "cc22b3aa126f470675fa2ec84793a31e9ac0d11beab08e2c66d989a1e1b89db8d11439ad0d0e79617eafe0160e88384f936c15eb15ece4ff00e1ba80b0f9fb7a7d6138bdf0bf48d5d2ad494deae0ccf448c4bd60f0788d3f2b76de8ad1456f7572bd0ffd27bc2836d704",+ "sum": "638428365"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000002d",+ "node": {+ "value": "7fafda03b834dd225ad9714d2bd182b4103faa5975180f90d5d6cac1825a19b9d4c87cc825512ae9dbeb33d2759c990905050f960cdb3eb364c15b593524c882902b2a1d7fe40ea3f54fb0202fd8821463c7e34b02a1209ba0048a9805f0468a13e03d18009318ecd92042959be263a51a407f1e660632c4247419659a4e073a8e9cd4a226763a7daea464d54272707efd053cb4efc0504602c4f63e7d247b55db2ce1c07138f585d16cec97a3",+ "sum": "765551426"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000002e",+ "node": {+ "value": "0731bae1af8a2e67c2d5a3ac5487ffe8640f308ace6137e83576b79d586b663122221c20aba7a6bf60f73958f43659f087f850ba6e2d7fd862249c5fa6b20e3e43d4f2aa10d4c9cebfcbdf026b8d103e4f89b93dd8af172f421001c8b162bd6d0b847a58ac108b6d6cc49c7a9ba069deeee3d21f9674f72ae65661aebe726a8a6496dd3cc4b3319f797e75ccbc98125caabaaea2b4b4cbe9dbc4fa193c376271f40a9e216836dc35ac8012476e9abd43dac6b9ce67dc6815904e6c84a5730cea0f9b4c6900a04ae2f7344fd84658a99513ffb268c6899dfe98d605c11e7d",+ "sum": "3087892798"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000002f",+ "node": {+ "value": "c77de77b9aa9ca1140cfdf4c586b7fe726a8bc403249396a11cfee0a6af6c5e72259785cfd13c2897384fe527100170001ea19106aed38f7d5d9a7ad43f0b41451e19989192a46b4f9734a774b6304cb74feb7d83822044a242e51d55c0b8318e0439493bd1a57cc13f6079166cabc46877d003dcd39b2c0b90f6b32fc77acf04a6c125e11b35d91e2b18401cd53df4aff804e3c67a8bb3894b27c6e9b0070b53a85aafab0c0a253f9cfd4d3cd3be52428385b24a3f9f71660ca2c38474d14a0309e2f400e2c21af6e379099283ff241d751da5a96a8dcbfdc43b913b29cc8cf8020eebb4a67f5bed31f2e383f86568c815ff172382b425e95902e80f5fc21",+ "sum": "2026958138"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000030",+ "node": {+ "value": "9e76a23648680a472d02ba71476e0afb29a0e084984f4eac3befbf8dd8022b7dca4dadd18bbe58e49c49ce48a06a71557a9a620c51e2623f818e4d62c2564c7b",+ "sum": "85646258"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000031",+ "node": {+ "value": "c7a65049fc57cb10fb01951ea525332782d691f9759ec2ecd68bebb9c7aece5d522a08ce7830be520db4c9d60a2e490eaa0c91e37b256a97f84b39fe3c77953748c3b86fd84e9547a298c049cb28b8c85d59548b8dce635d59487c9de615802d16a8adc4c0e780f35b9f10588a431b39b499dca929ab9d225f26e5721820627fe62427fe06d5773a50878b6effe840dc55bd3ea0c35168f6b6a972d57e8f88c5993d1ae33e0b7e9459c123753b518c184de7aaf429df078c9a18a29af77c727b796f5c1a501fa8105ee873c4e78c907142eb19690638a182fddb413adb06d66db19c7f6f46dac582bd72a6347b4427a576eb769d233febaf7be8f7",+ "sum": "67487063"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000032",+ "node": {+ "value": "68b783703a81454a1dd7a8772a9ab1eeb851be33e0c6c0708f3cc2012cabe8e2f0c38e35372abe27bc",+ "sum": "2938435426"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000033",+ "node": {+ "value": "148fdd77928a3678ebd7d09ba7b4e1d83227257292c0b8bc4a76de36bff6c9deb383029afaf4f37d5b935dc080a18665545e4acc195da0b9545d89024088",+ "sum": "2624047255"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000034",+ "node": {+ "value": "86204bb3be97800c2e2b945cb09a75a0a49e5d4d81c4194d91e839333b2b",+ "sum": "3856799619"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000035",+ "node": {+ "value": "9bfa70ff063f0090fd842f89dfc5cc44affcce4e1e1b8b11c612f66b074c03ac2a055fd8f51ac9ed4f2e624589ff5730721d077afb4c19e43abf8cf3ffa698362be8be51e92c2c91a4a56be64d9ac6d3fbaf5536a24c7fd0adaf74ca84c508e5e8c8bf7d4254e0c44158bd26acdf3f64e78438b3aaff89ac9986cef1e3a88d5bf2016340367a1cacd01ec167ec6d185d93a2a220d718b43ce1d429d2cb59",+ "sum": "455896540"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000036",+ "node": {+ "value": "8605660b196a40a88285b18b24c5d2d594bab3d457e6f9e503e38cd470a69ff8037c9a0a0f110a434335d954fa856a3721e0edcfb14287c3dd9639ba4db32b7da067",+ "sum": "670338106"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000037",+ "node": {+ "value": "0df7a011bbae1493c01e642757491189f8664be3ec6437c4f3c76abfb0276e44a4d28871d3487c2cce2f230452cb06184bb8620919659a7ba0a3d5c12ec25678b03403715ee4acb6a53d281036d8f3a085143cf5ecc3a0c6c92129caa7ac1f645c7bb95e4f63da38dc319e2ccff4a9006f9b9b1a38c4c39f6dc686bb82d43fb9fce40c767d",+ "sum": "240369901"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000038",+ "node": {+ "value": "3f08a777d49b70946665f4a7335099376b276a43dc9a6382bb2d40425f6481b1846148434c672b84",+ "sum": "1383080257"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000039",+ "node": {+ "value": "dd7a206deb48629e1abf51e68748deffb756a3ed9e0807506b248a024cd509f539f4161366547c62c72933584e851599b682ec16f1d79e9c6a01cff6f51ba7f46b67cdca09f3ab8496322b990a61168d7574854a1cb1cb8f30a303dbd13a095df56dbb940dd16ce79879cd2d7380a419842fa1b34da668286de4c1ff5917b7aaa64713c349dc8f855d04aede9a3a4d0739dfc36510b1e7bb1695418164285c44631b4b1a7c5798ecb2d976c1a3679a827bf0e8c662567e402bcc13542220",+ "sum": "1043507731"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000003a",+ "node": {+ "value": "36ade154d778fc80a011592771d55801c7e1297b00b77f80d6314ebd1f5b3057398d1943599897cfabb65e7568d8fbdfcbecfd4b8a83ca0a7bed08ab9a656424831e0d7718c15727af7c83b2ef5eb5684aa044eca2ba896811246766248b20a325094a4b4159f9cde1ee349be6dc3c9a1904530349212a9537f65ae333c288753cd2bef6c5beb2f4164168d965a2c0fb9cc8c73d9e776e23d53ddc",+ "sum": "1795806895"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000003b",+ "node": {+ "value": "fb10faf8b53e89e6a611d6d3f42f2aaed5259730d149b3e7dabdc9f865bc1555374738c8456abe112e9628fb31efc2ecdc972da05987aafce728ccaed246cfcdf5183fe5dae528bbfb99d33194167e0f84d462d3d0da83e92227cf57922c79564fe44648d87c69ad708e",+ "sum": "46384071"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000003c",+ "node": {+ "value": "2e3d39c3cd163920f1d7ed83992bc4116d9351ae1c6c4827d1374242e374310409f32d5f0f38c78b6489c568b791c70394d29ea2516dcb10e51bdad862ce3339d5e614fe14f150961809c36e0a2c8eb872e9f7a1c0956fbc9194cb63ff99",+ "sum": "2043497183"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000003d",+ "node": {+ "value": "93e5d0dcb766ae9a11254f9970618f1b33c8f339f440de240170f7a21f03ff2da42102b323ce2b9b7d0de5aae324d1bac87b1e4c5279a566bf659778f8b03882aded57377a0f1b063af2897060e423be7cefd4aa9a28479c16773944d254fc21d3e1acdf508b7972372b59913b8b088e93471a7d54c6ae4c52ba465ef07f19f269677fc2f64d3fb3d7f19069d6c7001d4b002ed6683c59bd5651a450503b68a4a00820b8c17e326318f32c21",+ "sum": "3808480522"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000003e",+ "node": {+ "value": "aaf3",+ "sum": "1280325402"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000003f",+ "node": {+ "value": "d1a7fb41aaacc91182addf8c5bdfbd0626702694b8d652a63c658d6b2b7c75d015630de508195e1fca9573b61bc549ca017c4bd888194d443e031f36170215a301f922736a819f3ffda69117170d1933300366c5f2ae1052446ef7c3b82c5868be158a881597132f51c91c80c24ebf621393dc4505fe057364a76ae67494a8a5f67acb551cfe89f447df272ed9c1509fc3302c3e16541452d4d684",+ "sum": "567456431"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000040",+ "node": {+ "value": "38f268588336a341e032988f39cf53535789b320b5424d07b6bf5f8792e3aceb0e868765b8611d7905089949e0c273e2410c72a146cd63981f420405bd883e5390e9858214a8db714e8400a21d0636d7e5d9671a3582ab9ff032170b8dd6b9d5a2144d065228fa54aea9a22654df67f3f62c5fc59d68914d8b219829b536cd2ae937ecccdb6031d94cb384373472e362a356bd5c9b50f55c588d067b939009944f02564f136c62dac36b860d9b2954c3daf18fd67eb8bd9e6e3de2e4988ad9b04b1987219204dee2388db1c59a935de27bce29e7cd3ebdf038",+ "sum": "930636912"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000041",+ "node": {+ "value": "785efb353cfe5eb10b4ec6152cd8f21dea415421b452efc7cc4ea6bf1ab85fa6614e7f6d650125424865386ff8ab53247a63ff023b2d0753a9e5bd458d6ab0156fd3cf2d5002f902f927a847e8c4a8426b0a5191f5e237d5902659ce9be90247",+ "sum": "144446369"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000042",+ "node": {+ "value": "50d1d618a6b89391aa9e8a620a2a7d64bb7e943c",+ "sum": "1397632045"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000043",+ "node": {+ "value": "2b4eb97372a05416706b2644e2687bf1d42c0cf06e5eef8a1f",+ "sum": "122212299"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000044",+ "node": {+ "value": "c7e1789728a999c5e04291576e757510f22bca11583a4e93688b442f2b2dab8d5ea9441ff09b8287862ca538ad979297cc75510a3d9ef36a662b4b7c373f184202befa5bf3f315642e6210763d033b7e2c59731cb356045e9470bf2f83cd62f11b3e904b0c0b1be99bcb805150ba7ef12b8df3cabfc5055640687d710ab88e0fa8034b26112ebfd044a4b290b1c6f6d18c31ba9880b1cf2d81b5d02f00d6d351da5dbf47b6a5cb7b53eaf6de52c8a68d053602ccffa37ccb44a7683ab4f8a58c4bbc9e140e4e6f3cc10a5c07ebd6070818db",+ "sum": "2136433314"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000045",+ "node": {+ "value": "983f9feadd",+ "sum": "2916505075"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000046",+ "node": {+ "value": "8bfd8d028bfc9d6e482ecf99beeabc38d70efbb9a0d4b79a1c5d2835adf8e25111352eabd24d562644efc9",+ "sum": "1278230574"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000047",+ "node": {+ "value": "7637f695e289adf159865d013046985d7fe2598014bf2dbbc528b4166fc2180e724ded8e7ea1c8d66338ec50d955d5594a0a7b4655338b70e8978485a722df814fdc6fd2436dbc060121fcb575672b2a5e454c1209bc2bb21a99d39dcb3c697306dbc2104d60fd8051c43ea2fce268987d0ec249a5c02f91d3b0dfee181b3cf8ef1ba9665daf7ea1f1d3b216e378943b78b6bb41e5dba095748bc776f8df6383033a1f5504955da3f42153b1c7ea83e2f90b990ea0c5bd3906b5c4060b19f447ec7762916b8766e5a23bc4d39cdf8e27752df8129b60ccee1731e47383b589d4fcad865eed4041a186df206e9f",+ "sum": "3013227733"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000048",+ "node": {+ "value": "b69ab6ea09e29404d617317c75c832854427848237cfc18486c95f7213b9d53f324da036e8d298133b5003984ab9d71836f9f1b059db90005a9067c261bd85aaeed4d623df2220eb52b73dd683abcdee5cebd411996f853752f638bd28df6d78bec2ed",+ "sum": "2511183276"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000049",+ "node": {+ "value": "3e00d7be3a2e0570650c1384f1818d76fbefe3a7ef3f461381",+ "sum": "2523538426"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000004a",+ "node": {+ "value": "19c23905dc60d7fa4d666fa52fe7737db15126d3262c3a4c385cdb23ff3b56c131e43b241f4a6062a1a248de9f13eb82c11f7b6a22c28904a1eb6513cdb11179067b13c7b5f83a58c14f2753f19fdb356f124f52923249d6e4a2c8dadc8bb0fc91e360155a14c5c194334b9f0a566d51fad98592b5",+ "sum": "4277463456"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000004b",+ "node": {+ "value": "9c1c0583f853398c343dabc29b9444be1e316309fb8d81304d654b3d4bc4cff355fc31278fe22e649324ef10acd247c0b72397edf96a1c16bbbef06402964d219575fd23c36efc1fb8f8a34b510ba9bdfb3b478e236777ef7c6c47f55a2bd0383d8eed375945",+ "sum": "717273890"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000004c",+ "node": {+ "value": "6ffcffb15ef883f69f096dcc72a96888c3af76db57a54be701759670bf05cc9015f5bf1a745cf755a25b1403a870875701427f820c4b29eccc260f301136",+ "sum": "724748643"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000004d",+ "node": {+ "value": "29ba03e27850811788686d5a45820d2980bf7d69d5c820a09bad7bd95166f63dcfbe8652565c285e60e2704955d69b3037d87f5e6567d95b8891276d5cf7c59047d10a02ae4a28794405e2524ec2d5951b36ad1b9d5265fa098a033b88aa66cd9eaf01eea49c7dc4cc51c486f624507a2be23f152f43709b2cfecee44945ca506950e90e70164b77e12e1c130b4d1021c2afa20038f190096276cd22e89b6e7dd10fd58fa033c9d4253698de",+ "sum": "1570050789"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000004e",+ "node": {+ "value": "3f49982b4a837cae7139e27182b61b4dfbcc50e42d5ab8532edfbd30f668879824e9ebc34b63ff1526cda81ae38352a774d79f73219500e57f0159a32326195d8895d965071834876a45c1a3c0bc4b1638535f7d40011cd5b23343fc27fa318c1aa3f9d8c43351c66148dc2175e0e620813266da3000954dfa22048f305244629d512e8523766248a897a3ec3e2983aaa8a0f025f18feea57a5153a59b02604ebfcc7a9fb03e62443df88ead9dee955e23bcf6528c278a353f254c9484a67a7b263da301923a4efb6866aeaaafd428e6",+ "sum": "1253412211"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000004f",+ "node": {+ "value": "da48781379d14012b5a8299a651917b6a829488753b6ca449a14e8dd8c5fd5ef657d627b8e7773475b802655dc033694f24376e3b01e519d1aa8365d0e5592d0a4adbf555639b6d75d7ee59a7d12c6c11317b7927f11bbe75ed90508b0698420e231206704d22dd1f1740edbdcaf19a47d66ace4eecbcefb77b085cfcfaced4d2d6048ce76434eb79990f0898adb4af2c377b581ebab3f3a150f40dcae002d4caa60050591c0de",+ "sum": "3719417163"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000050",+ "node": {+ "value": "4ba83bfd596eb8b2f3e864a98676a67271a82cffdca2b3590a0b5f97efa5d4ba062b4798707159782bedc75e5363d5f5d55ec2bef70db22955adf401fac3b7af937816eb25d54d9f2a92e5a2a04bd8b8d7568204fd289f5ed2e033a76209d288e11e8a4dbb06b9029e90cb186446746853f02d738e06bba538894e03e2658ab3d7f9ac861d2cffdf12396004d1cd15f18812d3803ab9e06f41c9b374d6a0678bb82ce06d9e3b9dbc8d2e90b8f64d0d040f",+ "sum": "1886043430"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000051",+ "node": {+ "value": "3fa8a33689d842f7d7052e5699dcc70ab2b587617041e5aa1e2f41911d525505f061d3ca45152f5a7a1fab50c674e4597a52b46aafb4ba57413879cad1308321843abb7c39696fc2f2e225878bb1191ee151cc76f1a1b8d491c1672fecbf710db82dcd32554361967fc839c8e5d4e488856e1b9382eb3fc3bdc3b6886a3cd79761b02bafa080a745ef6afa26822f1d10d5e8eefb842837d82c9986e78fc3390caa142b7643de8f613e5a890a57f5883409549537f8139534f4ca1b60f33e42be25433f1d82add5306a4cfce258c0d4f1f3c9148ffb5c4b626d51f78ac20bff0393b7fdb4b9cd70fee7f69892c8a9ee089c6c5c7bee0a1b825e",+ "sum": "2269076075"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000052",+ "node": {+ "value": "5b9517f2c82d55b6230697053092eca450b7b0d3242b2689efe36409e820d91fa4932034d96495d9dd3baa4b385da815a7cb69438ff648b326e7efe8d688e88570ba59df7c439faf72c95317a10c984c5ec0043407e9fc9b46487810eac19d2bb40e0a654935f76e7d8861480c5f48419eb33084d40e1070e5ad542c94f58b49e67dd05b6637a2c67d",+ "sum": "737373517"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000053",+ "node": {+ "value": "414534a2b95980d274a89579feccf1c7df3787a9435e588f249606a93b7ac41c8aaa84b91c95cad9463d4881de7353d95b13bbde4c9da90bf1fe96257309a416407c64368b5564f022c4a493f2a39df1696f45801e42a52d0035a30d19b9cbc7a27561f3ab474c01115c4499b4adec660ea06ebaa1a14c4e667580ba4f38f64e5cb5566bffb486dcae10cd17",+ "sum": "1406187694"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000054",+ "node": {+ "value": "acb329ba538f97f3556548d163be25e69f88fff0743150623be0a1d82af9384ca335927a0e9cacc3dadbdf1e24fa5c81f2602d109e140033929e409b9a0fa4f2653944edcb8b3ef963ba7f8806196c73bff0ded670c6def5d240c5f3daa121f8d5bec9b2a0b0f1d62d54b013dc742d6bd46325460f692b76d4991f0796820ddebf150c7d33829795784dd2759b334d270670a7264941be5d99d460d078a9eedc3660cb3176ad302f9365f0bd698e469f3e63511abc81109995dba17be1abe8bcd28407c7fc8d02c14794bb033e178a94f6dc73719d5bc235f980a16eccb4121ca83b13c4e165931ae4f1924292f8cfdf1c3ed40feb71e13d919b48fa296ddd",+ "sum": "1944966754"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000055",+ "node": {+ "value": "b4d23114a3d8f4c7bc44cb8424df1f70e8d77366161c7cdd709e97610aca3a24fb2202ffe15eaaa25d711cb5179212a2c6497a13e5d7c3657bc502b3d2ebde2e57b714dd9bc21e73795f3d35d620613918c4c9aa0e89031481c97a5a4c15ec6abe42d40498c33d71c823bf1d5bb5fee457e2fff0bf777c80c6e3336ab3ce793440e74b336a8f7034f6ea2e4ff5ea4e",+ "sum": "251883668"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000056",+ "node": {+ "value": "a7c350202b5e4cf7ed097da49b970a6db41e5e98f3845b42f46663b1d1ff01da71389a8737ba8f51eac1ef357ba5ac9a80dd2c7f9476111dcd651fc33f4c86dc8658656f3f02a8878bc38ff0d0a1af2e31fb92eaef08c50195490818661feaf90e8b6f5daa1ebedb2cdbc8d5dc16db3505f9611ac46bc37931e02c1fd6aad6e4",+ "sum": "1490229468"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000057",+ "node": {+ "value": "b7f68b0db3890b11113ecc839a4fa4de25160e574289aabe4d8fb79cecf9d2fa75ac8d0195beefbdfe0815f8d7d9751c1280a29b547149ec7c2295f5afa53cfb516158086bf203357eec2a5db71143f996c81555a47f92209719a71570a5553f1ff9b4b41827dd74657b463f36623565f0c9f4d2ee8735d6af56ceb3b3d0ec516b22f0ddafbc24647481f61ab169e2616c91c0e1f6a35436598ed801670e1dba76226cbd0544959ebe70f836c8a7df575cb907d7",+ "sum": "819571074"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000058",+ "node": {+ "value": "80ed5aaa49d4961db96dbb787f021d99231001360d532a70ee1fb94bd6f26524dd4b7556c6d40e08723d7f9905aca66c4743f2bf8b34493bdabcfca617809a867bfe0a4f94c756a6a3dcd04ffc0a3ac671a0afefe0d5d447efcec48c6368998760db6a572676d429b6d3d6e0c815650447748c4b27541c5447acfb8f7261b6378f",+ "sum": "532094584"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000059",+ "node": {+ "value": "96344f11aca912cc5098e9ee39e0b6794cc1dc2df1b10f927102705efa20e667b63a91f935c17764650b287f5289d5790766555f31985c5aad94c652ba41fa9c0195d15405f1fcce9e23054a42c8a252da83bf6268782ba44edec5d8f94a20b1830cd1c5894cc6b9b52ad0b12a5ecf3195",+ "sum": "172356692"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000005a",+ "node": {+ "value": "a32a0b02483a3a72138f3a2cb21e706427c4d604674dab88d429f28a67be7a996126e077a1dcf8989d90d08b08f4abb9a546b3c64ecaa287bf3468c59add86365b885f52afe13ed8d269ea61832a7ecbb96ff3336f58a1eeaa6dde3611f3ff7c2cc8c9b745b0e8b5919914245a49ac192cd77d10deb9a249623f696065a532c20eef9e9b0fe706579566a9eeb14d4e8251a7750e29eaa60f034c1a7a1d51aa03a45fff89acf41080deec5506128b06f003",+ "sum": "3028428940"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000005b",+ "node": {+ "value": "fa46bc409331b5ae80d873cd042bff079b2b9d8af8065a22c449c32a56dbbe7a80d0f3e30b9167532506915883dce0aa9cb749e4368c595c5bd33b57e36d98cc9bf91cbfa47331d69b5cbe9c92bc66c0fc9ca8717bfc108e1f71033314dba02a28b9aa05890cb01ae9175806c3c4215bd446f6cc96ec5d08982b4f83cd1646160e1d306b3cdec02d251f0901b03e8c3c35464eaa5082586bb55482db97599d513ed8d7a82e32fae302684b7ede058474c1fac789344416fec93fb982accd162dd956ba2f31a894e9366eca00e6e997fbbf9a29808b",+ "sum": "1771929795"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000005c",+ "node": {+ "value": "835715f735c1e0db273cdda6897c9f39bf0d7eb7caf93f657ef4d3fecea28baf69cf36d3cf347081df3114455eb4fe3e49ad3c3f14435e0b39b6c0d16db0fbcfd7ba8da8760d5952c03667251e7a4c3008cfb0904225e55c23b884bb09d26631650460c4240bd5a165b531ee76ba5749b3bc60adad35de519321c1672b47bc35fb59f7792a349511b2bb3504ba4a28717823a27a1f99ce6970290b26efcf1e7a0399b10eb10c1299c09b80f4520d00e7908d004d5b6a72a411759cfa9523f6b2912234481b1d8fe4c2365961c0528bd593d42bebb398b5836ae6ca013fe440adbb0090e8ea27",+ "sum": "2568302959"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000005d",+ "node": {+ "value": "4f4db40e4973a9797a23363d3c53e1b0d1a9159bfb26158f44734b3c34b571be641bba2db937d4ae1eedc807b95b1c2a7d44804885536316ad38aedf0d83b1519661f2bb5283cb9c50dd61c3753433e988189f26962d1f4befd444257d0b6d5b819d5fd57222c9fdff032e07a4d8686d451e71de4748965309c0",+ "sum": "3094672638"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000005e",+ "node": {+ "value": "a2d7c422ab7c1cb828b9f2be96bb9d6b5be7ef8134bd9ccf8151620937d720d83dbdddbfaba8ecd2eab6f1974090efde0ca963e9fdd691ed0cc5e074c5780779222552fa46ddcd951763a32aa3a044ff4a73cbab",+ "sum": "2371441201"+ }+ },+ {+ "key": "000000000000000000000000000000000000000000000000000000000000005f",+ "node": {+ "value": "41dabb3c2c03de721fba1a2db732a89629a8de3cfebc3918df1a9d5053d09da5b7316e3285bf62156ca28cb64d343e72445fd66757bf4ab374fe7932a65f3d7fb6e42cb1",+ "sum": "1583377072"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000060",+ "node": {+ "value": "2ee454a467df1aa7e468a6e7035515f473901efca5d46ff35870e0cc2575bbd7f8866c8e73cb157903a1694ff3051424f28de826984dcd065dc3658df144ae3a6d37b88c367e3cf7c58169dfdedda4a2821ce2218840472ff72f0dd1a6b0",+ "sum": "2740722353"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000061",+ "node": {+ "value": "100555ff1899f9307e27503b2cb7714bf3b636cc64b61d2e374119c8ef8adb21f1516c7fe238c807818065bf312003c12e02525d69d9629a99e4ac66ad2e792f302cd2a6f5f702dd28040738a084a7052f2c3ed0924c33b7a5d357b7c9a29cebd8621a4bfb7bb34676ff210d59f7f9d4eafb7c5c490c9ea48402af5bb072c4731bdebcbed4e8e08a67931b6d7342d4ef7bc4a75ca1dfbd32ed6027d8fcb71e3f55565c02e06daa8c579b69774889181291c470576a99e11f2c5acf77e0",+ "sum": "1861337517"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000062",+ "node": {+ "value": "91ef65ed24fa43b894a499b642adc01b2fa1c4b58801411941bb448f1f7a04794d2cfe5db1be61f7b86d6ecac547ee51d4c9050f9e9f31",+ "sum": "2208819645"+ }+ },+ {+ "key": "0000000000000000000000000000000000000000000000000000000000000063",+ "node": {+ "value": "8dae958c150a78c920838a0db752b080a32e67ac312fa76b589a385f31847196076ed81021fcc375bfcc8e1361878e2693860eb21ff0595e4eaaf7897f2b79367f7c4f711279bf0c93a97dcb1cd8d87e444ad5f4cb5c1de44e37868c6743f1cd72cec376726f26c8bd4836f9a9f9c68042f95ca6f9d7cde493e531c5538bf7ace6dd768db69ac7b41ce93e8ca27ff20a83ff2148ec5b89e05d8b8f5d78d0fe16b96f6e",+ "sum": "1286343043"+ }+ }+ ],+ "inclusion_proofs": null,+ "exclusion_proofs": null,+ "comment": "leaf replacement"+ }+ ],+ "error_test_cases": null+}
+ lib/Data/MSSMT.hs view
@@ -0,0 +1,27 @@+{-# OPTIONS_HADDOCK prune #-}++-- |+-- Module: Data.MSSMT+-- Copyright: (c) 2026 Jared Tobin+-- License: MIT+-- Maintainer: Jared Tobin <jared@jtobin.io>+--+-- High-performance, in-memory merkle-sum sparse merkle trees (MS-SMTs).+--+-- An MS-SMT has 2^256 leaves, addressed by 256-bit keys. Each leaf+-- holds a value and a sum, and each branch commits to its children+-- and to the sum of their sums. Branches can commit to their children+-- in one of two ways, each with its own tree type:+--+-- * "Data.MSSMT.Split": each branch commits to the hash and sum of+-- each of its children. This is the default, re-exported here.+--+-- * "Data.MSSMT.Aggregate": each branch commits to its children's+-- hashes and the sum of their sums, as in Taproot Assets.++module Data.MSSMT (+ module Data.MSSMT.Split+ ) where++import Data.MSSMT.Split+import Prelude hiding (lookup)
+ lib/Data/MSSMT/Aggregate.hs view
@@ -0,0 +1,110 @@+{-# OPTIONS_HADDOCK prune #-}++-- |+-- Module: Data.MSSMT.Aggregate+-- Copyright: (c) 2026 Jared Tobin+-- License: MIT+-- Maintainer: Jared Tobin <jared@jtobin.io>+--+-- A merkle-sum sparse merkle tree (MS-SMT) whose branches commit to+-- their children's hashes and the sum of their sums, as in Taproot+-- Assets.+--+-- The tree has 2^256 leaves, addressed by 256-bit keys. Each leaf+-- holds a value and a sum, and commits to both via sha256(value ||+-- sum). Each branch commits to the hashes of its children and the sum+-- of their sums, via sha256(left || right || sum). A subtree holding+-- no leaves is the full subtree of empty leaves (an empty value with+-- zero sum), hashed as any other.+--+-- Roots and proofs agree with those of the Taproot Assets MS-SMT.++module Data.MSSMT.Aggregate (+ -- * Keys, hashes, and commitments+ Key+ , key+ , Hash+ , parse_hash+ , serialize_hash+ , Commitment(..)++ -- * Tree+ , Tree+ , empty+ , insert+ , insert_many+ , delete+ , lookup+ , root++ -- * Proofs+ , Proof(..)+ , prove+ , verify+ ) where++import qualified Data.ByteString as BS+import Data.Coerce (coerce)+import Data.MSSMT.Internal (+ Commitment(..), Hash, Key, Scheme(..), key, parse_hash+ , serialize_hash+ )+import qualified Data.MSSMT.Internal as I+import Data.Void (Void)+import Data.Word (Word64)+import Prelude hiding (lookup)++-- | A merkle-sum sparse merkle tree whose branches commit to their+-- children's hashes and the sum of their sums.+newtype Tree = Tree (I.Tree Void)+ deriving (Eq, Show)++-- | The empty tree.+empty :: Tree+empty = Tree I.empty++-- | Insert a value and sum at a key, replacing any existing leaf.+--+-- Returns 'Nothing' if the tree's sum would overflow.+insert :: Key -> BS.ByteString -> Word64 -> Tree -> Maybe Tree+insert k v s (Tree t) = coerce (I.complete (I.insert_with Aggregate k v s t))++-- | Insert many values and sums, as if one at a time, but rehashing+-- each changed node once.+--+-- Where a key appears more than once, its last appearance wins, and+-- an empty value with zero sum deletes whatever is at its key.+-- Returns 'Nothing' if the resulting tree's sum would overflow.+insert_many :: [(Key, BS.ByteString, Word64)] -> Tree -> Maybe Tree+insert_many kvs (Tree t) =+ coerce (I.complete (I.insert_many_with Aggregate kvs t))++-- | Delete the leaf at a key.+delete :: Key -> Tree -> Tree+delete k (Tree t) = Tree (I.complete (I.delete_with Aggregate k t))++-- | Look up the value and sum at a key.+lookup :: Key -> Tree -> Maybe (BS.ByteString, Word64)+lookup k (Tree t) = I.complete (I.lookup k t)++-- | The tree's root commitment.+root :: Tree -> Commitment+root (Tree t) = I.root_with Aggregate t++-- | A merkle proof for a key: the commitments of the 256 siblings along+-- its path, from the leaf up to the root's.+newtype Proof = Proof [Commitment]+ deriving (Eq, Show)++-- | Produce a proof for the leaf at a key.+--+-- If no leaf exists at the key, this proves its exclusion.+prove :: Key -> Tree -> Proof+prove k (Tree t) = Proof (I.complete (I.prove_aggregate k t))++-- | Verify that a value and sum sit at a key, under a root.+--+-- An empty value with zero sum verifies the key's exclusion. Proofs+-- whose branch sums overflow are rejected.+verify :: Key -> BS.ByteString -> Word64 -> Proof -> Commitment -> Bool+verify k v s (Proof ps) = I.verify_aggregate k v s ps
+ lib/Data/MSSMT/Hash.hs view
@@ -0,0 +1,359 @@+{-# OPTIONS_HADDOCK hide #-}+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE MagicHash #-}+{-# LANGUAGE UnboxedTuples #-}+{-# LANGUAGE UnliftedFFITypes #-}++-- |+-- Module: Data.MSSMT.Hash+-- Copyright: (c) 2026 Jared Tobin+-- License: MIT+-- Maintainer: Jared Tobin <jared@jtobin.io>+--+-- MS-SMT hashing.++module Data.MSSMT.Hash (+ -- * Hashes+ Hash(..)+ , parse_hash+ , serialize_hash+ , unsafe_hash++ -- * Leaf and branch hashes+ , native+ , hash_value+ , hash_leaf_split+ , hash_leaf_aggregate+ , hash_node_split+ , hash_node_split_native+ , hash_node_split_pure+ , hash_node_aggregate+ , hash_node_aggregate_native+ , hash_node_aggregate_pure++ -- * Schemes+ , Scheme(..)+ , hash_branch++ -- * Scratch arrays+ , Buffer+ , with_scratch+ , hash_branch#+ , hash_leaf_split#+ ) where++import qualified Crypto.Hash.SHA256 as SHA256+import qualified Crypto.Hash.SHA256.Internal as SHA256I+import Data.Bits (unsafeShiftL, unsafeShiftR, (.|.))+import qualified Data.ByteString as BS+import qualified Data.ByteString.Internal as BI+import qualified Data.ByteString.Unsafe as BU+import Data.Word (Word8, Word64)+import Foreign.C.Types (CInt(..))+import Foreign.Marshal.Utils (copyBytes)+import Foreign.Ptr (Ptr, castPtr)+import Foreign.Storable (pokeByteOff)+import qualified GHC.Exts as Exts+import GHC.Exts (Int#, MutableByteArray#, State#, (+#), (*#))+import GHC.IO (unIO, unsafeDupablePerformIO)+import GHC.Word (Word32(..))++-- | A 256-bit hash.+data Hash = Hash+ {-# UNPACK #-} !Word64 {-# UNPACK #-} !Word64+ {-# UNPACK #-} !Word64 {-# UNPACK #-} !Word64+ deriving (Eq, Ord, Show)++-- | Parse a 32-byte hash.+parse_hash :: BS.ByteString -> Maybe Hash+parse_hash bs+ | BS.length bs == 32 = Just (unsafe_hash bs)+ | otherwise = Nothing++-- | Serialize a hash to 32 bytes.+serialize_hash :: Hash -> BS.ByteString+serialize_hash (Hash a b c d) = BI.unsafeCreate 32 $ \p -> do+ poke_be64 p 00 a+ poke_be64 p 08 b+ poke_be64 p 16 c+ poke_be64 p 24 d++-- bytes ----------------------------------------------------------------------++-- | Read a hash from 32 bytes. Callers check the length.+unsafe_hash :: BS.ByteString -> Hash+unsafe_hash bs = Hash (be64 00) (be64 08) (be64 16) (be64 24) where+ be64 i =+ byte i `unsafeShiftL` 56 .|. byte (i + 1) `unsafeShiftL` 48+ .|. byte (i + 2) `unsafeShiftL` 40 .|. byte (i + 3) `unsafeShiftL` 32+ .|. byte (i + 4) `unsafeShiftL` 24 .|. byte (i + 5) `unsafeShiftL` 16+ .|. byte (i + 6) `unsafeShiftL` 08 .|. byte (i + 7)+ byte i = fromIntegral (BU.unsafeIndex bs i) :: Word64+{-# INLINE unsafe_hash #-}++poke_be64 :: Ptr Word8 -> Int -> Word64 -> IO ()+poke_be64 p i w = do+ pokeByteOff p (i + 0) (fromIntegral (w `unsafeShiftR` 56) :: Word8)+ pokeByteOff p (i + 1) (fromIntegral (w `unsafeShiftR` 48) :: Word8)+ pokeByteOff p (i + 2) (fromIntegral (w `unsafeShiftR` 40) :: Word8)+ pokeByteOff p (i + 3) (fromIntegral (w `unsafeShiftR` 32) :: Word8)+ pokeByteOff p (i + 4) (fromIntegral (w `unsafeShiftR` 24) :: Word8)+ pokeByteOff p (i + 5) (fromIntegral (w `unsafeShiftR` 16) :: Word8)+ pokeByteOff p (i + 6) (fromIntegral (w `unsafeShiftR` 08) :: Word8)+ pokeByteOff p (i + 7) (fromIntegral w :: Word8)+{-# INLINE poke_be64 #-}++-- hashing --------------------------------------------------------------------++-- | sha256(value).+hash_value :: BS.ByteString -> Hash+hash_value = unsafe_hash . SHA256.hash++-- | sha256(key || value hash || sum), a split leaf's hash.+--+-- The 72-byte message has the same two-block layout as that of+-- 'hash_node_aggregate'.+hash_leaf_split :: Hash -> Hash -> Word64 -> Hash+hash_leaf_split = hash_node_aggregate+{-# INLINE hash_leaf_split #-}++-- | sha256(value || sum), an aggregate leaf's hash.+hash_leaf_aggregate :: BS.ByteString -> Word64 -> Hash+hash_leaf_aggregate v s = unsafe_hash . SHA256.hash $+ BI.unsafeCreate (l + 8) $ \p -> do+ BU.unsafeUseAsCString v $ \q -> copyBytes p (castPtr q) l+ poke_be64 p l s+ where+ l = BS.length v++-- | sha256(left || left sum || right || right sum).+--+-- The 80-byte message is exactly two blocks: left || left sum || the+-- 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_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.+--+-- The 72-byte message is exactly two blocks: left || right, then+-- sum || 0x80 || 0^47 || 576 (the message length in bits, as a+-- big-endian 64-bit word).+hash_node_aggregate :: Hash -> Hash -> Word64 -> Hash+hash_node_aggregate l r s+ | native = hash_node_aggregate_native l r s+ | otherwise = hash_node_aggregate_pure l r s+{-# INLINE hash_node_aggregate #-}++-- ppad-sha256's hardware block function, and its availability check;+-- the block function updates eight native-endian state words in+-- place, given sixteen native-endian message words+foreign import ccall unsafe "sha256_block_native"+ c_sha256_block+ :: MutableByteArray# Exts.RealWorld+ -> MutableByteArray# Exts.RealWorld+ -> IO ()++foreign import ccall unsafe "sha256_native_available"+ c_sha256_native_available :: IO CInt++-- | Are hardware SHA-256 instructions available?+native :: Bool+native = unsafeDupablePerformIO c_sha256_native_available /= 0+{-# NOINLINE native #-}++-- initial SHA-256 state+iv :: Hash+iv = Hash+ 0x6a09e667bb67ae85 0x3c6ef372a54ff53a+ 0x510e527f9b05688c 0x1f83d9ab5be0cd19++-- the hardware block function's state and block arrays+type Buffer = MutableByteArray# Exts.RealWorld++-- run a computation over fresh state and block arrays+with_scratch+ :: (Buffer -> Buffer -> State# Exts.RealWorld+ -> (# State# Exts.RealWorld, a #))+ -> a+with_scratch f = case Exts.runRW# go of+ (# _, a #) -> a+ where+ go s0 =+ case Exts.newByteArray# 32# s0 of { (# s1, st #) ->+ case Exts.newByteArray# 64# s1 of { (# s2, bk #) ->+ f st bk s2 }}+{-# INLINE with_scratch #-}++-- | '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 r sr =+ with_scratch (\st bk -> hash_node_split# st bk l sl r sr)++-- 'hash_node_split' via hardware SHA-256, over the given state and+-- block arrays, both of which it overwrites in full. callers check+-- 'native'+hash_node_split#+ :: Buffer -> Buffer -> Hash -> Word64 -> Hash -> Word64+ -> State# Exts.RealWorld -> (# State# Exts.RealWorld, Hash #)+hash_node_split# st bk l sl (Hash b0 b1 b2 b3) sr s0 =+ case put_hash st 0# iv s0 of { s1 ->+ case put_hash bk 0# l s1 of { s2 ->+ case put_w64 bk 4# sl s2 of { s3 ->+ case put_w64 bk 5# b0 s3 of { s4 ->+ case put_w64 bk 6# b1 s4 of { s5 ->+ case put_w64 bk 7# b2 s5 of { s6 ->+ case unIO (c_sha256_block st bk) s6 of { (# s7, () #) ->+ case put_w64 bk 0# b3 s7 of { s8 ->+ case put_w64 bk 1# sr s8 of { s9 ->+ case Exts.writeWord32Array# bk 4# (w32 0x80000000) s9 of { s10 ->+ case Exts.setByteArray# bk 20# 40# 0# s10 of { s11 ->+ case Exts.writeWord32Array# bk 15# (w32 640) s11 of { s12 ->+ case unIO (c_sha256_block st bk) s12 of { (# s13, () #) ->+ get_hash st s13 }}}}}}}}}}}}}+{-# INLINE hash_node_split# #-}++-- | '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)+ (hi sl) (lo sl) (hi b0) (lo b0) (hi b1) (lo b1) (hi b2) (lo b2)+ !(SHA256I.R x0 x1 x2 x3 x4 x5 x6 x7) = SHA256I.update r1 $ SHA256I.B+ (hi b3) (lo b3) (hi sr) (lo sr) (w32 0x80000000)+ z z z z z z z z z z (w32 640)+ in Hash (w64 x0 x1) (w64 x2 x3) (w64 x4 x5) (w64 x6 x7)+ where+ z = w32 0++-- | 'hash_node_aggregate', via hardware SHA-256. Callers check 'native'.+hash_node_aggregate_native :: Hash -> Hash -> Word64 -> Hash+hash_node_aggregate_native l r s =+ with_scratch (\st bk -> hash_node_aggregate# st bk l r s)++-- 'hash_node_aggregate' via hardware SHA-256, over the given state and+-- block arrays, both of which it overwrites in full. callers check+-- 'native'+hash_node_aggregate#+ :: Buffer -> Buffer -> Hash -> Hash -> Word64+ -> State# Exts.RealWorld -> (# State# Exts.RealWorld, Hash #)+hash_node_aggregate# st bk l r s s0 =+ case put_hash st 0# iv s0 of { s1 ->+ case put_hash bk 0# l s1 of { s2 ->+ case put_hash bk 4# r s2 of { s3 ->+ case unIO (c_sha256_block st bk) s3 of { (# s4, () #) ->+ case put_w64 bk 0# s s4 of { s5 ->+ case Exts.writeWord32Array# bk 2# (w32 0x80000000) s5 of { s6 ->+ case Exts.setByteArray# bk 12# 48# 0# s6 of { s7 ->+ case Exts.writeWord32Array# bk 15# (w32 576) s7 of { s8 ->+ case unIO (c_sha256_block st bk) s8 of { (# s9, () #) ->+ get_hash st s9 }}}}}}}}}+{-# INLINE hash_node_aggregate# #-}++-- | 'hash_node_aggregate', in pure Haskell.+hash_node_aggregate_pure :: Hash -> Hash -> Word64 -> Hash+hash_node_aggregate_pure (Hash a0 a1 a2 a3) (Hash b0 b1 b2 b3) s =+ 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)+ (hi b0) (lo b0) (hi b1) (lo b1) (hi b2) (lo b2) (hi b3) (lo b3)+ !(SHA256I.R x0 x1 x2 x3 x4 x5 x6 x7) = SHA256I.update r1 $ SHA256I.B+ (hi s) (lo s) (w32 0x80000000) z z z z z z z z z z z z (w32 576)+ in Hash (w64 x0 x1) (w64 x2 x3) (w64 x4 x5) (w64 x6 x7)+ where+ z = w32 0++-- words ----------------------------------------------------------------------++w32 :: Word -> Exts.Word32#+w32 (Exts.W# w) = Exts.wordToWord32# w+{-# INLINE w32 #-}++hi :: Word64 -> Exts.Word32#+hi w = case fromIntegral (w `unsafeShiftR` 32) of W32# x -> x+{-# INLINE hi #-}++lo :: Word64 -> Exts.Word32#+lo w = case fromIntegral w of W32# x -> x+{-# INLINE lo #-}++w64 :: Exts.Word32# -> Exts.Word32# -> Word64+w64 h l = fromIntegral (W32# h) `unsafeShiftL` 32 .|. fromIntegral (W32# l)+{-# INLINE w64 #-}++-- write a word as two 32-bit words, high first, at a 64-bit offset+put_w64+ :: MutableByteArray# s -> Int# -> Word64 -> State# s -> State# s+put_w64 a i w s0 =+ case Exts.writeWord32Array# a (2# *# i) (hi w) s0 of+ s1 -> Exts.writeWord32Array# a (2# *# i +# 1#) (lo w) s1+{-# INLINE put_w64 #-}++-- write a hash at a 64-bit offset+put_hash+ :: MutableByteArray# s -> Int# -> Hash -> State# s -> State# s+put_hash a i (Hash w0 w1 w2 w3) s0 =+ case put_w64 a i w0 s0 of { s1 ->+ case put_w64 a (i +# 1#) w1 s1 of { s2 ->+ case put_w64 a (i +# 2#) w2 s2 of { s3 ->+ put_w64 a (i +# 3#) w3 s3 }}}+{-# INLINE put_hash #-}++-- read a hash from eight 32-bit words+get_hash :: MutableByteArray# s -> State# s -> (# State# s, Hash #)+get_hash a s0 =+ case Exts.readWord32Array# a 0# s0 of { (# s1, x0 #) ->+ case Exts.readWord32Array# a 1# s1 of { (# s2, x1 #) ->+ case Exts.readWord32Array# a 2# s2 of { (# s3, x2 #) ->+ case Exts.readWord32Array# a 3# s3 of { (# s4, x3 #) ->+ case Exts.readWord32Array# a 4# s4 of { (# s5, x4 #) ->+ case Exts.readWord32Array# a 5# s5 of { (# s6, x5 #) ->+ case Exts.readWord32Array# a 6# s6 of { (# s7, x6 #) ->+ case Exts.readWord32Array# a 7# s7 of { (# s8, x7 #) ->+ (# s8, Hash (w64 x0 x1) (w64 x2 x3) (w64 x4 x5) (w64 x6 x7) #)+ }}}}}}}}+{-# INLINE get_hash #-}++-- schemes --------------------------------------------------------------------++-- | A branch hashing scheme.+data Scheme =+ -- | 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.+ | Aggregate+ deriving (Eq, Show)++-- 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_split l sl r sr+hash_branch Aggregate l sl r sr = hash_node_aggregate l r (sl + sr)+{-# INLINE hash_branch #-}++-- 'hash_branch', over the given state and block arrays where hardware+-- SHA-256 is available+hash_branch#+ :: Scheme -> Buffer -> Buffer -> Hash -> Word64 -> Hash -> Word64+ -> State# Exts.RealWorld -> (# State# Exts.RealWorld, Hash #)+hash_branch# sc st bk l sl r sr s0+ | native = case sc of+ Split -> hash_node_split# st bk l sl r sr s0+ Aggregate -> hash_node_aggregate# st bk l r (sl + sr) s0+ | otherwise = (# s0, hash_branch sc l sl r sr #)+{-# INLINE hash_branch# #-}++-- | 'hash_leaf_split', over the given state and block arrays where+-- hardware SHA-256 is available.+hash_leaf_split#+ :: Buffer -> Buffer -> Hash -> Hash -> Word64+ -> State# Exts.RealWorld -> (# State# Exts.RealWorld, Hash #)+hash_leaf_split# st bk k vh s s0+ | native = hash_node_aggregate# st bk k vh s s0+ | otherwise = (# s0, hash_leaf_split k vh s #)+{-# INLINE hash_leaf_split# #-}
+ lib/Data/MSSMT/Internal.hs view
@@ -0,0 +1,640 @@+{-# OPTIONS_HADDOCK hide #-}+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE EmptyCase #-}+{-# LANGUAGE MagicHash #-}+{-# LANGUAGE UnboxedSums #-}+{-# LANGUAGE UnboxedTuples #-}++-- |+-- Module: Data.MSSMT.Internal+-- Copyright: (c) 2026 Jared Tobin+-- License: MIT+-- Maintainer: Jared Tobin <jared@jtobin.io>+--+-- MS-SMT internals.++module Data.MSSMT.Internal (+ -- * Keys, hashes, and commitments+ Key(..)+ , key+ , Hash(..)+ , parse_hash+ , serialize_hash+ , Commitment(..)++ -- * Hashing+ , native+ , hash_value+ , hash_leaf_split+ , hash_leaf_aggregate+ , hash_node_split+ , hash_node_split_native+ , hash_node_split_pure+ , hash_node_aggregate+ , hash_node_aggregate_native+ , hash_node_aggregate_pure++ -- * Schemes+ , Scheme(..)++ -- * Tree+ , Tree(..)+ , Kind(..)+ , Payload(..)+ , Missing(..)+ , complete+ , expand+ , empty+ , insert_with+ , insert_many_with+ , delete_with+ , lookup+ , root_with++ -- * Proofs+ , Neighbor(..)+ , prove_split+ , verify_split+ , prove_aggregate+ , verify_aggregate+ ) where++import Data.Bits (unsafeShiftR, xor, (.&.))+import qualified Data.ByteString as BS+import Data.MSSMT.Hash+import Data.List (sortBy)+import qualified Data.Primitive.PrimArray as PA+import Data.Ord (comparing)+import Data.Void (Void, absurd)+import Data.Word (Word64)+import qualified GHC.Exts as Exts+import GHC.Exts (State#)+import Prelude hiding (lookup)++-- | A 256-bit key, held as a hash's big-endian words, so that keys+-- are ordered as their bytes are.+newtype Key = Key Hash+ deriving (Eq, Ord, Show)++-- | Parse a 32-byte key.+key :: BS.ByteString -> Maybe Key+key = fmap Key . parse_hash++-- | A node's commitment: its hash, and its sum.+data Commitment = Commitment {-# UNPACK #-} !Hash {-# UNPACK #-} !Word64+ deriving (Eq, Show)++-- | A merkle-sum sparse merkle tree, whose subtrees held elsewhere, if+-- it has any, are stood for by stubs carrying an @s@.+--+-- A subtree holding a single leaf is stored as that leaf, at the+-- subtree's height, and a branch is stored only where two or more+-- leaves lie beneath it. A complete tree, held entirely in memory, is+-- a @Tree Void@, which can't have stubs; one held partly elsewhere,+-- as in a store, is a @Tree Kind@.+data Tree s =+ Empty+ -- a subtree holding exactly one leaf: the subtree's commitment at+ -- its height, the leaf's hash, and the leaf's key and value+ | Leaf+ {-# UNPACK #-} !Commitment {-# UNPACK #-} !Hash {-# UNPACK #-} !Key+ !BS.ByteString+ | Node !(Tree s) {-# UNPACK #-} !Commitment !(Tree s)+ -- a subtree held elsewhere: what stands for it, and its commitment+ | Stub !s {-# UNPACK #-} !Commitment+ deriving (Eq, Show)++-- | What a subtree holds: a single leaf, or a branch over two or more.+data Kind = Single | Branch+ deriving (Eq, Show)++-- | What a stub can carry: something telling what kind of subtree it+-- stands for.+class Payload s where+ payload_kind :: s -> Kind++instance Payload Kind where+ payload_kind = id++instance Payload Void where+ payload_kind = absurd++-- | A subtree held elsewhere that an operation needed: what stands for+-- it, and its commitment.+data Missing s = Missing !s {-# UNPACK #-} !Commitment+ deriving (Eq, Show)++-- | The result of an operation on a complete tree, which can't have+-- needed a subtree held elsewhere.+complete :: Either (Missing Void) a -> a+complete = either (\m -> case m of {}) id+{-# INLINE complete #-}++-- structure ------------------------------------------------------------------++-- leaf depth+_HEIGHT :: Int+_HEIGHT = 256++-- hashes of empty subtrees in an aggregate tree, four words per depth:+-- an empty subtree is the full subtree of empty leaves, hashed as any+-- other subtree+empties :: PA.PrimArray Word64+empties = PA.primArrayFromListN (4 * (_HEIGHT + 1))+ . concatMap (\(Hash a b c d) -> [a, b, c, d])+ . reverse . take (_HEIGHT + 1) $+ iterate (\h -> hash_node_aggregate h h 0) (hash_leaf_aggregate mempty 0)+{-# NOINLINE empties #-}++-- hash of the empty subtree at the given depth; in a split tree, it's+-- the zero hash at any depth+empty_hash :: Scheme -> Int -> Hash+empty_hash Split _ = Hash 0 0 0 0+empty_hash Aggregate d = Hash (ix 0) (ix 1) (ix 2) (ix 3) where+ ix i = PA.indexPrimArray empties (4 * d + i)+{-# INLINE empty_hash #-}++-- commitment of a subtree at the given depth+commit :: Scheme -> Int -> Tree s -> Commitment+commit sc d Empty = Commitment (empty_hash sc d) 0+commit _ _ (Leaf c _ _ _) = c+commit _ _ (Node _ c _) = c+commit _ _ (Stub _ c) = c+{-# INLINE commit #-}++-- sum of a subtree+total :: Tree s -> Word64+total Empty = 0+total (Leaf (Commitment _ s) _ _ _) = s+total (Node _ (Commitment _ s) _) = s+total (Stub _ (Commitment _ s)) = s+{-# INLINE total #-}++-- path bit at the given depth; LSB-first within each byte. a word+-- holds its bytes big-endian, so the bit at depth d is at 8 * (7 - j) ++-- i in word d / 64, for j = d / 8 mod 8 and i = d mod 8: d mod 64 with+-- j's bits flipped+bit :: Key -> Int -> Bool+bit (Key (Hash w0 w1 w2 w3)) d =+ w `unsafeShiftR` ((d .&. 63) `xor` 56) .&. 1 /= 0+ where+ w = case d `unsafeShiftR` 6 of+ 0 -> w0+ 1 -> w1+ 2 -> w2+ _ -> w3+{-# INLINE bit #-}++-- whether two keys' paths agree above the given depth+agree :: Key -> Key -> Int -> Bool+agree k k' d = all (\j -> bit k j == bit k' j) [0 .. d - 1]++-- a key, as a hash's words+key_hash :: Key -> Hash+key_hash (Key h) = h++-- a leaf's hash under a scheme, over the given state and block arrays+hash_leaf#+ :: Scheme -> Buffer -> Buffer -> Key -> BS.ByteString -> Word64+ -> State# Exts.RealWorld -> (# State# Exts.RealWorld, Hash #)+hash_leaf# Split st bk k v s =+ hash_leaf_split# st bk (key_hash k) (hash_value v) s+hash_leaf# Aggregate _ _ _ v s = \s0 -> (# s0, hash_leaf_aggregate v s #)+{-# INLINE hash_leaf# #-}++-- the leaf at a key, if there's one, passed its sum and value, or the+-- stub on the key's path, if there's one+with_leaf+ :: Key -> Tree s -> r -> (Word64 -> BS.ByteString -> r) -> (Missing s -> r)+ -> r+with_leaf k t0 none some stub = go 0 t0 where+ go !d t = case t of+ Empty -> none+ Leaf (Commitment _ s) _ k' v+ | k' == k -> some s v+ | otherwise -> none+ Node l _ r -> go (d + 1) (if bit k d then r else l)+ Stub p c -> stub (Missing p c)+{-# INLINE with_leaf #-}++-- an operation's result in a tree, or what it needed but found held+-- elsewhere+done#+ :: (# State# Exts.RealWorld, Tree s #)+ -> (# State# Exts.RealWorld, (# Tree s | Missing s #) #)+done# (# s0, t #) = (# s0, (# t | #) #)+{-# INLINE done# #-}++-- the first depth, at or below the given one, at which two keys' paths+-- diverge; callers ensure the keys are distinct, and agree above it+diverge :: Key -> Key -> Int -> Int+diverge k k' = go where+ go !d+ | bit k d /= bit k' d = d+ | otherwise = go (d + 1)++-- raise a single-leaf subtree's commitment from one depth to a+-- shallower one: in a split tree, it's the same at any depth, and in an+-- aggregate tree, it's paired with an empty sibling at each level+-- between. strict in the key and depths under either scheme, so that+-- they're passed unboxed+raise#+ :: Scheme -> Buffer -> Buffer -> Key -> Int -> Int -> Commitment+ -> State# Exts.RealWorld -> (# State# Exts.RealWorld, Commitment #)+raise# Split _ _ !_ !_ !_ c = \s0 -> (# s0, c #)+raise# sc st bk !k !to from (Commitment h0 s) = go (from - 1) h0 where+ go !d !h s0+ | d < to = let !c = Commitment h s in (# s0, c #)+ | otherwise =+ let !e = empty_hash sc (d + 1)+ in case if bit k d+ then hash_branch# sc st bk e 0 h s s0+ else hash_branch# sc st bk h s e 0 s0 of+ (# s1, h' #) -> go (d - 1) h' s1++-- a single-leaf subtree at the given depth, given the leaf's hash+leaf#+ :: Scheme -> Buffer -> Buffer -> Int -> Key -> Hash -> Word64+ -> BS.ByteString+ -> State# Exts.RealWorld -> (# State# Exts.RealWorld, Tree s #)+leaf# sc st bk d k lh s v s0 =+ case raise# sc st bk k d _HEIGHT (Commitment lh s) s0 of+ (# s1, c #) -> let !t = Leaf c lh k v in (# s1, t #)++-- a subtree at the given depth with the given children, hashed over the+-- given state and block arrays. a lone leaf beside an empty subtree is+-- raised to this depth in their place, and two empty children make an+-- empty subtree. callers rule out sum overflow+node#+ :: Payload s+ => Scheme -> Buffer -> Buffer -> Int -> Tree s -> Tree s+ -> State# Exts.RealWorld -> (# State# Exts.RealWorld, Tree s #)+node# _ _ _ _ Empty Empty s0 = (# s0, Empty #)+node# sc st bk d Empty (Leaf c lh k v) s0 = lift# sc st bk d c lh k v s0+node# sc st bk d (Leaf c lh k v) Empty s0 = lift# sc st bk d c lh k v s0+-- a split leaf's commitment is the same at any height, so a lone leaf+-- held elsewhere moves up as it is. an aggregate one stays beneath a+-- branch, whose commitment is that of the leaf moved up a level+node# Split _ _ _ Empty t@(Stub p _) s0+ | payload_kind p == Single = (# s0, t #)+node# Split _ _ _ t@(Stub p _) Empty s0+ | payload_kind p == Single = (# s0, t #)+node# sc st bk d l r s0 =+ let !(Commitment hl sl) = commit sc (d + 1) l+ !(Commitment hr sr) = commit sc (d + 1) r+ in case hash_branch# sc st bk hl sl hr sr s0 of+ (# s1, h #) ->+ -- built strictly; a lazy tuple component would allocate a+ -- thunk for the node per level+ let !n = Node l (Commitment h (sl + sr)) r+ in (# s1, n #)+{-# INLINE node# #-}++-- raise a single-leaf subtree one level, to the given depth+lift#+ :: Scheme -> Buffer -> Buffer -> Int -> Commitment -> Hash -> Key+ -> BS.ByteString+ -> State# Exts.RealWorld -> (# State# Exts.RealWorld, Tree s #)+lift# sc st bk d c lh k v s0 = case raise# sc st bk k d (d + 1) c s0 of+ (# s1, c' #) -> let !t = Leaf c' lh k v in (# s1, t #)++-- insert a leaf, hashing it and rehashing the path to it over one pair+-- of state and block arrays+insert_leaf+ :: Payload s+ => Scheme -> Key -> BS.ByteString -> Word64 -> Tree s+ -> Either (Missing s) (Tree s)+insert_leaf sc k v s t0 = with_scratch $ \st bk s00 ->+ case hash_leaf# sc st bk k v s s00 of { (# s01, lh #) ->+ let go !d t s0 = case t of+ Empty -> done# (leaf# sc st bk d k lh s v s0)+ Leaf (Commitment _ s') lh' k' v'+ | k' == k -> done# (leaf# sc st bk d k lh s v s0)+ | otherwise ->+ let p = diverge k k' d+ -- the two leaves, beneath the branch where their paths+ -- diverge+ new = leaf# sc st bk (p + 1) k lh s v+ old = leaf# sc st bk (p + 1) k' lh' s' v'+ pair s1 =+ case new s1 of { (# s2, a #) ->+ case old s2 of { (# s3, b #) ->+ if bit k p+ then node# sc st bk p b a s3+ else node# sc st bk p a b s3 }}+ -- the branches from there up to this depth, each with+ -- an empty sibling+ up j s1+ | j == p = pair s1+ | otherwise = case up (j + 1) s1 of+ (# s2, c #)+ | bit k j -> node# sc st bk j Empty c s2+ | otherwise -> node# sc st bk j c Empty s2+ in done# (up d s0)+ Node l _ r+ | bit k d -> case go (d + 1) r s0 of+ (# s1, (# r' | #) #) -> done# (node# sc st bk d l r' s1)+ (# s1, (# | m #) #) -> (# s1, (# | m #) #)+ | otherwise -> case go (d + 1) l s0 of+ (# s1, (# l' | #) #) -> done# (node# sc st bk d l' r s1)+ (# s1, (# | m #) #) -> (# s1, (# | m #) #)+ Stub p c -> (# s0, (# | Missing p c #) #)+ in case go 0 t0 s01 of+ (# s1, (# t | #) #) -> (# s1, Right t #)+ (# s1, (# | m #) #) -> (# s1, Left m #) }+{-# INLINABLE insert_leaf #-}++-- a leaf in a subtree being rebuilt in a batch: one being put, one+-- being deleted, or an existing one, kept with its hash+data Item =+ Put {-# UNPACK #-} !Key !BS.ByteString {-# UNPACK #-} !Word64+ | Del {-# UNPACK #-} !Key+ | Kept+ {-# UNPACK #-} !Key {-# UNPACK #-} !Hash {-# UNPACK #-} !Word64+ !BS.ByteString++item_key :: Item -> Key+item_key (Put k _ _) = k+item_key (Del k) = k+item_key (Kept k _ _ _) = k++-- items whose paths go left and right at a depth+split :: Int -> [Item] -> ([Item], [Item])+split d = go [] [] where+ go !ls !rs is = case is of+ [] -> (ls, rs)+ i : rest+ | bit (item_key i) d -> go ls (i : rs) rest+ | otherwise -> go (i : ls) rs rest++-- apply a batch of puts and deletions, at distinct keys, rehashing each+-- changed node once over one pair of state and block arrays. callers+-- rule out sum overflow+batch+ :: Payload s => Scheme -> [Item] -> Tree s -> Either (Missing s) (Tree s)+batch sc items0 t0 = with_scratch $ \st bk s00 ->+ let -- the subtree at a depth holding the given items, which agree on+ -- their paths above it+ go !d t items s0 = case t of+ Empty -> done# (build d items s0)+ Leaf (Commitment _ s') lh' k' v'+ | any ((== k') . item_key) items -> done# (build d items s0)+ | otherwise -> done# (build d (Kept k' lh' s' v' : items) s0)+ Node l _ r ->+ let (ls, rs) = split d items+ side u is s1+ | null is = (# s1, (# u | #) #)+ | otherwise = go (d + 1) u is s1+ in case side l ls s0 of+ (# s1, (# | m #) #) -> (# s1, (# | m #) #)+ (# s1, (# l' | #) #) -> case side r rs s1 of+ (# s2, (# | m #) #) -> (# s2, (# | m #) #)+ (# s2, (# r' | #) #) -> done# (node# sc st bk d l' r' s2)+ Stub p c -> (# s0, (# | Missing p c #) #)++ -- the subtree at a depth holding exactly the given items' leaves+ build !d items s0 = case filter live items of+ [] -> (# s0, Empty #)+ [Put k v s] -> case hash_leaf# sc st bk k v s s0 of+ (# s1, lh #) -> leaf# sc st bk d k lh s v s1+ [Kept k lh s v] -> leaf# sc st bk d k lh s v s0+ is ->+ let (ls, rs) = split d is+ in case build (d + 1) ls s0 of+ (# s1, l #) -> case build (d + 1) rs s1 of+ (# s2, r #) -> node# sc st bk d l r s2++ live (Del _) = False+ live _ = True+ in case go 0 t0 items0 s00 of+ (# s1, (# t | #) #) -> (# s1, Right t #)+ (# s1, (# | m #) #) -> (# s1, Left m #)+{-# INLINABLE batch #-}++-- tree -----------------------------------------------------------------------++-- | The empty tree.+empty :: Tree s+empty = Empty++-- | Insert a value and sum at a key under a scheme, replacing any+-- existing leaf.+--+-- Returns 'Nothing' if the tree's sum would overflow, or what the+-- insertion needed, if it was held elsewhere.+insert_with+ :: Payload s+ => Scheme -> Key -> BS.ByteString -> Word64 -> Tree s+ -> Either (Missing s) (Maybe (Tree s))+insert_with sc k v s t = with_leaf k t (go 0) (\was _ -> go was) Left where+ go was+ | s > maxBound - (total t - was) = Right Nothing+ -- an empty value with zero sum is the empty leaf+ | BS.null v && s == 0 = Just <$> delete_with sc k t+ | otherwise = Just <$> insert_leaf sc k v s t+{-# INLINABLE insert_with #-}++-- | Insert many values and sums under a scheme, as if one at a time,+-- but rehashing each changed node once.+--+-- Where a key appears more than once, its last appearance wins, and+-- an empty value with zero sum deletes whatever is at its key.+-- Returns 'Nothing' if the resulting tree's sum would overflow, or+-- what the insertions needed, if it was held elsewhere.+insert_many_with+ :: Payload s+ => Scheme -> [(Key, BS.ByteString, Word64)] -> Tree s+ -> Either (Missing s) (Maybe (Tree s))+insert_many_with sc kvs t+ | null items = Right (Just t)+ | otherwise = do+ was <- traverse (\i -> with_leaf (item_key i) t+ (Right 0) (\s _ -> Right s) Left) items+ let after = toInteger (total t) + sum (zipWith change items was)+ if after > toInteger (maxBound :: Word64)+ then Right Nothing+ else Just <$> batch sc items t+ where+ -- the last item at each key+ items = last_each (sortBy (comparing (\(k, _, _) -> k)) kvs)+ last_each ((k, v, s) : rest@((k', _, _) : _))+ | k == k' = last_each rest+ | otherwise = item k v s : last_each rest+ last_each [(k, v, s)] = [item k v s]+ last_each [] = []++ item k v s+ | BS.null v && s == 0 = Del k+ | otherwise = Put k v s++ -- each item's change to the tree's sum, given what's at its key+ change i was = case i of+ Put _ _ s -> toInteger s - toInteger was+ Del _ -> negate (toInteger was)+ Kept {} -> 0+{-# INLINABLE insert_many_with #-}++-- | Delete the leaf at a key under a scheme.+--+-- Returns what the deletion needed, if it was held elsewhere.+delete_with+ :: Payload s => Scheme -> Key -> Tree s -> Either (Missing s) (Tree s)+delete_with sc k t0 = with_leaf k t0 (Right t0) (\_ _ -> deleted) Left where+ deleted = with_scratch $ \st bk s00 ->+ let go !d t s0 = case t of+ -- the key is present, so a leaf on its path is its own+ Empty -> (# s0, (# Empty | #) #)+ Leaf {} -> (# s0, (# Empty | #) #)+ Node l _ r+ | bit k d -> case go (d + 1) r s0 of+ (# s1, (# r' | #) #) -> done# (node# sc st bk d l r' s1)+ (# s1, (# | m #) #) -> (# s1, (# | m #) #)+ | otherwise -> case go (d + 1) l s0 of+ (# s1, (# l' | #) #) -> done# (node# sc st bk d l' r s1)+ (# s1, (# | m #) #) -> (# s1, (# | m #) #)+ Stub p c -> (# s0, (# | Missing p c #) #)+ in case go 0 t0 s00 of+ (# s1, (# t | #) #) -> (# s1, Right t #)+ (# s1, (# | m #) #) -> (# s1, Left m #)+{-# INLINABLE delete_with #-}++-- | Look up the value and sum at a key.+--+-- Returns what the lookup needed, if it was held elsewhere.+lookup :: Key -> Tree s -> Either (Missing s) (Maybe (BS.ByteString, Word64))+lookup k t = with_leaf k t (Right Nothing) (\s v -> Right (Just (v, s))) Left+{-# INLINE lookup #-}++-- | Load the subtrees held elsewhere along a key's path, down to the+-- key's slot, via a loader given what stands for each one and its+-- commitment, which returns its contents with its own subtrees held+-- elsewhere.+--+-- Operations at a key need only its path loaded.+expand+ :: Monad m => (s -> Commitment -> m (Tree s)) -> Key -> Tree s+ -> m (Tree s)+expand load k = go 0 where+ go !d t = case t of+ Stub p c -> load p c >>= go d+ Node l c r+ | bit k d -> (\r' -> Node l c r') <$> go (d + 1) r+ | otherwise -> (\l' -> Node l' c r) <$> go (d + 1) l+ Empty -> pure t+ Leaf {} -> pure t++-- | The tree's root commitment under a scheme.+root_with :: Scheme -> Tree s -> Commitment+root_with sc = commit sc 0++-- proofs ---------------------------------------------------------------------++-- | Another key's leaf, at which a key's path ends: its key, the hash+-- of its value, and its sum.+data Neighbor =+ Neighbor {-# UNPACK #-} !Key {-# UNPACK #-} !Hash {-# UNPACK #-} !Word64+ deriving (Eq, Show)++-- whether climbing from a commitment at the given depth on a key's+-- path, over that many siblings from the deepest up, reaches a root,+-- hashing over the given state and block arrays; a branch's sum mustn't+-- overflow. callers ensure the depth is at most 256+climb#+ :: Scheme -> Buffer -> Buffer -> Key -> Int -> Commitment+ -> [Commitment] -> Commitment+ -> State# Exts.RealWorld -> (# State# Exts.RealWorld, Bool #)+climb# sc st bk k d0 (Commitment h0 n0) sibs r = go (d0 - 1) h0 n0 sibs where+ go !d !h !hs ps s0 = case ps of+ [] -> (# s0, d == -1 && Commitment h hs == r #)+ Commitment g gs : rest+ | d < 0 || gs > maxBound - hs -> (# s0, False #)+ | otherwise ->+ case if bit k d+ then hash_branch# sc st bk g gs h hs s0+ else hash_branch# sc st bk h hs g gs s0 of+ (# s1, p #) -> go (d - 1) p (hs + gs) rest s1++-- | The siblings along a key's path in a split tree, from the deepest up+-- to the root's, and the leaf the path ends at, where that's another+-- key's.+--+-- Returns what the proof needed, if it was held elsewhere.+prove_split+ :: Key -> Tree s -> Either (Missing s) (Maybe Neighbor, [Commitment])+prove_split k = go 0 [] where+ go !d acc t = case t of+ Empty -> Right (Nothing, acc)+ Leaf (Commitment _ s) _ k' v+ | k' == k -> Right (Nothing, acc)+ | otherwise -> Right (Just (Neighbor k' (hash_value v) s), acc)+ Node l _ r+ | bit k d -> go (d + 1) (commit Split (d + 1) l : acc) r+ | otherwise -> go (d + 1) (commit Split (d + 1) r : acc) l+ Stub p c -> Left (Missing p c)++-- | Verify that a value and sum sit at a key in a split tree, under a+-- root, given the siblings along the key's path, and the leaf the path+-- ends at, where that's another key's.+--+-- An empty value with zero sum verifies the key's exclusion, for which+-- the path must end at an empty subtree or at another key's leaf.+-- Proofs with more than 256 siblings, or whose branch sums overflow,+-- are rejected.+verify_split+ :: Key -> BS.ByteString -> Word64 -> Maybe Neighbor -> [Commitment]+ -> Commitment -> Bool+verify_split k v s nb sibs r = d <= _HEIGHT && with_scratch go where+ d = length sibs+ vacant = BS.null v && s == 0+ up st bk c = climb# Split st bk k d c sibs r+ go st bk s0 = case nb of+ Nothing+ | vacant -> up st bk (commit Split d Empty) s0+ | otherwise -> case hash_leaf# Split st bk k v s s0 of+ (# s1, h #) -> up st bk (Commitment h s) s1+ Just (Neighbor k' h s')+ | vacant && k' /= k && agree k k' d ->+ case hash_leaf_split# st bk (key_hash k') h s' s0 of+ (# s1, h' #) -> up st bk (Commitment h' s') s1+ | otherwise -> (# s0, False #)++-- | The siblings along a key's path in an aggregate tree: all 256 of+-- them, from the leaf up to the root's.+--+-- Returns what the proof needed, if it was held elsewhere.+prove_aggregate :: Key -> Tree s -> Either (Missing s) [Commitment]+prove_aggregate k t0 = with_scratch $ \st bk ->+ let -- empty siblings at depths j through j1 - 1+ pad j j1 acc+ | j == j1 = acc+ | otherwise =+ pad (j + 1) j1 (commit Aggregate (j + 1) Empty : acc)+ go !d acc t s0 = case t of+ Empty -> (# s0, Right (pad d _HEIGHT acc) #)+ Leaf (Commitment _ s') lh' k' _+ | k' == k -> (# s0, Right (pad d _HEIGHT acc) #)+ | otherwise ->+ -- the leaf's subtree is the sibling where the paths diverge+ let p = diverge k k' d+ c0 = Commitment lh' s'+ in case raise# Aggregate st bk k' (p + 1) _HEIGHT c0 s0 of+ (# s1, c #) ->+ (# s1, Right (pad (p + 1) _HEIGHT (c : pad d p acc)) #)+ Node l _ r+ | bit k d -> go (d + 1) (commit Aggregate (d + 1) l : acc) r s0+ | otherwise -> go (d + 1) (commit Aggregate (d + 1) r : acc) l s0+ Stub q c -> (# s0, Left (Missing q c) #)+ in go 0 [] t0++-- | Verify that a value and sum sit at a key in an aggregate tree, under+-- a root, given the 256 siblings along the key's path.+--+-- An empty value with zero sum verifies the key's exclusion. Proofs+-- whose branch sums overflow are rejected.+verify_aggregate+ :: Key -> BS.ByteString -> Word64 -> [Commitment] -> Commitment -> Bool+verify_aggregate k v s sibs r =+ length sibs == _HEIGHT+ && with_scratch (\st bk -> climb# Aggregate st bk k _HEIGHT leaf sibs r)+ where+ leaf = Commitment (hash_leaf_aggregate v s) s
+ lib/Data/MSSMT/Split.hs view
@@ -0,0 +1,118 @@+{-# OPTIONS_HADDOCK prune #-}++-- |+-- Module: Data.MSSMT.Split+-- Copyright: (c) 2026 Jared Tobin+-- License: MIT+-- Maintainer: Jared Tobin <jared@jtobin.io>+--+-- A merkle-sum sparse merkle tree (MS-SMT) whose branches commit to+-- the hash and sum of each of their children.+--+-- The tree has 2^256 leaves, addressed by 256-bit keys. Each leaf+-- holds a value and a sum, and commits to its key, value, and sum via+-- sha256(key || sha256(value) || sum). Each branch commits to the hash+-- and sum of each of its children, via sha256(left || left sum ||+-- right || right sum), and its sum is the sum of theirs. A subtree+-- holding no leaves commits to the zero hash and a zero sum, and a+-- subtree holding a single leaf commits to that leaf, so that a key's+-- path runs only as deep as is needed to set it apart from the others.+--+-- Leaf and branch hashes are over exactly 72 and 80 bytes+-- respectively, so that no input to one is an input to the other.++module Data.MSSMT.Split (+ -- * Keys, hashes, and commitments+ Key+ , key+ , Hash+ , parse_hash+ , serialize_hash+ , Commitment(..)++ -- * Tree+ , Tree+ , empty+ , insert+ , insert_many+ , delete+ , lookup+ , root++ -- * Proofs+ , Proof(..)+ , Neighbor(..)+ , prove+ , verify+ ) where++import qualified Data.ByteString as BS+import Data.Coerce (coerce)+import Data.MSSMT.Internal (+ Commitment(..), Hash, Key, Neighbor(..), Scheme(..), key, parse_hash+ , serialize_hash+ )+import qualified Data.MSSMT.Internal as I+import Data.Void (Void)+import Data.Word (Word64)+import Prelude hiding (lookup)++-- | A merkle-sum sparse merkle tree whose branches commit to the+-- hash and sum of each of their children.+newtype Tree = Tree (I.Tree Void)+ deriving (Eq, Show)++-- | The empty tree.+empty :: Tree+empty = Tree I.empty++-- | Insert a value and sum at a key, replacing any existing leaf.+--+-- Returns 'Nothing' if the tree's sum would overflow.+insert :: Key -> BS.ByteString -> Word64 -> Tree -> Maybe Tree+insert k v s (Tree t) = coerce (I.complete (I.insert_with Split k v s t))++-- | Insert many values and sums, as if one at a time, but rehashing+-- each changed node once.+--+-- Where a key appears more than once, its last appearance wins, and+-- an empty value with zero sum deletes whatever is at its key.+-- Returns 'Nothing' if the resulting tree's sum would overflow.+insert_many :: [(Key, BS.ByteString, Word64)] -> Tree -> Maybe Tree+insert_many kvs (Tree t) =+ coerce (I.complete (I.insert_many_with Split kvs t))++-- | Delete the leaf at a key.+delete :: Key -> Tree -> Tree+delete k (Tree t) = Tree (I.complete (I.delete_with Split k t))++-- | Look up the value and sum at a key.+lookup :: Key -> Tree -> Maybe (BS.ByteString, Word64)+lookup k (Tree t) = I.complete (I.lookup k t)++-- | The tree's root commitment.+root :: Tree -> Commitment+root (Tree t) = I.root_with Split t++-- | A merkle proof for a key: the commitments of the siblings along its+-- path, from the deepest up to the root's, and the leaf the path ends+-- at, where that's another key's.+--+-- The number of siblings is the depth at which the path ends.+data Proof = Proof !(Maybe Neighbor) [Commitment]+ deriving (Eq, Show)++-- | Produce a proof for the leaf at a key.+--+-- If no leaf exists at the key, this proves its exclusion.+prove :: Key -> Tree -> Proof+prove k (Tree t) = case I.complete (I.prove_split k t) of+ (nb, ps) -> Proof nb ps++-- | Verify that a value and sum sit at a key, under a root.+--+-- An empty value with zero sum verifies the key's exclusion. Proofs+-- with more than 256 siblings, or whose branch sums overflow, are+-- rejected.+verify :: Key -> BS.ByteString -> Word64 -> Proof -> Commitment -> Bool+verify k v s (Proof nb ps) = I.verify_split k v s nb ps
+ mssmt.cabal view
@@ -0,0 +1,131 @@+cabal-version: 3.0+name: mssmt+version: 0.1.0+synopsis: A high-performance in-memory Merkle-Sum Sparse Merkle Tree.+license: MIT+license-file: LICENSE+author: Jared Tobin+maintainer: jared@jtobin.io+category: Data Structures+build-type: Simple+tested-with: GHC == 9.10.3+extra-doc-files: CHANGELOG+extra-source-files:+ etc/mssmt_tree_deletion.json+ , etc/mssmt_tree_error_cases.json+ , etc/mssmt_tree_proofs.json+ , etc/mssmt_tree_replacement.json+description:+ A high-performance, in-memory Merkle-Sum Sparse Merkle tree (MS-SMT),+ whose branches commit to their children either individually+ ("Data.MSSMT.Split"), or in aggregate ("Data.MSSMT.Aggregate").++flag llvm+ description: Use GHC's LLVM backend.+ default: False+ manual: True++library+ default-language: Haskell2010+ hs-source-dirs: lib+ ghc-options:+ -Wall+ if flag(llvm)+ ghc-options: -fllvm -O2+ exposed-modules:+ Data.MSSMT+ , Data.MSSMT.Aggregate+ , Data.MSSMT.Hash+ , Data.MSSMT.Internal+ , Data.MSSMT.Split+ build-depends:+ base >= 4.11 && < 5+ , bytestring >= 0.10.2 && < 0.13+ , ppad-sha256 >= 0.3.6 && < 0.4+ , primitive >= 0.7 && < 0.10++test-suite mssmt-tests+ type: exitcode-stdio-1.0+ default-language: Haskell2010+ hs-source-dirs: test+ main-is: Main.hs+ other-modules:+ Reference+ , Vectors++ ghc-options:+ -rtsopts -Wall -O2++ build-depends:+ aeson+ , base+ , bytestring+ , containers+ , mssmt+ , ppad-base16+ , ppad-sha256+ , tasty+ , tasty-hunit+ , tasty-quickcheck++benchmark mssmt-bench+ type: exitcode-stdio-1.0+ default-language: Haskell2010+ hs-source-dirs: bench+ main-is: Main.hs+ other-modules:+ Fixtures++ ghc-options:+ -rtsopts -O2 -Wall+ if flag(llvm)+ ghc-options: -fllvm++ build-depends:+ base+ , bytestring+ , criterion+ , deepseq+ , mssmt+ , ppad-sha256++benchmark mssmt-weigh+ type: exitcode-stdio-1.0+ default-language: Haskell2010+ hs-source-dirs: bench+ main-is: Weight.hs+ other-modules:+ Fixtures++ ghc-options:+ -rtsopts -O2 -Wall+ if flag(llvm)+ ghc-options: -fllvm++ build-depends:+ base+ , bytestring+ , deepseq+ , mssmt+ , ppad-sha256+ , weigh++benchmark mssmt-alloc+ type: exitcode-stdio-1.0+ default-language: Haskell2010+ hs-source-dirs: bench+ main-is: Alloc.hs+ other-modules:+ Fixtures++ ghc-options:+ -rtsopts -O2 -Wall "-with-rtsopts=-T"+ if flag(llvm)+ ghc-options: -fllvm++ build-depends:+ base+ , bytestring+ , deepseq+ , mssmt+ , ppad-sha256
+ test/Main.hs view
@@ -0,0 +1,517 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}++module Main where++import Control.Monad (foldM)+import qualified Data.Aeson as A+import Data.Bits (testBit)+import qualified Data.ByteString as BS+import qualified Data.Map.Strict as M+import Data.Maybe (isJust)+import Data.MSSMT+import qualified Data.MSSMT.Aggregate as Agg+import qualified Data.MSSMT.Hash as H+import qualified Data.MSSMT.Internal as I+import Data.Void (Void)+import Data.Word (Word32, Word64)+import Prelude hiding (lookup)+import Test.Tasty+import Test.Tasty.HUnit+import qualified Test.Tasty.QuickCheck as Q+import qualified Reference as R+import qualified Vectors as V++main :: IO ()+main = do+ vs <- traverse load files+ defaultMain $ testGroup "mssmt" [+ units+ , hashing+ , properties "split" split_ops+ , properties "aggregate" aggregate_ops+ , split_proofs+ , partial "split" I.Split I.prove_split+ (\k t -> I.complete (I.prove_split k t))+ , partial "aggregate" I.Aggregate I.prove_aggregate+ (\k t -> I.complete (I.prove_aggregate k t))+ , structure+ , testGroup "taproot-assets vectors" (zipWith V.execute files vs)+ ]+ where+ files = [+ "mssmt_tree_proofs.json"+ , "mssmt_tree_deletion.json"+ , "mssmt_tree_replacement.json"+ , "mssmt_tree_error_cases.json"+ ]+ load :: FilePath -> IO V.Vectors+ load f = A.eitherDecodeFileStrict' ("etc/" <> f)+ >>= either (\e -> fail (f <> ": " <> e)) pure++-- units ----------------------------------------------------------------------++units :: TestTree+units = testGroup "units" [+ testCase "keys are 32 bytes" $ do+ assertBool "31" (not (isJust (key (BS.replicate 31 0))))+ assertBool "32" (isJust (key (BS.replicate 32 0)))+ assertBool "33" (not (isJust (key (BS.replicate 33 0))))+ , testCase "hashes are 32 bytes" $ do+ assertBool "31" (not (isJust (parse_hash (BS.replicate 31 0))))+ assertBool "33" (not (isJust (parse_hash (BS.replicate 33 0))))+ , Q.testProperty "serialize_hash . parse_hash ~ id" $+ Q.forAll (BS.pack <$> Q.vector 32) $ \bs ->+ fmap serialize_hash (parse_hash bs) Q.=== Just bs+ , testCase "an empty value with zero sum is the empty leaf" $+ case key (BS.replicate 32 0) of+ Nothing -> assertFailure "key"+ Just k -> assertEqual mempty (Just empty) (insert k mempty 0 empty)+ , testCase "empty roots agree with the reference" $ do+ let Commitment h s = root empty+ Commitment g n = Agg.root Agg.empty+ assertEqual "split" (R.root M.empty) (serialize_hash h, s)+ assertEqual "aggregate" (R.root_aggregate M.empty) (serialize_hash g, n)+ , testCase "aggregate proofs have 256 siblings" $+ case key (BS.replicate 32 0) of+ Nothing -> assertFailure "key"+ Just k -> case Agg.insert k "a" 1 Agg.empty of+ Nothing -> assertFailure "insert"+ Just t -> do+ let Agg.Proof ps = Agg.prove k t+ r = Agg.root t+ assertEqual "length" 256 (length ps)+ assertBool "short" $+ not (Agg.verify k "a" 1 (Agg.Proof (drop 1 ps)) r)+ assertBool "long" $+ not (Agg.verify k "a" 1 (Agg.Proof (ps <> take 1 ps)) r)+ , testCase "split proofs run only as deep as their key's slot" $+ case key (BS.replicate 32 0) of+ Nothing -> assertFailure "key"+ Just k -> case insert k "a" 1 empty of+ Nothing -> assertFailure "insert"+ Just t -> do+ let p@(Proof nb ps) = prove k t+ r = root t+ e = root empty+ assertEqual "siblings" 0 (length ps)+ assertEqual "neighbor" Nothing nb+ assertBool "verify" (verify k "a" 1 p r)+ assertBool "long" $ not (verify k "a" 1 (Proof nb [e]) r)+ assertBool "too long" $+ not (verify k "a" 1 (Proof nb (replicate 257 e)) r)+ , testCase "proofs whose sums overflow are rejected" $+ case key z of+ Nothing -> assertFailure "key"+ Just k -> do+ -- roots over the leaf ("a", 1) at the all-zero key, whose path+ -- runs left at every level, and siblings of hash g, the+ -- deepest of the given sum and the rest of zero sum, with+ -- sums added as words, which wrap+ let g = H.unsafe_hash (BS.replicate 32 7)+ gb = serialize_hash g+ split_root n =+ let h = R.hash_node_split (R.hash_leaf_split z "a" 1) 1 gb n+ in Commitment (H.unsafe_hash h) (1 + n)+ aggregate_root n =+ let up (h, t) gs =+ (R.hash_node_aggregate h gb (t + gs), t + gs)+ (rh, rt) = foldl up (R.hash_leaf_aggregate "a" 1, 1)+ (n : replicate 255 0)+ in Commitment (H.unsafe_hash rh) rt+ split_proof n = Proof Nothing [Commitment g n]+ aggregate_proof n =+ Agg.Proof (Commitment g n : replicate 255 (Commitment g 0))+ fits = maxBound - 1+ assertBool "split, fits" $+ verify k "a" 1 (split_proof fits) (split_root fits)+ assertBool "split, overflows" . not $+ verify k "a" 1 (split_proof maxBound) (split_root maxBound)+ assertBool "aggregate, fits" $+ Agg.verify k "a" 1 (aggregate_proof fits) (aggregate_root fits)+ assertBool "aggregate, overflows" . not $+ Agg.verify k "a" 1 (aggregate_proof maxBound)+ (aggregate_root maxBound)+ ]+ where+ z = BS.replicate 32 0++-- hashing --------------------------------------------------------------------++gen_hash :: Q.Gen Hash+gen_hash = fmap BS.pack (Q.vector 32) `Q.suchThatMap` parse_hash++-- each hash agrees with the reference; the native paths are checked+-- only where hardware SHA-256 is available+hashing :: TestTree+hashing = testGroup "hashing" $ [+ Q.testProperty "hash_leaf_split ~ reference" $+ Q.forAll gen_hash $ \k v -> Q.forAll big $ \s ->+ serialize_hash (I.hash_leaf_split k (I.hash_value (BS.pack v)) s)+ Q.=== R.hash_leaf_split (serialize_hash k) (BS.pack v) s+ , Q.testProperty "hash_leaf_aggregate ~ reference" $+ \v -> Q.forAll big $ \s ->+ serialize_hash (I.hash_leaf_aggregate (BS.pack v) s)+ Q.=== R.hash_leaf_aggregate (BS.pack v) s+ , split "hash_node_split_pure" I.hash_node_split_pure+ , aggregate "hash_node_aggregate_pure" I.hash_node_aggregate_pure+ ]+ <> [ split "hash_node_split_native" I.hash_node_split_native | I.native ]+ <> [ aggregate "hash_node_aggregate_native" I.hash_node_aggregate_native+ | I.native+ ]+ where+ split name f = Q.testProperty (name <> " ~ reference") $+ 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_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 ->+ serialize_hash (f l r s)+ Q.=== R.hash_node_aggregate (serialize_hash l) (serialize_hash r) s++-- properties -----------------------------------------------------------------++-- a key with the given prefix+gen_key :: BS.ByteString -> Q.Gen Key+gen_key pre =+ fmap ((pre <>) . BS.pack) (Q.vector (32 - BS.length pre))+ `Q.suchThatMap` key++-- a nonempty leaf, with a sum small enough that trees of leaves don't+-- overflow+data E = E !Key !BS.ByteString !Word64+ deriving Show++-- leaves whose keys share a random prefix, so that their paths share+-- up to 256 levels (and keys may collide)+data Es = Es !BS.ByteString [E]+ deriving Show++instance Q.Arbitrary Es where+ arbitrary = do+ pre <- BS.pack <$> (Q.chooseInt (0, 32) >>= Q.vector)+ Es pre <$> Q.listOf (E+ <$> gen_key pre+ <*> fmap BS.pack (Q.listOf1 Q.arbitrary)+ <*> fmap fromIntegral (Q.arbitrary :: Q.Gen Word32))+ shrink (Es pre es) = Es pre <$> Q.shrinkList (const []) es++-- a tree module's operations, and its reference root+data Ops t p = Ops {+ o_empty :: t+ , o_insert :: Key -> BS.ByteString -> Word64 -> t -> Maybe t+ , o_insert_many :: [(Key, BS.ByteString, Word64)] -> t -> Maybe t+ , o_delete :: Key -> t -> t+ , o_lookup :: Key -> t -> Maybe (BS.ByteString, Word64)+ , o_root :: t -> Commitment+ , o_prove :: Key -> t -> p+ , o_verify :: Key -> BS.ByteString -> Word64 -> p -> Commitment -> Bool+ , o_ref :: R.Leaves -> (BS.ByteString, Word64)+ }++split_ops :: Ops Tree Proof+split_ops = Ops empty insert insert_many delete lookup root prove verify R.root++aggregate_ops :: Ops Agg.Tree Agg.Proof+aggregate_ops = Ops+ Agg.empty Agg.insert Agg.insert_many Agg.delete Agg.lookup Agg.root+ Agg.prove Agg.verify R.root_aggregate++build :: Ops t p -> [E] -> Maybe t+build Ops {..} = foldM (\t (E k v s) -> o_insert k v s t) o_empty++-- later leaves replace earlier ones+model :: [E] -> M.Map Key (BS.ByteString, Word64)+model es = M.fromList [(k, (v, s)) | E k v s <- es]++-- a key from the leaves, or a fresh one under their prefix+pick :: Es -> Q.Gen Key+pick (Es pre es) = Q.oneof (gen_key pre : [Q.elements ks | not (null ks)])+ where+ ks = [k | E k _ _ <- es]++-- a batch of puts and deletions, at keys from the leaves or fresh ones+-- under their prefix, with sums from the given generator+gen_batch :: Q.Gen Word64 -> Es -> Q.Gen [(Key, BS.ByteString, Word64)]+gen_batch sums x = Q.listOf $ do+ k <- pick x+ Q.frequency [+ (3, (,,) k <$> fmap BS.pack (Q.listOf1 Q.arbitrary) <*> sums)+ , (1, pure (k, mempty, 0))+ ]++-- a sum small enough that batches of them don't overflow+small :: Q.Gen Word64+small = fromIntegral <$> (Q.arbitrary :: Q.Gen Word32)++-- a sum, often near maxBound+big :: Q.Gen Word64+big = Q.oneof [+ Q.arbitrary+ , (maxBound -) . fromIntegral <$> (Q.arbitrary :: Q.Gen Word32)+ ]++-- a key's raw bytes+raw_key :: Key -> BS.ByteString+raw_key (I.Key h) = I.serialize_hash h++-- key the model by raw bytes+raw :: M.Map Key a -> M.Map BS.ByteString a+raw = M.mapKeysMonotonic raw_key++-- path bit at the given depth; LSB-first within each byte+kbit :: Key -> Int -> Bool+kbit k d = testBit (BS.index (raw_key k) (d `quot` 8)) (d `rem` 8)++-- every branch holds two or more leaves, and every leaf's key follows+-- its path+compact :: I.Tree Void -> Bool+compact = isJust . go 0 [] where+ go :: Int -> [Bool] -> I.Tree Void -> Maybe Int+ go _ _ I.Empty = Just 0+ go d path (I.Leaf _ _ k _)+ | reverse path == fmap (kbit k) [0 .. d - 1] = Just 1+ | otherwise = Nothing+ go d path (I.Node l _ r) = do+ a <- go (d + 1) (False : path) l+ b <- go (d + 1) (True : path) r+ if a + b >= 2 then Just (a + b) else Nothing++-- whether a key's path ends at another key's leaf+at_leaf :: Key -> I.Tree Void -> Bool+at_leaf k = go 0 where+ go :: Int -> I.Tree Void -> Bool+ go d t = case t of+ I.Empty -> False+ I.Leaf _ _ k' _ -> k' /= k+ I.Node l _ r -> go (d + 1) (if kbit k d then r else l)++-- the internal tree underlying a split tree+build_raw :: [E] -> Maybe (I.Tree Void)+build_raw = build_with I.Split++build_with :: I.Scheme -> [E] -> Maybe (I.Tree Void)+build_with sc =+ foldM (\t (E k v s) -> I.complete (I.insert_with sc k v s t)) I.empty++-- a tree held entirely elsewhere: its root as a stub, and a store of its+-- nodes by commitment, each with its subtrees as stubs+held+ :: I.Tree Void+ -> (I.Tree I.Kind, M.Map (Hash, Word64) (I.Tree I.Kind))+held t0 = (stub t0, go t0 M.empty) where+ stub :: I.Tree Void -> I.Tree I.Kind+ stub t = case t of+ I.Empty -> I.Empty+ I.Leaf c _ _ _ -> I.Stub I.Single c+ I.Node _ c _ -> I.Stub I.Branch c+ go+ :: I.Tree Void -> M.Map (Hash, Word64) (I.Tree I.Kind)+ -> M.Map (Hash, Word64) (I.Tree I.Kind)+ go t m = case t of+ I.Empty -> m+ I.Leaf c lh k v -> M.insert (ckey c) (I.Leaf c lh k v) m+ I.Node l c r ->+ go l (go r (M.insert (ckey c) (I.Node (stub l) c (stub r)) m))++ckey :: Commitment -> (Hash, Word64)+ckey (Commitment h s) = (h, s)++-- load a stub's contents from a store+from_store+ :: M.Map (Hash, Word64) (I.Tree I.Kind) -> I.Kind -> Commitment+ -> Maybe (I.Tree I.Kind)+from_store m _ c = M.lookup (ckey c) m++with_tree :: Ops t p -> [E] -> (t -> Q.Property) -> Q.Property+with_tree o es f = case build o es of+ Nothing -> Q.counterexample "overflow" False+ Just t -> f t++properties :: (Eq t, Show t) => String -> Ops t p -> TestTree+properties name o@Ops {..} = testGroup ("properties (" <> name <> ")") [+ Q.testProperty "lookup agrees with a map model" $ \(Es _ es) ->+ with_tree o es $ \t ->+ Q.property $+ all (\(k, l) -> o_lookup k t == Just l) (M.toList (model es))++ , Q.testProperty "root sum is the sum of leaf sums" $ \(Es _ es) ->+ with_tree o es $ \t ->+ let Commitment _ s = o_root t+ in toInteger s Q.=== sum (fmap (toInteger . snd) (model es))++ , Q.testProperty "root agrees with the reference" $ \(Es _ es) ->+ with_tree o es $ \t ->+ let Commitment h s = o_root t+ in (serialize_hash h, s) Q.=== o_ref (raw (model es))++ , Q.testProperty "trees are independent of insertion history" $+ \(Es _ es) ->+ let canonical = [E k v s | (k, (v, s)) <- M.toList (model es)]+ in build o es Q.=== build o canonical++ , Q.testProperty "delete k . insert k v s == delete k" $ \x@(Es _ es) ->+ Q.forAll (pick x) $ \k ->+ with_tree o es $ \t ->+ fmap (o_delete k) (o_insert k "v" 1 t) Q.=== Just (o_delete k t)++ , Q.testProperty "deleting every leaf yields the empty tree" $ \(Es _ es) ->+ with_tree o es $ \t ->+ foldr o_delete t (M.keys (model es)) Q.=== o_empty++ , Q.testProperty "inclusion proofs verify" $ \(Es _ es) ->+ with_tree o es $ \t ->+ Q.property $ all+ (\(k, (v, s)) -> o_verify k v s (o_prove k t) (o_root t))+ (M.toList (model es))++ , Q.testProperty "exclusion proofs verify" $ \x@(Es _ es) ->+ Q.forAll (pick x) $ \k ->+ M.notMember k (model es) Q.==>+ with_tree o es $ \t ->+ Q.classify (maybe False (at_leaf k) (build_raw es))+ "ends at another leaf" $+ o_verify k mempty 0 (o_prove k t) (o_root t)++ , Q.testProperty "proofs reject a wrong value or sum" $ \(Es _ es) ->+ with_tree o es $ \t ->+ let r = o_root t+ in Q.property $ all+ (\(k, (v, s)) ->+ not (o_verify k (v <> "x") s (o_prove k t) r)+ && not (o_verify k v (s + 1) (o_prove k t) r)+ && not (o_verify k mempty 0 (o_prove k t) r))+ (M.toList (model es))++ , Q.testProperty "insert_many agrees with successive inserts" $+ \x@(Es _ es) -> Q.forAll (gen_batch small x) $ \b ->+ with_tree o es $ \t ->+ o_insert_many b t+ Q.=== foldM (\u (k, v, s) -> o_insert k v s u) t b++ , Q.testProperty "insert_many fails iff the root sum would overflow" $+ \x@(Es _ es) -> Q.forAll (gen_batch (Q.oneof [small, big]) x) $ \b ->+ with_tree o es $ \t ->+ let apply m (k, v, s)+ | BS.null v && s == 0 = M.delete k m+ | otherwise = M.insert k (v, s) m+ final = foldl apply (model es) b+ fits = sum (fmap (toInteger . snd) final)+ <= toInteger (maxBound :: Word64)+ in Q.classify fits "fits" $ isJust (o_insert_many b t) Q.=== fits++ , Q.testProperty "insert fails iff the root sum would overflow" $+ \x@(Es _ es) -> Q.forAll (pick x) $ \k -> Q.forAll big $ \s ->+ with_tree o es $ \t ->+ let m = model es+ rest = sum (fmap (toInteger . snd) (M.delete k m))+ fits = rest + toInteger s <= toInteger (maxBound :: Word64)+ in Q.classify fits "fits" $ isJust (o_insert k "v" s t) Q.=== fits+ ]++-- split proofs, which run only as deep as their key's slot+split_proofs :: TestTree+split_proofs = testGroup "split proofs" [+ Q.testProperty "proofs end at their key's slot" $ \x@(Es _ es) ->+ Q.forAll (pick x) $ \k ->+ with_tree split_ops es $ \t ->+ let Proof nb ps = prove k t+ neighbor (Neighbor k' _ _) = raw_key k'+ in (length ps, fmap neighbor nb)+ Q.=== R.slot (raw (model es)) (raw_key k)++ , Q.testProperty "a present key's own leaf proves nothing" $+ \(Es _ es) ->+ with_tree split_ops es $ \t ->+ Q.property $ all+ (\(k, (v, s)) ->+ let Proof _ ps = prove k t+ own = Proof (Just (Neighbor k (I.hash_value v) s)) ps+ in not (verify k mempty 0 own (root t))+ && not (verify k v s own (root t)))+ (M.toList (model es))++ , Q.testProperty "exclusion proofs reject a forged neighbor" $+ \x@(Es _ es) -> Q.forAll (pick x) $ \k ->+ with_tree split_ops es $ \t -> case prove k t of+ Proof (Just (Neighbor k' h s)) ps ->+ let r = root t+ with n = verify k mempty 0 (Proof (Just n) ps) r+ in Q.property $+ with (Neighbor k' h s)+ && not (with (Neighbor k' h (s + 1)))+ && not (with (Neighbor k h s))+ Proof Nothing _ -> Q.discard+ ]++-- operations on a tree held entirely elsewhere, loaded along the paths+-- they touch, agree with those on the tree itself; and report what they+-- need, where they find it held elsewhere+partial+ :: (Eq p, Show p)+ => String+ -> I.Scheme+ -> (Key -> I.Tree I.Kind -> Either (I.Missing I.Kind) p)+ -> (Key -> I.Tree Void -> p)+ -> TestTree+partial name sc pf pf' = testGroup ("partial trees (" <> name <> ")") [+ Q.testProperty "lookup" $ \x@(Es _ es) -> Q.forAll (pick x) $ \k ->+ with es $ \t (h, m) ->+ fmap (I.lookup k) (I.expand (from_store m) k h)+ Q.=== Just (Right (I.complete (I.lookup k t)))++ , Q.testProperty "prove" $ \x@(Es _ es) -> Q.forAll (pick x) $ \k ->+ with es $ \t (h, m) ->+ fmap (pf k) (I.expand (from_store m) k h) Q.=== Just (Right (pf' k t))++ , Q.testProperty "insert" $ \x@(Es _ es) -> Q.forAll (pick x) $ \k ->+ with es $ \t (h, m) ->+ let ins u = I.insert_with sc k "v" 1 u+ in fmap (fmap (fmap root_of) . ins) (I.expand (from_store m) k h)+ Q.=== Just (Right (fmap root_of (I.complete (ins t))))++ , Q.testProperty "delete" $ \x@(Es _ es) -> Q.forAll (pick x) $ \k ->+ with es $ \t (h, m) ->+ let del u = I.delete_with sc k u+ in fmap (fmap root_of . del) (I.expand (from_store m) k h)+ Q.=== Just (Right (root_of (I.complete (del t))))++ , Q.testProperty "insert_many" $ \x@(Es _ es) ->+ Q.forAll (gen_batch small x) $ \b ->+ with es $ \t (h, m) ->+ let ins u = I.insert_many_with sc b u+ loaded = foldM (\u (k, _, _) -> I.expand (from_store m) k u) h b+ in fmap (fmap (fmap root_of) . ins) loaded+ Q.=== Just (Right (fmap root_of (I.complete (ins t))))++ , Q.testProperty "unloaded paths report what they need" $+ \x@(Es _ es) -> Q.forAll (pick x) $ \k ->+ with es $ \_ (h, _) -> case h of+ I.Stub p c ->+ let needed = Left (I.Missing p c)+ in I.lookup k h Q.=== needed+ Q..&&. fmap (const ()) (pf k h) Q.=== needed+ Q..&&. fmap (const ()) (I.insert_with sc k "v" 1 h) Q.=== needed+ Q..&&. fmap (const ()) (I.delete_with sc k h) Q.=== needed+ _ -> Q.property True+ ]+ where+ root_of = I.root_with sc+ with es f = case build_with sc es of+ Nothing -> Q.counterexample "overflow" False+ Just t -> f t (held t)++-- the shape of the underlying tree, which doesn't depend on the scheme+structure :: TestTree+structure = testGroup "structure" [+ Q.testProperty "trees are compact" $ \(Es _ es) ->+ Q.forAll (Q.sublistOf (M.keys (model es))) $ \ks ->+ case build_raw es of+ Nothing -> Q.counterexample "overflow" False+ Just t ->+ let del k u = I.complete (I.delete_with I.Split k u)+ in compact t Q..&&. compact (foldr del t ks)+ ]
+ test/Reference.hs view
@@ -0,0 +1,103 @@+-- Reference MS-SMT hashing over bytes, straight from the definitions.++module Reference (+ Leaves+ , hash_value+ , hash_leaf_split+ , hash_leaf_aggregate+ , hash_node_split+ , hash_node_aggregate+ , root+ , root_aggregate+ , slot+ ) where++import qualified Crypto.Hash.SHA256 as SHA256+import Data.Bits (testBit)+import qualified Data.ByteString as BS+import qualified Data.ByteString.Builder as BSB+import qualified Data.ByteString.Lazy as BL+import Data.List (partition)+import qualified Data.Map.Strict as M+import Data.Word (Word64)++-- leaves, by 32-byte key+type Leaves = M.Map BS.ByteString (BS.ByteString, Word64)++sha256 :: BSB.Builder -> BS.ByteString+sha256 = SHA256.hash . BL.toStrict . BSB.toLazyByteString++-- sha256(value)+hash_value :: BS.ByteString -> BS.ByteString+hash_value = SHA256.hash++-- sha256(key || sha256(value) || sum)+hash_leaf_split :: BS.ByteString -> BS.ByteString -> Word64 -> BS.ByteString+hash_leaf_split k v s = sha256 $+ BSB.byteString k <> BSB.byteString (hash_value v) <> BSB.word64BE s++-- sha256(value || sum)+hash_leaf_aggregate :: BS.ByteString -> Word64 -> BS.ByteString+hash_leaf_aggregate v s = sha256 (BSB.byteString v <> BSB.word64BE s)++-- sha256(left || left sum || right || right sum)+hash_node_split+ :: BS.ByteString -> Word64 -> BS.ByteString -> Word64 -> BS.ByteString+hash_node_split l sl r sr = sha256 $+ BSB.byteString l <> BSB.word64BE sl <> BSB.byteString r <> BSB.word64BE sr++-- sha256(left || right || sum)+hash_node_aggregate+ :: BS.ByteString -> BS.ByteString -> Word64 -> BS.ByteString+hash_node_aggregate l r s = sha256 $+ BSB.byteString l <> BSB.byteString r <> BSB.word64BE s++-- the root hash and sum of a split tree holding the given leaves: an+-- empty subtree commits to the zero hash, a single-leaf subtree to its+-- leaf, and any other subtree to its children+root :: Leaves -> (BS.ByteString, Word64)+root = go 0 . M.toList where+ go :: Int -> [(BS.ByteString, (BS.ByteString, Word64))]+ -> (BS.ByteString, Word64)+ go _ [] = (BS.replicate 32 0, 0)+ go _ [(k, (v, s))] = (hash_leaf_split k v s, s)+ go d ls =+ let (rs, ls') = partition (\(k, _) -> bit k d) ls+ (hl, sl) = go (d + 1) ls'+ (hr, sr) = go (d + 1) rs+ in (hash_node_split hl sl hr sr, sl + sr)++-- the root hash and sum of an aggregate tree holding the given leaves:+-- every leaf sits at depth 256, and an empty subtree is the full+-- subtree of empty leaves+root_aggregate :: Leaves -> (BS.ByteString, Word64)+root_aggregate = go empties 0 . M.toList where+ branch l sl r sr = hash_node_aggregate l r (sl + sr)++ -- the full subtrees of empty leaves, by depth+ empties = reverse . take 257 $+ iterate (\(h, _) -> (branch h 0 h 0, 0)) (hash_leaf_aggregate mempty 0, 0)++ go (e : es) d ls = case ls of+ [] -> e+ [(_, (v, s))] | d == 256 -> (hash_leaf_aggregate v s, s)+ _ ->+ let (rs, ls') = partition (\(k, _) -> bit k d) ls+ (hl, sl) = go es (d + 1) ls'+ (hr, sr) = go es (d + 1) rs+ in (branch hl sl hr sr, sl + sr)+ go [] _ _ = error "reference: below leaf depth"++-- the depth at which a key's path ends in a split tree holding the given+-- leaves, and the other key whose leaf it ends at, if any+slot :: Leaves -> BS.ByteString -> (Int, Maybe BS.ByteString)+slot m k = go 0 (M.keys m) where+ go :: Int -> [BS.ByteString] -> (Int, Maybe BS.ByteString)+ go d ks = case ks of+ [] -> (d, Nothing)+ [x] -> (d, if x == k then Nothing else Just x)+ _ -> go (d + 1) (filter (\x -> bit x d == bit k d) ks)++-- path bit at the given depth; LSB-first within each byte+bit :: BS.ByteString -> Int -> Bool+bit k d = testBit (BS.index k (d `quot` 8)) (d `rem` 8)
+ test/Vectors.hs view
@@ -0,0 +1,205 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}++-- Test vectors from taproot-assets (mssmt/testdata).++module Vectors (+ Vectors+ , execute+ ) where++import Control.Monad (foldM, forM_, guard)+import Data.Aeson ((.:), (.:?))+import qualified Data.Aeson as A+import qualified Data.Aeson.Key as AK+import qualified Data.Aeson.Types as AT+import Data.Bits (shiftL, testBit, (.|.))+import qualified Data.ByteString as BS+import qualified Data.ByteString.Base16 as B16+import qualified Data.ByteString.Char8 as B8+import qualified Data.Map.Strict as M+import Data.Maybe (fromMaybe, isJust, isNothing)+import Data.MSSMT.Aggregate+import qualified Data.Set as S+import Data.Word (Word64)+import Test.Tasty (TestTree, testGroup)+import Test.Tasty.HUnit++data Leaf = Leaf !Key !BS.ByteString !Word64++data Valid = Valid {+ v_root :: !Commitment+ , v_inserted :: ![Key]+ , v_deleted :: ![Key]+ , v_replaced :: ![Leaf]+ , v_included :: ![(Key, Proof)]+ , v_excluded :: ![(Key, Proof)]+ , v_comment :: !String+ }++data Invalid = Invalid {+ i_inserted :: ![Key]+ , i_comment :: !String+ }++-- | A file of test vectors.+data Vectors = Vectors {+ vs_leaves :: ![Leaf]+ , vs_valid :: ![Valid]+ , vs_invalid :: ![Invalid]+ }++-- execution ------------------------------------------------------------------++-- | Run a file's test cases.+execute :: String -> Vectors -> TestTree+execute name Vectors {..} = testGroup name $+ fmap (execute_valid vs_leaves) vs_valid+ <> fmap (execute_invalid vs_leaves) vs_invalid++-- leaves are inserted in file order, as in the taproot-assets runner+inserting :: [Leaf] -> [Key] -> [Leaf]+inserting ls ks = filter (\(Leaf k _ _) -> S.member k set) ls where+ set = S.fromList ks++insert_all :: Tree -> [Leaf] -> Maybe Tree+insert_all = foldM (\t (Leaf k v s) -> insert k v s t)++execute_valid :: [Leaf] -> Valid -> TestTree+execute_valid ls Valid {..} = testGroup v_comment [+ testCase "root" $+ assertEqual mempty (Just v_root) (fmap root tree)+ , testCase ("inclusion proofs (" <> show (length v_included) <> ")") $+ forM_ (zip [0 :: Int ..] v_included) $ \(i, (k, p)) ->+ case (tree, M.lookup k leaves) of+ (Just t, Just (Leaf _ v s)) -> do+ assertEqual ("prove " <> show i) p (prove k t)+ assertBool ("verify " <> show i) (verify k v s p (root t))+ _ -> assertFailure ("missing tree or leaf " <> show i)+ , testCase ("exclusion proofs (" <> show (length v_excluded) <> ")") $+ forM_ (zip [0 :: Int ..] v_excluded) $ \(i, (k, p)) ->+ case tree of+ Just t -> do+ assertEqual ("prove " <> show i) p (prove k t)+ assertBool ("verify " <> show i) (verify k mempty 0 p (root t))+ Nothing -> assertFailure "missing tree"+ ]+ where+ leaves = M.fromList [(k, l) | l@(Leaf k _ _) <- ls]+ tree = do+ t <- insert_all empty (inserting ls v_inserted)+ insert_all (foldr delete t v_deleted) v_replaced++-- every insert but the last succeeds; the last overflows+execute_invalid :: [Leaf] -> Invalid -> TestTree+execute_invalid ls Invalid {..} = testCase i_comment $ do+ let leaves = inserting ls i_inserted+ assertBool "no leaves" (not (null leaves))+ assertBool "prefix" $+ isJust (insert_all empty (take (length leaves - 1) leaves))+ assertBool "overflow" $+ isNothing (insert_all empty leaves)++-- parsing --------------------------------------------------------------------++instance A.FromJSON Vectors where+ parseJSON = A.withObject "Vectors" $ \o -> Vectors+ <$> o .: "all_tree_leaves"+ <*> list o "valid_test_cases"+ <*> list o "error_test_cases"++instance A.FromJSON Leaf where+ parseJSON = A.withObject "Leaf" $ \o -> do+ n <- o .: "node"+ Leaf+ <$> (o .: "key" >>= parse_key)+ <*> (n .: "value" >>= parse_hex)+ <*> (n .: "sum" >>= parse_sum)++instance A.FromJSON Valid where+ parseJSON = A.withObject "Valid" $ \o -> do+ h <- o .: "root_hash" >>= parse_hex >>= parse_digest+ s <- o .: "root_sum" >>= parse_sum+ Valid (Commitment h s)+ <$> (list o "inserted_leaves" >>= traverse parse_key)+ <*> (list o "deleted_leaves" >>= traverse parse_key)+ <*> list o "replaced_leaves"+ <*> (list o "inclusion_proofs" >>= traverse parse_case)+ <*> (list o "exclusion_proofs" >>= traverse parse_case)+ <*> o .: "comment"++instance A.FromJSON Invalid where+ parseJSON = A.withObject "Invalid" $ \o -> Invalid+ <$> (list o "inserted_leaves" >>= traverse parse_key)+ <*> o .: "comment"++-- absent and null lists are empty+list :: A.FromJSON a => A.Object -> AK.Key -> AT.Parser [a]+list o k = fromMaybe [] <$> o .:? k++parse_case :: A.Value -> AT.Parser (Key, Proof)+parse_case = A.withObject "ProofCase" $ \o -> (,)+ <$> (o .: "proof_key" >>= parse_key)+ <*> (o .: "compressed_proof" >>= parse_hex >>= parse_proof)++parse_hex :: String -> AT.Parser BS.ByteString+parse_hex s = maybe (fail ("bad hex: " <> s)) pure (B16.decode (B8.pack s))++parse_digest :: BS.ByteString -> AT.Parser Hash+parse_digest bs = maybe (fail "bad hash") pure (parse_hash bs)++parse_key :: String -> AT.Parser Key+parse_key s = parse_hex s >>= maybe (fail ("bad key: " <> s)) pure . key++parse_sum :: String -> AT.Parser Word64+parse_sum s = case reads s :: [(Integer, String)] of+ [(n, "")] | n >= 0 && n <= toInteger (maxBound :: Word64) ->+ pure (fromInteger n)+ _ -> fail ("bad sum: " <> s)++parse_proof :: BS.ByteString -> AT.Parser Proof+parse_proof = maybe (fail "bad compressed proof") pure . decompress++-- compressed proofs ----------------------------------------------------------++-- a compressed proof is a big-endian uint16 count n, then n siblings+-- as (32-byte hash, big-endian uint64 sum), then a 256-bit vector+-- (LSB-first per byte) marking which siblings are empty subtrees+decompress :: BS.ByteString -> Maybe Proof+decompress bs0 = do+ let (c, bs1) = BS.splitAt 2 bs0+ guard (BS.length c == 2)+ (nodes, bs2) <- siblings (fromIntegral (be c)) bs1+ guard (BS.length bs2 == 32)+ let bits = concatMap (\w -> fmap (testBit w) [0 .. 7]) (BS.unpack bs2)+ es <- empties+ Proof <$> fill bits nodes es+ where+ -- aggregate empty-subtree commitments, leaf up: the siblings of any+ -- key in the empty tree+ empties = do+ k <- key (BS.replicate 32 0)+ let Proof es = prove k empty+ pure es++ siblings :: Int -> BS.ByteString -> Maybe ([Commitment], BS.ByteString)+ siblings 0 bs = Just ([], bs)+ siblings n bs+ | BS.length bs < 40 = Nothing+ | otherwise = do+ let (h, rest0) = BS.splitAt 32 bs+ (s, rest1) = BS.splitAt 8 rest0+ d <- parse_hash h+ (ps, rest) <- siblings (n - 1) rest1+ pure (Commitment d (be s) : ps, rest)++ fill (b:bs) ns (e:es)+ | b = (e :) <$> fill bs ns es+ | otherwise = case ns of+ (n:rest) -> (n :) <$> fill bs rest es+ [] -> Nothing+ fill [] [] [] = Just []+ fill _ _ _ = Nothing++be :: BS.ByteString -> Word64+be = BS.foldl' (\acc w -> acc `shiftL` 8 .|. fromIntegral w) 0