Skip to content

Commit c74560f

Browse files
committed
PR feedback
1 parent c65ee5b commit c74560f

File tree

5 files changed

+23
-21
lines changed

5 files changed

+23
-21
lines changed

eth/_utils/bls.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,15 @@ def privtopub(k: int) -> int:
172172
def verify(message: bytes, pubkey: int, signature: bytes, domain: int) -> bool:
173173
try:
174174
final_exponentiation = final_exponentiate(
175-
pairing(FQP_point_to_FQ2_point(decompress_G2(signature)), G1, False) *
175+
pairing(
176+
FQP_point_to_FQ2_point(decompress_G2(signature)),
177+
G1,
178+
final_exponentiate=False,
179+
) *
176180
pairing(
177181
FQP_point_to_FQ2_point(hash_to_G2(message, domain)),
178182
neg(decompress_G1(pubkey)),
179-
False
183+
final_exponentiate=False,
180184
)
181185
)
182186
return final_exponentiation == FQ12.one()
@@ -220,8 +224,8 @@ def verify_multiple(pubkeys: Sequence[int],
220224
if messages[i] == m_pubs:
221225
group_pub = add(group_pub, decompress_G1(pubkeys[i]))
222226

223-
o *= pairing(hash_to_G2(m_pubs, domain), group_pub, False)
224-
o *= pairing(decompress_G2(signature), neg(G1), False)
227+
o *= pairing(hash_to_G2(m_pubs, domain), group_pub, final_exponentiate=False)
228+
o *= pairing(decompress_G2(signature), neg(G1), final_exponentiate=False)
225229

226230
final_exponentiation = final_exponentiate(o)
227231
return final_exponentiation == FQ12.one()

eth/beacon/deposit_helpers.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
ValidationError,
1111
)
1212

13-
from eth.utils import bls
13+
from eth._utils import bls
1414

1515
from eth.beacon.constants import (
1616
EMPTY_SIGNATURE,
@@ -33,11 +33,11 @@ def get_min_empty_validator_index(validators: Sequence[ValidatorRecord],
3333
current_slot: int,
3434
zero_balance_validator_ttl: int) -> int:
3535
for index, validator in enumerate(validators):
36-
if (
37-
validator.balance == 0 and
38-
validator.latest_status_change_slot + zero_balance_validator_ttl <=
39-
current_slot
40-
):
36+
is_empty = (
37+
validator.balance == 0 and
38+
validator.latest_status_change_slot + zero_balance_validator_ttl <= current_slot
39+
)
40+
if is_empty:
4141
return index
4242
raise MinEmptyValidatorIndexNotFound()
4343

@@ -89,7 +89,6 @@ def add_pending_validator(state: BeaconState,
8989
except MinEmptyValidatorIndexNotFound:
9090
index = None
9191

92-
if index is None:
9392
# Append to the validator_registry
9493
validator_registry = state.validator_registry + (validator,)
9594
state = state.copy(
@@ -122,7 +121,7 @@ def process_deposit(*,
122121
randao_commitment,
123122
)
124123

125-
validator_pubkeys = tuple([v.pubkey for v in state.validator_registry])
124+
validator_pubkeys = tuple(v.pubkey for v in state.validator_registry)
126125
if pubkey not in validator_pubkeys:
127126
validator = ValidatorRecord.get_pending_validator(
128127
pubkey=pubkey,
@@ -142,7 +141,7 @@ def process_deposit(*,
142141
index = validator_pubkeys.index(pubkey)
143142
validator = state.validator_registry[index]
144143

145-
if validator.withdrawal_credentials != validator.withdrawal_credentials:
144+
if validator.withdrawal_credentials != withdrawal_credentials:
146145
raise ValidationError(
147146
"`withdrawal_credentials` are incorrect:\n"
148147
"\texpected: %s, found: %s" % (

eth/beacon/helpers.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
get_bitfield_length,
2121
has_voted,
2222
)
23-
from eth.beacon._utils.hash import (
24-
hash_eth2,
25-
)
2623
from eth._utils.numeric import (
2724
clamp,
2825
)

eth/beacon/types/states.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def update_validator(self,
163163
validator: ValidatorRecord) -> 'BeaconState':
164164
validator_registry = list(self.validator_registry)
165165
validator_registry[validator_index] = validator
166-
self = self.copy(
166+
updated_state = self.copy(
167167
validator_registry=tuple(validator_registry),
168168
)
169-
return self
169+
return updated_state

tests/beacon/test_deposit_helpers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
ValidationError,
66
)
77

8-
from eth.utils import bls
8+
from eth._utils import bls
99

1010
from eth.beacon.constants import (
1111
EMPTY_SIGNATURE,
@@ -250,7 +250,7 @@ def test_process_deposit(sample_beacon_state_params,
250250
assert len(result_state.validator_registry) == 2
251251
assert result_state.validator_registry[1].pubkey == pubkey_2
252252

253-
# Force the first validator exited
253+
# Force the first validator exited -> a empty slot in state.validator_registry.
254254
result_state = result_state.copy(
255255
validator_registry=(
256256
result_state.validator_registry[0].copy(
@@ -261,7 +261,8 @@ def test_process_deposit(sample_beacon_state_params,
261261
)
262262
)
263263

264-
# Add the third validator
264+
# Add the third validator.
265+
# Should overwrite previously exited validator.
265266
privkey_3 = privkeys[2]
266267
pubkey_3 = pubkeys[2]
267268
deposit_input = make_deposit_input(
@@ -279,5 +280,6 @@ def test_process_deposit(sample_beacon_state_params,
279280
randao_commitment=randao_commitment,
280281
zero_balance_validator_ttl=zero_balance_validator_ttl,
281282
)
283+
# Overwrite the second validator.
282284
assert len(result_state.validator_registry) == 2
283285
assert result_state.validator_registry[0].pubkey == pubkey_3

0 commit comments

Comments
 (0)