pub fn diff_randao(
base_slot: u64,
target_slot: u64,
target_buffer: &[[u8; 32]],
) -> RandaoDiffExpand description
Computes the RANDAO delta between two consensus slots.
The returned delta contains one RANDAO mix for every epoch in the inclusive
range from the epoch containing base_slot through the epoch containing
target_slot.
Each mix is read from target_buffer using the circular-buffer indexing
rule:
buffer_index = epoch % target_buffer.len()Only the mixes corresponding to the covered epochs are stored. The complete target buffer is not copied.
§Arguments
base_slot- Starting consensus slot. The epoch containing this slot is the first epoch represented in the delta.target_slot- Ending consensus slot. The epoch containing this slot is the final epoch represented in the delta.target_buffer- RANDAO mix buffer belonging to the target state.
§Returns
A RandaoDiff containing one mix for each epoch from the base epoch
through the target epoch, inclusive.
§Panics
Panics if target_slot < base_slot.
Panics if target_buffer is empty because circular-buffer indexing requires
a non-zero capacity.
§Correctness
The delta stores mixes in chronological epoch order rather than storing their circular-buffer indices. During application, indices are reconstructed using modulo arithmetic and the capacity of the destination buffer.
The buffer used with apply_randao must therefore have the same capacity
as target_buffer.
§Example
use eth_state_diff::randao_mixes::diff_randao;
let base_slot = 0;
let target_slot = 64;
let target_buffer = vec![[0u8; 32]; 4];
let delta = diff_randao(base_slot, target_slot, &target_buffer);
// Slots 0 and 64 belong to epochs 0 and 2 respectively, so the delta
// contains one mix for each epoch in the inclusive range 0..=2.
assert_eq!(delta.mixes.len(), 3);§Complexity
If E is the number of epochs from the base epoch through the target
epoch, inclusive:
- Time: O(E)
- Additional space: O(E)