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

XCM: Derive remote accounts according to polkadot standards #2315

Merged
merged 73 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
6d394d0
update to v0.9.40
nbaztec Apr 1, 2023
d26b671
update benchmarking weight template
nbaztec Apr 3, 2023
2821987
fix build
nbaztec Apr 3, 2023
1ed2a6d
make test compile
nbaztec Apr 3, 2023
fb2df2a
Includes page heap fixes
crystalin Apr 5, 2023
c9c9faf
compile runtime-benchmarks
nbaztec Apr 18, 2023
02b81f3
Merge branch 'upgrade-v0.9.40' of github.com:PureStake/moonbeam into …
nbaztec Apr 18, 2023
2882824
make warp sync work
nbaztec Apr 19, 2023
7fd8681
merge master
nbaztec Apr 19, 2023
a723757
toml sort
nbaztec Apr 19, 2023
471a4d2
fix editorconfig
nbaztec Apr 19, 2023
e10550f
use new substrate version
nbaztec Apr 19, 2023
0fb006c
fix warp sync
nbaztec Apr 21, 2023
7d58b9d
merge conflicts
nbaztec Apr 21, 2023
d76bc6b
sort
nbaztec Apr 21, 2023
a4b0848
fix --dev
nbaztec Apr 25, 2023
0e45f47
remove duplicate SetMembersOrigin
nbaztec Apr 25, 2023
56ae6f8
toml-sort
nbaztec Apr 25, 2023
0ccee4a
remove kitchensink-runtime
nbaztec Apr 27, 2023
7da9ed8
fix builkd
nbaztec Apr 27, 2023
a1dead6
Merge branch 'master' into upgrade-v0.9.40
nbaztec Apr 28, 2023
eea7baa
use new weights
nbaztec Apr 28, 2023
aa5e0cc
Merge branch 'master' into upgrade-v0.9.40
nbaztec May 2, 2023
8091cee
set manual weights for xcm fungible
librelois May 2, 2023
817adaa
use Weight::from_parts
nbaztec May 3, 2023
f329f16
Merge branch 'upgrade-v0.9.40' of github.com:PureStake/moonbeam into …
nbaztec May 3, 2023
d41c37a
use 0 pov_size for ref_time weight
nbaztec May 3, 2023
6dbca4e
update nimbus
nbaztec May 3, 2023
d8136c1
exclude generated weight files from editorconfig
nbaztec May 4, 2023
5e801c5
fmt
nbaztec May 4, 2023
466953f
fmt
nbaztec May 4, 2023
57387ca
fix rust tests
nbaztec May 4, 2023
c3917d3
Merge branch 'master' into upgrade-v0.9.40
nbaztec May 4, 2023
2bfe372
fix import
nbaztec May 4, 2023
62df5a7
fix tests
nbaztec May 4, 2023
1527111
use Weight part pov_size to 0
nbaztec May 4, 2023
18aa311
make dalek test work
nbaztec May 5, 2023
f5f5e76
fix transfer tests
nbaztec May 8, 2023
4f94a30
merge master
nbaztec May 11, 2023
f3ab63d
use BoundedVec for auto compound delegations
nbaztec May 12, 2023
e42730c
fix modexp test
nbaztec May 12, 2023
9927390
fix modexp test
nbaztec May 12, 2023
fec3ec1
fix tests
nbaztec May 15, 2023
bcb720c
fix weight tests
nbaztec May 15, 2023
648606b
Merge branch 'upgrade-v0.9.40' of github.com:PureStake/moonbeam into …
nbaztec May 15, 2023
e7dd0a1
fix staking tests via chunking
nbaztec May 15, 2023
fde72fd
fix modexp test
nbaztec May 15, 2023
19b4228
fix lint and test
nbaztec May 15, 2023
8dff3c7
fix rust weight tests
nbaztec May 15, 2023
d243bb5
fix partial ts tests
nbaztec May 15, 2023
cd87118
Merge branch 'master' into upgrade-v0.9.40
crystalin May 15, 2023
b3049e7
temp fix for xcm v2
crystalin May 15, 2023
df27699
Fixes weight until benchmarking is fixed
crystalin May 16, 2023
7ef16e7
set manual weight, fix ts tests
nbaztec May 16, 2023
6669928
Adds temp hack for xcm tests
crystalin May 22, 2023
0d1f026
Use RefundSurplus as the no-op for saturating the queue, which does n…
girazoki May 23, 2023
882b85e
Update evm to 0.39
tgmichel May 23, 2023
389f757
Revert "Update evm to 0.39"
tgmichel May 23, 2023
d831644
upgrade polkadot for better support of xcm v2
librelois May 23, 2023
63c005a
prettier
librelois May 23, 2023
ea906b9
prettier
librelois May 23, 2023
f7d6b37
Revert temp fix for XCM weight
crystalin May 23, 2023
f54cc1b
upgrade polkadot fork
librelois May 23, 2023
6c044fc
Fixing hrmp-mock tests
girazoki May 24, 2023
1608234
clean up
girazoki May 24, 2023
a874fc4
Merge branch 'master' into upgrade-v0.9.40
librelois May 25, 2023
66441c3
update polkadot fork to expose ForeignChainAliasAccount
librelois May 25, 2023
76ffa64
Generate remote accounts according to polkadot standards
librelois May 25, 2023
0ca0b68
prettier
librelois May 25, 2023
407703e
Merge branch 'upgrade-v0.9.40' into elois-xcm-account-derivation
librelois May 25, 2023
6864f47
Merge branch 'master' into elois-xcm-account-derivation
librelois May 25, 2023
f815ba3
fix rust test
librelois May 25, 2023
c1cb146
ts tests first pass
librelois May 25, 2023
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
122 changes: 61 additions & 61 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions primitives/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ impl Into<[u8; 20]> for AccountId20 {
}
}

impl From<[u8; 32]> for AccountId20 {
fn from(bytes: [u8; 32]) -> Self {
let mut buffer = [0u8; 20];
buffer.copy_from_slice(&bytes[..20]);
Self(buffer)
}
}
Comment on lines +76 to +82
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be misleading to put here because there are many (most) cases where we don't want to create and use an AccountId20 from an arbitrary 32-byte array.

Whenever we use an AccountId20 in a trusted way, it's important that it come from something that a user either doesn't have influence over or is extremely hard to guess (e.g. guessing random private keys). I worry that putting this simple conversion could lead to misuse by using an AccountId20 that was generated from an insecure source of bytes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall you are right, but this conversion is only made because the conversion built by polkadot works with 32 byte accounts, so we need to pass from there to a 20 byte account.

This has no security concerns because the 32 byte account is derived with a hash in the first place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The particular usage of it isn't what concerns me, it's having it in the first place. Couldn't we create a fn that needs to be explicitly called, something like unsafe_from_bytes_32 or from_known_secure_bytes or something like that? Doing so would obviously avoid any possible confusion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is there a requirement that there be a From impl for it to work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@notlesh the From<[u8; 32]> impl is a requirement from ForeignChainAliasAccount, it can't compile without it


impl From<H160> for AccountId20 {
fn from(h160: H160) -> Self {
Self(h160.0)
Expand Down
3 changes: 0 additions & 3 deletions primitives/xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ pub use constants::*;
mod fee_handlers;
pub use fee_handlers::*;

mod location_conversion;
pub use location_conversion::*;

mod origin_conversion;
pub use origin_conversion::*;

Expand Down
43 changes: 0 additions & 43 deletions primitives/xcm/src/location_conversion.rs

This file was deleted.

4 changes: 2 additions & 2 deletions runtime/moonbase/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ pub type LocationToAccountId = (
SiblingParachainConvertsVia<polkadot_parachain::primitives::Sibling, AccountId>,
// If we receive a MultiLocation of type AccountKey20, just generate a native account
AccountKey20Aliases<RelayNetwork, AccountId>,
// The rest of multilocations convert via hashing it
xcm_primitives::Account20Hash<AccountId>,
// Generate remote accounts according to polkadot standards
xcm_builder::ForeignChainAliasAccount<AccountId>,
);

/// Wrapper type around `LocationToAccountId` to convert an `AccountId` to type `H160`.
Expand Down
9 changes: 5 additions & 4 deletions runtime/moonbase/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ use precompile_utils::testing::MockHandle;
use std::str::from_utf8;
use xcm_builder::{ParentIsPreset, SiblingParachainConvertsVia};
use xcm_executor::traits::Convert as XcmConvert;
use xcm_primitives::Account20Hash;

use moonbeam_xcm_benchmarks::weights::XcmWeight;
use nimbus_primitives::NimbusId;
Expand Down Expand Up @@ -3024,9 +3023,11 @@ fn test_xcm_utils_ml_tp_account() {
),
);
let expected_address_alice_in_parachain_2000: H160 =
Account20Hash::<AccountId>::convert_ref(alice_in_parachain_2000_multilocation.clone())
.unwrap()
.into();
xcm_builder::ForeignChainAliasAccount::<AccountId>::convert_ref(
alice_in_parachain_2000_multilocation.clone(),
)
.unwrap()
.into();

Precompiles::new()
.prepare_test(
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbase/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub type LocationToAccountId = (
SiblingParachainConvertsVia<Sibling, AccountId>,
AccountKey20Aliases<RelayNetwork, AccountId>,
// The rest of multilocations convert via hashing it
xcm_primitives::Account20Hash<AccountId>,
xcm_builder::ForeignChainAliasAccount<AccountId>,
);

/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
Expand Down
8 changes: 4 additions & 4 deletions runtime/moonbase/tests/xcm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2734,7 +2734,7 @@ fn transact_through_signed_multilocation_para_to_para() {
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_primitives::Account20Hash::<parachain::AccountId>::convert_ref(
let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down Expand Up @@ -2843,7 +2843,7 @@ fn transact_through_signed_multilocation_para_to_para_ethereum() {
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_primitives::Account20Hash::<parachain::AccountId>::convert_ref(
let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down Expand Up @@ -2969,7 +2969,7 @@ fn transact_through_signed_multilocation_para_to_para_ethereum_no_proxy_fails()
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_primitives::Account20Hash::<parachain::AccountId>::convert_ref(
let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down Expand Up @@ -3091,7 +3091,7 @@ fn transact_through_signed_multilocation_para_to_para_ethereum_proxy_succeeds()
.reanchor(&para_b_location, ancestry.interior)
.unwrap();

let derived = xcm_primitives::Account20Hash::<parachain::AccountId>::convert_ref(
let derived = xcm_builder::ForeignChainAliasAccount::<parachain::AccountId>::convert_ref(
descend_origin_multilocation,
)
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/test-fees/test-fee-multiplier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createContract, createContractExecution } from "../../util/transactions
import {
RawXcmMessage,
XcmFragment,
descendOriginFromAddress,
descendOriginFromAddress20,
injectHrmpMessageAndSeal,
} from "../../util/xcm";
import { expectOk } from "../../util/expect";
Expand Down Expand Up @@ -208,7 +208,7 @@ describeDevMoonbeam("Fee Multiplier - XCM Executions", (context) => {
let balancesPalletIndex: number;

before("Suite Setup", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
random = generateKeyringPair();
transferredBalance = 10_000_000_000_000_000_000n;
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/test-precompile/test-precompile-xcm-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { describeDevMoonbeamAllEthTxTypes, describeDevMoonbeam } from "../../uti
import { generateKeyringPair } from "../../util/accounts";
import { BN } from "@polkadot/util";
import type { XcmVersionedXcm } from "@polkadot/types/lookup";
import { descendOriginFromAddress } from "../../util/xcm";
import { descendOriginFromAddress20 } from "../../util/xcm";
import { ALITH_TRANSACTION_TEMPLATE, createTransaction } from "../../util/transactions";
import { expectEVMResult, extractRevertReason } from "../../util/eth-transactions";

Expand Down Expand Up @@ -102,7 +102,7 @@ describeDevMoonbeamAllEthTxTypes("Precompiles - xcm utils", (context) => {
]),
});

const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
expect(result.result).to.equal(`0x${descendOriginAddress.slice(2).padStart(64, "0")}`);
});

Expand Down
24 changes: 12 additions & 12 deletions tests/tests/test-xcm/test-mock-hrmp-transact-ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ethers } from "ethers";
import { alith, charleth, generateKeyringPair } from "../../util/accounts";
import { getCompiled } from "../../util/contracts";
import {
descendOriginFromAddress,
descendOriginFromAddress20,
registerForeignAsset,
injectHrmpMessageAndSeal,
RawXcmMessage,
Expand All @@ -30,7 +30,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact ETHEREUM (transfer)"
let random: KeyringPair;

before("should receive transact action with DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
descendAddress = descendOriginAddress;
random = generateKeyringPair();
Expand Down Expand Up @@ -168,7 +168,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact ETHEREUM (call)", (c

contractDeployed = contract;

const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
random = generateKeyringPair();
transferredBalance = 10_000_000_000_000_000_000n;
Expand Down Expand Up @@ -315,7 +315,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact ETHEREUM (asset fee)

contractDeployed = contract;

const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
descendedAddress = descendOriginAddress;
random = generateKeyringPair();
Expand Down Expand Up @@ -478,7 +478,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact ETHEREUM (proxy)", (
let random: KeyringPair;

before("should receive transact action with DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
descendAddress = descendOriginAddress;
random = generateKeyringPair();
Expand Down Expand Up @@ -611,7 +611,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact ETHEREUM (proxy)", (
let random: KeyringPair;

before("should receive transact action with DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(
context,
charleth.address
);
Expand Down Expand Up @@ -753,7 +753,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact ETHEREUM (proxy)", (
let random: KeyringPair;

before("Should receive transact action with DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(
context,
charleth.address
);
Expand Down Expand Up @@ -924,7 +924,7 @@ describeDevMoonbeam("Mock XCM - transact ETHEREUM (proxy) disabled switch", (con
let random: KeyringPair;

before("Should receive transact action with DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(
context,
charleth.address
);
Expand Down Expand Up @@ -1099,7 +1099,7 @@ describeDevMoonbeam("Mock XCM - transact ETHEREUM (non-proxy) disabled switch",
let random: KeyringPair;

before("should receive transact action with DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
descendAddress = descendOriginAddress;
random = generateKeyringPair();
Expand Down Expand Up @@ -1267,7 +1267,7 @@ describeDevMoonbeam("Mock XCM - transact ETHEREUM input size check succeeds", (c

contractDeployed = contract;

const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
transferredBalance = 10_000_000_000_000_000_000n;

Expand Down Expand Up @@ -1391,7 +1391,7 @@ describeDevMoonbeam("Mock XCM - transact ETHEREUM input size check fails", (cont

contractDeployed = contract;

const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
transferredBalance = 10_000_000_000_000_000_000n;

Expand Down Expand Up @@ -1511,7 +1511,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact ETHEREUM (transfer)"
let random: KeyringPair;

before("should receive ethereum transact and account weight used", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
descendAddress = descendOriginAddress;
random = generateKeyringPair();
Expand Down
10 changes: 5 additions & 5 deletions tests/tests/test-xcm/test-mock-hrmp-transact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { expect } from "chai";

import { generateKeyringPair } from "../../util/accounts";
import {
descendOriginFromAddress,
descendOriginFromAddress20,
injectHrmpMessageAndSeal,
RawXcmMessage,
XcmFragment,
Expand All @@ -22,7 +22,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact", (context) => {
let random: KeyringPair;

before("Should receive transact action with DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
random = generateKeyringPair();
transferredBalance = 10_000_000_000_000_000_000n;
Expand Down Expand Up @@ -105,7 +105,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact with two Descends",
let random: KeyringPair;

before("Should receive transact action with two DescendOrigin", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
random = generateKeyringPair();
transferredBalance = 10_000_000_000_000_000_000n;
Expand Down Expand Up @@ -189,7 +189,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact without withdraw", (
let random: KeyringPair;

before("Should receive transact action without Withdraw", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
random = generateKeyringPair();
transferredBalance = 10_000_000_000_000_000_000n;
Expand Down Expand Up @@ -271,7 +271,7 @@ describeDevMoonbeam("Mock XCM - receive horizontal transact without buy executio
let random: KeyringPair;

before("Should receive transact action without buy execution", async function () {
const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
sendingAddress = originAddress;
random = generateKeyringPair();
transferredBalance = 10_000_000_000_000_000_000n;
Expand Down
6 changes: 3 additions & 3 deletions tests/tracing-tests/test-trace-ethereum-xcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { expect } from "chai";

import { generateKeyringPair, alith } from "../util/accounts";
import {
descendOriginFromAddress,
descendOriginFromAddress20,
injectHrmpMessage,
injectHrmpMessageAndSeal,
RawXcmMessage,
Expand All @@ -27,7 +27,7 @@ describeDevMoonbeam("Trace ethereum xcm #1", (context) => {
const { contract, rawTx } = await createContract(context, "Incrementor");
await expectOk(context.createBlock(rawTx));

const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
const sendingAddress = originAddress;
const random = generateKeyringPair();
const transferredBalance = 10_000_000_000_000_000_000n;
Expand Down Expand Up @@ -145,7 +145,7 @@ describeDevMoonbeam("Trace ethereum xcm #2", (context) => {
);
await expectOk(context.createBlock(xcm_rawTx));

const { originAddress, descendOriginAddress } = descendOriginFromAddress(context);
const { originAddress, descendOriginAddress } = descendOriginFromAddress20(context);
ethereumXcmDescendedOrigin = descendOriginAddress;
xcmContractAddress = xcm_contract.options.address;
const sendingAddress = originAddress;
Expand Down
Loading