commit 4c756409e03f4112a352eccb33c3aca0189a343c
parent 88f312c1bd1f5074783f2dff864eaed30cd8b5d3
Author: Jared Tobin <jared@jtobin.io>
Date: Wed, 4 Nov 2026 22:01:50 +0400
readme: init
Diffstat:
| A | README.md | | | 93 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 93 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
@@ -0,0 +1,93 @@
+# mssmt
+
+A high-performance, in-memory merkle-sum sparse merkle tree (MS-SMT).
+
+An MS-SMT maps 256-bit keys to values carrying sums. Its root commits
+to every leaf and to the total of their sums, and it can prove any
+key's inclusion or exclusion. There are two kinds, each with its own
+tree type:
+
+* `Data.MSSMT.Split`, re-exported by `Data.MSSMT`: each branch commits
+ to the hash and sum of each of its children, and a subtree holding a
+ single leaf commits to that leaf directly, so that paths and proofs
+ run only as deep as is needed to set a key apart.
+
+* `Data.MSSMT.Aggregate`: each branch commits to its children's hashes
+ and the sum of their sums, at a fixed depth of 256. Roots and proofs
+ agree with those of the [Taproot Assets][tapd] MS-SMT, and are tested
+ against its vectors.
+
+## Usage
+
+A sample GHCi session:
+
+```
+ > :set -XOverloadedStrings
+ >
+ > import qualified Crypto.Hash.SHA256 as SHA256
+ > import qualified Data.MSSMT as M
+ >
+ > -- keys are 32 bytes
+ > let Just alice = M.key (SHA256.hash "alice")
+ > let Just bob = M.key (SHA256.hash "bob")
+ >
+ > -- insert a value and sum at a key
+ > let Just t = M.insert alice "alice's leaf" 100 M.empty
+ > M.lookup alice t
+ Just ("alice's leaf",100)
+ >
+ > -- the root commits to every leaf, and to the total of their sums
+ > let M.Commitment _ total = M.root t
+ > total
+ 100
+ >
+ > -- prove a key's inclusion, or, via an empty value with zero sum,
+ > -- its exclusion
+ > M.verify alice "alice's leaf" 100 (M.prove alice t) (M.root t)
+ True
+ > M.verify bob mempty 0 (M.prove bob t) (M.root t)
+ True
+ > M.verify alice "alice's leaf" 99 (M.prove alice t) (M.root t)
+ False
+```
+
+## Performance
+
+Hashing uses hardware SHA-256 instructions wherever the CPU supports
+them, via [ppad-sha256][sha256]. On a split tree of 1024 leaves, on an
+Apple M4, operations take roughly:
+
+```
+ insert 0.9 μs
+ delete 0.6 μs
+ lookup 17 ns
+ prove 60 ns
+ verify 0.75 μs
+```
+
+and the tree holds about 190 bytes per leaf. Use `cabal bench` to run
+the benchmark suites. You should compile with the 'llvm' flag for
+maximum performance.
+
+## Development
+
+You'll require [Nix][nixos] with [flake][flake] support enabled. Enter a
+development shell with:
+
+```
+$ nix develop
+```
+
+Then do e.g.:
+
+```
+$ cabal repl mssmt
+```
+
+to get a REPL for the main library, or `cabal test` to run the test
+suite.
+
+[tapd]: https://github.com/lightninglabs/taproot-assets
+[sha256]: https://github.com/ppad-tech/sha256
+[nixos]: https://nixos.org/
+[flake]: https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html