Expand description
Delta encoding for Ethereum RANDAO mix buffers.
Ethereum consensus maintains historical RANDAO mixes in a fixed-capacity circular buffer. Each epoch writes one mix, with the buffer index derived from the epoch number modulo the buffer capacity.
Rather than storing the complete RANDAO buffer, this module stores only the sequence of mixes needed to advance a buffer from one slot to another. Applying the delta replays those epoch writes using the same circular-buffer indexing rule.
The delta therefore contains no buffer indices. Indices are reconstructed deterministically from the starting slot and the destination buffer’s capacity.
§Representation
RandaoDiff stores one 32-byte RANDAO mix for each epoch represented by
the transition. For an epoch e and buffer capacity N, the mix is stored
at:
e % NDuring application, the same calculation is performed starting from the
epoch containing base_slot.
§Correctness
The source and destination buffers must have the same capacity. The delta does not store explicit buffer indices; instead, indices are reconstructed using the circular-buffer capacity.
Consequently, applying a delta to a buffer with a different capacity can write mixes to different positions and will not reconstruct the original target state.
§Workflow
The typical workflow is:
- Call
diff_randaowith the base slot, target slot, and target RANDAO buffer. - Serialize the resulting
RandaoDiffusingrkyv. - Store or compress the serialized delta.
- Deserialize/access the archived delta and apply it with
apply_randao.
§Complexity
If E is the number of epochs covered by the transition:
diff_randaoruns in O(E) time and uses O(E) additional space.apply_randaoruns in O(E) time and uses O(1) additional space.
Functions§
- apply_
randao - Applies a RANDAO delta to a circular mix buffer in place.
- diff_
randao - Computes the RANDAO delta between two consensus slots.