Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement SBliFF #255

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions sidechain/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ benchmarks! {
add_enclaves_to_registry::<T>(&accounts);

let shard: ShardIdentifier = H256::from_slice(&TEST4_SETUP.mrenclave);
let hash: H256 = [2; 32].into();
let block_number = 1;
let next_finalization_candidate_block_number = 20;
}: _(RawOrigin::Signed(accounts[0].clone()), shard, block_number, next_finalization_candidate_block_number, hash)
let ancestor = SidechainBlockConfirmation {
block_number: 2,
block_header_hash: [2; 32].into()
};
let candidate = SidechainBlockConfirmation {
block_number: 25,
block_header_hash: [25; 32].into()
};
}: _(RawOrigin::Signed(accounts[0].clone()), shard, Some(ancestor), candidate)
verify {
assert_latest_worker_update::<T>(&accounts[0], &shard)
}
Expand Down
45 changes: 29 additions & 16 deletions sidechain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ pub mod pallet {

#[pallet::error]
pub enum Error<T> {
/// A proposed block is unexpected.
ReceivedUnexpectedSidechainBlock,
/// The value for the next finalization candidate is invalid.
InvalidNextFinalizationCandidateBlockNumber,
/// A proposed finalization candidate block is outdated
FinalizationCandidateIsOutdated,
/// The provided last finalized ancestor block number doesn't match.
/// This can mean a fork happened or the sender validateer is not up to date with L1
AncestorNumberMismatch,
/// The provided last finalized ancestor block hash doesn't match.
/// This can mean a fork happened or the sender validateer is not up to date with L1
AncestorHashMismatch,
/// sender hasn't provided an ancestor although an ancestor has been finalized
AncestorMissing,
}

#[pallet::storage]
Expand All @@ -87,9 +93,8 @@ pub mod pallet {
pub fn confirm_imported_sidechain_block(
origin: OriginFor<T>,
shard: ShardIdentifier,
block_number: u64,
_next_finalization_candidate_block_number: u64, //fixme: can be removed next time we introduce breaking changes
block_header_hash: H256,
latest_finalized_ancestor: Option<SidechainBlockConfirmation>,
finalization_candidate: SidechainBlockConfirmation,
) -> DispatchResultWithPostInfo {
let sender = ensure_signed(origin)?;
let (_enclave, shard_status) =
Expand All @@ -100,25 +105,33 @@ pub mod pallet {
)?;

// TODO: Simple but robust logic for now:
// accept all blocks from first registered enclave for shard as long as blocknumber monotonically increases.
// https://github.com/integritee-network/pallets/issues/254
// accept only blocks from first validateer in shard_status
if sender != shard_status[0].signer {
log::debug!(
"Ignore block confirmation from registered enclave with index > 1: {:?}",
sender
);
return Ok(().into())
}
if let Some(ancestor) = Self::latest_sidechain_block_confirmation(shard) {

if let Some(known_ancestor) = Self::latest_sidechain_block_confirmation(shard) {
let provided_ancestor =
latest_finalized_ancestor.ok_or(Error::<T>::AncestorMissing)?;
ensure!(
finalization_candidate.block_number > known_ancestor.block_number,
<Error<T>>::FinalizationCandidateIsOutdated
);
ensure!(
known_ancestor.block_number == provided_ancestor.block_number,
<Error<T>>::AncestorNumberMismatch
);
ensure!(
ancestor.block_number < block_number,
<Error<T>>::ReceivedUnexpectedSidechainBlock
known_ancestor.block_header_hash == provided_ancestor.block_header_hash,
<Error<T>>::AncestorHashMismatch
);
}
Self::finalize_block(
shard,
SidechainBlockConfirmation { block_number, block_header_hash },
&sender,
);
Self::finalize_block(shard, finalization_candidate, &sender);
Ok(().into())
}
}
Expand Down
Loading
Loading