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

Bound finalized header, execution header and sync committee by RingBuffer and BoundedVec #815

Merged
merged 8 commits into from
May 10, 2023
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
2 changes: 1 addition & 1 deletion cumulus
1 change: 1 addition & 0 deletions parachain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions parachain/pallets/ethereum-beacon-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ primitives = { package = "snowbridge-beacon-primitives", path = "../../primitive
static_assertions = { version = "1.1.0" }

[dev-dependencies]
rand = "0.8.5"
sp-keyring = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
snowbridge-testutils = { path = "../../primitives/testutils" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ benchmarks! {
unblock_bridge {
}: _(RawOrigin::Root)
verify {
assert_eq!(<Blocked<T>>::get(),false);
assert!(!<Blocked<T>>::get());
}

bls_fast_aggregate_verify_pre_aggregated {
Expand All @@ -103,7 +103,7 @@ benchmarks! {
let agg_sig = prepare_aggregate_signature(&update.sync_aggregate.sync_committee_signature).unwrap();
let agg_pub_key = prepare_aggregate_pubkey(&participant_pubkeys).unwrap();
}:{
agg_sig.fast_aggregate_verify_pre_aggregated(&signing_root.as_bytes(), &agg_pub_key)
agg_sig.fast_aggregate_verify_pre_aggregated(signing_root.as_bytes(), &agg_pub_key)
}

bls_fast_aggregate_verify_legacy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ pub fn participant_pubkeys<T: Config>(
update: &SyncCommitteeUpdate,
) -> Result<Vec<PublicKeyPrepared>, &'static str> {
let sync_committee_bits =
decompress_sync_committee_bits(update.sync_aggregate.sync_committee_bits.clone());
decompress_sync_committee_bits(update.sync_aggregate.sync_committee_bits);
let current_sync_committee = sync_committee::<T>(update)?;
let pubkeys = EthereumBeaconClient::<T>::find_pubkeys(
&sync_committee_bits,
&current_sync_committee.pubkeys.to_vec(),
&current_sync_committee.pubkeys.as_ref(),
true,
);
Ok(pubkeys)
Expand All @@ -56,11 +56,11 @@ pub fn absent_pubkeys<T: Config>(
update: &SyncCommitteeUpdate,
) -> Result<Vec<PublicKeyPrepared>, &'static str> {
let sync_committee_bits =
decompress_sync_committee_bits(update.sync_aggregate.sync_committee_bits.clone());
decompress_sync_committee_bits(update.sync_aggregate.sync_committee_bits);
let current_sync_committee = sync_committee::<T>(update)?;
let pubkeys = EthereumBeaconClient::<T>::find_pubkeys(
&sync_committee_bits,
&current_sync_committee.pubkeys.to_vec(),
&current_sync_committee.pubkeys.as_ref(),
false,
);
Ok(pubkeys)
Expand All @@ -69,7 +69,7 @@ pub fn absent_pubkeys<T: Config>(
pub fn signing_root<T: Config>(update: &SyncCommitteeUpdate) -> Result<H256, &'static str> {
let validators_root = <ValidatorsRoot<T>>::get();
let signing_root = EthereumBeaconClient::<T>::signing_root(
update.attested_header.clone(),
update.attested_header,
validators_root,
update.signature_slot,
)?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub const SLOTS_PER_EPOCH: u64 = 32;
pub const SECONDS_PER_SLOT: u64 = 12;
pub const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: u64 = 256;
pub const SLOTS_PER_EPOCH: usize = 32;
pub const SECONDS_PER_SLOT: usize = 12;
pub const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: usize = 256;
pub const SYNC_COMMITTEE_SIZE: usize = 512;
pub const SYNC_COMMITTEE_BITS_SIZE: usize = SYNC_COMMITTEE_SIZE / 8;
pub const SLOTS_PER_HISTORICAL_ROOT: usize = 8192;
pub const IS_MINIMAL: bool = false;
pub const BLOCK_ROOT_AT_INDEX_PROOF_DEPTH: u64 = 13;
pub const BLOCK_ROOT_AT_INDEX_PROOF_DEPTH: usize = 13;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub const SLOTS_PER_EPOCH: u64 = 8;
pub const SECONDS_PER_SLOT: u64 = 6;
pub const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: u64 = 8;
pub const SLOTS_PER_EPOCH: usize = 8;
pub const SECONDS_PER_SLOT: usize = 6;
pub const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: usize = 8;
pub const SYNC_COMMITTEE_SIZE: usize = 32;
pub const SYNC_COMMITTEE_BITS_SIZE: usize = SYNC_COMMITTEE_SIZE / 8;
pub const SLOTS_PER_HISTORICAL_ROOT: usize = 64;
pub const IS_MINIMAL: bool = true;
pub const BLOCK_ROOT_AT_INDEX_PROOF_DEPTH: u64 = 6;
pub const BLOCK_ROOT_AT_INDEX_PROOF_DEPTH: usize = 6;
21 changes: 10 additions & 11 deletions parachain/pallets/ethereum-beacon-client/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@ pub use minimal::*;
#[cfg(not(feature = "minimal"))]
pub use mainnet::*;

pub const CURRENT_SYNC_COMMITTEE_INDEX: u64 = 22;
pub const NEXT_SYNC_COMMITTEE_INDEX: u64 = 23;
pub const SYNC_COMMITTEE_DEPTH: u64 = 5;
pub const CURRENT_SYNC_COMMITTEE_INDEX: usize = 22;
pub const NEXT_SYNC_COMMITTEE_INDEX: usize = 23;
pub const SYNC_COMMITTEE_DEPTH: usize = 5;

pub const FINALIZED_ROOT_DEPTH: u64 = 6;
pub const FINALIZED_ROOT_INDEX: u64 = 41;
pub const FINALIZED_ROOT_DEPTH: usize = 6;
pub const FINALIZED_ROOT_INDEX: usize = 41;

pub const BLOCK_ROOTS_DEPTH: u64 = 5;
pub const BLOCK_ROOTS_INDEX: u64 = 5;
pub const BLOCK_ROOTS_DEPTH: usize = 5;
pub const BLOCK_ROOTS_INDEX: usize = 5;

pub const EXECUTION_HEADER_DEPTH: u64 = 4;
pub const EXECUTION_HEADER_INDEX: u64 = 9;
pub const EXECUTION_HEADER_DEPTH: usize = 4;
pub const EXECUTION_HEADER_INDEX: usize = 9;

pub const MAX_EXTRA_DATA_BYTES: usize = 32;
pub const MAX_LOGS_BLOOM_SIZE: usize = 256;
pub const MAX_FEE_RECIPIENT_SIZE: usize = 20;

pub const MAX_FINALIZED_HEADER_SLOT_ARRAY: u32 = 1000;
pub const MAX_BRANCH_PROOF_SIZE: u32 = 20;
pub const MAX_BRANCH_PROOF_SIZE: usize = 20;

/// DomainType('0x07000000')
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/beacon-chain.md#domain-types
Expand Down
Loading