# README
zkbnb-smt
zkbnb-smt is an implementation code library based on the concept of SparseMerkleTree
, which implements the concepts of data persistence and data compression.
For an overview, see the design.
Installation
go get github.com/bnb-chain/zkbnb-smt@latest
Quickstart
package main
import (
"crypto/sha256"
"fmt"
bsmt "github.com/bnb-chain/zkbnb-smt"
"github.com/bnb-chain/zkbnb-smt/database/memory"
)
func main() {
db := memory.NewMemoryDB()
hasher := bsmt.NewHasher(sha256.New())
nilHash := hasher.Hash([]byte("nilHash"))
maxDepth := uint8(8)
smt, err := bsmt.NewBASSparseMerkleTree(hasher, db, maxDepth, nilHash)
if err != nil {
fmt.Println(err)
return
}
key1 := uint64(1)
key2 := uint64(2)
key3 := uint64(23)
val1 := hasher.Hash([]byte("test1"))
val2 := hasher.Hash([]byte("test2"))
val3 := hasher.Hash([]byte("test3"))
smt.Set(key1, val1)
smt.Set(key2, val2)
smt.Set(key3, val3)
version1, err := smt.Commit(nil)
if err != nil {
fmt.Println(err)
return
}
_, err = smt.Get(key1, &version1)
if err != nil {
fmt.Println(err)
return
}
_, err = smt.Get(key2, &version1)
if err != nil {
fmt.Println(err)
return
}
_, err = smt.Get(key3, &version1)
if err != nil {
fmt.Println(err)
return
}
proof, err := smt.GetProof(key1)
if err != nil {
fmt.Println(err)
return
}
if !smt.VerifyProof(key1, proof) {
fmt.Println("verify proof failed")
return
}
}
# Functions
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Interfaces
No description provided by the author
# Type aliases
No description provided by the author
Option is a function that configures SMT.
No description provided by the author
No description provided by the author