Documentation ¶
Index ¶
- Variables
- func GetFreshData(size, length int) [][]byte
- func GetFreshDataUnsorted(size, length int) [][]byte
- func GetNodeDB(txn *badger.Txn, prefix []byte, key []byte) ([]byte, error)
- func Hasher(data ...[]byte) []byte
- type DataArray
- type Hash
- type LeafNode
- type MemoryTrie
- type SMT
- func (s *SMT) Commit(txn *badger.Txn, height uint32) ([]byte, error)
- func (s *SMT) Discard()
- func (s *SMT) Drop(bDB *badger.DB) error
- func (s *SMT) FinalizeSnapShotRoot(txn *badger.Txn, root []byte, height uint32) error
- func (s *SMT) Get(txn *badger.Txn, key []byte) ([]byte, error)
- func (s *SMT) Height(txn *badger.Txn) (uint32, error)
- func (s *SMT) MerkleProof(txn *badger.Txn, key []byte) ([][]byte, bool, []byte, []byte, error)
- func (s *SMT) MerkleProofCompressed(txn *badger.Txn, key []byte) ([]byte, [][]byte, int, bool, []byte, []byte, error)
- func (s *SMT) MerkleProofCompressedR(txn *badger.Txn, key, root []byte) ([]byte, [][]byte, int, bool, []byte, []byte, error)
- func (s *SMT) MerkleProofR(txn *badger.Txn, key, root []byte) ([][]byte, bool, []byte, []byte, error)
- func (s *SMT) SnapShot(txn *badger.Txn, snapShotPrefix func() []byte) (*SMT, error)
- func (s *SMT) StoreSnapShotNode(txn *badger.Txn, batch []byte, root []byte, layer int) ([][]byte, int, []LeafNode, error)
- func (s *SMT) Update(txn *badger.Txn, keys, values [][]byte) ([]byte, error)
- func (s *SMT) VerifyInclusion(ap [][]byte, key, value []byte) bool
- func (s *SMT) VerifyInclusionC(bitmap, key, value []byte, ap [][]byte, length int) bool
- func (s *SMT) VerifyInclusionCR(root []byte, bitmap, key, value []byte, ap [][]byte, length int) bool
- func (s *SMT) VerifyNonInclusion(ap [][]byte, key, value, proofKey []byte) bool
- func (s *SMT) VerifyNonInclusionC(ap [][]byte, length int, bitmap, key, value, proofKey []byte) bool
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultLeaf is the value that may be passed to Update in order to delete // a key from the database. DefaultLeaf = Hasher([]byte{0}) )
var ErrCBDone = errors.New("cb done with iteration")
ErrCBDone should be passed up from the callback to walkNodes when the iteration will stop.
Functions ¶
func GetFreshData ¶
GetFreshData gets size number of byte slice where each slice should have a length of length
func GetFreshDataUnsorted ¶
GetFreshDataSorted gets size number of byte slice where each slice should have a length of length
Types ¶
type MemoryTrie ¶
type MemoryTrie struct {
// contains filtered or unexported fields
}
func NewMemoryTrie ¶
func NewMemoryTrie() *MemoryTrie
type SMT ¶
type SMT struct { // Root is the current root of the smt. Root []byte // TrieHeight is the number if bits in a key TrieHeight int // contains filtered or unexported fields }
SMT is a sparse Merkle tree.
func NewSMTForHeight ¶
func (*SMT) Commit ¶
Commit stores the updated nodes to disk Commit should be called for every block
func (*SMT) Discard ¶
func (s *SMT) Discard()
Discard rolls back the changes made by previous updates made without commit
func (*SMT) FinalizeSnapShotRoot ¶
func (*SMT) MerkleProof ¶
MerkleProof generates a Merkle proof of inclusion or non-inclusion for the current trie root returns the audit path, bool (key included), key, value, error (key,value) can be 1- (nil, value), value of the included key, 2- the kv of a LeafNode on the path of the non-included key, 3- (nil, nil) for a non-included key with a DefaultLeaf on the path
func (*SMT) MerkleProofCompressed ¶
func (s *SMT) MerkleProofCompressed(txn *badger.Txn, key []byte) ([]byte, [][]byte, int, bool, []byte, []byte, error)
MerkleProofCompressed returns a compressed merkle proof
func (*SMT) MerkleProofCompressedR ¶
func (s *SMT) MerkleProofCompressedR(txn *badger.Txn, key, root []byte) ([]byte, [][]byte, int, bool, []byte, []byte, error)
MerkleProofCompressedR returns a compressed merkle proof in the given trie
func (*SMT) MerkleProofR ¶
func (s *SMT) MerkleProofR(txn *badger.Txn, key, root []byte) ([][]byte, bool, []byte, []byte, error)
MerkleProofR generates a Merkle proof of inclusion or non-inclusion for a given past trie root returns the audit path, bool (key included), key, value, error (key,value) can be 1- (nil, value), value of the included key, 2- the kv of a LeafNode on the path of the non-included key, 3- (nil, nil) for a non-included key with a DefaultLeaf on the path
func (*SMT) SnapShot ¶
SnapShot allows the state of the database to be copied into a different prefix. This function will return that copy as an SMT object to the caller.
func (*SMT) StoreSnapShotNode ¶
func (*SMT) Update ¶
Update adds a sorted list of keys and their values to the trie If Update is called multiple times, only the state after the last update is committed. When calling Update multiple times without commit, make sure the values of different keys are unique(hash contains the key for example) otherwise some subtree may get overwritten with the wrong hash.
func (*SMT) VerifyInclusion ¶
VerifyInclusion verifies that key/value is included in the trie with latest root
func (*SMT) VerifyInclusionC ¶
VerifyInclusionC verifies that key/value is included in the trie with latest root
func (*SMT) VerifyInclusionCR ¶
func (s *SMT) VerifyInclusionCR(root []byte, bitmap, key, value []byte, ap [][]byte, length int) bool
VerifyInclusionCR verifies that key/value is included in the trie with latest root
func (*SMT) VerifyNonInclusion ¶
VerifyNonInclusion verifies a proof of non inclusion, Returns true if the non-inclusion is verified