merkleize

package
v0.1.1-experimental.2 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinParallelizationSize is the minimum size of the input list that
	// should be hashed using the default method. If the input list is smaller
	// than this size, the overhead of parallelizing the hashing process is.
	//
	// TODO: This value is arbitrary and should be benchmarked to find the
	// optimal value.
	MinParallelizationSize = 5000
)

Variables

View Source
var (
	// ErrOddLengthTreeRoots is returned when the input list length must be
	// even.
	ErrOddLengthTreeRoots = errors.New("input list length must be even")

	// ErrMaxRootsExceeded is returned when the number of roots exceeds the
	// maximum allowed.
	ErrMaxRootsExceeded = errors.New(
		"number of roots exceeds the maximum allowed",
	)
)

Functions

func BuildParentTreeRoots

func BuildParentTreeRoots(inputList [][32]byte) ([][32]byte, error)

BuildParentTreeRoots calls BuildParentTreeRootsWithNRoutines with the number of routines set to runtime.GOMAXPROCS(0)-1.

func BuildParentTreeRootsWithNRoutines

func BuildParentTreeRootsWithNRoutines(
	inputList [][32]byte, n int,
) ([][32]byte, error)

BuildParentTreeRootsWithNRoutines optimizes hashing of a list of roots using CPU-specific vector instructions and parallel processing. This method adapts to the host machine's hardware for potential performance gains over sequential hashing.

func ByteSliceSSZ

func ByteSliceSSZ(input []byte) ([32]byte, error)

ByteSliceSSZ hashes a byteslice by chunkifying it and returning the corresponding HTR as if it were a fixed vector of bytes of the given length.

func ListSSZ

func ListSSZ[T Hashable](
	elements []T,
	limit uint64,
) ([32]byte, error)

ListSSZ hashes each element in the list and then returns the HTR of the list of corresponding roots, with the length mixed in.

func Vector

func Vector(elements [][32]byte, length uint64) [32]byte

Vector uses our optimized routine to hash a list of 32-byte elements.

func VectorSSZ

func VectorSSZ[T Hashable](
	elements []T,
	length uint64,
) ([32]byte, error)

VectorSSZ hashes each element in the list and then returns the HTR of the corresponding list of roots.

Types

type Hashable

type Hashable interface {
	HashTreeRoot() ([32]byte, error)
}

Hashable is an interface representing objects that implement HashTreeRoot().

Jump to

Keyboard shortcuts

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