Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 3088bec

Browse files
Fix #1564, replace Blake with Keccak (#1611)
* replace blake with keccak * move test_hash.py to right directory * test hash_is_keccak and fix formatting
1 parent 8629750 commit 3088bec

File tree

15 files changed

+60
-55
lines changed

15 files changed

+60
-55
lines changed

eth/beacon/aggregation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from eth.utils.bitfield import (
1515
set_voted,
1616
)
17-
from eth.utils.blake import blake
17+
from eth.beacon.utils.hash import hash_
1818

1919

2020
def create_signing_message(slot: int,
@@ -26,7 +26,7 @@ def create_signing_message(slot: int,
2626
Return the signining message for attesting.
2727
"""
2828
# TODO: Will be updated with SSZ encoded attestation.
29-
return blake(
29+
return hash_(
3030
slot.to_bytes(8, byteorder='big') +
3131
b''.join(parent_hashes) +
3232
shard_id.to_bytes(2, byteorder='big') +

eth/beacon/helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
get_bitfield_length,
2121
has_voted,
2222
)
23-
from eth.utils.blake import (
24-
blake,
23+
from eth.beacon.utils.hash import (
24+
hash_,
2525
)
2626
from eth.utils.numeric import (
2727
clamp,
@@ -388,7 +388,7 @@ def get_new_validator_registry_delta_chain_tip(current_validator_registry_delta_
388388
"""
389389
Compute the next hash in the validator registry delta hash chain.
390390
"""
391-
return blake(
391+
return hash_(
392392
current_validator_registry_delta_chain_tip +
393393
flag.to_bytes(1, 'big') +
394394
index.to_bytes(3, 'big') +

eth/beacon/types/blocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
uint64,
2020
uint256,
2121
)
22-
from eth.utils.blake import blake
22+
from eth.beacon.utils.hash import hash_
2323

2424
from .attestations import Attestation
2525
from .proposer_slashings import ProposerSlashing
@@ -101,7 +101,7 @@ def __repr__(self) -> str:
101101
@property
102102
def hash(self) -> Hash32:
103103
if self._hash is None:
104-
self._hash = blake(rlp.encode(self))
104+
self._hash = hash_(rlp.encode(self))
105105
return self._hash
106106

107107
@property

eth/beacon/types/states.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
uint64,
2020
hash32,
2121
)
22-
from eth.utils.blake import (
23-
blake,
22+
from eth.beacon.utils.hash import (
23+
hash_,
2424
)
2525

2626
from .pending_attestation_records import PendingAttestationRecord
@@ -151,7 +151,7 @@ def __repr__(self) -> str:
151151
@property
152152
def hash(self) -> Hash32:
153153
if self._hash is None:
154-
self._hash = blake(rlp.encode(self))
154+
self._hash = hash_(rlp.encode(self))
155155
return self._hash
156156

157157
@property

eth/beacon/utils/hash.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from eth_typing import Hash32
2+
from eth_hash.auto import keccak
3+
4+
5+
def hash_(data: bytes) -> Hash32:
6+
return Hash32(keccak(data))

eth/beacon/utils/random.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
to_tuple,
1515
)
1616

17-
from eth.utils.blake import (
18-
blake,
17+
from eth.beacon.utils.hash import (
18+
hash_,
1919
)
2020
from eth.beacon.constants import (
2121
RAND_BYTES,
@@ -50,7 +50,7 @@ def shuffle(values: Sequence[Any],
5050
index = 0
5151
while index < values_count - 1:
5252
# Re-hash the `source` to obtain a new pattern of bytes.
53-
source = blake(source)
53+
source = hash_(source)
5454

5555
# Iterate through the `source` bytes in 3-byte chunks.
5656
for position in range(0, 32 - (32 % RAND_BYTES), RAND_BYTES):

eth/utils/blake.py

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

eth/utils/bls.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
curve_order,
2828
final_exponentiate
2929
)
30-
from eth.utils.blake import blake
30+
from eth.beacon.utils.hash import hash_
3131
from eth.utils.bn128 import (
3232
FQP_point_to_FQ2_point,
3333
)
@@ -75,8 +75,8 @@ def hash_to_G2(m: bytes) -> Tuple[FQ2, FQ2, FQ2]:
7575
return CACHE[m]
7676
k2 = m
7777
while 1:
78-
k1 = blake(k2)
79-
k2 = blake(k1)
78+
k1 = hash_(k2)
79+
k2 = hash_(k1)
8080
x1 = int.from_bytes(k1, 'big') % field_modulus
8181
x2 = int.from_bytes(k2, 'big') % field_modulus
8282
x = FQ2([x1, x2])

tests/beacon/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
ZERO_HASH32,
77
)
88
import eth.utils.bls as bls
9-
from eth.utils.blake import blake
9+
from eth.beacon.utils.hash import hash_
1010

1111
from eth.beacon.types.proposal_signed_data import (
1212
ProposalSignedData
@@ -46,7 +46,7 @@
4646

4747
@pytest.fixture(scope="session")
4848
def privkeys():
49-
return [int.from_bytes(blake(str(i).encode('utf-8'))[:4], 'big') for i in range(1000)]
49+
return [int.from_bytes(hash_(str(i).encode('utf-8'))[:4], 'big') for i in range(1000)]
5050

5151

5252
@pytest.fixture(scope="session")

tests/beacon/db/test_chaindb.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
BlockNotFound,
1515
ParentNotFound,
1616
)
17-
from eth.utils.blake import (
18-
blake,
17+
from eth.beacon.utils.hash import (
18+
hash_,
1919
)
2020
from eth.utils.rlp import (
2121
validate_rlp_equal,
@@ -68,7 +68,7 @@ def test_chaindb_persist_block_and_slot_to_hash(chaindb, block):
6868

6969
@given(seed=st.binary(min_size=32, max_size=32))
7070
def test_chaindb_persist_block_and_unknown_parent(chaindb, block, seed):
71-
n_block = block.copy(parent_root=blake(seed))
71+
n_block = block.copy(parent_root=hash_(seed))
7272
with pytest.raises(ParentNotFound):
7373
chaindb.persist_block(n_block)
7474

0 commit comments

Comments
 (0)