eth2.0-specs/specs/phase1/phase1-fork.md
Hsiao-Wei Wang 524ba166d1
[squashed] shard chain updates wip
Fix wrong field names

Fix `build_attestation_data` and other PR feedback from Danny and
Terence

1. Rename `get_previous_slot` to `compute_previous_slot`
2. Break down `build_empty_block` into
`get_state_and_beacon_parent_root_at_slot`, use it in
`build_shard_block`
3. Set defult `slot` to `shard_state.slot + 1` in `build_shard_block`

Update `verify_shard_block_message`: check beacon_parent_root at fork
choice rule stage instead of state transition

Fix  `beacon-chain.md`

1. Fix typo `attestation.slot == state.slot` -> `attestation.data.slot == state.slot` in `is_winning_attestation`
2. Check `verify_shard_transition_false_positives` **after** `process_operations`
3. Fix `shard_attestations` filter in `process_crosslinks`: since attestations come from block, should use `attestation.data.slot + MIN_ATTESTATION_INCLUSION_DELAY == state.slot`
4. [TBD] Allow empty `light_client_signature` to make the tests pass
5. [TBD] Add `is_shard_attestation`, filter out empty `ShardTransition()`

Rework `test_process_crosslink`

Add basic phase 1 `test_blocks`

Add more test cases

Revert `is_shard_attestation` and fix test cases backward compatibility.

Remove `test_process_beacon_block_no_shard_transition` and consider it as invalid case.
2020-05-02 02:32:31 +08:00

5.0 KiB

Table of Contents generated with DocToc

Ethereum 2.0 Phase 1 -- From Phase 0 to Phase 1

Notice: This document is a work-in-progress for researchers and implementers.

Table of contents

TODO

Introduction

This document describes the process of moving from Phase 0 to Phase 1 of Ethereum 2.0.

Configuration

Warning: this configuration is not definitive.

Name Value
PHASE_1_FORK_VERSION Version('0x01000000')
PHASE_1_GENESIS_SLOT 2**5 TBD
INITIAL_ACTIVE_SHARDS 2**6 (= 64)

Fork to Phase 1

Fork trigger

TBD. Social consensus, along with state conditions such as epoch boundary, finality, deposits, active validator count, etc. may be part of the decision process to trigger the fork. For now we assume the condition will be triggered at slot PHASE_1_GENESIS_SLOT, where PHASE_1_GENESIS_SLOT % SLOTS_PER_EPOCH == 0.

Upgrading the state

After process_slots of Phase 0 finishes, if state.slot == PHASE_1_GENESIS_SLOT, an irregular state change is made to upgrade to Phase 1.

def upgrade_to_phase1(pre: phase0.BeaconState) -> BeaconState:
    epoch = get_current_epoch(pre)
    post = BeaconState(
        genesis_time=pre.genesis_time,
        slot=pre.slot,
        fork=Fork(
            previous_version=pre.fork.current_version,
            current_version=PHASE_1_FORK_VERSION,
            epoch=epoch,
        ),
        # History
        latest_block_header=pre.latest_block_header,
        block_roots=pre.block_roots,
        state_roots=pre.state_roots,
        historical_roots=pre.historical_roots,
        # Eth1
        eth1_data=pre.eth1_data,
        eth1_data_votes=pre.eth1_data_votes,
        eth1_deposit_index=pre.eth1_deposit_index,
        # Registry
        validators=List[Validator, VALIDATOR_REGISTRY_LIMIT](
            Validator(
                pubkey=phase0_validator.pubkey,
                withdrawal_credentials=phase0_validator.withdrawal_credentials,
                effective_balance=phase0_validator.effective_balance,
                slashed=phase0_validator.slashed,
                activation_eligibility_epoch=phase0_validator.activation_eligibility_epoch,
                activation_epoch=phase0_validator.activation_eligibility_epoch,
                exit_epoch=phase0_validator.exit_epoch,
                withdrawable_epoch=phase0_validator.withdrawable_epoch,
                next_custody_secret_to_reveal=get_custody_period_for_validator(ValidatorIndex(i), epoch),
                max_reveal_lateness=0,  # TODO custody refactor. Outdated? 
            ) for i, phase0_validator in enumerate(pre.validators)
        ),
        balances=pre.balances,
        # Randomness
        randao_mixes=pre.randao_mixes,
        # Slashings
        slashings=pre.slashings,
        # Attestations
        # previous_epoch_attestations is cleared on upgrade. 
        previous_epoch_attestations=List[PendingAttestation, MAX_ATTESTATIONS * SLOTS_PER_EPOCH](),
        # empty in pre state, since the upgrade is performed just after an epoch boundary.
        current_epoch_attestations=List[PendingAttestation, MAX_ATTESTATIONS * SLOTS_PER_EPOCH](),
        # Finality
        justification_bits=pre.justification_bits,
        previous_justified_checkpoint=pre.previous_justified_checkpoint,
        current_justified_checkpoint=pre.current_justified_checkpoint,
        finalized_checkpoint=pre.finalized_checkpoint,
        # Phase 1
        shard_states=List[ShardState, MAX_SHARDS](
            ShardState(
                slot=pre.slot,
                gasprice=MIN_GASPRICE,
                transition_digest=Root(),
                latest_block_root=Root(),
            ) for i in range(INITIAL_ACTIVE_SHARDS)
        ),
        online_countdown=[ONLINE_PERIOD] * len(pre.validators),  # all online
        current_light_committee=CompactCommittee(),  # computed after state creation
        next_light_committee=CompactCommittee(),
        # Custody game
        exposed_derived_secrets=[] * EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS,
        # exposed_derived_secrets will fully default to zeroes
    )
    next_epoch = Epoch(epoch + 1)
    post.current_light_committee = committee_to_compact_committee(post, get_light_client_committee(post, epoch))
    post.next_light_committee = committee_to_compact_committee(post, get_light_client_committee(post, next_epoch))
    return post