htrutils

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2021 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package htrutils defines HashTreeRoot utility functions.

Package htrutils defines HashTreeRoot utility functions.

Package htrutils defines HashTreeRoot utility functions.

Package htrutils defines HashTreeRoot utility functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BitlistRoot

func BitlistRoot(hasher HashFn, bfield bitfield.Bitfield, maxCapacity uint64) ([32]byte, error)

BitlistRoot returns the mix in length of a bitwise Merkleized bitfield.

func BitwiseMerkleize

func BitwiseMerkleize(hasher HashFn, chunks [][]byte, count, limit uint64) ([32]byte, error)

BitwiseMerkleize - given ordered BYTES_PER_CHUNK-byte chunks, if necessary utilize zero chunks so that the number of chunks is a power of two, Merkleize the chunks, and return the root. Note that merkleize on a single chunk is simply that chunk, i.e. the identity when the number of chunks is one.

func BitwiseMerkleizeArrays

func BitwiseMerkleizeArrays(hasher HashFn, chunks [][32]byte, count, limit uint64) ([32]byte, error)

BitwiseMerkleizeArrays is used when a set of 32-byte root chunks are provided.

func CheckpointRoot

func CheckpointRoot(hasher HashFn, checkpoint *ethpb.Checkpoint) ([32]byte, error)

CheckpointRoot computes the HashTreeRoot Merkleization of a InitWithReset struct value according to the eth2 Simple Serialize specification.

func ConstructProof

func ConstructProof(hasher Hasher, count, limit uint64, leaf func(i uint64) []byte, index uint64) (branch [][32]byte)

ConstructProof builds a merkle-branch of the given depth, at the given index (at that depth), for a list of leafs of a balanced binary tree.

func Depth added in v1.2.0

func Depth(v uint64) (out uint8)

Depth retrieves the appropriate depth for the provided trie size.

func ForkRoot

func ForkRoot(fork *pb.Fork) ([32]byte, error)

ForkRoot computes the HashTreeRoot Merkleization of a Fork struct value according to the eth2 Simple Serialize specification.

func HistoricalRootsRoot

func HistoricalRootsRoot(historicalRoots [][]byte) ([32]byte, error)

HistoricalRootsRoot computes the HashTreeRoot Merkleization of a list of [32]byte historical block roots according to the eth2 Simple Serialize specification.

func Merkleize

func Merkleize(hasher Hasher, count, limit uint64, leaf func(i uint64) []byte) (out [32]byte)

Merkleize with log(N) space allocation

func MixInLength

func MixInLength(root [32]byte, length []byte) [32]byte

MixInLength appends hash length to root

func Pack

func Pack(serializedItems [][]byte) ([][]byte, error)

Pack a given byte array's final chunk with zeroes if needed.

func SlashingsRoot

func SlashingsRoot(slashings []uint64) ([32]byte, error)

SlashingsRoot computes the HashTreeRoot Merkleization of a list of uint64 slashing values according to the eth2 Simple Serialize specification.

func Uint64Root

func Uint64Root(val uint64) [32]byte

Uint64Root computes the HashTreeRoot Merkleization of a simple uint64 value according to the eth2 Simple Serialize specification.

Types

type HashFn

type HashFn func(input []byte) [32]byte

HashFn is the generic hash function signature.

type Hasher

type Hasher interface {
	Hash(a []byte) [32]byte
	Combi(a [32]byte, b [32]byte) [32]byte
	MixIn(a [32]byte, i uint64) [32]byte
}

Hasher describes an interface through which we can perform hash operations on byte arrays,indices,etc.

type HasherFunc

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

HasherFunc defines a structure to hold a hash function and can be used for multiple rounds of hashing.

func NewHasherFunc

func NewHasherFunc(h HashFn) *HasherFunc

NewHasherFunc is the constructor for the object that fulfills the Hasher interface.

func (*HasherFunc) Combi

func (h *HasherFunc) Combi(a, b [32]byte) [32]byte

Combi appends the two inputs and hashes them.

func (*HasherFunc) Hash

func (h *HasherFunc) Hash(a []byte) [32]byte

Hash utilizes the provided hash function for the object.

func (*HasherFunc) MixIn

func (h *HasherFunc) MixIn(a [32]byte, i uint64) [32]byte

MixIn works like Combi, but using an integer as the second input.

Jump to

Keyboard shortcuts

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