Skip to content

Commit 40243c8

Browse files
committed
PR feedback
1 parent cb8242b commit 40243c8

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

eth/_utils/merkle.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import math
99
from typing import (
1010
cast,
11-
Hashable,
1211
Iterable,
1312
NewType,
1413
Sequence,
14+
Union,
1515
)
1616

1717
from cytoolz import (
@@ -78,7 +78,7 @@ def _calc_parent_hash(left_node: Hash32, right_node: Hash32) -> Hash32:
7878

7979

8080
def verify_merkle_proof(root: Hash32,
81-
item: Hashable,
81+
item: Union[bytes, bytearray],
8282
item_index: int,
8383
proof: MerkleProof) -> bool:
8484
"""
@@ -108,15 +108,15 @@ def _hash_layer(layer: Sequence[Hash32]) -> Iterable[Hash32]:
108108
)
109109

110110

111-
def calc_merkle_tree(items: Sequence[Hashable]) -> MerkleTree:
111+
def calc_merkle_tree(items: Sequence[Union[bytes, bytearray]]) -> MerkleTree:
112112
"""
113113
Calculate the Merkle tree corresponding to a list of items.
114114
"""
115115
leaves = tuple(hash_eth2(item) for item in items)
116116
return calc_merkle_tree_from_leaves(leaves)
117117

118118

119-
def calc_merkle_root(items: Sequence[Hashable]) -> Hash32:
119+
def calc_merkle_root(items: Sequence[Union[bytes, bytearray]]) -> Hash32:
120120
"""
121121
Calculate the Merkle root corresponding to a list of items.
122122
"""
@@ -133,11 +133,15 @@ def calc_merkle_tree_from_leaves(leaves: Sequence[Hash32]) -> MerkleTree:
133133
tree = cast(
134134
MerkleTree,
135135
tuple(
136-
take(
137-
n_layers,
138-
iterate(_hash_layer, leaves),
136+
reversed(
137+
tuple(
138+
take(
139+
n_layers,
140+
iterate(_hash_layer, leaves),
141+
)
142+
)
139143
)
140-
)[::-1]
144+
)
141145
)
142146
if len(tree[0]) != 1:
143147
raise Exception("Invariant: There must only be one root")

eth/beacon/_utils/hash.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from typing import (
2-
Hashable,
2+
Union,
33
)
44

55
from eth_typing import Hash32
66
from eth_hash.auto import keccak
77

88

9-
def hash_eth2(data: Hashable) -> Hash32:
9+
def hash_eth2(data: Union[bytes, bytearray]) -> Hash32:
1010
"""
1111
Return Keccak-256 hashed result.
1212
Note: it's a placeholder and we aim to migrate to a S[T/N]ARK-friendly hash function in

0 commit comments

Comments
 (0)