Documentation
¶
Index ¶
- func GetZeroHash(depth int) []byte
- func GetZeroHashLevel(hash string) (int, bool)
- func GetZeroHashLevelBytes(hash []byte) (int, bool)
- func GetZeroHashes() [65][32]byte
- func ParseBitlist(dst, buf []byte) ([]byte, uint64)
- func ParseBitlistWithHasher(hw sszutils.HashWalker, buf []byte) ([]byte, uint64)
- func WithDefaultHasher(fn func(hh sszutils.HashWalker) error) error
- type HashFn
- type Hasher
- func (h *Hasher) Append(i []byte)
- func (h *Hasher) AppendBool(b bool)
- func (h *Hasher) AppendBytes32(b []byte)
- func (h *Hasher) AppendUint8(i uint8)
- func (h *Hasher) AppendUint16(i uint16)
- func (h *Hasher) AppendUint32(i uint32)
- func (h *Hasher) AppendUint64(i uint64)
- func (h *Hasher) Collapse()
- func (h *Hasher) CurrentIndex() int
- func (h *Hasher) FillUpTo32()
- func (h *Hasher) Hash() []byte
- func (h *Hasher) HashRoot() (res [32]byte, err error)
- func (h *Hasher) Index() int
- func (h *Hasher) Merkleize(indx int)
- func (h *Hasher) MerkleizeProgressive(indx int)
- func (h *Hasher) MerkleizeProgressiveWithActiveFields(indx int, activeFields []byte)
- func (h *Hasher) MerkleizeProgressiveWithMixin(indx int, num uint64)
- func (h *Hasher) MerkleizeWithMixin(indx int, num, limit uint64)
- func (h *Hasher) PutBitlist(bb []byte, maxSize uint64)
- func (h *Hasher) PutBool(b bool)
- func (h *Hasher) PutBytes(b []byte)
- func (h *Hasher) PutProgressiveBitlist(bb []byte)
- func (h *Hasher) PutRootVector(b [][]byte, maxCapacity ...uint64) error
- func (h *Hasher) PutUint8(i uint8)
- func (h *Hasher) PutUint16(i uint16)
- func (h *Hasher) PutUint32(i uint32)
- func (h *Hasher) PutUint64(i uint64)
- func (h *Hasher) PutUint64Array(b []uint64, maxCapacity ...uint64)
- func (h *Hasher) Reset()
- func (h *Hasher) StartTree(treeType sszutils.TreeType) int
- func (h *Hasher) WithTemp(fn func(tmp []byte) []byte)
- type HasherPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetZeroHash ¶ added in v1.1.1
GetZeroHash returns the precomputed zero hash at the given merkle tree depth.
func GetZeroHashLevel ¶ added in v1.1.1
GetZeroHashLevel returns the merkle tree depth level for a known zero hash. Returns the level and true if the hash is a recognized zero hash, or 0 and false otherwise.
func GetZeroHashLevelBytes ¶ added in v1.3.0
GetZeroHashLevelBytes returns the merkle tree depth level for a known zero hash. Returns the level and true if the hash is a recognized zero hash, or 0 and false otherwise.
func GetZeroHashes ¶ added in v1.1.1
func GetZeroHashes() [65][32]byte
GetZeroHashes returns the full array of precomputed zero hashes for all 65 merkle tree depth levels.
func ParseBitlist ¶
ParseBitlist decodes an SSZ-encoded bitlist into its raw bit representation.
SSZ bitlists include a mandatory termination bit: a single `1` bit appended immediately after the final data bit, then padded to a full byte. The position of this termination bit defines the logical length of the bitlist.
This function performs the inverse transformation:
- Identify the termination bit in the final byte and compute the logical bitlist length (`size`).
- Clear the termination bit, leaving only the actual data bits.
- Trim any trailing zero bytes introduced by SSZ padding.
- Return the compact raw bitlist (no termination bit, no padding) together with its logical size.
The returned `[]byte` contains the data bits packed little-endian in each byte, and `size` is the exact number of meaningful bits in that raw bitlist.
func ParseBitlistWithHasher ¶ added in v1.2.0
func ParseBitlistWithHasher(hw sszutils.HashWalker, buf []byte) ([]byte, uint64)
ParseBitlistWithHasher decodes an SSZ-encoded bitlist using the hasher's internal buffer to avoid allocations. It returns the raw bit data and the logical bit count, same as ParseBitlist.
IMPORTANT: The returned bitlist slice references the hasher's internal buffer spare capacity. It must be consumed (e.g. passed to AppendBytes32) before any operation that may grow the buffer, as a reallocation would invalidate it.
func WithDefaultHasher ¶ added in v1.1.1
func WithDefaultHasher(fn func(hh sszutils.HashWalker) error) error
WithDefaultHasher acquires a Hasher from the FastHasherPool, passes it to fn, and returns it to the pool when done. This is a convenience wrapper for one-off hashing operations.
Types ¶
type HashFn ¶
HashFn is a function that hashes pairs of 32-byte chunks from input into dst. It processes the input as consecutive 64-byte pairs and writes each 32-byte hash result into dst.
func NativeHashWrapper ¶
NativeHashWrapper wraps a hash.Hash function into a HashFn
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher is a utility tool to hash SSZ structs
func NewHasher ¶
func NewHasher() *Hasher
NewHasher creates a new Hasher with the default sha256 hash function.
func NewHasherWithHash ¶
NewHasherWithHash creates a new Hasher with a custom hash.Hash function.
func NewHasherWithHashFn ¶
NewHasherWithHashFn creates a new Hasher with a custom HashFn function.
func (*Hasher) AppendBool ¶
AppendBool appends a single byte (0 or 1) to the buffer without padding.
func (*Hasher) AppendBytes32 ¶
AppendBytes32 appends b to the buffer, right-padding with zeros to align to 32 bytes.
func (*Hasher) AppendUint8 ¶
AppendUint8 appends a uint8 to the buffer without padding.
func (*Hasher) AppendUint16 ¶
AppendUint16 appends a little-endian uint16 to the buffer without padding.
func (*Hasher) AppendUint32 ¶
AppendUint32 appends a little-endian uint32 to the buffer without padding.
func (*Hasher) AppendUint64 ¶
AppendUint64 appends a little-endian uint64 to the buffer without padding.
func (*Hasher) Collapse ¶ added in v1.3.0
func (h *Hasher) Collapse()
Collapse hints the hasher to collapse accumulated chunks in the current layer if the batch threshold is reached. This is a no-op for non-incremental layers or when no layer is active.
func (*Hasher) CurrentIndex ¶ added in v1.3.0
CurrentIndex returns the current buffer position without pushing a layer.
func (*Hasher) FillUpTo32 ¶
func (h *Hasher) FillUpTo32()
FillUpTo32 pads the buffer with zero bytes to align to a 32-byte boundary.
func (*Hasher) HashRoot ¶
HashRoot returns the final 32-byte hash root, or an error if the buffer is not exactly 32 bytes.
func (*Hasher) Index ¶
Index returns the current buffer position and pushes a non-incremental layer. This is for legacy/external code that doesn't use StartTree. The non-incremental layer blocks Collapse on this scope but is properly popped by Merkleize. Collapse on the parent layer is unaffected — it only sees completed child roots after the child's Merkleize pops this layer.
func (*Hasher) Merkleize ¶
Merkleize computes the binary merkle root of the buffer from indx onwards and replaces that region with the 32-byte root. Pops the matching layer if one exists.
func (*Hasher) MerkleizeProgressive ¶
MerkleizeProgressive computes the progressive merkle root of the buffer from indx onwards. If incremental progressive data was accumulated via Collapse, it is finalized; otherwise the standard recursive algorithm is used.
func (*Hasher) MerkleizeProgressiveWithActiveFields ¶
MerkleizeProgressiveWithActiveFields computes the progressive merkle root from indx and mixes in the active fields bitvector.
func (*Hasher) MerkleizeProgressiveWithMixin ¶
MerkleizeProgressiveWithMixin computes the progressive merkle root from indx and mixes in num as the list length.
func (*Hasher) MerkleizeWithMixin ¶
MerkleizeWithMixin computes the binary merkle root from indx with the given limit, then mixes in num as the list length. Pops the matching layer if one exists.
func (*Hasher) PutBitlist ¶
PutBitlist appends an SSZ-encoded bitlist, merkleizes its content, and mixes in the bit count with the given maxSize limit.
func (*Hasher) PutBytes ¶
PutBytes appends b as a 32-byte chunk. If b exceeds 32 bytes, the content is merkleized in-place to a single root without interacting with the layer stack.
func (*Hasher) PutProgressiveBitlist ¶
PutProgressiveBitlist appends an SSZ-encoded bitlist and merkleizes it using the progressive algorithm with a length mixin.
func (*Hasher) PutRootVector ¶
PutRootVector appends an array of 32-byte roots and merkleizes them. If maxCapacity is provided, the result includes a length mixin.
func (*Hasher) PutUint64Array ¶
PutUint64Array appends an array of uint64 values and merkleizes them. If maxCapacity is provided, the result includes a length mixin.
type HasherPool ¶
type HasherPool struct {
HashFn HashFn
// contains filtered or unexported fields
}
HasherPool may be used for pooling Hashers for similarly typed SSZs.
var DefaultHasherPool HasherPool
DefaultHasherPool is a default hasher pool
var FastHasherPool HasherPool = HasherPool{ HashFn: hashtree.HashByteSlice, }
FastHasherPool is the fast hasher pool that uses the hashtree library if cgo is enabled