Skip to main content

Module randao_mixes

Module randao_mixes 

Source
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 % N

During 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:

  1. Call diff_randao with the base slot, target slot, and target RANDAO buffer.
  2. Serialize the resulting RandaoDiff using rkyv.
  3. Store or compress the serialized delta.
  4. Deserialize/access the archived delta and apply it with apply_randao.

§Complexity

If E is the number of epochs covered by the transition:

  • diff_randao runs in O(E) time and uses O(E) additional space.
  • apply_randao runs 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.