trie_blake2b

package
v0.0.0-...-2b1eae4 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: Apache-2.0 Imports: 7 Imported by: 3

README

Package trie_blake2b

Package contains implementation of commitment model for the 256+ trie based on blake2b 20 byte (160 bit) hashing.

Documentation

Overview

Package trie_blake2b_20 implements trie.CommitmentModel based on blake2b 32-byte hashing

Index

Constants

View Source
const (
	HashSize160 = HashSize(20)
	HashSize256 = HashSize(32)
)

Variables

Functions

func CommitToDataRaw

func CommitToDataRaw(data []byte, sz HashSize) []byte

CommitToDataRaw commits to data

func HashTheVector

func HashTheVector(hashes [][]byte, arity trie.PathArity, sz HashSize) []byte

Types

type CommitmentModel

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

CommitmentModel provides commitment model implementation for the 256+ trie

func New

func New(arity trie.PathArity, hashSize HashSize, valueSizeOptimizationThreshold ...int) *CommitmentModel

New creates new CommitmentModel. Parameter valueSizeOptimizationThreshold means that for terminal commitments to values longer than threshold, the terminal commitments will always be stored with the trie node, i.e. ForceStoreTerminalWithNode will return true. For terminal commitments of this or smaller size, the choice depends on the trie setup Default valueSizeOptimizationThreshold = 0, which means that by default all values are stored in the node. If valueSizeOptimizationThreshold > 0 valueStore must be specified in the trie parameters Reasonable value of valueSizeOptimizationThreshold, allows significantly optimize trie storage without requiring hashing big data each time

func (*CommitmentModel) CalcNodeCommitment

func (m *CommitmentModel) CalcNodeCommitment(par *trie.NodeData) trie.VCommitment

CalcNodeCommitment computes commitment of the node. It is suboptimal in KZG trie. Used in computing root commitment

func (*CommitmentModel) CommitToData

func (m *CommitmentModel) CommitToData(data []byte) trie.TCommitment

func (*CommitmentModel) Description

func (m *CommitmentModel) Description() string

func (*CommitmentModel) EqualCommitments

func (m *CommitmentModel) EqualCommitments(c1, c2 trie.Serializable) bool

func (*CommitmentModel) ForceStoreTerminalWithNode

func (m *CommitmentModel) ForceStoreTerminalWithNode(c trie.TCommitment) bool

func (*CommitmentModel) HashSize

func (m *CommitmentModel) HashSize() HashSize

func (*CommitmentModel) NewTerminalCommitment

func (m *CommitmentModel) NewTerminalCommitment() trie.TCommitment

NewTerminalCommitment creates empty terminal commitment

func (*CommitmentModel) NewVectorCommitment

func (m *CommitmentModel) NewVectorCommitment() trie.VCommitment

NewVectorCommitment create empty vector commitment

func (*CommitmentModel) PathArity

func (m *CommitmentModel) PathArity() trie.PathArity

func (*CommitmentModel) Proof

func (m *CommitmentModel) Proof(key []byte, tr trie.NodeStore) *Proof

Proof converts generic proof path to the Merkle proof path

func (*CommitmentModel) ShortName

func (m *CommitmentModel) ShortName() string

func (*CommitmentModel) UpdateNodeCommitment

func (m *CommitmentModel) UpdateNodeCommitment(mutate *trie.NodeData, childUpdates map[byte]trie.VCommitment, _ bool, newTerminalUpdate trie.TCommitment, update *trie.VCommitment)

UpdateNodeCommitment computes update to the node data and, optionally, updates existing commitment In blake2b implementation delta it just means computing the hash of data

type HashSize

type HashSize byte

func (HashSize) MaxCommitmentSize

func (hs HashSize) MaxCommitmentSize() int

func (HashSize) String

func (hs HashSize) String() string

type Proof

type Proof struct {
	PathArity trie.PathArity
	HashSize  HashSize
	Key       []byte
	Path      []*ProofElement
}

Proof blake2b 20 byte model-specific proof of inclusion

func ProofFromBytes

func ProofFromBytes(data []byte) (*Proof, error)

func (*Proof) Bytes

func (p *Proof) Bytes() []byte

func (*Proof) Read

func (p *Proof) Read(r io.Reader) error

func (*Proof) Write

func (p *Proof) Write(w io.Writer) error

type ProofElement

type ProofElement struct {
	PathFragment []byte
	Children     map[byte][]byte
	Terminal     []byte
	ChildIndex   int
}

func (*ProofElement) Read

func (e *ProofElement) Read(r io.Reader, arity trie.PathArity, sz HashSize) error

func (*ProofElement) Write

func (e *ProofElement) Write(w io.Writer, arity trie.PathArity, sz HashSize) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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