2022-12-11 23:43:07 +00:00
# Capella Light Client -- Sync Protocol
**Notice**: This document is a work-in-progress for researchers and implementers.
## Table of contents
<!-- TOC -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE - RUN doctoc TO UPDATE -->
- [Introduction ](#introduction )
- [Constants ](#constants )
2023-12-27 11:54:36 +00:00
- [Helper types ](#helper-types )
- [`ExecutionBranch` ](#executionbranch )
2022-12-11 23:43:07 +00:00
- [Containers ](#containers )
2023-01-12 17:39:11 +00:00
- [Modified `LightClientHeader` ](#modified-lightclientheader )
2022-12-11 23:43:07 +00:00
- [Helper functions ](#helper-functions )
- [`get_lc_execution_root` ](#get_lc_execution_root )
2023-01-12 17:39:11 +00:00
- [Modified `is_valid_light_client_header` ](#modified-is_valid_light_client_header )
2022-12-11 23:43:07 +00:00
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- /TOC -->
## Introduction
This upgrade adds information about the execution payload to light client data as part of the Capella upgrade. It extends the [Altair Light Client specifications ](../../altair/light-client/sync-protocol.md ). The [fork document ](./fork.md ) explains how to upgrade existing Altair based deployments to Capella.
Additional documents describes the impact of the upgrade on certain roles:
- [Full node ](./full-node.md )
- [Networking ](./p2p-interface.md )
## Constants
| Name | Value |
| - | - |
| `EXECUTION_PAYLOAD_INDEX` | `get_generalized_index(BeaconBlockBody, 'execution_payload')` (= 25) |
2023-12-27 11:54:36 +00:00
## Helper types
### `ExecutionBranch`
2023-12-27 11:44:05 +00:00
```python
2023-12-27 12:59:31 +00:00
class ExecutionBranch(Vector[Bytes32, floorlog2(EXECUTION_PAYLOAD_INDEX)]):
2023-12-27 11:44:05 +00:00
pass
```
2022-12-11 23:43:07 +00:00
## Containers
2023-01-12 17:39:11 +00:00
### Modified `LightClientHeader`
2022-12-11 23:43:07 +00:00
```python
class LightClientHeader(Container):
# Beacon block header
beacon: BeaconBlockHeader
# Execution payload header corresponding to `beacon.body_root` (from Capella onward)
execution: ExecutionPayloadHeader
2023-12-27 11:44:05 +00:00
execution_branch: ExecutionBranch
2022-12-11 23:43:07 +00:00
```
## Helper functions
### `get_lc_execution_root`
```python
def get_lc_execution_root(header: LightClientHeader) -> Root:
2023-01-12 17:39:11 +00:00
epoch = compute_epoch_at_slot(header.beacon.slot)
2022-12-12 12:09:18 +00:00
if epoch >= CAPELLA_FORK_EPOCH:
2022-12-11 23:43:07 +00:00
return hash_tree_root(header.execution)
return Root()
```
2023-01-12 17:39:11 +00:00
### Modified `is_valid_light_client_header`
2022-12-11 23:43:07 +00:00
```python
def is_valid_light_client_header(header: LightClientHeader) -> bool:
2023-01-12 17:39:11 +00:00
epoch = compute_epoch_at_slot(header.beacon.slot)
2022-12-12 12:09:18 +00:00
if epoch < CAPELLA_FORK_EPOCH:
2022-12-12 12:39:14 +00:00
return (
header.execution == ExecutionPayloadHeader()
2023-12-27 12:59:31 +00:00
and header.execution_branch == ExecutionBranch()
2022-12-12 12:39:14 +00:00
)
2022-12-12 11:33:58 +00:00
return is_valid_merkle_branch(
leaf=get_lc_execution_root(header),
branch=header.execution_branch,
depth=floorlog2(EXECUTION_PAYLOAD_INDEX),
index=get_subtree_index(EXECUTION_PAYLOAD_INDEX),
root=header.beacon.body_root,
2022-12-11 23:43:07 +00:00
)
```