fix validator_indicies issue in process_attester_slashing

This commit is contained in:
Danny Ryan 2019-04-02 13:50:06 +11:00
parent f5c5c166af
commit 06d005999a
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
3 changed files with 45 additions and 2 deletions

View File

@ -2291,10 +2291,12 @@ def process_attester_slashing(state: BeaconState,
assert verify_indexed_attestation(state, attestation1)
assert verify_indexed_attestation(state, attestation2)
validator_indices_1 = attestation1.custody_bit_0_indices + attestation1.custody_bit_1_indices
validator_indices_2 = attestation2.custody_bit_0_indices + attestation2.custody_bit_1_indices
slashable_indices = [
index for index in attestation1.validator_indices
index for index in validator_indices_1
if (
index in attestation2.validator_indices and
index in validator_indices_2 and
is_slashable_validator(state.validator_registry[index], get_current_epoch(state))
)
]

View File

@ -12,6 +12,7 @@ from build.phase0.spec import (
Attestation,
AttestationData,
AttestationDataAndCustodyBit,
AttesterSlashing,
BeaconBlockHeader,
Deposit,
DepositData,
@ -19,6 +20,7 @@ from build.phase0.spec import (
ProposerSlashing,
VoluntaryExit,
# functions
convert_to_indexed,
get_active_validator_indices,
get_attestation_participants,
get_block_root,
@ -244,6 +246,17 @@ def get_valid_proposer_slashing(state):
)
def get_valid_attester_slashing(state):
attestation_1 = get_valid_attestation(state)
attestation_2 = deepcopy(attestation_1)
attestation_2.data.target_root = b'\x01'*32
return AttesterSlashing(
attestation_1=convert_to_indexed(state, attestation_1),
attestation_2=convert_to_indexed(state, attestation_2),
)
def get_valid_attestation(state, slot=None):
if slot is None:
slot = state.slot

View File

@ -40,6 +40,7 @@ from tests.phase0.helpers import (
build_empty_block_for_next_slot,
force_registry_change_at_next_epoch,
get_valid_attestation,
get_valid_attester_slashing,
get_valid_proposer_slashing,
privkeys,
pubkeys,
@ -140,6 +141,33 @@ def test_proposer_slashing(state):
return state, [block], test_state
def test_attester_slashing(state):
test_state = deepcopy(state)
attester_slashing = get_valid_attester_slashing(state)
validator_index = attester_slashing.attestation_1.custody_bit_0_indices[0]
#
# Add to state via block transition
#
block = build_empty_block_for_next_slot(test_state)
block.body.attester_slashings.append(attester_slashing)
state_transition(test_state, block)
assert not state.validator_registry[validator_index].initiated_exit
assert not state.validator_registry[validator_index].slashed
slashed_validator = test_state.validator_registry[validator_index]
assert not slashed_validator.initiated_exit
assert slashed_validator.slashed
assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH
assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH
# lost whistleblower reward
assert get_balance(test_state, validator_index) < get_balance(state, validator_index)
return state, [block], test_state
def test_deposit_in_block(state):
pre_state = deepcopy(state)
test_deposit_data_leaves = [ZERO_HASH] * len(pre_state.validator_registry)