Merge pull request #1137 from ethereum/v06x
Bugfix and additional test to release
This commit is contained in:
commit
cb9301a9fe
|
@ -1681,7 +1681,7 @@ def process_attester_slashing(state: BeaconState,
|
|||
slashed_any = False
|
||||
attesting_indices_1 = attestation_1.custody_bit_0_indices + attestation_1.custody_bit_1_indices
|
||||
attesting_indices_2 = attestation_2.custody_bit_0_indices + attestation_2.custody_bit_1_indices
|
||||
for index in set(attesting_indices_1).intersection(attesting_indices_2):
|
||||
for index in sorted(set(attesting_indices_1).intersection(attesting_indices_2)):
|
||||
if is_slashable_validator(state.validator_registry[index], get_current_epoch(state)):
|
||||
slash_validator(state, index)
|
||||
slashed_any = True
|
||||
|
|
|
@ -93,6 +93,22 @@ def test_invalid_sig_top_up(state):
|
|||
yield from run_deposit_processing(state, deposit, validator_index, valid=True, effective=True)
|
||||
|
||||
|
||||
@spec_state_test
|
||||
def test_invalid_withdrawal_credentials_top_up(state):
|
||||
validator_index = 0
|
||||
amount = spec.MAX_EFFECTIVE_BALANCE // 4
|
||||
withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX_BYTE + spec.hash(b"junk")[1:]
|
||||
deposit = prepare_state_and_deposit(
|
||||
state,
|
||||
validator_index,
|
||||
amount,
|
||||
withdrawal_credentials=withdrawal_credentials,
|
||||
)
|
||||
|
||||
# inconsistent withdrawal credentials, in top-ups, are allowed!
|
||||
yield from run_deposit_processing(state, deposit, validator_index, valid=True, effective=True)
|
||||
|
||||
|
||||
@spec_state_test
|
||||
def test_wrong_index(state):
|
||||
validator_index = len(state.validator_registry)
|
||||
|
|
|
@ -8,11 +8,10 @@ from eth2spec.utils.merkle_minimal import calc_merkle_tree_from_leaves, get_merk
|
|||
from eth2spec.utils.minimal_ssz import signing_root
|
||||
|
||||
|
||||
def build_deposit_data(state, pubkey, privkey, amount, signed=False):
|
||||
def build_deposit_data(state, pubkey, privkey, amount, withdrawal_credentials, signed=False):
|
||||
deposit_data = DepositData(
|
||||
pubkey=pubkey,
|
||||
# insecurely use pubkey as withdrawal key as well
|
||||
withdrawal_credentials=spec.BLS_WITHDRAWAL_PREFIX_BYTE + spec.hash(pubkey)[1:],
|
||||
withdrawal_credentials=withdrawal_credentials,
|
||||
amount=amount,
|
||||
)
|
||||
if signed:
|
||||
|
@ -37,8 +36,9 @@ def build_deposit(state,
|
|||
pubkey,
|
||||
privkey,
|
||||
amount,
|
||||
withdrawal_credentials,
|
||||
signed):
|
||||
deposit_data = build_deposit_data(state, pubkey, privkey, amount, signed)
|
||||
deposit_data = build_deposit_data(state, pubkey, privkey, amount, withdrawal_credentials, signed)
|
||||
|
||||
item = deposit_data.hash_tree_root()
|
||||
index = len(deposit_data_leaves)
|
||||
|
@ -57,7 +57,7 @@ def build_deposit(state,
|
|||
return deposit, root, deposit_data_leaves
|
||||
|
||||
|
||||
def prepare_state_and_deposit(state, validator_index, amount, signed=False):
|
||||
def prepare_state_and_deposit(state, validator_index, amount, withdrawal_credentials=None, signed=False):
|
||||
"""
|
||||
Prepare the state for the deposit, and create a deposit for the given validator, depositing the given amount.
|
||||
"""
|
||||
|
@ -67,13 +67,19 @@ def prepare_state_and_deposit(state, validator_index, amount, signed=False):
|
|||
|
||||
pubkey = pubkeys[validator_index]
|
||||
privkey = privkeys[validator_index]
|
||||
|
||||
# insecurely use pubkey as withdrawal key if no credentials provided
|
||||
if withdrawal_credentials is None:
|
||||
withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX_BYTE + spec.hash(pubkey)[1:]
|
||||
|
||||
deposit, root, deposit_data_leaves = build_deposit(
|
||||
state,
|
||||
deposit_data_leaves,
|
||||
pubkey,
|
||||
privkey,
|
||||
amount,
|
||||
signed
|
||||
withdrawal_credentials,
|
||||
signed,
|
||||
)
|
||||
|
||||
state.latest_eth1_data.deposit_root = root
|
||||
|
|
Loading…
Reference in New Issue