Skip to content

Commit fdcd880

Browse files
authored
primitives: single zero hash declaration (leanEthereum#189)
1 parent 49f70c7 commit fdcd880

12 files changed

Lines changed: 15 additions & 23 deletions

File tree

src/lean_spec/subspecs/containers/state/state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
justified and finalized.
77
"""
88

9-
from lean_spec.subspecs.ssz.constants import ZERO_HASH
109
from lean_spec.subspecs.ssz.hash import hash_tree_root
1110
from lean_spec.types import (
11+
ZERO_HASH,
1212
Boolean,
1313
Bytes32,
1414
Container,

src/lean_spec/subspecs/forkchoice/constants.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/lean_spec/subspecs/forkchoice/helpers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
Block,
1111
SignedAttestation,
1212
)
13-
from lean_spec.types import Bytes32, ValidatorIndex
14-
15-
from .constants import ZERO_HASH
13+
from lean_spec.types import ZERO_HASH, Bytes32, ValidatorIndex
1614

1715

1816
def get_fork_choice_head(

src/lean_spec/subspecs/ssz/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""SSZ (Simple Serialize) implementation."""
22

3-
from .constants import ZERO_HASH
3+
from lean_spec.types import ZERO_HASH
4+
45
from .hash import HashTreeRoot, hash_tree_root
56

67
__all__ = [
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
"""Constants defined in the SSZ specification."""
22

3-
from lean_spec.types.byte_arrays import Bytes32
4-
53
BYTES_PER_CHUNK: int = 32
64
"""Number of bytes per Merkle chunk."""
75

86
BITS_PER_BYTE: int = 8
97
"""Number of bits per byte."""
10-
11-
ZERO_HASH: Bytes32 = Bytes32(b"\x00" * BYTES_PER_CHUNK)
12-
"""A zero hash, used for padding in Merkleization."""

src/lean_spec/subspecs/ssz/merkle_proof/proof.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
from pydantic import Field, model_validator
88

9-
from lean_spec.types import StrictBaseModel
9+
from lean_spec.types import ZERO_HASH, StrictBaseModel
1010
from lean_spec.types.byte_arrays import Bytes32
1111

12-
from ..constants import ZERO_HASH
1312
from ..utils import hash_nodes
1413
from .gindex import GeneralizedIndex
1514

src/lean_spec/subspecs/ssz/merkle_proof/tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from typing import List, Sequence
44

5-
from lean_spec.subspecs.ssz.constants import ZERO_HASH
65
from lean_spec.subspecs.ssz.utils import get_power_of_two_ceil, hash_nodes
6+
from lean_spec.types import ZERO_HASH
77
from lean_spec.types.byte_arrays import Bytes32
88

99

src/lean_spec/subspecs/ssz/merkleization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from typing import List, Optional, Sequence
66

7-
from lean_spec.subspecs.ssz.constants import ZERO_HASH
87
from lean_spec.subspecs.ssz.utils import get_power_of_two_ceil, hash_nodes
8+
from lean_spec.types import ZERO_HASH
99
from lean_spec.types.byte_arrays import Bytes32
1010

1111

src/lean_spec/types/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .base import CamelModel, StrictBaseModel
44
from .basispt import BasisPoint
55
from .boolean import Boolean
6-
from .byte_arrays import Bytes32, Bytes52, Bytes3116
6+
from .byte_arrays import ZERO_HASH, Bytes32, Bytes52, Bytes3116
77
from .collections import SSZList, SSZVector
88
from .container import Container
99
from .uint import Uint64
@@ -15,6 +15,7 @@
1515
"Bytes32",
1616
"Bytes52",
1717
"Bytes3116",
18+
"ZERO_HASH",
1819
"CamelModel",
1920
"StrictBaseModel",
2021
"ValidatorIndex",

src/lean_spec/types/byte_arrays.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ class Bytes32(BaseBytes):
213213
LENGTH = 32
214214

215215

216+
ZERO_HASH: Bytes32 = Bytes32.zero()
217+
"""All-zero hash (32 bytes of zeros)."""
218+
219+
216220
class Bytes48(BaseBytes):
217221
"""Fixed-size byte array of exactly 48 bytes."""
218222

0 commit comments

Comments
 (0)