From a989dc155bd031ce162f7f2ac3b89400a92c7d6f Mon Sep 17 00:00:00 2001 From: notlesh Date: Tue, 9 May 2023 21:59:54 +0000 Subject: [PATCH 01/11] Add GMP precompile killswitch --- precompiles/gmp/src/lib.rs | 38 +++++++++++++++++++++++-- precompiles/gmp/src/mock.rs | 38 +++++++++++++++++++++++++ precompiles/gmp/src/tests.rs | 54 +++++++++++++++++++++++++++++++++++- 3 files changed, 126 insertions(+), 4 deletions(-) diff --git a/precompiles/gmp/src/lib.rs b/precompiles/gmp/src/lib.rs index ae2db69c65..3ea730476c 100644 --- a/precompiles/gmp/src/lib.rs +++ b/precompiles/gmp/src/lib.rs @@ -19,7 +19,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use evm::ExitReason; -use fp_evm::{Context, PrecompileFailure, PrecompileHandle}; +use fp_evm::{Context, ExitRevert, PrecompileFailure, PrecompileHandle}; use frame_support::{ codec::Decode, dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo}, @@ -78,12 +78,14 @@ where log::debug!(target: "gmp-precompile", "wormhole_vaa: {:?}", wormhole_vaa.clone()); // tally up gas cost: + // 1 read for enabled flag // 2 reads for contract addresses // 2500 as fudge for computation, esp. payload decoding (TODO: benchmark?) - let initial_gas = 2500 + 2 * RuntimeHelper::::db_read_gas_cost(); - log::warn!("initial_gas: {:?}", initial_gas); + let initial_gas = 2500 + 3 * RuntimeHelper::::db_read_gas_cost(); handle.record_cost(initial_gas)?; + ensure_enabled()?; + let wormhole = storage::CoreAddress::get() .ok_or(RevertReason::custom("invalid wormhole core address"))?; @@ -242,11 +244,30 @@ fn ensure_exit_reason_success(reason: ExitReason, output: &[u8]) -> EvmResult<() } } +pub fn is_enabled() -> bool { + match storage::PrecompileEnabled::get() { + Some(enabled) => enabled, + _ => false, + } +} + +fn ensure_enabled() -> EvmResult<()> { + if is_enabled() { + Ok(()) + } else { + Err(PrecompileFailure::Revert { + exit_status: ExitRevert::Reverted, + output: b"GMP Precompile is not enabled".to_vec(), + }) + } +} + /// We use pallet storage in our precompile by implementing a StorageInstance for each item we need /// to store. /// twox_128("gmp") => 0xb7f047395bba5df0367b45771c00de50 /// twox_128("CoreAddress") => 0x59ff23ff65cc809711800d9d04e4b14c /// twox_128("BridgeAddress") => 0xc1586bde54b249fb7f521faf831ade45 +/// twox_128("PrecompileEnabled") => 0x2551bba17abb82ef3498bab688e470b8 mod storage { use super::*; use frame_support::{ @@ -273,4 +294,15 @@ mod storage { } } pub type BridgeAddress = StorageValue; + + // storage for precompile enabled + // None or Some(false) both mean that the precompile is disabled; only Some(true) means enabled. + pub struct PrecompileEnabledStorageInstance; + impl StorageInstance for PrecompileEnabledStorageInstance { + const STORAGE_PREFIX: &'static str = "PrecompileEnabled"; + fn pallet_prefix() -> &'static str { + "gmp" + } + } + pub type PrecompileEnabled = StorageValue; } diff --git a/precompiles/gmp/src/mock.rs b/precompiles/gmp/src/mock.rs index 9f7aa8140f..7788aa058e 100644 --- a/precompiles/gmp/src/mock.rs +++ b/precompiles/gmp/src/mock.rs @@ -385,3 +385,41 @@ impl orml_xtokens::Config for Runtime { type ReserveProvider = AbsoluteReserveProvider; type UniversalLocation = UniversalLocation; } + +pub(crate) struct ExtBuilder { + /// Endowed accounts with balances + balances: Vec<(AccountId, Balance)>, +} + +impl Default for ExtBuilder { + fn default() -> ExtBuilder { + ExtBuilder { balances: vec![] } + } +} + +impl ExtBuilder { + /// Fund some accounts before starting the test + pub(crate) fn with_balances(mut self, balances: Vec<(AccountId, Balance)>) -> Self { + self.balances = balances; + self + } + + /// Build the test externalities for use in tests + pub(crate) fn build(self) -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::default() + .build_storage::() + .expect("Frame system builds valid default genesis config"); + + pallet_balances::GenesisConfig:: { + balances: self.balances.clone(), + } + .assimilate_storage(&mut t) + .expect("Pallet balances storage can be assimilated"); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + }); + ext + } +} diff --git a/precompiles/gmp/src/tests.rs b/precompiles/gmp/src/tests.rs index 2e9cff642f..e3398a610f 100644 --- a/precompiles/gmp/src/tests.rs +++ b/precompiles/gmp/src/tests.rs @@ -14,9 +14,61 @@ // You should have received a copy of the GNU General Public License // along with Moonbeam. If not, see . -use crate::mock::PCall; +use crate::mock::{ExtBuilder, PCall}; +use fp_evm::{ExitRevert, PrecompileFailure}; use precompile_utils::testing::*; +#[test] +fn contract_disabling_default_value_is_false() { + ExtBuilder::default() + .with_balances(vec![(Alice.into(), 100_000)]) + .build() + .execute_with(|| { + // default should be false + assert_eq!(crate::storage::PrecompileEnabled::get(), None); + assert_eq!(crate::is_enabled(), false); + assert_eq!( + crate::ensure_enabled(), + Err(PrecompileFailure::Revert { + exit_status: ExitRevert::Reverted, + output: b"GMP Precompile is not enabled".to_vec(), + }) + ); + }) +} + +#[test] +fn contract_enabling_works() { + ExtBuilder::default() + .with_balances(vec![(Alice.into(), 100_000)]) + .build() + .execute_with(|| { + crate::storage::PrecompileEnabled::set(Some(true)); + assert_eq!(crate::storage::PrecompileEnabled::get(), Some(true)); + assert_eq!(crate::is_enabled(), true); + assert_eq!(crate::ensure_enabled(), Ok(())); + }) +} + +#[test] +fn contract_disabling_works() { + ExtBuilder::default() + .with_balances(vec![(Alice.into(), 100_000)]) + .build() + .execute_with(|| { + crate::storage::PrecompileEnabled::set(Some(false)); + assert_eq!(crate::storage::PrecompileEnabled::get(), Some(false)); + assert_eq!(crate::is_enabled(), false); + assert_eq!( + crate::ensure_enabled(), + Err(PrecompileFailure::Revert { + exit_status: ExitRevert::Reverted, + output: b"GMP Precompile is not enabled".to_vec(), + }) + ); + }) +} + #[test] fn test_solidity_interface_has_all_function_selectors_documented_and_implemented() { check_precompile_implements_solidity_interfaces(&["Gmp.sol"], PCall::supports_selector) From 98f370070900182b8cf13cf77fdef6bdf9415f84 Mon Sep 17 00:00:00 2001 From: notlesh Date: Wed, 10 May 2023 18:04:35 +0000 Subject: [PATCH 02/11] Test revert values --- precompiles/gmp/src/tests.rs | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/precompiles/gmp/src/tests.rs b/precompiles/gmp/src/tests.rs index e3398a610f..6efd31d685 100644 --- a/precompiles/gmp/src/tests.rs +++ b/precompiles/gmp/src/tests.rs @@ -14,10 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moonbeam. If not, see . -use crate::mock::{ExtBuilder, PCall}; +use crate::mock::*; use fp_evm::{ExitRevert, PrecompileFailure}; use precompile_utils::testing::*; +fn precompiles() -> Precompiles { + PrecompilesValue::get() +} + #[test] fn contract_disabling_default_value_is_false() { ExtBuilder::default() @@ -34,6 +38,16 @@ fn contract_disabling_default_value_is_false() { output: b"GMP Precompile is not enabled".to_vec(), }) ); + + precompiles() + .prepare_test( + CryptoAlith, + Precompile1, + PCall::wormhole_transfer_erc20 { + wormhole_vaa: Vec::new().into(), + }, + ) + .execute_reverts(|output| output == b"GMP Precompile is not enabled"); }) } @@ -47,6 +61,17 @@ fn contract_enabling_works() { assert_eq!(crate::storage::PrecompileEnabled::get(), Some(true)); assert_eq!(crate::is_enabled(), true); assert_eq!(crate::ensure_enabled(), Ok(())); + + // should fail at a later point since contract addresses are not set + precompiles() + .prepare_test( + CryptoAlith, + Precompile1, + PCall::wormhole_transfer_erc20 { + wormhole_vaa: Vec::new().into(), + }, + ) + .execute_reverts(|output| output == b"invalid wormhole core address"); }) } @@ -66,6 +91,16 @@ fn contract_disabling_works() { output: b"GMP Precompile is not enabled".to_vec(), }) ); + + precompiles() + .prepare_test( + CryptoAlith, + Precompile1, + PCall::wormhole_transfer_erc20 { + wormhole_vaa: Vec::new().into(), + }, + ) + .execute_reverts(|output| output == b"GMP Precompile is not enabled"); }) } From 2eb93a9fc590fbeb4fcfc0a68a49b0e172490a5d Mon Sep 17 00:00:00 2001 From: notlesh Date: Wed, 10 May 2023 19:03:42 +0000 Subject: [PATCH 03/11] Don't decode revert message --- precompiles/gmp/src/tests.rs | 4 ++-- precompiles/utils/src/testing/execution.rs | 26 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/precompiles/gmp/src/tests.rs b/precompiles/gmp/src/tests.rs index 6efd31d685..ddb7072894 100644 --- a/precompiles/gmp/src/tests.rs +++ b/precompiles/gmp/src/tests.rs @@ -47,7 +47,7 @@ fn contract_disabling_default_value_is_false() { wormhole_vaa: Vec::new().into(), }, ) - .execute_reverts(|output| output == b"GMP Precompile is not enabled"); + .execute_reverts_no_decode(|output| output == b"GMP Precompile is not enabled"); }) } @@ -100,7 +100,7 @@ fn contract_disabling_works() { wormhole_vaa: Vec::new().into(), }, ) - .execute_reverts(|output| output == b"GMP Precompile is not enabled"); + .execute_reverts_no_decode(|output| output == b"GMP Precompile is not enabled"); }) } diff --git a/precompiles/utils/src/testing/execution.rs b/precompiles/utils/src/testing/execution.rs index 8e45aaa772..8928476a85 100644 --- a/precompiles/utils/src/testing/execution.rs +++ b/precompiles/utils/src/testing/execution.rs @@ -222,6 +222,32 @@ impl<'p, P: PrecompileSet> PrecompilesTester<'p, P> { self.assert_optionals(); } + /// Execute the precompile set and check if it reverts. + /// Take a closure allowing to perform custom matching on the output. + /// Output is not automatically decoded. + pub fn execute_reverts_no_decode(mut self, check: impl Fn(&[u8]) -> bool) { + let res = self.execute(); + + match res { + Some(Err(PrecompileFailure::Revert { output, .. })) => { + if !check(&output) { + eprintln!( + "Revert message (bytes): {:?}", + sp_core::hexdisplay::HexDisplay::from(&output) + ); + eprintln!( + "Revert message (string): {:?}", + core::str::from_utf8(&output).ok() + ); + panic!("Revert reason doesn't match !"); + } + } + other => panic!("Didn't revert, instead returned {:?}", other), + } + + self.assert_optionals(); + } + /// Execute the precompile set and check it returns provided output. pub fn execute_error(mut self, error: ExitError) { let res = self.execute(); From 9f024a15aebb1786288ec02e00c782a635cac3ea Mon Sep 17 00:00:00 2001 From: notlesh Date: Thu, 11 May 2023 16:15:14 +0000 Subject: [PATCH 04/11] Properly encode revert string --- precompiles/gmp/src/lib.rs | 4 ++-- precompiles/gmp/src/tests.rs | 4 ++-- precompiles/utils/src/testing/execution.rs | 26 ---------------------- 3 files changed, 4 insertions(+), 30 deletions(-) diff --git a/precompiles/gmp/src/lib.rs b/precompiles/gmp/src/lib.rs index 3ea730476c..6bbf62fd1e 100644 --- a/precompiles/gmp/src/lib.rs +++ b/precompiles/gmp/src/lib.rs @@ -27,7 +27,7 @@ use frame_support::{ }; use pallet_evm::AddressMapping; use parity_scale_codec::DecodeLimit; -use precompile_utils::prelude::*; +use precompile_utils::{prelude::*, solidity::revert::revert_as_bytes}; use sp_core::{H160, U256}; use sp_std::boxed::Box; use sp_std::{marker::PhantomData, vec::Vec}; @@ -257,7 +257,7 @@ fn ensure_enabled() -> EvmResult<()> { } else { Err(PrecompileFailure::Revert { exit_status: ExitRevert::Reverted, - output: b"GMP Precompile is not enabled".to_vec(), + output: revert_as_bytes("GMP Precompile is not enabled"), }) } } diff --git a/precompiles/gmp/src/tests.rs b/precompiles/gmp/src/tests.rs index ddb7072894..6efd31d685 100644 --- a/precompiles/gmp/src/tests.rs +++ b/precompiles/gmp/src/tests.rs @@ -47,7 +47,7 @@ fn contract_disabling_default_value_is_false() { wormhole_vaa: Vec::new().into(), }, ) - .execute_reverts_no_decode(|output| output == b"GMP Precompile is not enabled"); + .execute_reverts(|output| output == b"GMP Precompile is not enabled"); }) } @@ -100,7 +100,7 @@ fn contract_disabling_works() { wormhole_vaa: Vec::new().into(), }, ) - .execute_reverts_no_decode(|output| output == b"GMP Precompile is not enabled"); + .execute_reverts(|output| output == b"GMP Precompile is not enabled"); }) } diff --git a/precompiles/utils/src/testing/execution.rs b/precompiles/utils/src/testing/execution.rs index 8928476a85..8e45aaa772 100644 --- a/precompiles/utils/src/testing/execution.rs +++ b/precompiles/utils/src/testing/execution.rs @@ -222,32 +222,6 @@ impl<'p, P: PrecompileSet> PrecompilesTester<'p, P> { self.assert_optionals(); } - /// Execute the precompile set and check if it reverts. - /// Take a closure allowing to perform custom matching on the output. - /// Output is not automatically decoded. - pub fn execute_reverts_no_decode(mut self, check: impl Fn(&[u8]) -> bool) { - let res = self.execute(); - - match res { - Some(Err(PrecompileFailure::Revert { output, .. })) => { - if !check(&output) { - eprintln!( - "Revert message (bytes): {:?}", - sp_core::hexdisplay::HexDisplay::from(&output) - ); - eprintln!( - "Revert message (string): {:?}", - core::str::from_utf8(&output).ok() - ); - panic!("Revert reason doesn't match !"); - } - } - other => panic!("Didn't revert, instead returned {:?}", other), - } - - self.assert_optionals(); - } - /// Execute the precompile set and check it returns provided output. pub fn execute_error(mut self, error: ExitError) { let res = self.execute(); From ca63b0f7ee502b6c2bb5fbb719ef79b5c08f2b6b Mon Sep 17 00:00:00 2001 From: notlesh Date: Thu, 11 May 2023 16:35:37 +0000 Subject: [PATCH 05/11] Test against encoded output --- precompiles/gmp/src/tests.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/precompiles/gmp/src/tests.rs b/precompiles/gmp/src/tests.rs index 6efd31d685..c219e1c922 100644 --- a/precompiles/gmp/src/tests.rs +++ b/precompiles/gmp/src/tests.rs @@ -16,7 +16,7 @@ use crate::mock::*; use fp_evm::{ExitRevert, PrecompileFailure}; -use precompile_utils::testing::*; +use precompile_utils::{solidity::revert::revert_as_bytes, testing::*}; fn precompiles() -> Precompiles { PrecompilesValue::get() @@ -35,7 +35,7 @@ fn contract_disabling_default_value_is_false() { crate::ensure_enabled(), Err(PrecompileFailure::Revert { exit_status: ExitRevert::Reverted, - output: b"GMP Precompile is not enabled".to_vec(), + output: revert_as_bytes("GMP Precompile is not enabled"), }) ); @@ -88,7 +88,7 @@ fn contract_disabling_works() { crate::ensure_enabled(), Err(PrecompileFailure::Revert { exit_status: ExitRevert::Reverted, - output: b"GMP Precompile is not enabled".to_vec(), + output: revert_as_bytes("GMP Precompile is not enabled"), }) ); From daac6f4a83739e3df5728b7187ea699c4bc2d1ec Mon Sep 17 00:00:00 2001 From: notlesh Date: Thu, 11 May 2023 17:24:06 +0000 Subject: [PATCH 06/11] Disable killswitch in wormhole test --- .../test-precompile/test-precompile-wormhole.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/tests/test-precompile/test-precompile-wormhole.ts b/tests/tests/test-precompile/test-precompile-wormhole.ts index a92fd8f523..192e855ef7 100644 --- a/tests/tests/test-precompile/test-precompile-wormhole.ts +++ b/tests/tests/test-precompile/test-precompile-wormhole.ts @@ -209,6 +209,21 @@ describeDevMoonbeam(`Test local Wormhole`, (context) => { .signAndSend(alith); await context.createBlock(); + // we also need to disable the killswitch by setting the 'enabled' flag to Some(true) + const ENABLED_FLAG_STORAGE_ADDRESS = + "0xb7f047395bba5df0367b45771c00de502551bba17abb82ef3498bab688e470b8"; + await context.polkadotApi.tx.sudo + .sudo( + context.polkadotApi.tx.system.setStorage([ + [ + ENABLED_FLAG_STORAGE_ADDRESS, + context.polkadotApi.registry.createType("Option", true).toHex() + ] + ]) + ) + .signAndSend(alith); + await context.createBlock(); + const transferVAA = await genTransferWithPayloadVAA( signerPKs, GUARDIAN_SET_INDEX, From 1a6850f8d730dec3ec657e6032030ea050d672db Mon Sep 17 00:00:00 2001 From: notlesh Date: Thu, 11 May 2023 21:14:01 +0000 Subject: [PATCH 07/11] prettier --- tests/tests/test-precompile/test-precompile-wormhole.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tests/test-precompile/test-precompile-wormhole.ts b/tests/tests/test-precompile/test-precompile-wormhole.ts index 192e855ef7..8a89f0d226 100644 --- a/tests/tests/test-precompile/test-precompile-wormhole.ts +++ b/tests/tests/test-precompile/test-precompile-wormhole.ts @@ -217,8 +217,8 @@ describeDevMoonbeam(`Test local Wormhole`, (context) => { context.polkadotApi.tx.system.setStorage([ [ ENABLED_FLAG_STORAGE_ADDRESS, - context.polkadotApi.registry.createType("Option", true).toHex() - ] + context.polkadotApi.registry.createType("Option", true).toHex(), + ], ]) ) .signAndSend(alith); From c9635d0883a716f977035b344feef421dbb9de53 Mon Sep 17 00:00:00 2001 From: notlesh Date: Thu, 18 May 2023 20:23:48 +0000 Subject: [PATCH 08/11] Add basic TS test covering killswitch default --- .../test-precompile/test-precompile-wormhole.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/tests/test-precompile/test-precompile-wormhole.ts b/tests/tests/test-precompile/test-precompile-wormhole.ts index 8a89f0d226..07cd30a11c 100644 --- a/tests/tests/test-precompile/test-precompile-wormhole.ts +++ b/tests/tests/test-precompile/test-precompile-wormhole.ts @@ -253,4 +253,21 @@ describeDevMoonbeam(`Test local Wormhole`, (context) => { expectEVMResult(result.result.events, "Succeed", "Returned"); expectSubstrateEvents(result, "xTokens", "TransferredMultiAssets"); }); + + it("should fail with killswitch enabled by default", async function () { + // payload should be irrelevant since the precompile will fail before attempting to decode + const transferVAA = "deadbeef"; + + const data = GMP_INTERFACE.encodeFunctionData("wormholeTransferERC20", [`0x${transferVAA}`]); + + const result = await context.createBlock( + createTransaction(context, { + to: PRECOMPILE_GMP_ADDRESS, + gas: 500_000, + data, + }) + ); + + expectEVMResult(result.result.events, "Revert", "Reverted"); + }); }); From ea08987145a5cd86db7d6e0373f6c7fc897b1af5 Mon Sep 17 00:00:00 2001 From: notlesh Date: Thu, 18 May 2023 20:34:31 +0000 Subject: [PATCH 09/11] Expect revert reason to match killswitch --- tests/tests/test-precompile/test-precompile-wormhole.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/tests/test-precompile/test-precompile-wormhole.ts b/tests/tests/test-precompile/test-precompile-wormhole.ts index 07cd30a11c..85bbbd5d81 100644 --- a/tests/tests/test-precompile/test-precompile-wormhole.ts +++ b/tests/tests/test-precompile/test-precompile-wormhole.ts @@ -16,7 +16,8 @@ import { alith, ALITH_ADDRESS, ALITH_PRIVATE_KEY, BALTATHAR_ADDRESS } from "../. import { PRECOMPILE_GMP_ADDRESS } from "../../util/constants"; import { expectSubstrateEvent, expectSubstrateEvents } from "../../util/expect"; -import { expectEVMResult } from "../../util/eth-transactions"; +import { expectEVMResult, extractRevertReason } from "../../util/eth-transactions"; +import { expect } from "chai"; const debug = require("debug")("test:wormhole"); const GUARDIAN_SET_INDEX = 0; @@ -269,5 +270,7 @@ describeDevMoonbeam(`Test local Wormhole`, (context) => { ); expectEVMResult(result.result.events, "Revert", "Reverted"); + const revertReason = await extractRevertReason(result.result.hash, context.ethers); + expect(revertReason).to.contain("GMP Precompile is not enabled"); }); }); From 88fe957250aa3f3f2f21a422f5733ed7be3b0b29 Mon Sep 17 00:00:00 2001 From: notlesh Date: Thu, 18 May 2023 21:52:43 +0000 Subject: [PATCH 10/11] Don't share test suite with killswitch test --- tests/tests/test-precompile/test-precompile-wormhole.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/tests/test-precompile/test-precompile-wormhole.ts b/tests/tests/test-precompile/test-precompile-wormhole.ts index 85bbbd5d81..7acf735303 100644 --- a/tests/tests/test-precompile/test-precompile-wormhole.ts +++ b/tests/tests/test-precompile/test-precompile-wormhole.ts @@ -254,7 +254,9 @@ describeDevMoonbeam(`Test local Wormhole`, (context) => { expectEVMResult(result.result.events, "Succeed", "Returned"); expectSubstrateEvents(result, "xTokens", "TransferredMultiAssets"); }); +}); +describeDevMoonbeam(`Test GMP Killswitch`, (context) => { it("should fail with killswitch enabled by default", async function () { // payload should be irrelevant since the precompile will fail before attempting to decode const transferVAA = "deadbeef"; From 751af8383ee5483f4fba2bf62233cc8cea3fca6c Mon Sep 17 00:00:00 2001 From: notlesh Date: Fri, 19 May 2023 20:51:34 +0000 Subject: [PATCH 11/11] Derive magic storage keys --- .../test-precompile-wormhole.ts | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/tests/tests/test-precompile/test-precompile-wormhole.ts b/tests/tests/test-precompile/test-precompile-wormhole.ts index 7acf735303..2124677892 100644 --- a/tests/tests/test-precompile/test-precompile-wormhole.ts +++ b/tests/tests/test-precompile/test-precompile-wormhole.ts @@ -15,6 +15,8 @@ import { ethers } from "ethers"; import { alith, ALITH_ADDRESS, ALITH_PRIVATE_KEY, BALTATHAR_ADDRESS } from "../../util/accounts"; import { PRECOMPILE_GMP_ADDRESS } from "../../util/constants"; import { expectSubstrateEvent, expectSubstrateEvents } from "../../util/expect"; +import { u8aConcat, u8aToHex } from "@polkadot/util"; +import { xxhashAsU8a } from "@polkadot/util-crypto"; import { expectEVMResult, extractRevertReason } from "../../util/eth-transactions"; import { expect } from "chai"; @@ -188,8 +190,13 @@ describeDevMoonbeam(`Test local Wormhole`, (context) => { // before interacting with the precompile, we need to set some contract addresses from our // our deployments above - const CORE_CONTRACT_STORAGE_ADDRESS = - "0xb7f047395bba5df0367b45771c00de5059ff23ff65cc809711800d9d04e4b14c"; + const CORE_CONTRACT_STORAGE_ADDRESS = u8aToHex( + u8aConcat(xxhashAsU8a("gmp", 128), xxhashAsU8a("CoreAddress", 128)) + ); + expect(CORE_CONTRACT_STORAGE_ADDRESS).to.eq( + "0xb7f047395bba5df0367b45771c00de5059ff23ff65cc809711800d9d04e4b14c" + ); + await context.polkadotApi.tx.sudo .sudo( context.polkadotApi.tx.system.setStorage([ @@ -199,8 +206,13 @@ describeDevMoonbeam(`Test local Wormhole`, (context) => { .signAndSend(alith); await context.createBlock(); - const BRIDGE_CONTRACT_STORAGE_ADDRESS = - "0xb7f047395bba5df0367b45771c00de50c1586bde54b249fb7f521faf831ade45"; + const BRIDGE_CONTRACT_STORAGE_ADDRESS = u8aToHex( + u8aConcat(xxhashAsU8a("gmp", 128), xxhashAsU8a("BridgeAddress", 128)) + ); + expect(BRIDGE_CONTRACT_STORAGE_ADDRESS).to.eq( + "0xb7f047395bba5df0367b45771c00de50c1586bde54b249fb7f521faf831ade45" + ); + await context.polkadotApi.tx.sudo .sudo( context.polkadotApi.tx.system.setStorage([ @@ -211,8 +223,13 @@ describeDevMoonbeam(`Test local Wormhole`, (context) => { await context.createBlock(); // we also need to disable the killswitch by setting the 'enabled' flag to Some(true) - const ENABLED_FLAG_STORAGE_ADDRESS = - "0xb7f047395bba5df0367b45771c00de502551bba17abb82ef3498bab688e470b8"; + const ENABLED_FLAG_STORAGE_ADDRESS = u8aToHex( + u8aConcat(xxhashAsU8a("gmp", 128), xxhashAsU8a("PrecompileEnabled", 128)) + ); + expect(ENABLED_FLAG_STORAGE_ADDRESS).to.eq( + "0xb7f047395bba5df0367b45771c00de502551bba17abb82ef3498bab688e470b8" + ); + await context.polkadotApi.tx.sudo .sudo( context.polkadotApi.tx.system.setStorage([