trie_blake2b

package
v0.0.0-...-1223896 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: MIT Imports: 9 Imported by: 1

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)
	HashSize192 = HashSize(24)
	HashSize256 = HashSize(32)
)

Variables

Functions

func CompressToHashSize

func CompressToHashSize(data []byte, sz HashSize) ([]byte, bool)

CompressToHashSize hashes data if longer than hash size, otherwise copies it

func HashTheVector

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

Types

type CommitmentModel

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

CommitmentModel provides commitment common implementation for the 256+ trie

func New

func New(arity common.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 value commitments 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) AlwaysStoreTerminalWithNode

func (m *CommitmentModel) AlwaysStoreTerminalWithNode() bool

func (*CommitmentModel) CalcNodeCommitment

func (m *CommitmentModel) CalcNodeCommitment(par *common.NodeData, nodePath []byte) common.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) common.TCommitment

func (*CommitmentModel) Description

func (m *CommitmentModel) Description() string

func (*CommitmentModel) EqualCommitments

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

func (*CommitmentModel) ForceStoreTerminalWithNode

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

func (*CommitmentModel) HashSize

func (m *CommitmentModel) HashSize() HashSize

func (*CommitmentModel) NewTerminalCommitment

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

NewTerminalCommitment creates empty terminal commitment

func (*CommitmentModel) NewVectorCommitment

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

NewVectorCommitment create empty vector commitment

func (*CommitmentModel) PathArity

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

func (*CommitmentModel) ProofImmutable

func (m *CommitmentModel) ProofImmutable(key []byte, tr *immutable.TrieReader) *MerkleProof

ProofImmutable converts generic proof path of the immutable trie implementation to the Merkle proof path

func (*CommitmentModel) ProofMut

func (m *CommitmentModel) ProofMut(key []byte, tr mutable.NodeStore) *MerkleProof

ProofMut converts generic proof path of the mutable trie implementation to the Merkle proof path

func (*CommitmentModel) ShortName

func (m *CommitmentModel) ShortName() string

func (*CommitmentModel) UpdateNodeCommitment

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

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

type HashSize

type HashSize byte

func (HashSize) String

func (hs HashSize) String() string

type MerkleProof

type MerkleProof struct {
	PathArity common.PathArity
	HashSize  HashSize
	Key       []byte
	Path      []*MerkleProofElement
}

MerkleProof blake2b model specific proof of inclusion

func ProofFromBytes

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

func (*MerkleProof) Bytes

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

func (*MerkleProof) Read

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

func (*MerkleProof) Write

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

type MerkleProofElement

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

func (*MerkleProofElement) Read

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

func (*MerkleProofElement) Write

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

Directories

Path Synopsis
Package trie_blake2b_verify contains functions for verification of the proofs of inclusion or absence in the trie with trie_blake2b commitment model.
Package trie_blake2b_verify contains functions for verification of the proofs of inclusion or absence in the trie with trie_blake2b commitment model.

Jump to

Keyboard shortcuts

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