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 reconstruct the target buffer over the epochs covered by a slot transition. 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 in the inclusive
range from the epoch containing base_slot through the epoch containing
target_slot.
For an epoch e and buffer capacity N, the mix is stored at:
buffer_index = e % NDuring application, the same indexing rule is used 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 from the starting epoch and the destination 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.
The caller must also provide the same base_slot used when generating the
delta. Because the delta stores only the sequence of mixes, changing the
starting slot changes the epochs and therefore the destination indices at
which those mixes are written.
§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_randaousing the samebase_slot.
§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 a RANDAO delta between two consensus slots.