{"id":14256820,"url":"https://github.com/celestiaorg/nmt","last_synced_at":"2025-05-16T02:09:35.048Z","repository":{"id":39615362,"uuid":"279900200","full_name":"celestiaorg/nmt","owner":"celestiaorg","description":"Namespaced Merkle Tree","archived":false,"fork":false,"pushed_at":"2025-02-26T15:00:15.000Z","size":1252,"stargazers_count":119,"open_issues_count":34,"forks_count":47,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-01T12:03:50.285Z","etag":null,"topics":["namespaced-merkle-tree"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/celestiaorg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-15T15:06:30.000Z","updated_at":"2025-03-22T10:38:34.000Z","dependencies_parsed_at":"2023-02-03T17:16:23.165Z","dependency_job_id":"eab38b13-b2e4-45e2-aa6e-1c949d4bd9bf","html_url":"https://github.com/celestiaorg/nmt","commit_stats":null,"previous_names":["lazyledger/nmt"],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celestiaorg%2Fnmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celestiaorg%2Fnmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celestiaorg%2Fnmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celestiaorg%2Fnmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/celestiaorg","download_url":"https://codeload.github.com/celestiaorg/nmt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247847611,"owners_count":21006100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["namespaced-merkle-tree"],"created_at":"2024-08-22T07:01:16.011Z","updated_at":"2025-04-08T13:07:49.700Z","avatar_url":"https://github.com/celestiaorg.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Namespaced Merkle Tree (NMT)\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/celestiaorg/nmt.svg)](https://pkg.go.dev/github.com/celestiaorg/nmt)\n![golangci-lint](https://github.com/celestiaorg/nmt/workflows/lint/badge.svg)\u003c!-- it retrieves the lint workflow status badge for the default branch i.e., main, for a different branch, specify the branch parameter in the URL() --\u003e\n![Go](https://github.com/celestiaorg/nmt/workflows/Go/badge.svg)\n\nA Namespaced Merkle Tree is\n\u003e [...] an ordered Merkle tree that uses a modified hash function\n  so that each node in the tree includes the range of\n  namespaces of the messages in all of the descendants\n  of each node. The leafs in the tree are ordered by the\n  namespace identifiers of the messages.\n  In a namespaced Merkle tree, each non-leaf node in\n  the tree contains the lowest and highest namespace\n  identifiers found in all the leaf nodes that are descendants of the non-leaf node, in addition to the hash of\n  the concatenation of the children of the node. This\n  enables Merkle inclusion proofs to be created that prove to a verifier that all the elements of the tree for\n  a specific namespace have been included in a Merkle\n  inclusion proof.\n\nThe concept was first introduced by [@musalbas] in the LazyLedger [academic paper].\n\n## Example\n\n```go\npackage main\n\nimport (\n    \"bytes\"\n    \"crypto/sha256\"\n    \"fmt\"\n\n    \"github.com/celestiaorg/nmt\"\n    \"github.com/celestiaorg/nmt/namespace\"\n)\n\nfunc main() {\n    // the tree will use this namespace size (number of bytes)\n    nidSize := 1\n    // the leaves that will be pushed\n    data := [][]byte{\n      append(namespace.ID{0}, []byte(\"leaf_0\")...),\n      append(namespace.ID{0}, []byte(\"leaf_1\")...),\n      append(namespace.ID{1}, []byte(\"leaf_2\")...),\n      append(namespace.ID{1}, []byte(\"leaf_3\")...)}\n    // Init a tree with the namespace size as well as\n    // the underlying hash function:\n    tree := nmt.New(sha256.New(), nmt.NamespaceIDSize(nidSize))\n    for _, d := range data {\n      if err := tree.Push(d); err != nil {\n        panic(fmt.Sprintf(\"unexpected error: %v\", err))\n      }\n    }\n    // compute the root\n    root, err := tree.Root()\n    if err != nil {\n      panic(fmt.Sprintf(\"unexpected error: %v\", err))\n    }\n    // the root's min/max namespace is the min and max namespace of all leaves:\n    minNS := nmt.MinNamespace(root, tree.NamespaceSize())\n    maxNS := nmt.MaxNamespace(root, tree.NamespaceSize())\n    if bytes.Equal(minNS, namespace.ID{0}) {\n      fmt.Printf(\"Min namespace: %x\\n\", minNS)\n    }\n    if bytes.Equal(maxNS, namespace.ID{1}) {\n      fmt.Printf(\"Max namespace: %x\\n\", maxNS)\n    }\n\n    // compute proof for namespace 0:\n    proof, err := tree.ProveNamespace(namespace.ID{0})\n    if err != nil {\n      panic(\"unexpected error\")\n    }\n\n    // verify proof using the root and the leaves of namespace 0:\n    leafs := [][]byte{\n      append(namespace.ID{0}, []byte(\"leaf_0\")...),\n      append(namespace.ID{0}, []byte(\"leaf_1\")...),\n    }\n\n    if proof.VerifyNamespace(sha256.New(), namespace.ID{0}, leafs, root) {\n      fmt.Printf(\"Successfully verified namespace: %x\\n\", namespace.ID{0})\n    }\n\n    if proof.VerifyNamespace(sha256.New(), namespace.ID{2}, leafs, root) {\n      panic(fmt.Sprintf(\"Proof for namespace %x, passed for namespace: %x\\n\", namespace.ID{0}, namespace.ID{2}))\n    }\n}\n```\n\nThe above will create a Namespaced merkle tree with four leafs which looks like this:\n\n![example](imgs/example_4-leaves.png)\n\nWhere `nid_0 = nid_1 = 0` and `nid_2 = nid_3 = 1` and `data_i = \"leaf_i\"` for `i = 0,...,3`.\n\n## Related\n\nThis implementation was heavily inspired by the initial implementation in [celestiaorg/lazyledger-prototype](https://github.com/celestiaorg/lazyledger-prototype).\n\nNon-endorsed implementations of NMT exist in other languages:\n\nLanguage | Repo\n---------|------------------------------------------------------------------\nRust     | [Sovereign-Labs/nmt-rs](https://github.com/Sovereign-Labs/nmt-rs)\n\n\u003c!--- TODO references ---\u003e\n[academic paper]: https://arxiv.org/abs/1905.09274\n[@musalbas]: https://github.com/musalbas\n\n## Contributing\n\nMarkdown files must conform to [GitHub Flavored Markdown](https://github.github.com/gfm/). Markdown must be formatted with:\n\n- [markdownlint](https://github.com/DavidAnson/markdownlint)\n- [Markdown Table Prettifier](https://github.com/darkriszty/MarkdownTablePrettify-VSCodeExt)\n\n## Audits\n\nDate      | Auditor                                       | Report\n----------|-----------------------------------------------|--------------------------------------------------------\n2023/8/18 | [Informal Systems](https://informal.systems/) | [informal-systems.pdf](docs/audit/informal-systems.pdf)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcelestiaorg%2Fnmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcelestiaorg%2Fnmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcelestiaorg%2Fnmt/lists"}