Documentation
¶
Overview ¶
Package ssz defines HashTreeRoot utility functions.
Index ¶
- func BitlistRoot(hasher HashFn, bfield bitfield.Bitfield, maxCapacity uint64) ([32]byte, error)
- func BitwiseMerkleize(hasher HashFn, chunks [][]byte, count, limit uint64) ([32]byte, error)
- func BitwiseMerkleizeArrays(hasher HashFn, chunks [][32]byte, count, limit uint64) ([32]byte, error)
- func ByteArrayRootWithLimit(roots [][]byte, limit uint64) ([32]byte, error)
- func CheckpointRoot(hasher HashFn, checkpoint *ethpb.Checkpoint) ([32]byte, error)
- func ConstructProof(hasher Hasher, count, limit uint64, leaf func(i uint64) []byte, index uint64) (branch [][32]byte)
- func DeepEqual(x, y interface{}) bool
- func Depth(v uint64) (out uint8)
- func ForkRoot(fork *ethpb.Fork) ([32]byte, error)
- func IsProto(item interface{}) bool
- func Merkleize(hasher Hasher, count, limit uint64, leaf func(i uint64) []byte) (out [32]byte)
- func MixInLength(root [32]byte, length []byte) [32]byte
- func Pack(serializedItems [][]byte) ([][]byte, error)
- func SlashingsRoot(slashings []uint64) ([32]byte, error)
- func Uint64Root(val uint64) [32]byte
- type HashFn
- type Hasher
- type HasherFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BitlistRoot ¶
BitlistRoot returns the mix in length of a bitwise Merkleized bitfield.
func BitwiseMerkleize ¶
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 ByteArrayRootWithLimit ¶
ByteArrayRootWithLimit computes the HashTreeRoot Merkleization of a list of [32]byte roots according to the Ethereum Simple Serialize specification.
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 Ethereum 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 DeepEqual ¶
func DeepEqual(x, y interface{}) bool
DeepEqual reports whether two SSZ-able values x and y are “deeply equal,” defined as follows: Two values of identical type are deeply equal if one of the following cases applies:
Values of distinct types are never deeply equal.
Array values are deeply equal when their corresponding elements are deeply equal.
Struct values are deeply equal if their corresponding fields, both exported and unexported, are deeply equal.
Interface values are deeply equal if they hold deeply equal concrete values.
Pointer values are deeply equal if they are equal using Go's == operator or if they point to deeply equal values.
Slice values are deeply equal when all of the following are true: they are both nil, one is nil and the other is empty or vice-versa, they have the same length, and either they point to the same initial entry of the same array (that is, &x[0] == &y[0]) or their corresponding elements (up to length) are deeply equal.
Other values - numbers, bools, strings, and channels - are deeply equal if they are equal using Go's == operator.
In general DeepEqual is a recursive relaxation of Go's == operator. However, this idea is impossible to implement without some inconsistency. Specifically, it is possible for a value to be unequal to itself, either because it is of func type (uncomparable in general) or because it is a floating-point NaN value (not equal to itself in floating-point comparison), or because it is an array, struct, or interface containing such a value.
On the other hand, pointer values are always equal to themselves, even if they point at or contain such problematic values, because they compare equal using Go's == operator, and that is a sufficient condition to be deeply equal, regardless of content. DeepEqual has been defined so that the same short-cut applies to slices and maps: if x and y are the same slice or the same map, they are deeply equal regardless of content.
As DeepEqual traverses the data values it may find a cycle. The second and subsequent times that DeepEqual compares two pointer values that have been compared before, it treats the values as equal rather than examining the values to which they point. This ensures that DeepEqual terminates.
Credits go to the Go team as this is an extension of the official Go source code's reflect.DeepEqual function to handle special SSZ edge cases.
func ForkRoot ¶
ForkRoot computes the HashTreeRoot Merkleization of a Fork struct value according to the Ethereum Simple Serialize specification.
func MixInLength ¶
MixInLength appends hash length to root
func SlashingsRoot ¶
SlashingsRoot computes the HashTreeRoot Merkleization of a list of uint64 slashing values according to the Ethereum Simple Serialize specification.
func Uint64Root ¶
Uint64Root computes the HashTreeRoot Merkleization of a simple uint64 value according to the Ethereum Simple Serialize specification.
Types ¶
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.