Loading
Settings

Phase 0 accompanying resource

Resources

High level overview

The beacon chain is the core system-level blockchain for Ethereum 2.0. The name comes from that fact that it serves as a random beacon, but could just as easily be called the “system chain”, “spine chain”, etc. This chain is where the validators exist, where they are assigned their duties, where they perform the RNG MPC, where they vote on the head of the chain for the fork choice, where they finalize checkpoints, and where they link back in references to shard chains (crosslinks) to serve as the root of each shard chain and to faciliate cross-shard communication. It is both the brains behind the operation and the scaffolding upon which the rest of the sharded system is built.

The beacon chain’s state (BeaconState) is the core object around which the specification is built. The BeaconState encapsulates all of the information pertaining to: who the validators are, in what state each of them is in, which chain in the tree this state belongs to and a hash-reference to the Ethereum 1 chain.

Beginning with the genesis state, the post state of a block is considered valid if it passes all of the guards within the state transition function. Thus, the precondition of a block is recursively defined as being a valid postcondition of running the state transition function on the previous block and its state all the way back to the genesis state.

Fork Choice Rule

Given a block tree, the fork choice rule provides a single chain (the canonical chain) and resulting state based upon recent messages from validators. The fork choice rule consumes the block-tree along with the set of most recent attestations from the validator set and returns a block as the current head of the chain. LMD GHOST, the fork choice rule of Eth2.0, considers which block the latest attestation from each validator points to and uses this to calculate the total balance that recursively attests to each block in the tree. This is done by setting the weight of a node in the tree to be the sum of the balances of the validators whose latest attestations were for that node or any descendent of that node. The GHOST algorithm then starts at the base of the tree, selecting the child of the current node with the heaviest weight until reaching a leaf node. This leaf node is the head of the chain and recursively defines the canonical chain.

Concretely, validators are given the opportunity to produce a single attestation during an assigned slot at each epoch. The committed to attestation.data.beacon_block_root serves as a fork choice vote. A view takes into account all of the most recent of these votes from the current active validator set when computing the fork choice.

Finality

The fork choice rule allows us to choose a single canonical blockchain through the block tree whereas “finality” provides guarantees that certain blocks will remain within the canonical chain. The beacon chain uses a modified version of Casper FFG for finality. Casper provides “accountable safety” that certain blocks will always remain in the canonical chain unless some threshold of validators burn their staked up capital. This is what we call a “crypto-economic” claim of safety rather than a more traditional safety found in traditional consensus algorithms.

Concretely, validators are given the opportunity to produce a single attestation during an assigned slot at each epoch. The committed to (attestation.data.source_root, attestation.data.source_epoch) serves as the FFG source pair discussed in depth in “Combining GHOST and Casper”, while the committed to (attestation.data.target_root, attestation.data.target_epoch) serves as the FFG target pair.

Crosslinks are references in the beacon chain to the recent state/blocks for each shard chain. These references serve both as the root of the shard chain fork choice as well as a means for asynchronous communication between shards. In the normal case, each shard can be crosslinked into the beacon chain once per epoch (with a low validator count, this is sometimes once every N epochs).

Although shard chains are not added until phase 1, crosslink committees in phase 0 are still assigned to a shard and attempt to form a crosslink each epoch. In phase 0, data roots inside of crosslinks are simply stubbed as 0x00.

Validator responsibilities

A detailed discussion of the responsibilities of validators in phase 0 can be found here.

The two primary responsibilities are (1) attesting to the beacon chain at each epoch and (2) infrequently creating beacon blocks when selected. Validators are split into “crosslink committees” at each epoch. Each committee is assigned to a slot and shard. The validator attests to the head of the beacon chain and the recent data of the shard (phase 1) at the assigned slot. At each slot, a single beacon block proposer is selected (via get_beacon_proposer_index) from one of the committees assigned to the slot.

Validators gain rewards by regularly attesting to the canonical beacon chain and shard chains and incur penalties if they fail to do so. A validator can be slashed (a more severe penalty) if they violate the Casper FFG rules or if they create two beacon blocks in one epoch. More details on slashing can be found here.

Data structures

A note on data structures

Data structures and hashes of data structures within the beacon chain are encoded as Simple SerialiZe (SSZ) objects. One of the benefits of SSZ-hashing is its support for non-homgenous tree depths when merkleizing the underlying data. As a result of this and the rest of SSZ’s clever design, the hash tree root of an SSZ object is the same whether the object’s sub-objects are represented by the full sub-objects or just their partial merkle root.

Beacon operations

Beacon operations are datastructures that can be added to a BeaconBlock by a block proposer. This is how various messages related to system level validation/construction of the chain are incorporated. They are essentially validator-level transactions to the beacon chain state machine. Each operation has a maximum allowed per block defined in the constants in max operations per block.

ProposerSlashing

AttesterSlashing

Attestation

Deposit

VoluntaryExit

Transfer

Beacon blocks

Beacon state

The BeaconState is the resulting state of running the state transition function on a series of blocks starting from the genesis state. It contains the validator registry, information about randomness, information about finality, relevant caches, and data about the eth1 chain.

State Transition

Epoch Processing

Epoch processing occurs at the start of the 0th slot (slot % EPOCH_LENGTH == 0) of each epoch. Note that state.slot is still equal to the previous slot when process_epoch is run, only incremented after.

process_epoch is the primary container function that calls the rest of the epoch processing sub-functions.

Justification and Finilization

Crosslinks

Rewards and Penalties

Registry updates

Slashings

Final updates

Block Processing

process_block is the main function that calls the sub-functions of block processing. If any asserts or exceptions are thrown in block processing, then the block is seen as invalid and should be discarded.

Block Header

process_block_header determines whether, at a high level, a block is valid. It does so by verifying that:

process_block_header also stores the block header in state for later uses in the state transition function.

RANDAO

process_randao verifies that the block’s RANDAO reveal is the valid signature of the current epoch by the proposer and if so, mixes it into the epoch’s mix.

Eth1 data

process_eth1_data adds the block’s eth1-data to state’s eth1-data-votes. If more than half of the votes in the voting period are for the same eth1-data, update latest_eth1_data.

Operations

process_operations makes sure that the appropriate number of slashings, attestations, depoists, exits and transfers occur as determined by the functions in the following sections. It does so by processing the ProposerSlashing, AttesterSlashing, Attestation, Deposit, VoluntaryExit, and Transfer objects as described above.