Skip to content
Snippets Groups Projects
Unverified Commit 6caa18df authored by Alistair Singh's avatar Alistair Singh Committed by GitHub
Browse files

Statically define Gateway address in runtime (#953)

parent 6fcec88c
No related merge requests found
Subproject commit 38c2e26a4ead087d0837b5abdc3cdc3e0e6e0d8e
Subproject commit 539170ab797c82004047216a8aed970614a42c7e
......@@ -12,9 +12,6 @@ use frame_system::RawOrigin;
mod benchmarks {
use super::*;
use crate::benchmarking::fixtures::make_create_message;
use hex_literal::hex;
const GATEWAY_ADDRESS: [u8; 20] = hex!["eda338e4dc46038493b885327842fd3e301cab39"];
#[benchmark]
fn submit() -> Result<(), BenchmarkError> {
......@@ -27,8 +24,6 @@ mod benchmarks {
create_message.execution_header,
);
<Gateway<T>>::put(H160(GATEWAY_ADDRESS));
let dest_para: ParaId = 1000u32.into();
let sovereign_account = dest_para.into_account_truncating();
......@@ -62,9 +57,5 @@ mod benchmarks {
Ok(())
}
impl_benchmark_test_suite!(
InboundQueue,
crate::test::new_tester(crate::H160::default()),
crate::test::Test
);
impl_benchmark_test_suite!(InboundQueue, crate::test::new_tester(), crate::test::Test);
}
......@@ -19,11 +19,8 @@ mod test;
use codec::{Decode, DecodeAll, Encode};
use frame_support::{
traits::{
fungible::{Inspect, Mutate},
GenesisBuild,
},
CloneNoBound, DefaultNoBound, EqNoBound, PartialEqNoBound,
traits::fungible::{Inspect, Mutate},
CloneNoBound, EqNoBound, PartialEqNoBound,
};
use frame_system::ensure_signed;
use scale_info::TypeInfo;
......@@ -91,6 +88,10 @@ pub mod pallet {
type WeightInfo: WeightInfo;
// Gateway contract address
#[pallet::constant]
type GatewayAddress: Get<H160>;
#[cfg(feature = "runtime-benchmarks")]
type Helper: BenchmarkHelper<Self>;
}
......@@ -126,11 +127,6 @@ pub mod pallet {
BridgeModule(bp_runtime::OwnedBridgeModuleError),
}
/// The address of the Gateway contract on Ethereum
#[pallet::storage]
#[pallet::getter(fn gateway)]
pub type Gateway<T: Config> = StorageValue<_, H160, ValueQuery>;
/// The current nonce for each parachain
#[pallet::storage]
pub type Nonce<T: Config> = StorageMap<_, Twox64Concat, ParaId, u64, ValueQuery>;
......@@ -150,20 +146,6 @@ pub mod pallet {
#[pallet::storage]
pub type PalletOperatingMode<T: Config> = StorageValue<_, BasicOperatingMode, ValueQuery>;
#[pallet::genesis_config]
#[derive(DefaultNoBound)]
pub struct GenesisConfig {
/// The address of the Gateway contract on Ethereum
pub gateway: H160,
}
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
fn build(&self) {
Gateway::<T>::put(self.gateway);
}
}
impl<T: Config> OwnedBridgeModule<T> for Pallet<T> {
const LOG_TARGET: &'static str = LOG_TARGET;
type OwnerStorage = PalletOwner<T>;
......@@ -186,7 +168,7 @@ pub mod pallet {
let envelope = Envelope::try_from(log).map_err(|_| Error::<T>::InvalidEnvelope)?;
// Verify that the message was submitted from the known Gateway contract
ensure!(Gateway::<T>::get() == envelope.gateway, Error::<T>::InvalidGateway,);
ensure!(T::GatewayAddress::get() == envelope.gateway, Error::<T>::InvalidGateway,);
// Verify message nonce
<Nonce<T>>::try_mutate(envelope.dest, |nonce| -> DispatchResult {
......@@ -243,14 +225,6 @@ pub mod pallet {
Ok(())
}
#[pallet::call_index(1)]
#[pallet::weight((T::DbWeight::get().writes(1), DispatchClass::Normal))]
pub fn set_gateway(origin: OriginFor<T>, gateway: H160) -> DispatchResult {
ensure_root(origin)?;
Gateway::<T>::put(gateway);
Ok(())
}
/// Change `PalletOwner`.
/// May only be called either by root, or by `PalletOwner`.
#[pallet::call_index(3)]
......
......@@ -130,8 +130,11 @@ impl Verifier for MockVerifier {
}
}
const GATEWAY_ADDRESS: [u8; 20] = hex!["eda338e4dc46038493b885327842fd3e301cab39"];
parameter_types! {
pub const EthereumNetwork: xcm::v3::NetworkId = xcm::v3::NetworkId::Ethereum { chain_id: 15};
pub const EthereumNetwork: xcm::v3::NetworkId = xcm::v3::NetworkId::Ethereum { chain_id: 15 };
pub const GatewayAddress: H160 = H160(GATEWAY_ADDRESS);
}
#[cfg(feature = "runtime-benchmarks")]
......@@ -147,6 +150,7 @@ impl inbound_queue::Config for Test {
type Reward = ConstU64<100>;
type XcmSender = ();
type WeightInfo = ();
type GatewayAddress = GatewayAddress;
#[cfg(feature = "runtime-benchmarks")]
type Helper = Test;
}
......@@ -165,15 +169,8 @@ fn expect_events(e: Vec<RuntimeEvent>) {
assert_eq!(last_events(e.len()), e);
}
pub fn new_tester(gateway: H160) -> sp_io::TestExternalities {
new_tester_with_config(inbound_queue::GenesisConfig { gateway })
}
pub fn new_tester_with_config(config: inbound_queue::GenesisConfig) -> sp_io::TestExternalities {
let mut storage = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
GenesisBuild::<Test>::assimilate_storage(&config, &mut storage).unwrap();
pub fn new_tester() -> sp_io::TestExternalities {
let storage = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let mut ext: sp_io::TestExternalities = storage.into();
ext.execute_with(|| System::set_block_number(1));
ext
......@@ -195,20 +192,23 @@ fn parse_dest(message: Message) -> ParaId {
envelope.dest
}
// The originating channel address for the messages below
const GATEWAY_ADDRESS: [u8; 20] = hex!["EDa338E4dC46038493b885327842fD3E301CaB39"];
const OUTBOUND_QUEUE_EVENT_LOG: [u8; 253] = hex!(
"
f8fb94eda338e4dc46038493b885327842fd3e301cab39f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b8a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000034000f000000000000000057a2d4ff0c3866d96556884bf09fecdd7ccd530c87d1f7fdfee7f651fabc8bfcb6e086c278b77a7d3500000000000000000000000000
"
);
const BAD_OUTBOUND_QUEUE_EVENT_LOG: [u8; 253] = hex!(
"
f8fb940000000000000000000000000000000000000000f842a0d56f1b8dfd3ba41f19c499ceec5f9546f61befa5f10398a75d7dba53a219fecea000000000000000000000000000000000000000000000000000000000000003e8b8a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000034000f000000000000000057a2d4ff0c3866d96556884bf09fecdd7ccd530c87d1f7fdfee7f651fabc8bfcb6e086c278b77a7d3500000000000000000000000000
"
);
use snowbridge_core::ParaId;
#[test]
fn test_submit_happy_path() {
new_tester(GATEWAY_ADDRESS.into()).execute_with(|| {
new_tester().execute_with(|| {
let relayer: AccountId = Keyring::Bob.into();
let origin = RuntimeOrigin::signed(relayer);
......@@ -240,7 +240,7 @@ fn test_submit_happy_path() {
#[test]
fn test_submit_with_invalid_gateway() {
new_tester(H160::zero()).execute_with(|| {
new_tester().execute_with(|| {
let relayer: AccountId = Keyring::Bob.into();
let origin = RuntimeOrigin::signed(relayer);
......@@ -251,7 +251,7 @@ fn test_submit_with_invalid_gateway() {
// Submit message
let message = Message {
data: OUTBOUND_QUEUE_EVENT_LOG.into(),
data: BAD_OUTBOUND_QUEUE_EVENT_LOG.into(),
proof: Proof {
block_hash: Default::default(),
tx_index: Default::default(),
......@@ -267,7 +267,7 @@ fn test_submit_with_invalid_gateway() {
#[test]
fn test_submit_with_invalid_nonce() {
new_tester(GATEWAY_ADDRESS.into()).execute_with(|| {
new_tester().execute_with(|| {
let relayer: AccountId = Keyring::Bob.into();
let origin = RuntimeOrigin::signed(relayer);
......@@ -301,7 +301,7 @@ fn test_submit_with_invalid_nonce() {
#[test]
fn test_submit_no_funds_to_reward_relayers() {
new_tester(GATEWAY_ADDRESS.into()).execute_with(|| {
new_tester().execute_with(|| {
let relayer: AccountId = Keyring::Bob.into();
let origin = RuntimeOrigin::signed(relayer);
......@@ -327,31 +327,3 @@ fn test_submit_no_funds_to_reward_relayers() {
);
});
}
#[test]
fn test_set_gateway_with_root_succeeds() {
new_tester_with_config(Default::default()).execute_with(|| {
let origin = RuntimeOrigin::root();
let default_gateway_address = hex!("0000000000000000000000000000000000000000").into();
let gateway_address = hex!("1000000000000000000000000000000000000000").into();
assert_eq!(<Gateway<Test>>::get(), default_gateway_address);
assert_ok!(InboundQueue::set_gateway(origin, gateway_address));
assert_eq!(<Gateway<Test>>::get(), gateway_address);
});
}
#[test]
fn test_set_gateway_without_root_yields_bad_origin() {
new_tester_with_config(Default::default()).execute_with(|| {
let gateway_address = hex!("0000000000000000000000000000000000000000").into();
let relayer: AccountId = Keyring::Bob.into();
let origin = RuntimeOrigin::signed(relayer);
assert_noop!(
InboundQueue::set_gateway(origin, gateway_address),
sp_runtime::DispatchError::BadOrigin,
);
});
}
......@@ -12,15 +12,6 @@ config_beacon_checkpoint()
send_governance_transact_from_relaychain $BRIDGE_HUB_PARAID "$check_point_call" 180000000000 900000
}
config_inbound_queue()
{
local pallet="30"
local callindex="01"
local payload="0x$pallet$callindex$(address_for GatewayProxy | tr "[:upper:]" "[:lower:]" | cut -c3-)"
send_governance_transact_from_relaychain $BRIDGE_HUB_PARAID "$payload"
}
wait_beacon_chain_ready()
{
local initial_beacon_block=""
......@@ -45,7 +36,6 @@ fund_accounts()
configure_bridgehub()
{
fund_accounts
config_inbound_queue
wait_beacon_chain_ready
config_beacon_checkpoint
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment