Skip to content

Commit

Permalink
Merge pull request #2924 from etan-status/lc-genesis
Browse files Browse the repository at this point in the history
Allow `LightClientUpdate` with genesis finality
  • Loading branch information
hwwhww committed Jun 29, 2022
2 parents 0ba5b3b + 65cfede commit f810b67
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions specs/altair/sync-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class LightClientStore(object):

```python
def is_finality_update(update: LightClientUpdate) -> bool:
return update.finalized_header != BeaconBlockHeader()
return update.finality_branch != [Bytes32() for _ in range(floorlog2(FINALIZED_ROOT_INDEX))]
```

### `get_subtree_index`
Expand Down Expand Up @@ -170,13 +170,19 @@ def validate_light_client_update(store: LightClientStore,
signature_period = compute_sync_committee_period(compute_epoch_at_slot(update.signature_slot))
assert signature_period in (finalized_period, finalized_period + 1)

# Verify that the `finalized_header`, if present, actually is the finalized header saved in the
# state of the `attested_header`
# Verify that the `finality_branch`, if present, confirms `finalized_header`
# to match the finalized checkpoint root saved in the state of `attested_header`.
# Note that the genesis finalized checkpoint root is represented as a zero hash.
if not is_finality_update(update):
assert update.finality_branch == [Bytes32() for _ in range(floorlog2(FINALIZED_ROOT_INDEX))]
assert update.finalized_header == BeaconBlockHeader()
else:
if update.finalized_header.slot == GENESIS_SLOT:
finalized_root = Bytes32()
assert update.finalized_header == BeaconBlockHeader()
else:
finalized_root = hash_tree_root(update.finalized_header)
assert is_valid_merkle_branch(
leaf=hash_tree_root(update.finalized_header),
leaf=finalized_root,
branch=update.finality_branch,
depth=floorlog2(FINALIZED_ROOT_INDEX),
index=get_subtree_index(FINALIZED_ROOT_INDEX),
Expand Down

0 comments on commit f810b67

Please sign in to comment.