verkle

package module
v0.0.0-...-5cce0a6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2021 License: Unlicense Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

verkle-tree-blake3

ci

A very very experimental implementation of Verkle 🌳🌲

This is a simple adaption of go-verkle that replaces Golang's crypto/sha256 (SHA2) with BLAKE3-256, for faster leaf hashing, maintaining an adequate 128-bit collision resistance.

readables

test

$ go test .

bench

$ go test . -bench Bench

Documentation

Index

Constants

View Source
const ErrInvalidNodeEncoding = "invalid node encoding"

Variables

This section is empty.

Functions

func ComputeKZGProof

func ComputeKZGProof(tc *TreeConfig, poly []bls.Fr, z, y *bls.Fr) *bls.G1Point

func MakeVerkleProofOneLeaf

func MakeVerkleProofOneLeaf(root VerkleNode, key []byte) (d *bls.G1Point, y *bls.Fr, sigma *bls.G1Point)

func VerifyVerkleProof

func VerifyVerkleProof(ks *kzg.KZGSettings, d, sigma *bls.G1Point, y *bls.Fr, commitments []*bls.G1Point, zis, yis []*bls.Fr, tc *TreeConfig) bool

Types

type Empty

type Empty struct{}

func (Empty) ComputeCommitment

func (e Empty) ComputeCommitment() *bls.G1Point

func (Empty) Copy

func (e Empty) Copy() VerkleNode

func (Empty) Delete

func (e Empty) Delete(k []byte) error

func (Empty) Get

func (e Empty) Get(k []byte, _ NodeResolverFn) ([]byte, error)

func (Empty) GetCommitment

func (e Empty) GetCommitment() *bls.G1Point

func (Empty) GetCommitmentsAlongPath

func (e Empty) GetCommitmentsAlongPath(key []byte) ([]*bls.G1Point, []*bls.Fr, []*bls.Fr, [][]bls.Fr)

func (Empty) Hash

func (e Empty) Hash() common.Hash

func (Empty) Insert

func (e Empty) Insert(k []byte, value []byte) error

func (Empty) InsertOrdered

func (e Empty) InsertOrdered(key []byte, value []byte, _ chan FlushableNode) error

func (Empty) Serialize

func (e Empty) Serialize() ([]byte, error)

type FlushableNode

type FlushableNode struct {
	Hash [32]byte
	Node VerkleNode
}

FlushableNode is a tuple of a node and its hash, to be passed to a consumer (e.g. the routine responsible for saving it to the db) once the node is no longer used by the tree.

type HashedNode

type HashedNode struct {
	// contains filtered or unexported fields
}

func (*HashedNode) ComputeCommitment

func (n *HashedNode) ComputeCommitment() *bls.G1Point

func (*HashedNode) Copy

func (n *HashedNode) Copy() VerkleNode

func (*HashedNode) Delete

func (n *HashedNode) Delete(k []byte) error

func (*HashedNode) Get

func (n *HashedNode) Get(k []byte, _ NodeResolverFn) ([]byte, error)

func (*HashedNode) GetCommitment

func (n *HashedNode) GetCommitment() *bls.G1Point

func (*HashedNode) GetCommitmentsAlongPath

func (n *HashedNode) GetCommitmentsAlongPath(key []byte) ([]*bls.G1Point, []*bls.Fr, []*bls.Fr, [][]bls.Fr)

func (*HashedNode) Hash

func (n *HashedNode) Hash() common.Hash

func (*HashedNode) Insert

func (n *HashedNode) Insert(k []byte, value []byte) error

func (*HashedNode) InsertOrdered

func (n *HashedNode) InsertOrdered(key []byte, value []byte, _ chan FlushableNode) error

func (*HashedNode) Serialize

func (n *HashedNode) Serialize() ([]byte, error)

type InternalNode

type InternalNode struct {
	// contains filtered or unexported fields
}

Represents an internal node at any level

func (*InternalNode) Children

func (n *InternalNode) Children() []VerkleNode

func (*InternalNode) ComputeCommitment

func (n *InternalNode) ComputeCommitment() *bls.G1Point

func (*InternalNode) Copy

func (n *InternalNode) Copy() VerkleNode

func (*InternalNode) Delete

func (n *InternalNode) Delete(key []byte) error

func (*InternalNode) Depth

func (n *InternalNode) Depth() int

func (*InternalNode) Flush

func (n *InternalNode) Flush(flush chan FlushableNode)

Flush hashes the children of an internal node and replaces them with HashedNode. It also sends the current node on the flush channel.

func (*InternalNode) Get

func (n *InternalNode) Get(k []byte, getter NodeResolverFn) ([]byte, error)

func (*InternalNode) GetCommitment

func (n *InternalNode) GetCommitment() *bls.G1Point

func (*InternalNode) GetCommitmentsAlongPath

func (n *InternalNode) GetCommitmentsAlongPath(key []byte) ([]*bls.G1Point, []*bls.Fr, []*bls.Fr, [][]bls.Fr)

func (*InternalNode) Hash

func (n *InternalNode) Hash() common.Hash

func (*InternalNode) Insert

func (n *InternalNode) Insert(key []byte, value []byte) error

func (*InternalNode) InsertOrdered

func (n *InternalNode) InsertOrdered(key []byte, value []byte, flush chan FlushableNode) error

func (*InternalNode) Serialize

func (n *InternalNode) Serialize() ([]byte, error)

func (*InternalNode) SetChild

func (n *InternalNode) SetChild(i int, c VerkleNode) error

func (*InternalNode) SetDepth

func (n *InternalNode) SetDepth(depth int)

func (*InternalNode) Width

func (n *InternalNode) Width() int

type LeafNode

type LeafNode struct {
	// contains filtered or unexported fields
}

func (*LeafNode) ComputeCommitment

func (n *LeafNode) ComputeCommitment() *bls.G1Point

func (*LeafNode) Copy

func (n *LeafNode) Copy() VerkleNode

func (*LeafNode) Delete

func (n *LeafNode) Delete(k []byte) error

func (*LeafNode) Get

func (n *LeafNode) Get(k []byte, _ NodeResolverFn) ([]byte, error)

func (*LeafNode) GetCommitment

func (n *LeafNode) GetCommitment() *bls.G1Point

func (*LeafNode) GetCommitmentsAlongPath

func (n *LeafNode) GetCommitmentsAlongPath(key []byte) ([]*bls.G1Point, []*bls.Fr, []*bls.Fr, [][]bls.Fr)

func (*LeafNode) Hash

func (n *LeafNode) Hash() common.Hash

func (*LeafNode) Insert

func (n *LeafNode) Insert(k []byte, value []byte) error

func (*LeafNode) InsertOrdered

func (n *LeafNode) InsertOrdered(key []byte, value []byte, flush chan FlushableNode) error

func (*LeafNode) Serialize

func (n *LeafNode) Serialize() ([]byte, error)

type NodeResolverFn

type NodeResolverFn func([]byte) ([]byte, error)

type TreeConfig

type TreeConfig struct {
	// contains filtered or unexported fields
}

func GetTreeConfig

func GetTreeConfig(width int) *TreeConfig

type VerkleNode

type VerkleNode interface {
	// Insert or Update value `v` at key `k`
	Insert(k []byte, v []byte) error

	// Insert "à la" Stacktrie. Same thing as insert, except that
	// values are expected to be ordered, and the commitments and
	// hashes for each subtrie are computed online, as soon as it
	// is clear that no more values will be inserted in there.
	InsertOrdered([]byte, []byte, chan FlushableNode) error

	// Delete a leaf with the given key
	Delete([]byte) error

	// Get value at a given key
	Get([]byte, NodeResolverFn) ([]byte, error)

	// Hash of the current node
	Hash() common.Hash

	// ComputeCommitment computes the commitment of the node
	ComputeCommitment() *bls.G1Point

	// GetCommitment retrieves the (previously computed)
	// commitment of a node.
	GetCommitment() *bls.G1Point

	// GetCommitmentAlongPath follows the path that one key
	// traces through the tree, and collects the various
	// elements needed to build a proof. The order of elements
	// is from the bottom of the tree, up to the root.
	GetCommitmentsAlongPath([]byte) ([]*bls.G1Point, []*bls.Fr, []*bls.Fr, [][]bls.Fr)

	// Serialize encodes the node to RLP.
	Serialize() ([]byte, error)

	// Copy a node and its children
	Copy() VerkleNode
}

func New

func New(width int) VerkleNode

New creates a new tree root

func ParseNode

func ParseNode(serialized []byte, depth, width int) (VerkleNode, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址