Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Reject finalized updates without a sync committee in next store period (
Browse files Browse the repository at this point in the history
#145)

* sync committee handover fix

* remove comment

* Update bridges/snowbridge/pallets/ethereum-client/src/lib.rs

Co-authored-by: Vincent Geddes <[email protected]>

* add extra check

* move checks around

* remove extra validation

* fix compiler error

* reject updates in next period without sync committee

* fix test

* polish

* Update bridges/snowbridge/pallets/ethereum-client/src/lib.rs

Co-authored-by: Vincent Geddes <[email protected]>

---------

Co-authored-by: Vincent Geddes <[email protected]>
  • Loading branch information
claravanstaden and vgeddes authored May 16, 2024
1 parent 3f495e5 commit d95751b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 7 additions & 0 deletions bridges/snowbridge/pallets/ethereum-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub mod pallet {
#[pallet::error]
pub enum Error<T> {
SkippedSyncCommitteePeriod,
SyncCommitteeUpdateRequired,
/// Attested header is older than latest finalized header.
IrrelevantUpdate,
NotBootstrapped,
Expand Down Expand Up @@ -320,6 +321,7 @@ pub mod pallet {

// Verify update is relevant.
let update_attested_period = compute_period(update.attested_header.slot);
let update_finalized_period = compute_period(update.finalized_header.slot);
let update_has_next_sync_committee = !<NextSyncCommittee<T>>::exists() &&
(update.next_sync_committee_update.is_some() &&
update_attested_period == store_period);
Expand Down Expand Up @@ -395,6 +397,11 @@ pub mod pallet {
),
Error::<T>::InvalidSyncCommitteeMerkleProof
);
} else {
ensure!(
update_finalized_period == store_period,
Error::<T>::SyncCommitteeUpdateRequired
);
}

// Verify sync committee aggregate signature.
Expand Down
16 changes: 13 additions & 3 deletions bridges/snowbridge/pallets/ethereum-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,23 +362,33 @@ fn submit_update_with_sync_committee_in_current_period() {
}

#[test]
fn submit_update_in_next_period() {
fn reject_submit_update_in_next_period() {
let checkpoint = Box::new(load_checkpoint_update_fixture());
let sync_committee_update = Box::new(load_sync_committee_update_fixture());
let update = Box::new(load_next_finalized_header_update_fixture());
let sync_committee_period = compute_period(sync_committee_update.finalized_header.slot);
let next_sync_committee_period = compute_period(update.finalized_header.slot);
assert_eq!(sync_committee_period + 1, next_sync_committee_period);
let next_sync_committee_update = Box::new(load_next_sync_committee_update_fixture());

new_tester().execute_with(|| {
assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint));
assert_ok!(EthereumBeaconClient::submit(
RuntimeOrigin::signed(1),
sync_committee_update.clone()
));
// check an update in the next period is rejected
assert_err!(
EthereumBeaconClient::submit(RuntimeOrigin::signed(1), update.clone()),
Error::<Test>::SyncCommitteeUpdateRequired
);
// submit update with next sync committee
assert_ok!(EthereumBeaconClient::submit(
RuntimeOrigin::signed(1),
next_sync_committee_update
));
// check same header in the next period can now be submitted successfully
assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), update.clone()));
let block_root: H256 = update.finalized_header.clone().hash_tree_root().unwrap();
assert!(<FinalizedBeaconState<Test>>::contains_key(block_root));
});
}

Expand Down

0 comments on commit d95751b

Please sign in to comment.