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

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

  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 using the same base_slot.

§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 a RANDAO delta between two consensus slots.