コード例 #1
0
def test_with_shard_transition_with_custody_challenge_and_response(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)
    body = get_sample_shard_block_body(spec)
    shard_block = build_shard_block(spec, state, shard, body=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

    # CustodyChunkChallenge operation
    challenge = get_valid_chunk_challenge(spec, state, attestation, shard_transitions[shard])
    block.body.chunk_challenges = [challenge]
    # CustodyChunkResponse operation
    chunk_challenge_index = state.custody_chunk_challenge_index
    custody_response = get_valid_custody_chunk_response(
        spec, state, challenge, chunk_challenge_index, block_length_or_custody_data=body)
    block.body.chunk_challenge_responses = [custody_response]

    yield from run_beacon_block(spec, state, block)
コード例 #2
0
def test_invalid_proposer_index(spec, state):
    beacon_state = state.copy()
    transition_to_valid_shard_slot(spec, beacon_state)
    shard = 0
    shard_state = beacon_state.shard_states[shard]
    signed_shard_block = build_shard_block(spec,
                                           beacon_state,
                                           shard,
                                           slot=beacon_state.slot,
                                           signed=True)
    active_validator_indices = spec.get_active_validator_indices(
        beacon_state, spec.get_current_epoch(beacon_state))
    proposer_index = ((spec.get_shard_proposer_index(
        beacon_state, signed_shard_block.message.slot, shard) + 1) %
                      len(active_validator_indices))
    signed_shard_block.message.proposer_index = proposer_index
    sign_shard_block(spec,
                     beacon_state,
                     shard,
                     signed_shard_block,
                     proposer_index=proposer_index)

    yield from run_shard_blocks(spec,
                                shard_state,
                                signed_shard_block,
                                beacon_state,
                                valid=False)
コード例 #3
0
def test_challenge_appended(spec, state):
    transition_to_valid_shard_slot(spec, state)
    transition_to(spec, state, state.slot + 1)  # Make len(offset_slots) == 1
    shard = 0
    offset_slots = spec.get_offset_slots(state, shard)
    shard_transition = get_sample_shard_transition(
        spec, state.slot, [2**15 // 3] * len(offset_slots))
    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)

    challenge = get_valid_chunk_challenge(spec, state, attestation,
                                          shard_transition)

    yield from run_chunk_challenge_processing(spec, state, challenge)
コード例 #4
0
def test_pending_shard_parent_block(spec, state):
    # Block N
    beacon_state = state.copy()
    transition_to_valid_shard_slot(spec, beacon_state)
    shard = 0
    shard_state = beacon_state.shard_states[shard]
    signed_shard_block_1 = build_shard_block(spec,
                                             beacon_state,
                                             shard,
                                             slot=beacon_state.slot,
                                             signed=True)
    _, _, _, _ = run_shard_blocks(spec, shard_state, signed_shard_block_1,
                                  beacon_state)

    # Block N+1
    next_slot(spec, beacon_state)
    signed_shard_block_2 = build_shard_block(spec,
                                             beacon_state,
                                             shard,
                                             slot=beacon_state.slot,
                                             shard_parent_state=shard_state,
                                             signed=True)

    assert signed_shard_block_2.message.shard_parent_root == shard_state.latest_block_root
    assert signed_shard_block_2.message.slot == signed_shard_block_1.message.slot + 1
    yield from run_shard_blocks(spec, shard_state, signed_shard_block_2,
                                beacon_state)
コード例 #5
0
def test_validator_withdrawal_reenable_after_custody_reveal(spec, state):
    transition_to_valid_shard_slot(spec, state)
    transition_to(spec, state, state.slot + 1)  # Make len(offset_slots) == 1
    spec.initiate_validator_exit(state, 0)
    assert state.validators[0].withdrawable_epoch < spec.FAR_FUTURE_EPOCH

    next_epoch_via_block(spec, state)

    assert state.validators[0].withdrawable_epoch == spec.FAR_FUTURE_EPOCH

    while spec.get_current_epoch(state) < state.validators[0].exit_epoch:
        next_epoch_via_block(spec, state)

    while (state.validators[0].next_custody_secret_to_reveal <=
           spec.get_custody_period_for_validator(
               0, state.validators[0].exit_epoch - 1)):
        custody_key_reveal = get_valid_custody_key_reveal(spec,
                                                          state,
                                                          validator_index=0)
        _, _, _ = run_custody_key_reveal_processing(spec, state,
                                                    custody_key_reveal)

    yield from run_process_custody_final_updates(spec, state)

    assert state.validators[0].withdrawable_epoch < spec.FAR_FUTURE_EPOCH
コード例 #6
0
def test_early_derived_secret_reveal(spec, state):
    transition_to_valid_shard_slot(spec, state)
    block = build_empty_block(spec, state, slot=state.slot + 1)
    early_derived_secret_reveal = get_valid_early_derived_secret_reveal(spec, state)
    block.body.early_derived_secret_reveals = [early_derived_secret_reveal]

    yield from run_beacon_block(spec, state, block)
コード例 #7
0
def test_custody_response_many_epochs(spec, state):
    transition_to_valid_shard_slot(spec, state)
    transition_to(spec, state, state.slot + spec.SLOTS_PER_EPOCH * 20)

    shard = 0
    offset_slots = spec.get_offset_slots(state, shard)
    shard_transition = get_sample_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
    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))

    challenge = get_valid_chunk_challenge(spec, state, attestation, shard_transition)

    _, _, _ = run_chunk_challenge_processing(spec, state, challenge)

    chunk_challenge_index = state.custody_chunk_challenge_index - 1

    custody_response = get_valid_custody_chunk_response(
        spec, state, challenge, chunk_challenge_index, block_length_or_custody_data=2**15 // 3)

    yield from run_custody_chunk_response_processing(spec, state, custody_response)
def test_validator_slashed_after_chunk_challenge(spec, state):
    transition_to_valid_shard_slot(spec, state)
    transition_to(spec, state, state.slot + 1)  # Make len(offset_slots) == 1
    shard = 0
    offset_slots = spec.get_offset_slots(state, shard)
    shard_transition = get_sample_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
    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)

    validator_index = spec.get_beacon_committee(
        state,
        attestation.data.slot,
        attestation.data.index
    )[0]

    challenge = get_valid_chunk_challenge(spec, state, attestation, shard_transition)

    _, _, _ = run_chunk_challenge_processing(spec, state, challenge)

    assert state.validators[validator_index].slashed == 0

    transition_to(spec, state, state.slot + spec.MAX_CHUNK_CHALLENGE_DELAY * spec.SLOTS_PER_EPOCH)

    state.validators[validator_index].slashed = 0

    yield from run_process_challenge_deadlines(spec, state)

    assert state.validators[validator_index].slashed == 1
コード例 #9
0
def get_initial_env(spec, state, target_len_offset_slot):
    transition_to_valid_shard_slot(spec, state)
    committee_index = spec.CommitteeIndex(0)
    target_shard_slot = state.slot + target_len_offset_slot - 1
    shard = spec.compute_shard_from_committee_index(state, committee_index,
                                                    target_shard_slot)
    assert state.shard_states[shard].slot == state.slot - 1
    return state, shard, target_shard_slot
コード例 #10
0
def test_custody_key_reveal(spec, state):
    transition_to_valid_shard_slot(spec, state)
    transition_to(spec, state, state.slot + spec.EPOCHS_PER_CUSTODY_PERIOD * spec.SLOTS_PER_EPOCH)

    block = build_empty_block(spec, state, slot=state.slot + 1)
    custody_key_reveal = get_valid_custody_key_reveal(spec, state)
    block.body.custody_key_reveals = [custody_key_reveal]

    yield from run_beacon_block(spec, state, block)
コード例 #11
0
ファイル: test_blocks.py プロジェクト: hryer/eth2.0-specs
def test_process_beacon_block_with_empty_proposal_transition(spec, state):
    transition_to_valid_shard_slot(spec, state)

    target_len_offset_slot = 1
    committee_index = spec.CommitteeIndex(0)
    shard = spec.compute_shard_from_committee_index(state, committee_index, state.slot + target_len_offset_slot - 1)
    assert state.shard_states[shard].slot == state.slot - 1

    yield from run_beacon_block_with_shard_blocks(spec, state, target_len_offset_slot, committee_index, shard)
コード例 #12
0
def test_validator_withdrawal_delay(spec, state):
    transition_to_valid_shard_slot(spec, state)
    transition_to(spec, state, state.slot + 1)  # Make len(offset_slots) == 1
    spec.initiate_validator_exit(state, 0)
    assert state.validators[0].withdrawable_epoch < spec.FAR_FUTURE_EPOCH

    yield from run_process_custody_final_updates(spec, state)

    assert state.validators[0].withdrawable_epoch == spec.FAR_FUTURE_EPOCH
コード例 #13
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)
コード例 #14
0
def test_validator_withdrawal_resume_after_chunk_challenge_response(spec, state):
    transition_to_valid_shard_slot(spec, state)
    transition_to(spec, state, state.slot + 1)  # Make len(offset_slots) == 1
    shard = 0
    offset_slots = spec.get_offset_slots(state, shard)
    shard_transition = get_sample_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
    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)

    validator_index = spec.get_beacon_committee(
        state,
        attestation.data.slot,
        attestation.data.index
    )[0]

    spec.initiate_validator_exit(state, validator_index)
    assert state.validators[validator_index].withdrawable_epoch < spec.FAR_FUTURE_EPOCH

    next_epoch_via_block(spec, state)

    assert state.validators[validator_index].withdrawable_epoch == spec.FAR_FUTURE_EPOCH

    while spec.get_current_epoch(state) < state.validators[validator_index].exit_epoch:
        next_epoch_via_block(spec, state)

    while (state.validators[validator_index].next_custody_secret_to_reveal
           <= spec.get_custody_period_for_validator(
               validator_index,
               state.validators[validator_index].exit_epoch - 1)):
        custody_key_reveal = get_valid_custody_key_reveal(spec, state, validator_index=validator_index)
        _, _, _ = run_custody_key_reveal_processing(spec, state, custody_key_reveal)

    next_epoch_via_block(spec, state)

    challenge = get_valid_chunk_challenge(spec, state, attestation, shard_transition)

    _, _, _ = run_chunk_challenge_processing(spec, state, challenge)

    next_epoch_via_block(spec, state)

    assert state.validators[validator_index].withdrawable_epoch == spec.FAR_FUTURE_EPOCH

    chunk_challenge_index = state.custody_chunk_challenge_index - 1
    custody_response = get_valid_custody_chunk_response(
        spec, state, challenge, chunk_challenge_index, block_length_or_custody_data=2**15 // 3)

    _, _, _ = run_custody_chunk_response_processing(spec, state, custody_response)

    yield from run_process_custody_final_updates(spec, state)

    assert state.validators[validator_index].withdrawable_epoch < spec.FAR_FUTURE_EPOCH
コード例 #15
0
def test_valid_shard_block(spec, state):
    beacon_state = state.copy()
    transition_to_valid_shard_slot(spec, beacon_state)

    shard = 0
    shard_state = beacon_state.shard_states[shard]
    signed_shard_block = build_shard_block(spec,
                                           state,
                                           shard,
                                           slot=beacon_state.slot,
                                           signed=True)

    yield from run_shard_blocks(spec, shard_state, signed_shard_block,
                                beacon_state)
コード例 #16
0
def test_off_chain_attestation(spec, state):
    transition_to_valid_shard_slot(spec, state)
    transition_to(spec, state, state.slot + spec.SLOTS_PER_EPOCH)

    shard = 0
    offset_slots = spec.get_offset_slots(state, shard)
    shard_transition = get_sample_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
    attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
                                                shard_transition=shard_transition)

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

    challenge = get_valid_chunk_challenge(spec, state, attestation, shard_transition)

    yield from run_chunk_challenge_processing(spec, state, challenge)
コード例 #17
0
def test_process_beacon_block_with_normal_shard_transition(spec, state):
    state = transition_to_valid_shard_slot(spec, state)

    target_len_offset_slot = 1
    committee_index = spec.CommitteeIndex(0)
    shard = spec.compute_shard_from_committee_index(state, committee_index,
                                                    state.slot)
    assert state.shard_states[shard].slot == state.slot - 1

    pre_gasprice = state.shard_states[shard].gasprice

    # Create SignedShardBlock at slot `shard_state.slot + 1`
    body = b'\x56' * spec.MAX_SHARD_BLOCK_SIZE
    shard_block = build_shard_block(spec, state, shard, body=body, signed=True)
    shard_blocks: Dict[spec.Shard, Sequence[spec.SignedShardBlock]] = {
        shard: [shard_block]
    }

    yield from run_beacon_block_with_shard_blocks(spec, state, shard_blocks,
                                                  target_len_offset_slot,
                                                  committee_index)

    shard_state = state.shard_states[shard]

    if target_len_offset_slot == 1 and len(shard_blocks) > 0:
        assert shard_state.gasprice > pre_gasprice
コード例 #18
0
def test_invalid_slot(spec, state):
    if not is_full_crosslink(spec, state):
        # skip
        return

    beacon_state = transition_to_valid_shard_slot(spec, state)
    shard = 0
    shard_state = beacon_state.shard_states[shard]
    signed_shard_block = build_shard_block(spec,
                                           beacon_state,
                                           shard,
                                           slot=beacon_state.slot,
                                           signed=True)
    signed_shard_block.message.slot = beacon_state.slot + 1
    proposer_index = spec.get_shard_proposer_index(
        beacon_state, signed_shard_block.message.slot, shard)
    sign_shard_block(spec,
                     beacon_state,
                     shard,
                     signed_shard_block,
                     proposer_index=proposer_index)

    yield from run_shard_blocks(spec,
                                shard_state,
                                signed_shard_block,
                                beacon_state,
                                valid=False)
コード例 #19
0
def test_out_of_bound_offset(spec, state):
    # TODO: Handle this edge case properly
    if not is_full_crosslink(spec, state):
        # skip
        return

    beacon_state = transition_to_valid_shard_slot(spec, state)
    shard = 0
    slot = (
        beacon_state.shard_states[shard].slot +
        spec.SHARD_BLOCK_OFFSETS[spec.MAX_SHARD_BLOCKS_PER_ATTESTATION - 1] +
        1  # out-of-bound
    )
    transition_to(spec, beacon_state, slot)

    shard_state = beacon_state.shard_states[shard]
    signed_shard_block = build_shard_block(spec,
                                           beacon_state,
                                           shard,
                                           slot=beacon_state.slot,
                                           signed=True)

    yield from run_shard_blocks(spec,
                                shard_state,
                                signed_shard_block,
                                beacon_state,
                                valid=False)
コード例 #20
0
def test_max_offset(spec, state):
    beacon_state = state.copy()
    transition_to_valid_shard_slot(spec, beacon_state)
    shard = 0
    slot = beacon_state.shard_states[shard].slot + spec.SHARD_BLOCK_OFFSETS[
        spec.MAX_SHARD_BLOCKS_PER_ATTESTATION - 1]
    transition_to(spec, beacon_state, slot)

    shard_state = beacon_state.shard_states[shard]
    signed_shard_block = build_shard_block(spec,
                                           beacon_state,
                                           shard,
                                           slot=beacon_state.slot,
                                           signed=True)

    yield from run_shard_blocks(spec, shard_state, signed_shard_block,
                                beacon_state)
コード例 #21
0
def test_invalid_beacon_parent_root(spec, state):
    beacon_state = state.copy()
    transition_to_valid_shard_slot(spec, beacon_state)
    shard = 0
    shard_state = beacon_state.shard_states[shard]
    signed_shard_block = build_shard_block(spec,
                                           beacon_state,
                                           shard,
                                           slot=beacon_state.slot,
                                           signed=True)
    signed_shard_block.message.beacon_parent_root = b'\x12' * 32
    sign_shard_block(spec, beacon_state, shard, signed_shard_block)

    yield from run_shard_blocks(spec,
                                shard_state,
                                signed_shard_block,
                                beacon_state,
                                valid=False)
コード例 #22
0
ファイル: test_blocks.py プロジェクト: tfalencar/eth2.0-specs
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)
コード例 #23
0
def test_invalid_offset(spec, state):
    beacon_state = state.copy()
    transition_to_valid_shard_slot(spec, beacon_state)
    # 4 is not in `SHARD_BLOCK_OFFSETS`
    shard = 0
    slot = beacon_state.shard_states[shard].slot + 4
    assert slot not in spec.SHARD_BLOCK_OFFSETS
    transition_to(spec, beacon_state, slot)

    shard_state = beacon_state.shard_states[shard]
    signed_shard_block = build_shard_block(spec,
                                           beacon_state,
                                           shard,
                                           slot=beacon_state.slot,
                                           signed=True)

    yield from run_shard_blocks(spec,
                                shard_state,
                                signed_shard_block,
                                beacon_state,
                                valid=False)
コード例 #24
0
def run_basic_crosslink_tests(spec, state, target_len_offset_slot, valid=True):
    state = transition_to_valid_shard_slot(spec, state)
    # At the beginning, let `x = state.slot`, `state.shard_states[shard].slot == x - 1`
    slot_x = state.slot
    committee_index = spec.CommitteeIndex(0)
    shard = spec.compute_shard_from_committee_index(state, committee_index,
                                                    state.slot)
    assert state.shard_states[shard].slot == slot_x - 1

    # Create SignedShardBlock
    body = b'\x56' * spec.MAX_SHARD_BLOCK_SIZE
    shard_block = build_shard_block(spec, state, shard, body=body, signed=True)
    shard_blocks = [shard_block]
    # Create a shard_transitions that would be included at beacon block `state.slot + target_len_offset_slot`
    shard_transitions = build_shard_transitions_till_slot(
        spec,
        state,
        shard_blocks={shard: shard_blocks},
        on_time_slot=state.slot + target_len_offset_slot,
    )
    shard_transition = shard_transitions[shard]
    # Create an attestation that would be included at beacon block `state.slot + target_len_offset_slot`
    attestation = build_attestation_with_shard_transition(
        spec,
        state,
        index=committee_index,
        on_time_slot=state.slot + target_len_offset_slot,
        shard_transition=shard_transition,
    )
    pre_gasprice = state.shard_states[shard].gasprice

    transition_to(spec, state, state.slot + target_len_offset_slot)
    pre_shard_state = state.shard_states[shard]

    yield from run_crosslinks_processing(spec,
                                         state,
                                         shard_transitions, [attestation],
                                         valid=valid)

    if valid:
        # After state transition,
        assert state.slot == slot_x + target_len_offset_slot
        shard_state = state.shard_states[shard]
        assert shard_state != pre_shard_state
        assert shard_state == shard_transition.shard_states[
            len(shard_transition.shard_states) - 1]

        if target_len_offset_slot == 1:
            assert shard_state.gasprice > pre_gasprice
コード例 #25
0
def test_invalid_slot(spec, state):
    beacon_state = state.copy()
    transition_to_valid_shard_slot(spec, beacon_state)
    shard = 0
    shard_state = beacon_state.shard_states[shard]
    signed_shard_block = build_shard_block(spec,
                                           beacon_state,
                                           shard,
                                           slot=beacon_state.slot,
                                           signed=True)
    signed_shard_block.message.slot = beacon_state.slot + 1
    proposer_index = spec.get_shard_proposer_index(
        beacon_state, signed_shard_block.message.slot, shard)
    sign_shard_block(spec,
                     beacon_state,
                     shard,
                     signed_shard_block,
                     proposer_index=proposer_index)

    yield from run_shard_blocks(spec,
                                shard_state,
                                signed_shard_block,
                                beacon_state,
                                valid=False)
コード例 #26
0
def test_valid_shard_block(spec, state):
    if not is_full_crosslink(spec, state):
        # skip
        return

    beacon_state = transition_to_valid_shard_slot(spec, state)
    shard = 0
    shard_state = beacon_state.shard_states[shard]
    signed_shard_block = build_shard_block(spec,
                                           beacon_state,
                                           shard,
                                           slot=beacon_state.slot,
                                           signed=True)

    yield from run_shard_blocks(spec, shard_state, signed_shard_block,
                                beacon_state)
コード例 #27
0
ファイル: test_blocks.py プロジェクト: tfalencar/eth2.0-specs
def test_process_beacon_block_with_empty_proposal_transition(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)

    target_len_offset_slot = 1
    committee_index = spec.CommitteeIndex(0)
    shard = spec.compute_shard_from_committee_index(
        state, committee_index, state.slot + target_len_offset_slot - 1)
    assert state.shard_states[shard].slot == state.slot - 1

    yield from run_beacon_block_with_shard_blocks(spec, state,
                                                  target_len_offset_slot,
                                                  committee_index, shard)
コード例 #28
0
def test_process_beacon_block_with_empty_proposal_transition(spec, state):
    state = transition_to_valid_shard_slot(spec, state)

    target_len_offset_slot = 1
    committee_index = spec.CommitteeIndex(0)
    shard = spec.compute_shard_from_committee_index(state, committee_index,
                                                    state.slot)
    assert state.shard_states[shard].slot == state.slot - 1

    # No new shard block
    shard_blocks = {}

    pre_gasprice = state.shard_states[shard].gasprice

    yield from run_beacon_block_with_shard_blocks(spec, state, shard_blocks,
                                                  target_len_offset_slot,
                                                  committee_index)

    if target_len_offset_slot == 1 and len(shard_blocks) > 0:
        assert state.shard_states[shard].gasprice > pre_gasprice
コード例 #29
0
def test_max_offset(spec, state):
    if not is_full_crosslink(spec, state):
        # skip
        return

    beacon_state = transition_to_valid_shard_slot(spec, state)
    shard = 0
    slot = beacon_state.shard_states[shard].slot + spec.SHARD_BLOCK_OFFSETS[
        spec.MAX_SHARD_BLOCKS_PER_ATTESTATION - 1]
    transition_to(spec, beacon_state, slot)

    shard_state = beacon_state.shard_states[shard]
    signed_shard_block = build_shard_block(spec,
                                           beacon_state,
                                           shard,
                                           slot=beacon_state.slot,
                                           signed=True)

    yield from run_shard_blocks(spec, shard_state, signed_shard_block,
                                beacon_state)
コード例 #30
0
def test_invalid_shard_parent_root(spec, state):
    if not is_full_crosslink(spec, state):
        # skip
        return

    beacon_state = transition_to_valid_shard_slot(spec, state)
    shard = 0
    shard_state = beacon_state.shard_states[shard]
    signed_shard_block = build_shard_block(spec,
                                           beacon_state,
                                           shard,
                                           slot=beacon_state.slot,
                                           signed=True)
    signed_shard_block.message.shard_parent_root = b'\x12' * 32
    sign_shard_block(spec, beacon_state, shard, signed_shard_block)

    yield from run_shard_blocks(spec,
                                shard_state,
                                signed_shard_block,
                                beacon_state,
                                valid=False)