2021-09-13 16:35:13 +00:00
|
|
|
# beacon_chain
|
2022-01-04 06:08:19 +00:00
|
|
|
# Copyright (c) 2021-2022 Status Research & Development GmbH
|
2021-09-13 16:35:13 +00:00
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
{.used.}
|
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
import
|
2021-09-13 16:35:13 +00:00
|
|
|
# Standard library
|
|
|
|
std/[algorithm, sequtils, sets],
|
|
|
|
# Status libraries
|
|
|
|
stew/bitops2,
|
|
|
|
# Beacon chain internals
|
2022-02-28 19:58:32 +00:00
|
|
|
../../../beacon_chain/spec/datatypes/altair,
|
2021-09-13 16:35:13 +00:00
|
|
|
../../../beacon_chain/spec/
|
2022-02-28 19:58:32 +00:00
|
|
|
[beaconstate, forks, helpers, light_client_sync, signatures,
|
|
|
|
state_transition],
|
2021-09-13 16:35:13 +00:00
|
|
|
# Mock helpers
|
2022-05-23 12:02:54 +00:00
|
|
|
../../mocking/mock_genesis,
|
2021-09-13 16:35:13 +00:00
|
|
|
# Test utilities
|
|
|
|
../../testutil, ../../testblockutil
|
|
|
|
|
2022-03-08 12:21:56 +00:00
|
|
|
# References to `vFuture` refer to the pre-release proposal of the libp2p based
|
|
|
|
# light client sync protocol. Conflicting release versions are not in use.
|
|
|
|
# https://github.com/ethereum/consensus-specs/pull/2802
|
|
|
|
|
2022-05-23 12:02:54 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/vFuture/tests/core/pyspec/eth2spec/test/helpers/light_client.py#L63-L93
|
2021-09-13 16:35:13 +00:00
|
|
|
proc compute_aggregate_sync_committee_signature(
|
2022-05-23 12:02:54 +00:00
|
|
|
cfg: RuntimeConfig,
|
2021-09-13 16:35:13 +00:00
|
|
|
forked: ForkedHashedBeaconState,
|
2022-03-02 10:46:17 +00:00
|
|
|
signature_slot: Slot,
|
2021-09-13 16:35:13 +00:00
|
|
|
participants: openArray[ValidatorIndex],
|
2022-02-28 19:58:32 +00:00
|
|
|
block_root: Eth2Digest): ValidatorSig =
|
2022-05-23 12:02:54 +00:00
|
|
|
template state(): auto = forked.altairData.data
|
2021-09-13 16:35:13 +00:00
|
|
|
|
|
|
|
if len(participants) == 0:
|
|
|
|
return ValidatorSig.infinity
|
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
var
|
2022-02-16 22:24:44 +00:00
|
|
|
aggregateSig {.noinit.}: AggregateSignature
|
2021-09-13 16:35:13 +00:00
|
|
|
initialized = false
|
|
|
|
for validator_index in participants:
|
2021-10-13 14:24:36 +00:00
|
|
|
let
|
2021-09-13 16:35:13 +00:00
|
|
|
privkey = MockPrivKeys[validator_index]
|
2021-12-09 12:56:54 +00:00
|
|
|
signature = get_sync_committee_message_signature(
|
2022-02-28 19:58:32 +00:00
|
|
|
state.fork,
|
|
|
|
state.genesis_validators_root,
|
2022-03-02 10:46:17 +00:00
|
|
|
signature_slot,
|
2022-02-28 19:58:32 +00:00
|
|
|
block_root,
|
|
|
|
privkey)
|
2021-09-13 16:35:13 +00:00
|
|
|
if not initialized:
|
|
|
|
initialized = true
|
|
|
|
aggregateSig.init(signature)
|
|
|
|
else:
|
|
|
|
aggregateSig.aggregate(signature)
|
|
|
|
aggregateSig.finish.toValidatorSig
|
|
|
|
|
2022-05-23 12:02:54 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/vFuture/tests/core/pyspec/eth2spec/test/helpers/light_client.py#L63-L93
|
|
|
|
proc get_sync_aggregate(
|
|
|
|
cfg: RuntimeConfig,
|
|
|
|
forked: ForkedHashedBeaconState,
|
|
|
|
num_participants = SYNC_COMMITTEE_SIZE.uint64,
|
|
|
|
signature_slot = FAR_FUTURE_SLOT): (SyncAggregate, Slot) =
|
|
|
|
template state(): auto = forked.altairData.data
|
|
|
|
|
|
|
|
let
|
|
|
|
block_root =
|
|
|
|
BeaconBlockHeader(
|
|
|
|
slot: state.latest_block_header.slot,
|
|
|
|
proposer_index: state.latest_block_header.proposer_index,
|
|
|
|
parent_root: state.latest_block_header.parent_root,
|
|
|
|
state_root: hash_tree_root(state),
|
|
|
|
body_root: state.latest_block_header.body_root
|
|
|
|
).hash_tree_root()
|
|
|
|
|
|
|
|
# By default, the sync committee signs the previous slot
|
|
|
|
sig_slot =
|
|
|
|
if signature_slot == FAR_FUTURE_SLOT:
|
|
|
|
state.slot + 1
|
|
|
|
else:
|
|
|
|
signature_slot
|
|
|
|
|
|
|
|
# Ensure correct sync committee and fork version are selected
|
|
|
|
var
|
|
|
|
signature_forked = assignClone(forked)
|
|
|
|
cache: StateCache
|
|
|
|
info: ForkedEpochInfo
|
|
|
|
template signature_state(): auto = signature_forked.altairData.data
|
|
|
|
process_slots(cfg, signature_forked[], sig_slot, cache, info, flags = {})
|
|
|
|
.expect("no failure")
|
|
|
|
|
|
|
|
# Fetch sync committee
|
|
|
|
let
|
|
|
|
all_pubkeys = signature_state.validators.mapIt(it.pubkey)
|
|
|
|
committee_indices = signature_state.current_sync_committee.pubkeys
|
|
|
|
.mapIt(all_pubkeys.find(it).ValidatorIndex)
|
|
|
|
committee_size = lenu64(committee_indices)
|
|
|
|
|
|
|
|
# By default, use full participation
|
|
|
|
doAssert committee_size == SYNC_COMMITTEE_SIZE
|
|
|
|
doAssert committee_size >= num_participants
|
|
|
|
|
|
|
|
# Compute sync aggregate
|
|
|
|
var sync_committee_bits: BitArray[SYNC_COMMITTEE_SIZE]
|
|
|
|
for i in 0 ..< num_participants:
|
|
|
|
sync_committee_bits[i] = true
|
|
|
|
let
|
|
|
|
sync_committee_signature = compute_aggregate_sync_committee_signature(
|
|
|
|
cfg,
|
|
|
|
signature_forked[],
|
|
|
|
sig_slot,
|
|
|
|
committee_indices[0 ..< num_participants],
|
|
|
|
block_root)
|
|
|
|
sync_aggregate = SyncAggregate(
|
|
|
|
sync_committee_bits: sync_committee_bits,
|
|
|
|
sync_committee_signature: sync_committee_signature
|
|
|
|
)
|
|
|
|
(sync_aggregate, sig_slot)
|
|
|
|
|
2021-09-13 16:35:13 +00:00
|
|
|
proc block_for_next_slot(
|
|
|
|
cfg: RuntimeConfig,
|
|
|
|
forked: var ForkedHashedBeaconState,
|
|
|
|
cache: var StateCache,
|
|
|
|
withAttestations = false): ForkedSignedBeaconBlock =
|
2022-05-23 12:02:54 +00:00
|
|
|
template state(): auto = forked.altairData.data
|
2021-09-13 16:35:13 +00:00
|
|
|
|
|
|
|
let attestations =
|
|
|
|
if withAttestations:
|
2022-03-16 07:20:40 +00:00
|
|
|
let block_root = withState(forked): state.latest_block_root
|
2021-11-18 12:02:43 +00:00
|
|
|
makeFullAttestations(forked, block_root, state.slot, cache)
|
2021-09-13 16:35:13 +00:00
|
|
|
else:
|
|
|
|
@[]
|
2021-10-13 14:24:36 +00:00
|
|
|
|
2021-09-13 16:35:13 +00:00
|
|
|
addTestBlock(
|
2021-11-18 12:02:43 +00:00
|
|
|
forked, cache, attestations = attestations, cfg = cfg)
|
2021-09-13 16:35:13 +00:00
|
|
|
|
|
|
|
let full_sync_committee_bits = block:
|
|
|
|
var res: BitArray[SYNC_COMMITTEE_SIZE]
|
|
|
|
res.bytes.fill(byte.high)
|
|
|
|
res
|
|
|
|
|
2022-03-03 13:03:08 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.10/tests/core/pyspec/eth2spec/test/helpers/light_client.py#L6-L15
|
2022-01-03 13:06:14 +00:00
|
|
|
func initialize_light_client_store(state: auto): LightClientStore =
|
|
|
|
LightClientStore(
|
|
|
|
finalized_header: BeaconBlockHeader(),
|
|
|
|
current_sync_committee: state.current_sync_committee,
|
|
|
|
next_sync_committee: state.next_sync_committee,
|
2022-02-28 19:58:32 +00:00
|
|
|
best_valid_update: none(altair.LightClientUpdate),
|
2022-01-03 13:06:14 +00:00
|
|
|
optimistic_header: BeaconBlockHeader(),
|
|
|
|
previous_max_active_participants: 0,
|
|
|
|
current_max_active_participants: 0,
|
|
|
|
)
|
|
|
|
|
2022-01-05 08:42:56 +00:00
|
|
|
suite "EF - Altair - Unittests - Sync protocol" & preset():
|
2021-10-13 14:24:36 +00:00
|
|
|
let
|
2021-09-13 16:35:13 +00:00
|
|
|
cfg = block:
|
|
|
|
var res = defaultRuntimeConfig
|
|
|
|
res.ALTAIR_FORK_EPOCH = GENESIS_EPOCH
|
|
|
|
res
|
|
|
|
genesisState = newClone(initGenesisState(cfg = cfg))
|
|
|
|
|
2022-05-23 12:02:54 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/vFuture/tests/core/pyspec/eth2spec/test/altair/unittests/test_sync_protocol.py#L25-L67
|
2022-01-03 13:06:14 +00:00
|
|
|
test "test_process_light_client_update_not_timeout":
|
2022-02-20 20:13:06 +00:00
|
|
|
let forked = assignClone(genesisState[])
|
2022-05-23 12:02:54 +00:00
|
|
|
template state(): auto = forked[].altairData.data
|
2022-01-03 13:06:14 +00:00
|
|
|
var store = initialize_light_client_store(state)
|
2021-09-13 16:35:13 +00:00
|
|
|
|
|
|
|
# Block at slot 1 doesn't increase sync committee period,
|
|
|
|
# so it won't update snapshot
|
2022-05-23 12:02:54 +00:00
|
|
|
var cache: StateCache
|
2021-09-13 16:35:13 +00:00
|
|
|
let
|
2022-05-23 12:02:54 +00:00
|
|
|
attested_block = block_for_next_slot(cfg, forked[], cache).altairData
|
|
|
|
attested_header = attested_block.toBeaconBlockHeader
|
2022-01-03 13:06:14 +00:00
|
|
|
|
2022-05-23 12:02:54 +00:00
|
|
|
# Sync committee signing the attested_header
|
|
|
|
(sync_aggregate, signature_slot) = get_sync_aggregate(cfg, forked[])
|
|
|
|
next_sync_committee = SyncCommittee()
|
|
|
|
next_sync_committee_branch =
|
|
|
|
default(array[log2trunc(altair.NEXT_SYNC_COMMITTEE_INDEX), Eth2Digest])
|
2021-09-13 16:35:13 +00:00
|
|
|
|
|
|
|
# Ensure that finality checkpoint is genesis
|
2022-05-23 12:02:54 +00:00
|
|
|
check state.finalized_checkpoint.epoch == 0
|
2021-09-13 16:35:13 +00:00
|
|
|
# Finality is unchanged
|
2022-01-03 13:06:14 +00:00
|
|
|
let
|
|
|
|
finality_header = BeaconBlockHeader()
|
2022-05-23 12:02:54 +00:00
|
|
|
finality_branch =
|
|
|
|
default(array[log2trunc(altair.FINALIZED_ROOT_INDEX), Eth2Digest])
|
2021-10-13 14:24:36 +00:00
|
|
|
|
2022-02-28 19:58:32 +00:00
|
|
|
update = altair.LightClientUpdate(
|
2022-05-23 12:02:54 +00:00
|
|
|
attested_header: attested_header,
|
2022-02-28 19:58:32 +00:00
|
|
|
next_sync_committee: next_sync_committee,
|
|
|
|
next_sync_committee_branch: next_sync_committee_branch,
|
|
|
|
finalized_header: finality_header,
|
|
|
|
finality_branch: finality_branch,
|
|
|
|
sync_aggregate: sync_aggregate,
|
2022-05-23 12:02:54 +00:00
|
|
|
signature_slot: signature_slot)
|
|
|
|
|
|
|
|
pre_store_finalized_header = store.finalized_header
|
|
|
|
|
2022-02-28 19:58:32 +00:00
|
|
|
res = process_light_client_update(
|
2022-03-04 16:09:33 +00:00
|
|
|
store, update, signature_slot, cfg, state.genesis_validators_root)
|
2021-09-13 16:35:13 +00:00
|
|
|
|
2022-02-28 19:58:32 +00:00
|
|
|
check:
|
2022-03-14 09:25:54 +00:00
|
|
|
res.isOk
|
2022-01-03 13:06:14 +00:00
|
|
|
store.finalized_header == pre_store_finalized_header
|
|
|
|
store.best_valid_update.get == update
|
2022-05-23 12:02:54 +00:00
|
|
|
store.optimistic_header == update.attested_header
|
|
|
|
store.current_max_active_participants > 0
|
2021-09-13 16:35:13 +00:00
|
|
|
|
2022-05-23 12:02:54 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/vFuture/tests/core/pyspec/eth2spec/test/altair/unittests/test_sync_protocol.py#L70-L116
|
2022-03-08 12:21:56 +00:00
|
|
|
test "test_process_light_client_update_at_period_boundary":
|
|
|
|
var forked = assignClone(genesisState[])
|
2022-05-23 12:02:54 +00:00
|
|
|
template state(): auto = forked[].altairData.data
|
2022-03-08 12:21:56 +00:00
|
|
|
var store = initialize_light_client_store(state)
|
|
|
|
|
2022-05-23 12:02:54 +00:00
|
|
|
# Forward to slot before next sync committee period so that next block is
|
|
|
|
# final one in period
|
2022-03-08 12:21:56 +00:00
|
|
|
var
|
2022-05-23 12:02:54 +00:00
|
|
|
cache: StateCache
|
|
|
|
info: ForkedEpochInfo
|
2022-03-08 12:21:56 +00:00
|
|
|
process_slots(
|
2022-05-23 12:02:54 +00:00
|
|
|
cfg, forked[], Slot(UPDATE_TIMEOUT - 2), cache, info, flags = {}
|
|
|
|
).expect("no failure")
|
2022-03-08 12:21:56 +00:00
|
|
|
let
|
2022-05-23 12:02:54 +00:00
|
|
|
store_period = sync_committee_period(store.optimistic_header.slot)
|
2022-03-08 12:21:56 +00:00
|
|
|
update_period = sync_committee_period(state.slot)
|
2022-05-23 12:02:54 +00:00
|
|
|
check: store_period == update_period
|
2022-03-08 12:21:56 +00:00
|
|
|
|
|
|
|
let
|
2022-05-23 12:02:54 +00:00
|
|
|
attested_block = block_for_next_slot(cfg, forked[], cache).altairData
|
|
|
|
attested_header = attested_block.toBeaconBlockHeader
|
|
|
|
|
|
|
|
# Sync committee signing the attested_header
|
|
|
|
(sync_aggregate, signature_slot) = get_sync_aggregate(cfg, forked[])
|
2022-03-08 12:21:56 +00:00
|
|
|
next_sync_committee = SyncCommittee()
|
2022-05-23 12:02:54 +00:00
|
|
|
next_sync_committee_branch =
|
|
|
|
default(array[log2trunc(altair.NEXT_SYNC_COMMITTEE_INDEX), Eth2Digest])
|
|
|
|
|
2022-03-08 12:21:56 +00:00
|
|
|
# Finality is unchanged
|
|
|
|
let
|
|
|
|
finality_header = BeaconBlockHeader()
|
2022-05-23 12:02:54 +00:00
|
|
|
finality_branch =
|
|
|
|
default(array[log2trunc(altair.FINALIZED_ROOT_INDEX), Eth2Digest])
|
2022-03-08 12:21:56 +00:00
|
|
|
|
|
|
|
update = altair.LightClientUpdate(
|
2022-05-23 12:02:54 +00:00
|
|
|
attested_header: attested_header,
|
2022-03-08 12:21:56 +00:00
|
|
|
next_sync_committee: next_sync_committee,
|
|
|
|
next_sync_committee_branch: next_sync_committee_branch,
|
|
|
|
finalized_header: finality_header,
|
|
|
|
finality_branch: finality_branch,
|
|
|
|
sync_aggregate: sync_aggregate,
|
2022-05-23 12:02:54 +00:00
|
|
|
signature_slot: signature_slot)
|
|
|
|
|
|
|
|
pre_store_finalized_header = store.finalized_header
|
|
|
|
|
2022-03-08 12:21:56 +00:00
|
|
|
res = process_light_client_update(
|
|
|
|
store, update, signature_slot, cfg, state.genesis_validators_root)
|
|
|
|
|
|
|
|
check:
|
2022-03-14 09:25:54 +00:00
|
|
|
res.isOk
|
2022-03-08 12:21:56 +00:00
|
|
|
store.finalized_header == pre_store_finalized_header
|
|
|
|
store.best_valid_update.get == update
|
2022-05-23 12:02:54 +00:00
|
|
|
store.optimistic_header == update.attested_header
|
|
|
|
store.current_max_active_participants > 0
|
2022-03-08 12:21:56 +00:00
|
|
|
|
2022-05-23 12:02:54 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/vFuture/tests/core/pyspec/eth2spec/test/altair/unittests/test_sync_protocol.py#L119-L166
|
2021-09-13 16:35:13 +00:00
|
|
|
test "process_light_client_update_timeout":
|
2022-02-20 20:13:06 +00:00
|
|
|
let forked = assignClone(genesisState[])
|
2022-05-23 12:02:54 +00:00
|
|
|
template state(): auto = forked[].altairData.data
|
2022-01-03 13:06:14 +00:00
|
|
|
var store = initialize_light_client_store(state)
|
2021-09-13 16:35:13 +00:00
|
|
|
|
|
|
|
# Forward to next sync committee period
|
|
|
|
var
|
2022-05-23 12:02:54 +00:00
|
|
|
cache: StateCache
|
|
|
|
info: ForkedEpochInfo
|
2022-01-17 11:19:58 +00:00
|
|
|
process_slots(
|
2022-05-23 12:02:54 +00:00
|
|
|
cfg, forked[], Slot(UPDATE_TIMEOUT), cache, info, flags = {}
|
|
|
|
).expect("no failure")
|
2021-09-13 16:35:13 +00:00
|
|
|
let
|
2022-05-23 12:02:54 +00:00
|
|
|
store_period = sync_committee_period(store.optimistic_header.slot)
|
2021-11-02 20:32:34 +00:00
|
|
|
update_period = sync_committee_period(state.slot)
|
2022-05-23 12:02:54 +00:00
|
|
|
check: store_period + 1 == update_period
|
2021-09-13 16:35:13 +00:00
|
|
|
|
|
|
|
let
|
2022-05-23 12:02:54 +00:00
|
|
|
attested_block = block_for_next_slot(cfg, forked[], cache).altairData
|
|
|
|
attested_header = attested_block.toBeaconBlockHeader
|
|
|
|
|
|
|
|
# Sync committee signing the attested_header
|
|
|
|
(sync_aggregate, signature_slot) = get_sync_aggregate(cfg, forked[])
|
2021-10-13 14:24:36 +00:00
|
|
|
|
2021-09-13 16:35:13 +00:00
|
|
|
# Sync committee is updated
|
2022-02-28 19:58:32 +00:00
|
|
|
template next_sync_committee(): auto = state.next_sync_committee
|
2021-10-13 14:24:36 +00:00
|
|
|
var next_sync_committee_branch {.noinit.}:
|
2022-02-28 19:58:32 +00:00
|
|
|
array[log2trunc(altair.NEXT_SYNC_COMMITTEE_INDEX), Eth2Digest]
|
|
|
|
state.build_proof(
|
|
|
|
altair.NEXT_SYNC_COMMITTEE_INDEX, next_sync_committee_branch)
|
|
|
|
|
2022-05-23 12:02:54 +00:00
|
|
|
# Finality is unchanged
|
2022-01-03 13:06:14 +00:00
|
|
|
let
|
2022-05-23 12:02:54 +00:00
|
|
|
finality_header = BeaconBlockHeader()
|
|
|
|
finality_branch =
|
|
|
|
default(array[log2trunc(altair.FINALIZED_ROOT_INDEX), Eth2Digest])
|
|
|
|
|
2022-02-28 19:58:32 +00:00
|
|
|
update = altair.LightClientUpdate(
|
2022-05-23 12:02:54 +00:00
|
|
|
attested_header: attested_header,
|
2022-02-28 19:58:32 +00:00
|
|
|
next_sync_committee: next_sync_committee,
|
|
|
|
next_sync_committee_branch: next_sync_committee_branch,
|
|
|
|
finalized_header: finality_header,
|
|
|
|
finality_branch: finality_branch,
|
|
|
|
sync_aggregate: sync_aggregate,
|
2022-05-23 12:02:54 +00:00
|
|
|
signature_slot: signature_slot)
|
|
|
|
|
|
|
|
pre_store_finalized_header = store.finalized_header
|
|
|
|
|
2022-02-28 19:58:32 +00:00
|
|
|
res = process_light_client_update(
|
2022-03-04 16:09:33 +00:00
|
|
|
store, update, signature_slot, cfg, state.genesis_validators_root)
|
2021-09-13 16:35:13 +00:00
|
|
|
|
2022-02-28 19:58:32 +00:00
|
|
|
check:
|
2022-03-14 09:25:54 +00:00
|
|
|
res.isOk
|
2022-05-23 12:02:54 +00:00
|
|
|
store.finalized_header == pre_store_finalized_header
|
|
|
|
store.best_valid_update.get == update
|
2022-01-03 13:06:14 +00:00
|
|
|
store.optimistic_header == update.attested_header
|
2022-05-23 12:02:54 +00:00
|
|
|
store.current_max_active_participants > 0
|
2021-09-13 16:35:13 +00:00
|
|
|
|
2022-05-23 12:02:54 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/vFuture/tests/core/pyspec/eth2spec/test/altair/unittests/test_sync_protocol.py#L169-L223
|
2021-09-13 16:35:13 +00:00
|
|
|
test "process_light_client_update_finality_updated":
|
2022-02-20 20:13:06 +00:00
|
|
|
let forked = assignClone(genesisState[])
|
2022-05-23 12:02:54 +00:00
|
|
|
template state(): auto = forked[].altairData.data
|
2022-01-03 13:06:14 +00:00
|
|
|
var store = initialize_light_client_store(state)
|
2021-09-13 16:35:13 +00:00
|
|
|
|
|
|
|
# Change finality
|
2021-10-13 14:24:36 +00:00
|
|
|
var
|
2022-05-23 12:02:54 +00:00
|
|
|
cache: StateCache
|
|
|
|
info: ForkedEpochInfo
|
2021-09-13 16:35:13 +00:00
|
|
|
blocks = newSeq[ForkedSignedBeaconBlock]()
|
2022-01-17 11:19:58 +00:00
|
|
|
process_slots(
|
|
|
|
cfg, forked[], Slot(SLOTS_PER_EPOCH * 2), cache, info, flags = {}).expect("no failure")
|
2022-05-23 12:02:54 +00:00
|
|
|
for slot in 0 ..< 3 * SLOTS_PER_EPOCH:
|
2022-02-28 19:58:32 +00:00
|
|
|
blocks.add block_for_next_slot(cfg, forked[], cache,
|
|
|
|
withAttestations = true)
|
2021-09-13 16:35:13 +00:00
|
|
|
# Ensure that finality checkpoint has changed
|
|
|
|
check: state.finalized_checkpoint.epoch == 3
|
|
|
|
# Ensure that it's same period
|
|
|
|
let
|
2022-05-23 12:02:54 +00:00
|
|
|
store_period = sync_committee_period(store.optimistic_header.slot)
|
2022-01-11 10:01:54 +00:00
|
|
|
update_period = sync_committee_period(state.slot)
|
2022-05-23 12:02:54 +00:00
|
|
|
check: store_period == update_period
|
2021-09-13 16:35:13 +00:00
|
|
|
|
|
|
|
let
|
2022-05-23 12:02:54 +00:00
|
|
|
attested_block = blocks[^1].altairData
|
|
|
|
attested_header = attested_block.toBeaconBlockHeader
|
|
|
|
|
|
|
|
# Sync committee signing the attested_header
|
|
|
|
(sync_aggregate, signature_slot) = get_sync_aggregate(cfg, forked[])
|
|
|
|
|
|
|
|
# Updated sync_committee and finality
|
|
|
|
next_sync_committee = SyncCommittee()
|
|
|
|
next_sync_committee_branch =
|
|
|
|
default(array[log2trunc(altair.NEXT_SYNC_COMMITTEE_INDEX), Eth2Digest])
|
2021-10-18 16:37:27 +00:00
|
|
|
finalized_block = blocks[SLOTS_PER_EPOCH - 1].altairData
|
2022-05-23 12:02:54 +00:00
|
|
|
finalized_header = finalized_block.toBeaconBlockHeader
|
2021-10-13 14:24:36 +00:00
|
|
|
check:
|
2022-05-23 12:02:54 +00:00
|
|
|
finalized_header.slot == start_slot(state.finalized_checkpoint.epoch)
|
|
|
|
finalized_header.hash_tree_root() == state.finalized_checkpoint.root
|
2021-10-13 14:24:36 +00:00
|
|
|
var finality_branch {.noinit.}:
|
2022-02-28 19:58:32 +00:00
|
|
|
array[log2trunc(altair.FINALIZED_ROOT_INDEX), Eth2Digest]
|
|
|
|
state.build_proof(
|
|
|
|
altair.FINALIZED_ROOT_INDEX, finality_branch)
|
2021-10-13 14:24:36 +00:00
|
|
|
|
|
|
|
let
|
2022-02-28 19:58:32 +00:00
|
|
|
update = altair.LightClientUpdate(
|
2022-05-23 12:02:54 +00:00
|
|
|
attested_header: attested_header,
|
2022-02-28 19:58:32 +00:00
|
|
|
next_sync_committee: next_sync_committee,
|
2021-09-13 16:35:13 +00:00
|
|
|
next_sync_committee_branch: next_sync_committee_branch,
|
2022-05-23 12:02:54 +00:00
|
|
|
finalized_header: finalized_header,
|
2021-09-13 16:35:13 +00:00
|
|
|
finality_branch: finality_branch,
|
2022-02-01 07:31:53 +00:00
|
|
|
sync_aggregate: sync_aggregate,
|
2022-05-23 12:02:54 +00:00
|
|
|
signature_slot: signature_slot)
|
|
|
|
|
2022-02-28 19:58:32 +00:00
|
|
|
res = process_light_client_update(
|
2022-03-04 16:09:33 +00:00
|
|
|
store, update, signature_slot, cfg, state.genesis_validators_root)
|
2021-09-13 16:35:13 +00:00
|
|
|
|
2022-02-28 19:58:32 +00:00
|
|
|
check:
|
2022-03-14 09:25:54 +00:00
|
|
|
res.isOk
|
2022-01-03 13:06:14 +00:00
|
|
|
store.finalized_header == update.finalized_header
|
|
|
|
store.best_valid_update.isNone
|
2022-05-23 12:02:54 +00:00
|
|
|
store.optimistic_header == update.attested_header
|
|
|
|
store.current_max_active_participants > 0
|