Example #1
0
def test_verify_indexed_attestation_signature(
        slots_per_epoch, validator_count, genesis_state, config, privkeys,
        sample_beacon_state_params, genesis_validators, genesis_balances,
        sample_indexed_attestation_params, sample_fork_params):
    state = genesis_state.copy(fork=Fork(**sample_fork_params), )

    # NOTE: we can do this before "correcting" the params as they
    # touch disjoint subsets of the provided params
    message_hashes = _create_indexed_attestation_messages(
        sample_indexed_attestation_params)

    valid_params = _correct_indexed_attestation_params(
        validator_count,
        message_hashes,
        sample_indexed_attestation_params,
        privkeys,
        state,
        config,
    )
    valid_votes = IndexedAttestation(**valid_params)

    validate_indexed_attestation_aggregate_signature(state, valid_votes,
                                                     slots_per_epoch)

    invalid_params = _corrupt_signature(slots_per_epoch, valid_params,
                                        state.fork)
    invalid_votes = IndexedAttestation(**invalid_params)
    with pytest.raises(ValidationError):
        validate_indexed_attestation_aggregate_signature(
            state, invalid_votes, slots_per_epoch)
Example #2
0
def validate_attestation_signature(state: BeaconState,
                                   attestation: Attestation,
                                   config: Eth2Config) -> None:
    indexed_attestation = get_indexed_attestation(state, attestation, config)
    validate_indexed_attestation_aggregate_signature(state,
                                                     indexed_attestation,
                                                     config.SLOTS_PER_EPOCH)
def test_verify_indexed_attestation_signature(
    slots_per_epoch,
    validator_count,
    genesis_state,
    config,
    privkeys,
    sample_attestation_params,
    sample_indexed_attestation_params,
    sample_fork_params,
):
    state = genesis_state.set("fork", Fork.create(**sample_fork_params))
    attestation = Attestation.create(**sample_attestation_params)

    valid_params = _correct_indexed_attestation_params(
        validator_count,
        attestation,
        sample_indexed_attestation_params,
        privkeys,
        state,
        config,
    )
    valid_votes = IndexedAttestation.create(**valid_params)

    validate_indexed_attestation_aggregate_signature(state, valid_votes,
                                                     slots_per_epoch)

    invalid_params = _corrupt_signature(slots_per_epoch, valid_params,
                                        state.fork)
    invalid_votes = IndexedAttestation.create(**invalid_params)
    with pytest.raises(ValidationError):
        validate_indexed_attestation_aggregate_signature(
            state, invalid_votes, slots_per_epoch)