sparse-merkle-trees

Build sparse Merkle trees with Poseidon or SHA-256 hashing for ZK circuits in .NET.

2.3k|744|Updated Nov 23, 2015
One-click install
npx skills add https://github.com/Nethereum/Nethereum --skill sparse-merkle-trees
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sparse-merkle-trees
Source: https://github.com/Nethereum/Nethereum/tree/main/plugins/nethereum-skills/skills/sparse-merkle-trees
Command: npx skills add https://github.com/Nethereum/Nethereum --skill sparse-merkle-trees

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires Nethereum.Merkle, Nethereum.Util.

What problem does it solve?

Developers building zero-knowledge circuits, privacy pools, or state commitments need sparse Merkle trees whose roots are compatible with ZK proof systems like Circom, but implementing Poseidon-based SMTs with correct bit ordering and hashing from scratch is error-prone.

Core Features & Use Cases

  • Poseidon SMT for ZK Circuits: Create trees with PoseidonSmtHasher (CircomT3 leaf, CircomT2 node) producing roots usable directly as Circom public inputs.
  • Celestia-Compatible Trees: Build SHA-256 domain-separated sparse Merkle trees matching Celestia's specification.
  • Persistent Storage & Proofs: Store trees with ISmtNodeStorage backends, lazy-load nodes via LoadRootAsync, and generate membership or non-membership proofs for privacy pools and anonymous voting.
  • Use Case: A developer building a privacy pool nullifier set inserts commitment keys into a Poseidon SMT, computes the root, and feeds it into a Circom proof verifying membership without revealing the leaf.

Quick Start

Ask the AI to create a Poseidon-based sparse Merkle tree in C# using Nethereum.Merkle, insert key-value pairs, and compute the root hash for a ZK circuit.

Frequently Asked Questions about sparse-merkle-trees

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a Poseidon sparse Merkle tree in C#?

Install Nethereum.Merkle, then create a SparseMerkleBinaryTree with PoseidonSmtHasher, a byte-array convertor, and IdentitySmtKeyHasher. Call Put to insert entries and ComputeRoot to get a Circom-compatible root hash.

What is the difference between PoseidonSmtHasher and CelestiaSmtHasher?

PoseidonSmtHasher uses Poseidon hashing (CircomT3 for leaves, CircomT2 for nodes) for ZK circuits with LSB-first bit ordering. CelestiaSmtHasher uses SHA-256 with domain prefixes matching Celestia's spec and MSB-first ordering.

Can I persist a sparse Merkle tree across process restarts?

Yes, pass an ISmtNodeStorage implementation to the tree constructor and use the async API. Call FlushAsync to persist nodes, then LoadRootAsync later to reload the tree with lazy node loading.

Does insertion order affect the sparse Merkle tree root?

No, the root hash is deterministic regardless of insertion order. Keys are converted to fixed bit paths, so the same set of key-value pairs always produces the same root.

Why does IdentitySmtKeyHasher fail with variable-length keys?

IdentitySmtKeyHasher requires keys to match the exact bit length specified in its constructor. For variable-length keys, use Sha256SmtKeyHasher, which hashes keys to a fixed 256-bit path.