Skip to content
/ smt Public
forked from celestiaorg/smt

A Go library that implements a Sparse Merkle tree for a key-value map.

License

Notifications You must be signed in to change notification settings

vulcanize/smt

This branch is 29 commits ahead of celestiaorg/smt:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

db66d9c · Jun 10, 2022
Apr 14, 2022
Apr 19, 2022
Aug 19, 2018
Sep 27, 2021
Apr 19, 2022
May 11, 2022
Apr 29, 2022
Apr 19, 2022
Apr 20, 2022
Mar 10, 2021
Aug 24, 2020
Apr 20, 2022
Jul 29, 2021
Apr 29, 2022
Apr 19, 2022
May 6, 2022
Apr 19, 2022
May 6, 2022
Apr 19, 2022
Apr 29, 2022
Apr 29, 2022
Apr 29, 2022

Repository files navigation

smt

A Go library that implements a Sparse Merkle tree for a key-value map. The tree implements the same optimisations specified in the Libra whitepaper, to reduce the number of hash operations required per tree operation to O(k) where k is the number of non-empty elements in the tree.

Tests codecov GoDoc

Example

package main

import (
	"crypto/sha256"
	"fmt"

	"github.com/celestiaorg/smt"
)

func main() {
	// Initialise two new key-value store to store the nodes and values of the tree
	nodeStore := smt.NewSimpleMap()
	valueStore := smt.NewSimpleMap()
	// Initialise the tree
	tree := smt.NewSparseMerkleTree(nodeStore, valueStore, sha256.New())

	// Update the key "foo" with the value "bar"
	_, _ = tree.Update([]byte("foo"), []byte("bar"))

	// Generate a Merkle proof for foo=bar
	proof, _ := tree.Prove([]byte("foo"))
	root := tree.Root() // We also need the current tree root for the proof

	// Verify the Merkle proof for foo=bar
	if smt.VerifyProof(proof, root, []byte("foo"), []byte("bar"), sha256.New()) {
		fmt.Println("Proof verification succeeded.")
	} else {
		fmt.Println("Proof verification failed.")
	}
}

About

A Go library that implements a Sparse Merkle tree for a key-value map.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.7%
  • Shell 0.3%