Skip to content

Commit bfa1f2f

Browse files
Merge pull request #1623 from ChihChengLiang/rename-hash_-to-hash_eth2
* rename hash_ to hash_eth2 * Add docstring for hash_eth2 Co-Authored-By: ChihChengLiang <[email protected]>
2 parents f3fd374 + 5a308cd commit bfa1f2f

File tree

11 files changed

+26
-22
lines changed

11 files changed

+26
-22
lines changed

eth/beacon/aggregation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from eth.utils.bitfield import (
1111
set_voted,
1212
)
13-
1413
from eth.beacon.enums import SignatureDomain
1514

1615

eth/beacon/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
has_voted,
2222
)
2323
from eth.beacon.utils.hash import (
24-
hash_,
24+
hash_eth2,
2525
)
2626
from eth.utils.numeric import (
2727
clamp,
@@ -371,7 +371,7 @@ def get_new_validator_registry_delta_chain_tip(current_validator_registry_delta_
371371
"""
372372
Compute the next hash in the validator registry delta hash chain.
373373
"""
374-
return hash_(
374+
return hash_eth2(
375375
current_validator_registry_delta_chain_tip +
376376
flag.to_bytes(1, 'big') +
377377
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.beacon.utils.hash import hash_
22+
from eth.beacon.utils.hash import hash_eth2
2323

2424
from .attestations import Attestation
2525
from .proposer_slashings import ProposerSlashing
@@ -99,7 +99,7 @@ def __repr__(self) -> str:
9999
@property
100100
def hash(self) -> Hash32:
101101
if self._hash is None:
102-
self._hash = hash_(rlp.encode(self))
102+
self._hash = hash_eth2(rlp.encode(self))
103103
return self._hash
104104

105105
@property

eth/beacon/types/states.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
hash32,
2121
)
2222
from eth.beacon.utils.hash import (
23-
hash_,
23+
hash_eth2,
2424
)
2525

2626
from .pending_attestation_records import PendingAttestationRecord
@@ -141,7 +141,7 @@ def __repr__(self) -> str:
141141
@property
142142
def hash(self) -> Hash32:
143143
if self._hash is None:
144-
self._hash = hash_(rlp.encode(self))
144+
self._hash = hash_eth2(rlp.encode(self))
145145
return self._hash
146146

147147
@property

eth/beacon/utils/hash.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@
22
from eth_hash.auto import keccak
33

44

5-
def hash_(data: bytes) -> Hash32:
5+
def hash_eth2(data: bytes) -> Hash32:
6+
"""
7+
Return Keccak-256 hashed result.
8+
Note: it's a placeholder and we aim to migrate to a S[T/N]ARK-friendly hash function in
9+
a future Ethereum 2.0 deployment phase.
10+
"""
611
return Hash32(keccak(data))

eth/beacon/utils/random.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
)
1616

1717
from eth.beacon.utils.hash import (
18-
hash_,
18+
hash_eth2,
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 = hash_(source)
53+
source = hash_eth2(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/bls.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
curve_order,
3232
final_exponentiate
3333
)
34-
from eth.beacon.utils.hash import hash_
34+
from eth.beacon.utils.hash import hash_eth2
3535

3636

3737
G2_cofactor = 305502333931268344200999753193121504214466019254188142667664032982267604182971884026507427359259977847832272839041616661285803823378372096355777062779109 # noqa: E501
@@ -77,8 +77,8 @@ def hash_to_G2(message: bytes, domain: int) -> Tuple[FQ2, FQ2, FQ2]:
7777
domain_in_bytes = domain.to_bytes(8, 'big')
7878

7979
# Initial candidate x coordinate
80-
x_re = big_endian_to_int(hash_(domain_in_bytes + b'\x01' + message))
81-
x_im = big_endian_to_int(hash_(domain_in_bytes + b'\x02' + message))
80+
x_re = big_endian_to_int(hash_eth2(domain_in_bytes + b'\x01' + message))
81+
x_im = big_endian_to_int(hash_eth2(domain_in_bytes + b'\x02' + message))
8282
x_coordinate = FQ2([x_re, x_im]) # x_re + x_im * i
8383

8484
# Test candidate y coordinates until a one is found

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.beacon.utils.hash import hash_
9+
from eth.beacon.utils.hash import hash_eth2
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(hash_(str(i).encode('utf-8'))[:4], 'big') for i in range(1000)]
49+
return [int.from_bytes(hash_eth2(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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ParentNotFound,
1616
)
1717
from eth.beacon.utils.hash import (
18-
hash_,
18+
hash_eth2,
1919
)
2020
from eth.utils.rlp import (
2121
validate_rlp_equal,
@@ -68,7 +68,7 @@ def test_chaindb_persist_block_and_slot_to_root(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=hash_(seed))
71+
n_block = block.copy(parent_root=hash_eth2(seed))
7272
with pytest.raises(ParentNotFound):
7373
chaindb.persist_block(n_block)
7474

tests/beacon/types/test_states.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
CrosslinkRecord,
1313
)
1414
from eth.beacon.utils.hash import (
15-
hash_,
15+
hash_eth2,
1616
)
1717

1818
from tests.beacon.helpers import (
@@ -98,4 +98,4 @@ def test_num_crosslink_records(expected,
9898

9999
def test_hash(sample_beacon_state_params):
100100
state = BeaconState(**sample_beacon_state_params)
101-
assert state.root == hash_(rlp.encode(state))
101+
assert state.root == hash_eth2(rlp.encode(state))

0 commit comments

Comments
 (0)