Skip to content

Commit

Permalink
straightforward light client edits
Browse files Browse the repository at this point in the history
  • Loading branch information
djrtwo committed Dec 7, 2020
1 parent b2d25f7 commit 3b7c025
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
31 changes: 23 additions & 8 deletions specs/lightclient/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,28 @@ This is a standalone beacon chain patch adding light client support via sync com

### Extended containers

#### `BeaconBlockBody`
*Note*: Extended SSZ containers inherit all fields from the parent in the original
order and append any additional fields to the end.

#### `BeaconBlock`

```python
class BeaconBlockBody(phase0.BeaconBlockBody):
class BeaconBlock(phase0.BeaconBlock):
# Sync committee aggregate signature
sync_committee_bits: Bitvector[SYNC_COMMITTEE_SIZE]
sync_committee_signature: BLSSignature
```

#### `BeaconBlockHeader`

```python
class BeaconBlockHeader(phase0.BeaconBlockHeader):
# Sync committee aggregate signature
sync_committee_bits: Bitvector[SYNC_COMMITTEE_SIZE]
sync_committee_signature: BLSSignature
```


#### `BeaconState`

```python
Expand Down Expand Up @@ -105,6 +118,7 @@ def get_sync_committee_indices(state: BeaconState, epoch: Epoch) -> Sequence[Val
"""
Return the sync committee indices for a given state and epoch.
"""
MAX_RANDOM_BYTE = 2**8 - 1
base_epoch = Epoch((max(epoch // EPOCHS_PER_SYNC_COMMITTEE_PERIOD, 1) - 1) * EPOCHS_PER_SYNC_COMMITTEE_PERIOD)
active_validator_indices = get_active_validator_indices(state, base_epoch)
active_validator_count = uint64(len(active_validator_indices))
Expand Down Expand Up @@ -143,21 +157,22 @@ def get_sync_committee(state: BeaconState, epoch: Epoch) -> SyncCommittee:
```python
def process_block(state: BeaconState, block: BeaconBlock) -> None:
phase0.process_block(state, block)
process_sync_committee(state, block.body)
process_sync_committee(state, block)
```

#### Sync committee processing

```python
def process_sync_committee(state: BeaconState, body: BeaconBlockBody) -> None:
def process_sync_committee(state: BeaconState, block: BeaconBlock) -> None:
# Verify sync committee aggregate signature signing over the previous slot block root
previous_slot = max(state.slot, Slot(1)) - Slot(1)
previous_slot = Slot(max(state.slot, 1) - 1)
committee_indices = get_sync_committee_indices(state, get_current_epoch(state))
participant_indices = [committee_indices[i] for i in range(len(committee_indices)) if body.sync_committee_bits[i]]
participant_pubkeys = [state.validators[participant_index].pubkey for participant_index in participant_indices]
participant_indices = [index for index, bit in zip(committee_indices, body.sync_committee_bits) if bit]
committee_pubkeys = state.current_sync_committee.pubkeys
participant_pubkeys = [pubkey for pubkey, bit in zip(committee_pubkeys, body.sync_committee_bits) if bit]
domain = get_domain(state, DOMAIN_SYNC_COMMITTEE, compute_epoch_at_slot(previous_slot))
signing_root = compute_signing_root(get_block_root_at_slot(state, previous_slot), domain)
assert bls.FastAggregateVerify(participant_pubkeys, signing_root, body.sync_committee_signature)
assert bls.FastAggregateVerify(participant_pubkeys, signing_root, block.sync_committee_signature)

# Reward sync committee participants
participant_rewards = Gwei(0)
Expand Down
8 changes: 6 additions & 2 deletions specs/lightclient/sync-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@

## Introduction

Eth2 is designed to be light client friendly for constrained environments to access Eth2 with reasonable satefy and liveness. Such environments include resource-constrained devices (e.g. phones for trust-minimised wallets) and metered VMs (e.g. blockchain VMs for cross-chain bridges).
Eth2 is designed to be light client friendly for constrained environments to
access Eth2 with reasonable safety and liveness.
Such environments include resource-constrained devices (e.g. phones for trust-minimised wallets)
and metered VMs (e.g. blockchain VMs for cross-chain bridges).

This document suggests a minimal light client design for the beacon chain that uses sync committees introduced in [this beacon chain extension](./beacon-chain.md).
This document suggests a minimal light client design for the beacon chain that
uses sync committees introduced in [this beacon chain extension](./beacon-chain.md).

## Constants

Expand Down

0 comments on commit 3b7c025

Please sign in to comment.