Helper functions closely related to the EIP-4788 specification.
Source code in tests/cancun/eip4788_beacon_root/spec.py
| @dataclass(frozen=True)
class SpecHelpers:
"""Helper functions closely related to the EIP-4788 specification."""
def timestamp_index(self, timestamp: int) -> int:
"""Derive the timestamp index into the timestamp ring buffer."""
return timestamp % Spec.HISTORY_BUFFER_LENGTH
def root_index(self, timestamp: int) -> int:
"""Derive the root index into the root ring buffer."""
return self.timestamp_index(timestamp) + Spec.HISTORY_BUFFER_LENGTH
@staticmethod
def expected_storage(
*,
beacon_root: bytes,
valid_call: bool,
valid_input: bool,
) -> Storage:
"""
Derive expected storage for a given beacon root contract call
dependent on:
- success or failure of the call
- validity of the timestamp input used within the call.
"""
# By default assume the call is unsuccessful and all keys are zero
storage = Storage(dict.fromkeys(range(4), 0)) # type: ignore
if valid_call and valid_input:
# beacon root contract call is successful
storage[0] = 1
storage[1] = beacon_root
storage[2] = 32
storage[3] = beacon_root
return storage
|