Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Dec 21, 2018
1 parent 590d305 commit f3a4b8c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
12 changes: 8 additions & 4 deletions eth/_utils/bls.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,15 @@ def privtopub(k: int) -> int:
def verify(message: bytes, pubkey: int, signature: bytes, domain: int) -> bool:
try:
final_exponentiation = final_exponentiate(
pairing(FQP_point_to_FQ2_point(decompress_G2(signature)), G1, False) *
pairing(
FQP_point_to_FQ2_point(decompress_G2(signature)),
G1,
final_exponentiate=False,
) *
pairing(
FQP_point_to_FQ2_point(hash_to_G2(message, domain)),
neg(decompress_G1(pubkey)),
False
final_exponentiate=False,
)
)
return final_exponentiation == FQ12.one()
Expand Down Expand Up @@ -220,8 +224,8 @@ def verify_multiple(pubkeys: Sequence[int],
if messages[i] == m_pubs:
group_pub = add(group_pub, decompress_G1(pubkeys[i]))

o *= pairing(hash_to_G2(m_pubs, domain), group_pub, False)
o *= pairing(decompress_G2(signature), neg(G1), False)
o *= pairing(hash_to_G2(m_pubs, domain), group_pub, final_exponentiate=False)
o *= pairing(decompress_G2(signature), neg(G1), final_exponentiate=False)

final_exponentiation = final_exponentiate(o)
return final_exponentiation == FQ12.one()
Expand Down
17 changes: 8 additions & 9 deletions eth/beacon/deposit_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ValidationError,
)

from eth.utils import bls
from eth._utils import bls

from eth.beacon.constants import (
EMPTY_SIGNATURE,
Expand All @@ -33,11 +33,11 @@ def get_min_empty_validator_index(validators: Sequence[ValidatorRecord],
current_slot: int,
zero_balance_validator_ttl: int) -> int:
for index, validator in enumerate(validators):
if (
validator.balance == 0 and
validator.latest_status_change_slot + zero_balance_validator_ttl <=
current_slot
):
is_empty = (
validator.balance == 0 and
validator.latest_status_change_slot + zero_balance_validator_ttl <= current_slot
)
if is_empty:
return index
raise MinEmptyValidatorIndexNotFound()

Expand Down Expand Up @@ -89,7 +89,6 @@ def add_pending_validator(state: BeaconState,
except MinEmptyValidatorIndexNotFound:
index = None

if index is None:
# Append to the validator_registry
validator_registry = state.validator_registry + (validator,)
state = state.copy(
Expand Down Expand Up @@ -122,7 +121,7 @@ def process_deposit(*,
randao_commitment,
)

validator_pubkeys = tuple([v.pubkey for v in state.validator_registry])
validator_pubkeys = tuple(v.pubkey for v in state.validator_registry)
if pubkey not in validator_pubkeys:
validator = ValidatorRecord.get_pending_validator(
pubkey=pubkey,
Expand All @@ -142,7 +141,7 @@ def process_deposit(*,
index = validator_pubkeys.index(pubkey)
validator = state.validator_registry[index]

if validator.withdrawal_credentials != validator.withdrawal_credentials:
if validator.withdrawal_credentials != withdrawal_credentials:
raise ValidationError(
"`withdrawal_credentials` are incorrect:\n"
"\texpected: %s, found: %s" % (
Expand Down
3 changes: 0 additions & 3 deletions eth/beacon/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
get_bitfield_length,
has_voted,
)
from eth.beacon._utils.hash import (
hash_eth2,
)
from eth._utils.numeric import (
clamp,
)
Expand Down
4 changes: 2 additions & 2 deletions eth/beacon/types/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def update_validator(self,
validator: ValidatorRecord) -> 'BeaconState':
validator_registry = list(self.validator_registry)
validator_registry[validator_index] = validator
self = self.copy(
updated_state = self.copy(
validator_registry=tuple(validator_registry),
)
return self
return updated_state
8 changes: 5 additions & 3 deletions tests/beacon/test_deposit_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ValidationError,
)

from eth.utils import bls
from eth._utils import bls

from eth.beacon.constants import (
EMPTY_SIGNATURE,
Expand Down Expand Up @@ -250,7 +250,7 @@ def test_process_deposit(sample_beacon_state_params,
assert len(result_state.validator_registry) == 2
assert result_state.validator_registry[1].pubkey == pubkey_2

# Force the first validator exited
# Force the first validator exited -> a empty slot in state.validator_registry.
result_state = result_state.copy(
validator_registry=(
result_state.validator_registry[0].copy(
Expand All @@ -261,7 +261,8 @@ def test_process_deposit(sample_beacon_state_params,
)
)

# Add the third validator
# Add the third validator.
# Should overwrite previously exited validator.
privkey_3 = privkeys[2]
pubkey_3 = pubkeys[2]
deposit_input = make_deposit_input(
Expand All @@ -279,5 +280,6 @@ def test_process_deposit(sample_beacon_state_params,
randao_commitment=randao_commitment,
zero_balance_validator_ttl=zero_balance_validator_ttl,
)
# Overwrite the second validator.
assert len(result_state.validator_registry) == 2
assert result_state.validator_registry[0].pubkey == pubkey_3

0 comments on commit f3a4b8c

Please sign in to comment.