Skip to main content

Module merkle

Module merkle 

Source
Expand description

SSZ merkleization primitives.

All hashes are 32-byte digests, threaded through the [digest::Digest] trait with OutputSize = U32. No domain bytes or prefixes are mixed in at the node level — concatenation is the only operation.

Functions§

ceil_log2
Returns ceil(log2(max(1, n))).
hash_pair
Hash two 32-byte children into their parent node.
leaves_at_depth
Number of leaves in a balanced tree of depth levels.
merkleize
SSZ merkleize — pad chunks to max(limit, chunks.len()) rounded up to the next power of two, build a balanced binary tree using hash(left || right), and return the root.
mix_in_length
mix_in_length(root, len) = hash(root || u256_le(len)).
mix_in_selector
mix_in_selector(root, sel) = hash(root || u256_le(sel)).
pack_bytes
Pack a byte slice into 32-byte chunks, zero-padding the tail.
zero_hash
Cached zero-hash table: zero_hash(d) = hash(zero_hash(d-1), zero_hash(d-1)), with zero_hash(0) == [0u8; 32].