Skip to main content

Crate ssz

Crate ssz 

Source
Expand description

SimpleSerialize (SSZ) codec with hash_tree_root.

Implements the Ethereum consensus SSZ wire format plus two jar-specific extensions (MissingOr, SparseList) that allow precomputed subtree roots to substitute transparently for materialized leaves.

The default hash function is SHA-256 (via the optional sha2 feature); the HashTreeRoot trait is generic over any digest::Digest with a 32-byte output, so callers can plug in alternative hashes at compile time.

§Wire format

See encoding for the spec we implement. Notable deviations:

  • Option / SSZ Union: byte 0 = None (no payload), byte 1 = Some(T) + T’s bytes.
  • MissingOr: byte 0 = Materialized + T’s bytes, byte 1 = Missing + 32 raw bytes.
  • SparseList: same wire format as a List<T, N> plus a length prefix.

Re-exports§

pub use bits::Bitlist;
pub use bits::Bitvector;
pub use list::List;
pub use merkle::merkleize;
pub use merkle::mix_in_length;
pub use merkle::mix_in_selector;
pub use merkle::pack_bytes;
pub use merkle::zero_hash;
pub use missing::MissingOr;
pub use primitives::U256;
pub use sparse::SparseList;
pub use vector::FixedVector;
pub use digest;

Modules§

bits
Bitvector<N> and Bitlist<N> — bit-packed homogeneous boolean storage.
collections
SSZ blanket impls for alloc::collections::BTreeMap.
list
List<T, N> — variable-length list with compile-time cap of N elements.
merkle
SSZ merkleization primitives.
missing
MissingOr<T> — first-class summary placeholder for SSZ subtree substitution.
primitives
SSZ blanket impls for built-in scalar and array types.
sparse
SparseList<T, N> — a list view that may omit materializing parts of the tree, using cached subtree roots or zero-hashes for empty regions.
union
Helpers for SSZ Union types (used by Option<T> and derived enums).
vector
FixedVector<T, N> — homogeneous list with compile-time-fixed length.

Enums§

DecodeError
Errors encountered while decoding an SSZ-encoded byte slice.

Constants§

BYTES_PER_CHUNK
Chunk size in bytes for SSZ merkleization.
BYTES_PER_LENGTH_OFFSET
The number of bytes used to encode a variable-length list offset.

Traits§

Decode
SSZ decoding trait.
Encode
SSZ encoding trait.
HashTreeRoot
Computes a 32-byte hash tree root for SSZ types.

Functions§

hash_tree_root
Convenience SHA-256 entry point.

Derive Macros§

Decode
Derive the ssz::Decode trait for a struct or enum.
Encode
Derive the ssz::Encode trait for a struct or enum.
HashTreeRoot
Derive the ssz::HashTreeRoot trait for a struct or enum.