More polish and fixes to the sync protocol

This commit is contained in:
Justin 2020-11-17 14:18:58 +00:00 committed by GitHub
parent 99219c874f
commit 7ffc9c5bc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 16 deletions

View File

@ -36,7 +36,6 @@ This document suggests a minimal light client design for the beacon chain that u
| Name | Value | | Name | Value |
| - | - | | - | - |
| `NEXT_SYNC_COMMITTEE_INDEX` | `IndexConcat(Index(BeaconBlock, 'state_root'), Index(BeaconState, 'next_sync_committee'))` | | `NEXT_SYNC_COMMITTEE_INDEX` | `IndexConcat(Index(BeaconBlock, 'state_root'), Index(BeaconState, 'next_sync_committee'))` |
| `FORK_INDEX` | `IndexConcat(Index(BeaconBlock, 'state_root'), Index(BeaconState, 'fork'))` |
## Configuration ## Configuration
@ -60,8 +59,6 @@ This document suggests a minimal light client design for the beacon chain that u
class LightClientSnapshot(Container): class LightClientSnapshot(Container):
# Beacon block header # Beacon block header
header: BeaconBlockHeader header: BeaconBlockHeader
# Fork data corresponding to the header
fork: Fork
# Sync committees corresponding to the header # Sync committees corresponding to the header
current_sync_committee: SyncCommittee current_sync_committee: SyncCommittee
next_sync_committee: SyncCommittee next_sync_committee: SyncCommittee
@ -73,12 +70,13 @@ class LightClientSnapshot(Container):
class LightClientUpdate(Container): class LightClientUpdate(Container):
# Updated snapshot # Updated snapshot
snapshot: LightClientSnapshot snapshot: LightClientSnapshot
# Merkle branches for the updated snapshot # Merkle branches for the next sync committee
fork_branch: Vector[Bytes32, log_2(FORK_INDEX)] next_sync_committee_branch: Vector[Bytes32, log2(NEXT_SYNC_COMMITTEE_INDEX)]
next_sync_committee_branch: Vector[Bytes32, log_2(NEXT_SYNC_COMMITTEE_INDEX)]
# Sync committee aggregate signature # Sync committee aggregate signature
sync_committee_bits: Bitlist[MAX_SYNC_COMMITTEE_SIZE] sync_committee_bits: Bitlist[MAX_SYNC_COMMITTEE_SIZE]
sync_committee_signature: BLSSignature sync_committee_signature: BLSSignature
# Fork version corresponding to the aggregate signature
fork_version
``` ```
#### `LightClientStore` #### `LightClientStore`
@ -121,22 +119,13 @@ def is_valid_light_client_update(store: LightClientStore, update: LightClientUpd
root=hash_tree_root(new_snapshot.header), root=hash_tree_root(new_snapshot.header),
) )
# Verify new snapshot fork
assert is_valid_merkle_branch(
leaf=hash_tree_root(new_snapshot.fork),
branch=update.fork_branch,
depth=log2(FORK_INDEX),
index=FORK_INDEX % 2**log2(FORK_INDEX),
root=hash_tree_root(new_snapshot.header),
)
# Verify sync committee bitfield length # Verify sync committee bitfield length
sync_committee = new_snapshot.current_sync_committee sync_committee = new_snapshot.current_sync_committee
assert len(update.sync_committee_bits) == len(sync_committee) assert len(update.sync_committee_bits) == len(sync_committee)
# Verify sync committee aggregate signature # Verify sync committee aggregate signature
participant_pubkeys = [pubkey for (bit, pubkey) in zip(update.sync_committee_bits, sync_committee.pubkeys) if bit] participant_pubkeys = [pubkey for (bit, pubkey) in zip(update.sync_committee_bits, sync_committee.pubkeys) if bit]
domain = compute_domain(DOMAIN_SYNC_COMMITTEE, fork_version.current_version) domain = compute_domain(DOMAIN_SYNC_COMMITTEE, update.fork_version)
signing_root = compute_signing_root(new_snapshot.header, domain) signing_root = compute_signing_root(new_snapshot.header, domain)
assert bls.FastAggregateVerify(participant_pubkeys, signing_root, update.sync_committee_signature) assert bls.FastAggregateVerify(participant_pubkeys, signing_root, update.sync_committee_signature)