Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lean_spec/subspecs/ssz/constants.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Constants defined in the SSZ specification."""

from lean_spec.types.hash import Bytes32
from lean_spec.types.byte_arrays import Bytes32

BYTES_PER_CHUNK: int = 32
"""The number of bytes in a Merkle tree chunk."""

ZERO_HASH: Bytes32 = b"\x00" * BYTES_PER_CHUNK
ZERO_HASH: Bytes32 = Bytes32(b"\x00" * BYTES_PER_CHUNK)
"""A zero hash, used for padding in the Merkle tree."""
4 changes: 2 additions & 2 deletions src/lean_spec/subspecs/ssz/merkle/proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from pydantic import Field, model_validator

from lean_spec.types.base import StrictBaseModel
from lean_spec.types.hash import Bytes32
from lean_spec.types.byte_arrays import Bytes32

from ..constants import ZERO_HASH
from ..gindex import GeneralizedIndex
from ..utils import hash_nodes

Root = bytes
Root = Bytes32
"""The type of a Merkle tree root."""
Proof = Sequence[Bytes32]
"""The type of a Merkle proof."""
Expand Down
2 changes: 1 addition & 1 deletion src/lean_spec/subspecs/ssz/merkle/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from lean_spec.subspecs.ssz.constants import ZERO_HASH
from lean_spec.subspecs.ssz.utils import get_power_of_two_ceil, hash_nodes
from lean_spec.types.hash import Bytes32
from lean_spec.types.byte_arrays import Bytes32


def build_merkle_tree(leaves: Sequence[Bytes32]) -> List[Bytes32]:
Expand Down
4 changes: 2 additions & 2 deletions src/lean_spec/subspecs/ssz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import hashlib

from lean_spec.types.hash import Bytes32
from lean_spec.types.byte_arrays import Bytes32


def get_power_of_two_ceil(x: int) -> int:
Expand All @@ -18,4 +18,4 @@ def get_power_of_two_ceil(x: int) -> int:

def hash_nodes(node_a: Bytes32, node_b: Bytes32) -> Bytes32:
"""Hashes two 32-byte nodes together using SHA-256."""
return hashlib.sha256(node_a + node_b).digest()
return Bytes32(hashlib.sha256(node_a + node_b).digest())
2 changes: 1 addition & 1 deletion src/lean_spec/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .base import StrictBaseModel
from .basispt import BasisPoint
from .hash import Bytes32
from .byte_arrays import Bytes32
from .uint import Uint64
from .validator import ValidatorIndex

Expand Down
Loading
Loading