mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-03 06:13:31 +00:00
pr feedback
This commit is contained in:
parent
577fc740d0
commit
014138baab
@ -1187,6 +1187,9 @@ def verify_indexed_attestation(state: BeaconState, indexed_attestation: IndexedA
|
||||
custody_bit_0_indices = indexed_attestation.custody_bit_0_indices
|
||||
custody_bit_1_indices = indexed_attestation.custody_bit_1_indices
|
||||
|
||||
# ensure no duplicate indices across custody bits
|
||||
assert len(set(custody_bit_0_indices).intersection(set(custody_bit_1_indices))) == 0
|
||||
|
||||
if len(custody_bit_1_indices) > 0: # [TO BE REMOVED IN PHASE 1]
|
||||
return False
|
||||
|
||||
@ -2291,12 +2294,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
|
||||
attesting_indices_1 = attestation1.custody_bit_0_indices + attestation1.custody_bit_1_indices
|
||||
attesting_indices_2 = attestation2.custody_bit_0_indices + attestation2.custody_bit_1_indices
|
||||
slashable_indices = [
|
||||
index for index in validator_indices_1
|
||||
index for index in attesting_indices_1
|
||||
if (
|
||||
index in validator_indices_2 and
|
||||
index in attesting_indices_2 and
|
||||
is_slashable_validator(state.validator_registry[index], get_current_epoch(state))
|
||||
)
|
||||
]
|
||||
|
@ -4,7 +4,7 @@ import pytest
|
||||
import build.phase0.spec as spec
|
||||
from build.phase0.spec import (
|
||||
get_balance,
|
||||
get_current_epoch,
|
||||
get_beacon_proposer_index,
|
||||
process_attester_slashing,
|
||||
)
|
||||
from tests.phase0.helpers import (
|
||||
@ -29,16 +29,22 @@ def run_attester_slashing_processing(state, attester_slashing, valid=True):
|
||||
|
||||
process_attester_slashing(post_state, attester_slashing)
|
||||
|
||||
validator_index = attester_slashing.attestation_1.custody_bit_0_indices[0]
|
||||
slashed_validator = post_state.validator_registry[validator_index]
|
||||
slashed_index = attester_slashing.attestation_1.custody_bit_0_indices[0]
|
||||
slashed_validator = post_state.validator_registry[slashed_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(post_state, validator_index) <
|
||||
get_balance(state, validator_index)
|
||||
get_balance(post_state, slashed_index) <
|
||||
get_balance(state, slashed_index)
|
||||
)
|
||||
proposer_index = get_beacon_proposer_index(state, state.slot)
|
||||
# gained whistleblower reward
|
||||
assert (
|
||||
get_balance(post_state, proposer_index) >
|
||||
get_balance(state, proposer_index)
|
||||
)
|
||||
|
||||
return state, post_state
|
||||
@ -96,3 +102,14 @@ def test_participants_already_slashed(state):
|
||||
pre_state, post_state = run_attester_slashing_processing(state, attester_slashing, False)
|
||||
|
||||
return pre_state, attester_slashing, post_state
|
||||
|
||||
|
||||
def test_custody_bit_0_and_1(state):
|
||||
attester_slashing = get_valid_attester_slashing(state)
|
||||
|
||||
attester_slashing.attestation_1.custody_bit_1_indices = (
|
||||
attester_slashing.attestation_1.custody_bit_0_indices
|
||||
)
|
||||
pre_state, post_state = run_attester_slashing_processing(state, attester_slashing, False)
|
||||
|
||||
return pre_state, attester_slashing, post_state
|
||||
|
@ -17,6 +17,7 @@ from build.phase0.spec import (
|
||||
# functions
|
||||
get_active_validator_indices,
|
||||
get_balance,
|
||||
get_beacon_proposer_index,
|
||||
get_block_root,
|
||||
get_current_epoch,
|
||||
get_domain,
|
||||
@ -164,6 +165,13 @@ def test_attester_slashing(state):
|
||||
# lost whistleblower reward
|
||||
assert get_balance(test_state, validator_index) < get_balance(state, validator_index)
|
||||
|
||||
proposer_index = get_beacon_proposer_index(test_state, test_state.slot)
|
||||
# gained whistleblower reward
|
||||
assert (
|
||||
get_balance(test_state, proposer_index) >
|
||||
get_balance(state, proposer_index)
|
||||
)
|
||||
|
||||
return state, [block], test_state
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user