Skip to main content

Module sync_committee

Module sync_committee 

Source
Expand description

Delta encoding for Ethereum sync committees.

A sync committee remains unchanged for an entire sync committee period and is replaced when a new period begins. This makes equality-based encoding sufficient: unchanged committees require no payload, while a committee transition stores the complete serialized target committee.

The module operates on the serialized SSZ representation of a SyncCommittee. It does not inspect individual committee members or SSZ fields; the serialized bytes are treated as an opaque payload.

§Encoding strategy

Two representations are supported:

A sparse representation is intentionally not provided. Unlike some consensus-state fields, a sync committee is replaced as a whole when it changes, so storing the complete target representation is straightforward and deterministic.

§State transition

Applying a delta reconstructs the target bytes:

base committee + delta -> target committee

SyncCommitteeDiff::Unchanged leaves the base bytes untouched, so the base and target must already be identical for the delta to represent the target state.

SyncCommitteeDiff::FullReplacement replaces the base bytes entirely, so the original base contents do not affect the resulting state.

The delta does not depend on the sync committee period number. The caller is responsible for determining which consensus-state field is being diffed.

§SSZ representation

The functions accept the raw serialized SSZ representation of the SyncCommittee container. The bytes are treated as opaque data and are copied without decoding or re-encoding individual committee members.

SyncCommittee is a fixed-size consensus container. Callers should therefore provide the serialized container bytes directly rather than adding a list-length prefix.

The examples below use simple byte strings to represent opaque serialized data; they are illustrative and are not intended to be valid SyncCommittee SSZ encodings.

§Complexity

Let n be the serialized size of the committee.

Additional memory is O(n) when a changed committee is encoded because the target bytes are copied into the replacement payload.

§Example

use eth_state_diff::sync_committee::diff_sync_committee;
use eth_state_diff::types::SyncCommitteeDiff;

let base = b"committee-a";
let target = b"committee-a";

let delta = diff_sync_committee(base, target);

assert_eq!(delta, SyncCommitteeDiff::Unchanged);

A committee transition produces a full replacement:

use eth_state_diff::sync_committee::diff_sync_committee;
use eth_state_diff::types::SyncCommitteeDiff;

let base = b"committee-a";
let target = b"committee-b";

let delta = diff_sync_committee(base, target);

assert_eq!(
    delta,
    SyncCommitteeDiff::FullReplacement(target.to_vec())
);

Functions§

apply_sync_committee
Applies a sync committee delta to a serialized SSZ committee in place.
diff_sync_committee
Computes a delta between two serialized Ethereum sync committees.