Example #1
0
def run_standard_custody_slashing_test(spec,
                                       state,
                                       shard_lateness=None,
                                       shard=None,
                                       validator_index=None,
                                       block_lengths=None,
                                       slashing_message_data=None,
                                       correct=True,
                                       valid=True):
    if shard_lateness is None:
        shard_lateness = spec.SLOTS_PER_EPOCH
    transition_to(spec, state, state.slot + shard_lateness)

    if shard is None:
        shard = 0
    if validator_index is None:
        validator_index = spec.get_beacon_committee(state, state.slot,
                                                    shard)[0]

    offset_slots = spec.get_offset_slots(state, shard)
    if block_lengths is None:
        block_lengths = [2**15 // 3] * len(offset_slots)

    custody_secret = get_custody_secret(spec, state, validator_index)
    shard_transition, slashable_test_vector = get_custody_slashable_shard_transition(
        spec,
        state.slot,
        block_lengths,
        custody_secret,
        slashable=correct,
    )

    attestation = get_valid_on_time_attestation(
        spec,
        state,
        index=shard,
        signed=True,
        shard_transition=shard_transition)

    transition_to(spec, state,
                  state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)

    _, _, _ = run_attestation_processing(spec, state, attestation)

    transition_to(
        spec, state, state.slot + spec.SLOTS_PER_EPOCH *
        (spec.EPOCHS_PER_CUSTODY_PERIOD - 1))

    slashing = get_valid_custody_slashing(spec, state, attestation,
                                          shard_transition, custody_secret,
                                          slashable_test_vector)

    if slashing_message_data is not None:
        slashing.message.data = slashing_message_data

    yield from run_custody_slashing_processing(spec,
                                               state,
                                               slashing,
                                               valid=valid,
                                               correct=correct)
Example #2
0
def test_custody_slashing(spec, state):
    transition_to_valid_shard_slot(spec, state)

    # Build shard block
    shard = 0
    committee_index = get_committee_index_of_shard(spec, state, state.slot,
                                                   shard)
    # Create slashable shard block body
    validator_index = spec.get_beacon_committee(state, state.slot,
                                                committee_index)[0]
    custody_secret = spec.get_custody_secret(
        state,
        validator_index,
        privkeys[validator_index],
        spec.get_current_epoch(state),
    )
    slashable_body = get_custody_slashable_test_vector(spec,
                                                       custody_secret,
                                                       length=100,
                                                       slashable=True)
    shard_block = build_shard_block(spec,
                                    state,
                                    shard,
                                    body=slashable_body,
                                    slot=state.slot,
                                    signed=True)
    shard_block_dict: Dict[spec.Shard, Sequence[spec.SignedShardBlock]] = {
        shard: [shard_block]
    }
    shard_transitions = get_shard_transitions(spec, state, shard_block_dict)

    attestation = get_valid_on_time_attestation(
        spec,
        state,
        index=committee_index,
        shard_transition=shard_transitions[shard],
        signed=True,
    )
    block = build_empty_block(spec, state, slot=state.slot + 1)
    block.body.attestations = [attestation]
    block.body.shard_transitions = shard_transitions

    _, _, _ = run_beacon_block(spec, state, block)

    transition_to(
        spec, state, state.slot + spec.SLOTS_PER_EPOCH *
        (spec.EPOCHS_PER_CUSTODY_PERIOD - 1))

    block = build_empty_block(spec, state, slot=state.slot + 1)
    custody_slashing = get_valid_custody_slashing(spec, state, attestation,
                                                  shard_transitions[shard],
                                                  custody_secret,
                                                  slashable_body)
    block.body.custody_slashings = [custody_slashing]

    yield from run_beacon_block(spec, state, block)
Example #3
0
def test_custody_slashing(spec, state):
    # NOTE: this test is only for full crosslink (minimal config), not for mainnet
    if not is_full_crosslink(spec, state):
        # skip
        return

    state = transition_to_valid_shard_slot(spec, state)

    # Build shard block
    shard = 0
    committee_index = get_committee_index_of_shard(spec, state, state.slot,
                                                   shard)
    # Create slashable shard block body
    validator_index = spec.get_beacon_committee(state, state.slot,
                                                committee_index)[0]
    custody_secret = get_custody_secret(spec, state, validator_index)
    slashable_body = get_custody_slashable_test_vector(spec,
                                                       custody_secret,
                                                       length=100,
                                                       slashable=True)
    shard_block = build_shard_block(spec,
                                    state,
                                    shard,
                                    body=slashable_body,
                                    slot=state.slot,
                                    signed=True)
    shard_block_dict: Dict[spec.Shard, Sequence[spec.SignedShardBlock]] = {
        shard: [shard_block]
    }
    shard_transitions = get_shard_transitions(spec, state, shard_block_dict)

    attestation = get_valid_on_time_attestation(
        spec,
        state,
        index=committee_index,
        shard_transition=shard_transitions[shard],
        signed=True,
    )
    block = build_empty_block(spec, state, slot=state.slot + 1)
    block.body.attestations = [attestation]
    block.body.shard_transitions = shard_transitions

    _, _, _ = run_beacon_block(spec, state, block)

    transition_to(
        spec, state, state.slot + spec.SLOTS_PER_EPOCH *
        (spec.EPOCHS_PER_CUSTODY_PERIOD - 1))

    block = build_empty_block(spec, state, slot=state.slot + 1)
    custody_slashing = get_valid_custody_slashing(spec, state, attestation,
                                                  shard_transitions[shard],
                                                  custody_secret,
                                                  slashable_body)
    block.body.custody_slashings = [custody_slashing]

    yield from run_beacon_block(spec, state, block)