Skip to content

Spec

Documentation for tests/cancun/eip4788_beacon_root/spec.py.

Defines EIP-4788 specification constants and functions.

Spec dataclass

Parameters from the EIP-4788 specifications as defined at https://eips.ethereum.org/EIPS/eip-4788#specification

Source code in tests/cancun/eip4788_beacon_root/spec.py
23
24
25
26
27
28
29
30
31
32
33
34
35
@dataclass(frozen=True)
class Spec:
    """
    Parameters from the EIP-4788 specifications as defined at
    https://eips.ethereum.org/EIPS/eip-4788#specification
    """

    BEACON_ROOTS_ADDRESS = 0x000F3DF6D732807EF1319FB7B8BB8522D0BEAC02
    BEACON_ROOTS_CALL_GAS = 100_000
    BEACON_ROOTS_DEPLOYER_ADDRESS = 0x0B799C86A49DEEB90402691F1041AA3AF2D3C875
    HISTORY_BUFFER_LENGTH = 8_191
    SYSTEM_ADDRESS = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE
    FORK_TIMESTAMP = 15_000  # ShanghaiToCancun timestamp

SpecHelpers dataclass

Helper functions closely related to the EIP-4788 specification.

Source code in tests/cancun/eip4788_beacon_root/spec.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
@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:
        """
        Derives the 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({k: 0 for k in range(4)})
        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