def test_validate_bitfield(attestation_validation_fixture, cycle_length): ( crystallized_state, _, attestation, _, _, _, ) = attestation_validation_fixture attestation_indices = get_attestation_indices( crystallized_state, attestation, cycle_length, ) # Case 1: Attestation has incorrect bitfield length attestation_case_1 = attestation.copy( attester_bitfield=get_empty_bitfield(10), ) with pytest.raises(ValidationError): validate_bitfield(attestation_case_1, attestation_indices) # Case 2: End bits are not all zero last_bit = len(attestation_indices) attestation_case_2 = attestation.copy(attester_bitfield=set_voted( attestation.attester_bitfield, last_bit), ) with pytest.raises(ValidationError): validate_bitfield(attestation_case_2, attestation_indices)
def test_validate_attestation_aggregate_sig(attestation_validation_fixture, cycle_length): (crystallized_state, active_state, attestation, block, _, _) = attestation_validation_fixture attestation_indices = get_attestation_indices( crystallized_state, attestation, cycle_length, ) parent_hashes = get_signed_parent_hashes( active_state.recent_block_hashes, block, attestation, cycle_length, ) attestation = attestation.copy(aggregate_sig=[0, 0]) with pytest.raises(ValidationError): validate_aggregate_sig( crystallized_state, attestation, attestation_indices, parent_hashes, )
def validate_attestation(block: BaseBeaconBlock, parent_block: BaseBeaconBlock, crystallized_state: CrystallizedState, recent_block_hashes: Iterable[Hash32], attestation: 'AttestationRecord', chaindb: BaseBeaconChainDB, cycle_length: int, is_validating_signatures: bool = True) -> None: """ Validate the given ``attestation``. Raise ``ValidationError`` if it's invalid. """ validate_slot( parent_block, attestation, cycle_length, ) validate_justified( crystallized_state, attestation, chaindb, ) attestation_indices = get_attestation_indices( crystallized_state, attestation, cycle_length, ) validate_bitfield(attestation, attestation_indices) # TODO: implement versioning validate_version(crystallized_state, attestation) if is_validating_signatures: parent_hashes = get_signed_parent_hashes( recent_block_hashes, block, attestation, cycle_length, ) validate_aggregate_sig( crystallized_state, attestation, attestation_indices, parent_hashes, )
def test_get_attestation_indices(genesis_crystallized_state, sample_attestation_record_params, min_committee_size, beacon_config): attestation = AttestationRecord(**sample_attestation_record_params) attestation = attestation.copy( slot=0, shard_id=0, ) attestation_indices = get_attestation_indices( genesis_crystallized_state, attestation, beacon_config.cycle_length, ) assert len(attestation_indices) >= min_committee_size