Skip to content

Commit

Permalink
upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden authored and claravanstaden committed Dec 15, 2023
1 parent c03175b commit 932745f
Show file tree
Hide file tree
Showing 37 changed files with 400 additions and 314 deletions.
78 changes: 43 additions & 35 deletions parachain/pallets/ethereum-beacon-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
serde = { version = "1.0.188", optional = true }
serde_json = { version = "1.0.96", optional = true }
codec = { version = "3.6.1", package = "parity-scale-codec", default-features = false, features = [ "derive" ] }
scale-info = { version = "2.9.0", default-features = false, features = [ "derive" ] }
ssz_rs = { version="0.9.0", default-features = false }
ssz_rs_derive = { version="0.9.0", default-features = false }
codec = { version = "3.6.1", package = "parity-scale-codec", default-features = false, features = ["derive"] }
scale-info = { version = "2.9.0", default-features = false, features = ["derive"] }
ssz_rs = { version = "0.9.0", default-features = false }
ssz_rs_derive = { version = "0.9.0", default-features = false }
byte-slice-cast = { version = "1.2.1", default-features = false }
rlp = { version = "0.5.2", default-features = false }
hex-literal = { version = "0.4.1", optional = true }
Expand Down Expand Up @@ -49,40 +49,48 @@ serde = "1.0.188"
[features]
default = ["std"]
fuzzing = [
"sp-io",
"pallet-timestamp",
"serde",
"serde_json",
"hex-literal"
"hex-literal",
"pallet-timestamp",
"serde",
"serde_json",
"sp-io",
]
std = [
"serde",
"codec/std",
"scale-info/std",
"frame-support/std",
"frame-system/std",
'frame-benchmarking/std',
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
"sp-io/std",
"snowbridge-core/std",
"snowbridge-ethereum/std",
"primitives/std",
"ssz_rs/std",
"byte-slice-cast/std",
"bp-runtime/std",
"byte-slice-cast/std",
"rlp/std",
"log/std",
"pallet-timestamp/std",
"bp-runtime/std",
"byte-slice-cast/std",
"byte-slice-cast/std",
"codec/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-timestamp/std",
"primitives/std",
"rlp/std",
"scale-info/std",
"serde",
"snowbridge-core/std",
"snowbridge-ethereum/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"ssz_rs/std",
'frame-benchmarking/std',
]
runtime-benchmarks = [
"beacon-spec-mainnet",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex-literal",
"snowbridge-core/runtime-benchmarks",
"beacon-spec-mainnet",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex-literal",
"pallet-timestamp?/runtime-benchmarks",
"snowbridge-core/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-timestamp?/try-runtime",
"sp-runtime/try-runtime",
]
beacon-spec-mainnet = []
6 changes: 3 additions & 3 deletions parachain/pallets/ethereum-beacon-client/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ edition = "2021"
cargo-fuzz = true

[dependencies]
libfuzzer-sys = { version = "0.4", features = [ "arbitrary-derive" ]}
libfuzzer-sys = { version = "0.4", features = ["arbitrary-derive"] }
arbitrary = { version = "1", optional = true, features = ["derive"] }
snowbridge-ethereum-beacon-client = {path = "..", features = [ "fuzzing" ]}
snowbridge-beacon-primitives= {path = "../../../primitives/beacon"}
snowbridge-ethereum-beacon-client = { path = "..", features = ["fuzzing"] }
snowbridge-beacon-primitives = { path = "../../../primitives/beacon" }
hex-literal = "0.4.1"
sp-core = { path = "../../../../polkadot-sdk/substrate/primitives/core", default-features = false }

Expand Down
2 changes: 1 addition & 1 deletion parachain/pallets/ethereum-beacon-client/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub const MAX_FEE_RECIPIENT_SIZE: usize = 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
/// <https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/beacon-chain.md#domain-types>
pub const DOMAIN_SYNC_COMMITTEE: [u8; 4] = [7, 0, 0, 0];

pub const PUBKEY_SIZE: usize = 48;
Expand Down
12 changes: 6 additions & 6 deletions parachain/pallets/ethereum-beacon-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ pub mod pallet {
Ok(())
}

/// References and strictly follows https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#validate_light_client_update
/// References and strictly follows <https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#validate_light_client_update>
/// Verifies that provided next sync committee is valid through a series of checks
/// (including checking that a sync committee period isn't skipped and that the header is
/// signed by the current sync committee.
Expand Down Expand Up @@ -468,7 +468,7 @@ pub mod pallet {
Self::validators_root(),
update.signature_slot,
)?;
// Improvement here per https://eth2book.info/capella/part2/building_blocks/signatures/#sync-aggregates
// Improvement here per <https://eth2book.info/capella/part2/building_blocks/signatures/#sync-aggregates>
// suggested start from the full set aggregate_pubkey then subtracting the absolute
// minority that did not participate.
fast_aggregate_verify(
Expand All @@ -482,7 +482,7 @@ pub mod pallet {
Ok(())
}

/// Reference and strictly follows https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#apply_light_client_update
/// Reference and strictly follows <https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#apply_light_client_update
/// Applies a finalized beacon header update to the beacon client. If a next sync committee
/// is present in the update, verify the sync committee by converting it to a
/// SyncCommitteePrepared type. Stores the provided finalized header.
Expand Down Expand Up @@ -722,16 +722,16 @@ pub mod pallet {
/// Stores the validators root in storage. Validators root is the hash tree root of all the
/// validators at genesis and is used to used to identify the chain that we are on
/// (used in conjunction with the fork version).
/// https://eth2book.info/capella/part3/containers/state/#genesis_validators_root
/// <https://eth2book.info/capella/part3/containers/state/#genesis_validators_root>
fn store_validators_root(validators_root: H256) {
<ValidatorsRoot<T>>::set(validators_root);
}

/// Returns the domain for the domain_type and fork_version. The domain is used to
/// distinguish between the different players in the chain (see DomainTypes
/// https://eth2book.info/capella/part3/config/constants/#domain-types) and to ensure we are
/// <https://eth2book.info/capella/part3/config/constants/#domain-types>) and to ensure we are
/// addressing the correct chain.
/// https://eth2book.info/capella/part3/helper/misc/#compute_domain
/// <https://eth2book.info/capella/part3/helper/misc/#compute_domain>
pub(super) fn compute_domain(
domain_type: Vec<u8>,
fork_version: ForkVersion,
Expand Down
2 changes: 2 additions & 0 deletions parachain/pallets/ethereum-beacon-client/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub mod minimal {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeTask = RuntimeTask;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
Expand Down Expand Up @@ -209,6 +210,7 @@ pub mod mainnet {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeTask = RuntimeTask;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
Expand Down
72 changes: 42 additions & 30 deletions parachain/pallets/inbound-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
serde = { version = "1.0.188", optional = true }
codec = { version = "3.6.1", package = "parity-scale-codec", default-features = false, features = [ "derive" ] }
scale-info = { version = "2.9.0", default-features = false, features = [ "derive" ] }
codec = { version = "3.6.1", package = "parity-scale-codec", default-features = false, features = ["derive"] }
scale-info = { version = "2.9.0", default-features = false, features = ["derive"] }
hex-literal = { version = "0.4.1", optional = true }
log = { version = "0.4.20", default-features = false }
alloy-primitives = { version = "0.4.2", default-features = false, features = ["rlp"] }
Expand Down Expand Up @@ -47,34 +47,46 @@ hex-literal = { version = "0.4.1" }
[features]
default = ["std"]
std = [
"serde",
"log/std",
"codec/std",
"scale-info/std",
"alloy-primitives/std",
"alloy-sol-types/std",
"alloy-rlp/std",
"frame-support/std",
"frame-system/std",
"pallet-balances/std",
"frame-benchmarking/std",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
"sp-io/std",
"num-traits/std",
"snowbridge-core/std",
"snowbridge-ethereum/std",
"snowbridge-router-primitives/std",
"xcm/std",
"xcm-builder/std",
"alloy-primitives/std",
"alloy-rlp/std",
"alloy-sol-types/std",
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"log/std",
"num-traits/std",
"pallet-balances/std",
"scale-info/std",
"serde",
"snowbridge-core/std",
"snowbridge-ethereum/std",
"snowbridge-router-primitives/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"xcm-builder/std",
"xcm/std",
]
runtime-benchmarks = [
"snowbridge-core/runtime-benchmarks",
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex-literal",
"snowbridge-beacon-primitives",
"xcm-builder/runtime-benchmarks",
"frame-benchmarking",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex-literal",
"pallet-balances/runtime-benchmarks",
"snowbridge-beacon-primitives",
"snowbridge-core/runtime-benchmarks",
"snowbridge-ethereum-beacon-client/runtime-benchmarks",
"snowbridge-router-primitives/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-balances/try-runtime",
"snowbridge-ethereum-beacon-client/try-runtime",
"sp-runtime/try-runtime",
]
6 changes: 3 additions & 3 deletions parachain/pallets/inbound-queue/src/benchmarking/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use snowbridge_core::inbound::{Log, Message, Proof};
use sp_std::vec;

pub struct InboundQueueTest {
pub execution_header: CompactExecutionHeader,
pub message: Message,
pub execution_header: CompactExecutionHeader,
pub message: Message,
}

pub fn make_create_message() -> InboundQueueTest {
InboundQueueTest{
InboundQueueTest{
execution_header: CompactExecutionHeader{
parent_hash: hex!("b5608f0af7c3b6fe5c593772fc25436b8d6549eb236adb0855c6ad33e0004e04").into(),
block_number: 115,
Expand Down
19 changes: 6 additions & 13 deletions parachain/pallets/inbound-queue/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use super::*;
use crate::Pallet as InboundQueue;
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
use sp_std::vec;

#[benchmarks]
mod benchmarks {
Expand All @@ -28,23 +27,17 @@ mod benchmarks {
let sovereign_account = sibling_sovereign_account::<T>(1000u32.into());

let minimum_balance = T::Token::minimum_balance();
let minimum_balance_u32: u32 = minimum_balance
.try_into()
.unwrap_or_else(|_| panic!("unable to cast minimum balance to u32"));

// Make sure the sovereign balance is enough. This is a funny number, because
// in some cases the minimum balance is really high, in other cases very low.
// e.g. on bridgehub the minimum balance is 33333, on test it is 1. So this equation makes
// it is at least twice the minimum balance (so as to satisfy the minimum balance
// requirement, and then some (in case the minimum balance is very low, even lower
// than the relayer reward fee).
let sovereign_balance = (minimum_balance_u32 * 2) + 5000;

// So that the receiving account exists
let _ = T::Token::mint_into(&caller, minimum_balance.into());
// Fund the sovereign account (parachain sovereign account) so it can transfer a reward
// fee to the caller account
let _ = T::Token::mint_into(&sovereign_account, sovereign_balance.into());
let _ = T::Token::mint_into(
&sovereign_account,
3_000_000_000_000u128
.try_into()
.unwrap_or_else(|_| panic!("unable to cast sovereign account balance")),
);

#[block]
{
Expand Down
7 changes: 4 additions & 3 deletions parachain/pallets/inbound-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl frame_system::Config for Test {
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeTask = RuntimeTask;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
Expand Down Expand Up @@ -178,7 +179,7 @@ parameter_types! {
pub Parameters: PricingParameters<u128> = PricingParameters {
exchange_rate: FixedU128::from_rational(1, 400),
fee_per_gas: gwei(20),
rewards: Rewards { local: 1 * DOT, remote: meth(1) }
rewards: Rewards { local: DOT, remote: meth(1) }
};
}

Expand All @@ -195,7 +196,7 @@ impl StaticLookup for MockChannelLookup {
{
return None
}
Some(Channel { agent_id: H256::zero().into(), para_id: ASSET_HUB_PARAID.into() })
Some(Channel { agent_id: H256::zero(), para_id: ASSET_HUB_PARAID.into() })
}
}

Expand Down Expand Up @@ -251,7 +252,7 @@ pub fn setup() {
pub fn new_tester() -> sp_io::TestExternalities {
let storage = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut ext: sp_io::TestExternalities = storage.into();
ext.execute_with(|| setup());
ext.execute_with(setup);
ext
}

Expand Down
Loading

0 comments on commit 932745f

Please sign in to comment.