2020-01-03 14:49:23 +00:00
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE - RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
- [Ethereum 2.0 Phase 1 -- From Phase 0 to Phase 1 ](#ethereum-20-phase-1----from-phase-0-to-phase-1 )
- [Table of contents ](#table-of-contents )
- [Introduction ](#introduction )
- [Configuration ](#configuration )
- [Fork to Phase 1 ](#fork-to-phase-1 )
2020-04-16 11:43:48 +00:00
- [Fork trigger ](#fork-trigger )
2020-01-03 14:49:23 +00:00
- [Upgrading the state ](#upgrading-the-state )
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2019-11-16 11:23:45 +00:00
# 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
<!-- TOC -->
TODO
<!-- /TOC -->
## Introduction
This document describes the process of moving from Phase 0 to Phase 1 of Ethereum 2.0.
## Configuration
2020-01-05 22:37:42 +00:00
Warning: this configuration is not definitive.
2019-11-16 11:23:45 +00:00
2020-01-05 22:37:42 +00:00
| Name | Value |
2020-01-29 22:08:48 +00:00
| - | - |
2020-01-13 18:47:33 +00:00
| `PHASE_1_FORK_VERSION` | `Version('0x01000000')` |
2020-07-16 08:34:21 +00:00
| `PHASE_1_FORK_SLOT` | `Slot(0)` **TBD** |
2020-01-05 22:37:42 +00:00
| `INITIAL_ACTIVE_SHARDS` | `2**6` (= 64) |
2019-11-16 11:23:45 +00:00
## Fork to Phase 1
2020-04-16 11:43:48 +00:00
### Fork trigger
2019-11-16 11:23:45 +00:00
2020-07-16 08:34:21 +00:00
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_FORK_SLOT` , where `PHASE_1_FORK_SLOT % SLOTS_PER_EPOCH == 0` .
2019-11-16 11:23:45 +00:00
### Upgrading the state
2020-07-16 08:34:21 +00:00
After `process_slots` of Phase 0 finishes, if `state.slot == PHASE_1_FORK_SLOT` , an irregular state change is made to upgrade to Phase 1.
2019-11-16 11:23:45 +00:00
```python
def upgrade_to_phase1(pre: phase0.BeaconState) -> BeaconState:
2019-11-16 11:33:24 +00:00
epoch = get_current_epoch(pre)
2019-11-16 11:23:45 +00:00
post = BeaconState(
genesis_time=pre.genesis_time,
slot=pre.slot,
fork=Fork(
2020-01-05 22:37:42 +00:00
previous_version=pre.fork.current_version,
2019-11-16 11:23:45 +00:00
current_version=PHASE_1_FORK_VERSION,
2019-11-16 11:33:24 +00:00
epoch=epoch,
2019-11-16 11:23:45 +00:00
),
# 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,
2019-11-16 11:33:24 +00:00
slashed=phase0_validator.slashed,
2019-11-16 11:23:45 +00:00
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,
2019-11-20 04:11:19 +00:00
next_custody_secret_to_reveal=get_custody_period_for_validator(ValidatorIndex(i), epoch),
2020-04-28 00:09:20 +00:00
all_custody_secrets_revealed_epoch=FAR_FUTURE_EPOCH,
2019-11-20 04:11:19 +00:00
) for i, phase0_validator in enumerate(pre.validators)
2019-11-16 11:23:45 +00:00
),
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
2020-05-29 15:50:18 +00:00
current_epoch_start_shard=Shard(0),
2019-11-16 11:23:45 +00:00
shard_states=List[ShardState, MAX_SHARDS](
ShardState(
2020-07-16 08:34:21 +00:00
slot=compute_previous_slot(pre.slot),
2020-03-25 06:59:41 +00:00
gasprice=MIN_GASPRICE,
2019-12-05 19:36:48 +00:00
latest_block_root=Root(),
2020-01-05 19:20:20 +00:00
) for i in range(INITIAL_ACTIVE_SHARDS)
2019-11-16 11:23:45 +00:00
),
2020-01-05 23:44:22 +00:00
online_countdown=[ONLINE_PERIOD] * len(pre.validators), # all online
2019-11-16 11:23:45 +00:00
current_light_committee=CompactCommittee(), # computed after state creation
next_light_committee=CompactCommittee(),
# Custody game
2020-06-19 22:02:19 +00:00
exposed_derived_secrets=[()] * EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS,
2020-01-05 22:37:42 +00:00
# exposed_derived_secrets will fully default to zeroes
2019-11-16 11:23:45 +00:00
)
2020-01-13 17:55:21 +00:00
next_epoch = Epoch(epoch + 1)
2020-01-05 22:37:42 +00:00
post.current_light_committee = committee_to_compact_committee(post, get_light_client_committee(post, epoch))
2020-01-13 17:55:21 +00:00
post.next_light_committee = committee_to_compact_committee(post, get_light_client_committee(post, next_epoch))
2019-11-16 11:23:45 +00:00
return post
```