Expand description
Delta encoding for fixed-size Ethereum consensus root buffers.
Ethereum consensus stores historical roots, such as block roots and state roots, in fixed-capacity circular buffers. As new slots are processed, entries are written at positions derived from their slot number, eventually wrapping around and overwriting older entries.
Rather than diffing the complete root buffer, this module records only the roots written during a requested slot range. Applying the delta replays those writes into another root buffer using the same slot-to-index mapping.
The delta contains no explicit buffer indices. Each index is reconstructed from the slot number and the buffer capacity:
buffer_index = slot % buffer_capacity§Representation
RootsDiff stores one 32-byte root for every slot in the half-open range
[base_slot, target_slot).
For example, a transition from slot 100 to slot 103 records the roots
for slots:
100, 101, 102The root for target_slot itself is not included.
§Correctness
The destination buffer must have the same capacity as the buffer supplied
to diff_roots. The delta does not store explicit indices, so changing
the capacity changes the modulo mapping and can cause roots to be written
to different positions.
This representation is independent of the absolute buffer contents. Only the slot range, buffer capacity, and recorded roots are required to replay the writes.
§Complexity
If N = target_slot - base_slot:
diff_rootsruns in O(N) time and uses O(N) additional space.apply_rootsruns in O(N) time and uses O(1) additional space.
Functions§
- apply_
roots - Applies a root delta to a circular root buffer in place.
- diff_
roots - Computes the sequence of roots written during a slot range.