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:
SyncCommitteeDiff::Unchangedwhen the serialized base and target committees are identical.SyncCommitteeDiff::FullReplacementwhen the serialized committees differ. The complete serialized target committee is stored in the replacement payload.
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 committeeSyncCommitteeDiff::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.
diff_sync_committeeperforms an O(n) byte comparison.apply_sync_committeeis O(1) forSyncCommitteeDiff::Unchanged.apply_sync_committeeis O(n) forSyncCommitteeDiff::FullReplacement.
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.