Skip to main content

Module sync_committee

Module sync_committee 

Source
Expand description

Delta encoding for Ethereum sync committees.

Sync committees remain unchanged for an entire sync committee period and are replaced when a new period begins. This makes equality-based encoding sufficient for the normal state-diff window: unchanged committees require no payload, while a committee transition stores the complete 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 possible:

The replacement representation stores the complete serialized target committee. This is intentional: unlike validator balances or participation flags, there is no useful sparse update representation for a committee in this module.

§State transition

Applying a delta to the same base committee used during diff generation reconstructs the target bytes:

base committee + delta -> target committee

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

§SSZ representation

The functions accept the raw serialized bytes 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 normally provide the serialized container bytes directly rather than adding a list-length prefix.

§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.