Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

XCM: Remote account converter #6662

Merged

Conversation

mustermeiszer
Copy link
Contributor

Based on the discussion in #6612 this PR adds a converter to the codebase that allows to have a stable conversion from a local account (xcm sending location) to a remote account (xcm receiving location).

@mustermeiszer
Copy link
Contributor Author

@xlc @joepetrowski @jak-pan @girazoki WDYT about the converter like this?

Happy to adapt to what is the compromise everybody is happy with.

@mustermeiszer
Copy link
Contributor Author

Also @KiChjang do you already have some remarks?

@xlc
Copy link
Contributor

xlc commented Feb 3, 2023

I think a fixed prefix that includes parachain id could be useful. This acts as metadata and namespaced addresses. By only looking at an address, we will know it is an account belong to a certain parachain and impossible for one parachain to access account belong to another parachain

@mustermeiszer
Copy link
Contributor Author

mustermeiszer commented Feb 3, 2023

You mean as part of the resulting [u8; 32]?

I am not sure this adds a lot, but I am also not against it.

  • Security is already derived from the input of the hash to prevent access from other parachains
  • From UI perspective this won't help, as the ss58 is not helping here.
  • The raw-bytes will have a clear prefix that signal the "origin"

Happy to add that if we want that to be part of it.

@mustermeiszer mustermeiszer marked this pull request as ready for review February 6, 2023 12:24
@mustermeiszer
Copy link
Contributor Author

@xlc I thought about adding a fixed prefix to the resulting [u8; 32] and my main thoughts against it are

  • a short prefix (e.g. *b"P1000") → higher probability to have collisions with "local" accounts
  • a larger prefix (e.g. *b"ForeignP1000") → the entropy of the bytes is too low

Basically, these are just thoughts of someone who barely knows stuff about cryptography and the probabilities of collisions. But I think if we want a prefix we need to inspect this more thoroughly while we can trust the blake2_256 output.

MultiLocation {
parents: 0,
interior: X2(Parachain(para_id), AccountId32 { id, .. }),
} => ForeignChainAliasAccount::<AccountId>::from_para_32(para_id, id),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} => ForeignChainAliasAccount::<AccountId>::from_para_32(para_id, id),
} => ForeignChainAliasAccount::<AccountId>::from_relay_32(para_id, id),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This matching arms matches against messages received on the relay chain coming from a para-chain. I would argue that this should use the conversion from the parachain, allowing to have the same alias on each consuming chain of this converter.

Copy link
Member

Choose a reason for hiding this comment

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

Then I would add another item from_child_32, and with its own prefix.

MultiLocation {
parents: 0,
interior: X2(Parachain(para_id), AccountKey20 { key, .. }),
} => ForeignChainAliasAccount::<AccountId>::from_para_20(para_id, key),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} => ForeignChainAliasAccount::<AccountId>::from_para_20(para_id, key),
} => ForeignChainAliasAccount::<AccountId>::from_relay_20(para_id, key),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This matching arms matches against messages received on the relay chain coming from a para-chain. I would argue that this should use the conversion from the parachain, allowing to have the same alias on each consuming chain of this converter.

Copy link
Member

Choose a reason for hiding this comment

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

Then I would add another item from_child_20, and with its own prefix.


impl<AccountId> ForeignChainAliasAccount<AccountId> {
fn from_para_32(para_id: &u32, id: &[u8; 32]) -> [u8; 32] {
(FOREIGN_CHAIN_PREFIX, para_id, id).using_encoded(blake2_256)
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest different prefixes for each mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why so? Can add that of course, just am curious about the reasoning.

Copy link
Member

Choose a reason for hiding this comment

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

To avoid the possibility of unintended collision.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. I assumed that having a 32 bits difference between from_relay_32 and from_para_32 and a 256 bits difference between the from_para_* methods in the input stream would be enough difference to have sufficient bitflips with blake.

Will adapt then!

@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/multilocation-based-account-derivation/436/10

@mustermeiszer
Copy link
Contributor Author

RE: Methods

My reasoning for having only

  • from_para_32
  • from_para_20
  • from_relay_32

Is that the user will for a given Account A always know that his alias account A' is consistent across all chains using this converter. Making integrations with UI and wallets easier, where as when having the from_child_* this breaks this assumption for the relay chain.

@gavofyork if having this is a blocker, I will adapt the PR.

@mustermeiszer
Copy link
Contributor Author

@gavofyork or @KiChjang a last comment on the above and then we can probably finish this.

@gavofyork
Copy link
Member

There may be unintended security consequences from having the same account ID used as the alias across multiple chains. I would certainly feel more confident if the aliases were different over each chain. That said, as long as it's strictly only for chains within the same security apparatus (i.e. not bridged locations), then it's probably fine to reuse the account alias.

@gavofyork
Copy link
Member

gavofyork commented Mar 14, 2023

To avoid the possibility of unintended collision.

This will break horribly with multi-level relay-chains: Account A on para index P controls account h(A, P) on all sibling, parent and child chains which use these primitives.

If you have multiple sets of parachains, then you'll naturally have index collisions. E.g.

         R
      /     \
    P1        P2
  /   \     /    \
P1.1 P1.2  P2.1 P2.2

Here, P1.2 would be index 2 to P1, P2.2 would be index 2 to P2 and P2 would be index 2 to R. Account h(A, 2) would therefore be controllable on P2 by both A on R, and A on P2.2; this might be very problematic if you trust the logic of R much more than P2.2.

This will never be a problem if you include the relationship within the hashed data.

@mustermeiszer
Copy link
Contributor Author

mustermeiszer commented Mar 15, 2023

Account h(A, 2) would therefore be controllable on P2 by both A on R, and A on P2.2; this might be very problematic if you trust the logic of R much more than P2.2.

The indices are wrong, but you are right:

  • A on R → controls h(A) on P1 and P2
  • A on P1.2 → controls h(A, 2) on P1 and P1.1
  • A on P2 → controls h(A, 2) on R and P1

→ account h(A, 2) on P1 is controllable by both P2 and P1.2.

TBH I have not thought about multi-relay-chain setup. What do you mean with relationship in this context, how would that be extracted from the MultiLocation? (edit)

Yes, we could include the parents-value in the conversion. WDYT?

@girazoki
Copy link
Contributor

girazoki commented Mar 15, 2023

I think we can just use a different conversion for sibling or child parachains (similar to how the sovereign conversion is different since you append the "child" alias for child chains and "sibl" for chains).

A on P1.2 → controls h("child", A, 2) on P1 and h("sibl", A, 2)  P1.1
A on P2 → controls h("child", A, 2)  on R and P1 h("sibl", A, 2)

I think you wouldnt have colisions in this case

@gavofyork
Copy link
Member

Yes; including the parents value is slightly more general, but either way would be fine.

@crystalin
Copy link

Hi @mustermeiszer, do you think you can do changes to adapt to the comments in the next days? We are waiting for this one to be merged before releasing a new runtime. If not, let me know and @girazoki can do the modifications
Thank you

@mustermeiszer
Copy link
Contributor Author

@crystalin Its updated. Can be reviewed and merged if all are happy.

@crystalin
Copy link

@mustermeiszer
Copy link
Contributor Author

Docs did not format the tree correctly...

@mustermeiszer
Copy link
Contributor Author

@crystalin the two jobs failing seem not connected to this pr. cc @bkchr

@gavofyork are you otherwise fine with the current state of the pr?

@mustermeiszer
Copy link
Contributor Author

@gavofyork how do you feel about the current state? Can we merge it?

@girazoki
Copy link
Contributor

@KiChjang @gavofyork is there anything else missing for this PR to be merged?

Copy link
Member

@gavofyork gavofyork left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@mustermeiszer
Copy link
Contributor Author

@KiChjang are you also happy with that? Can we merge that?

Copy link
Contributor

@KiChjang KiChjang left a comment

Choose a reason for hiding this comment

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

Ok for me, but needs an audit. Doesn't prevent this PR from landing however.

@KiChjang KiChjang added A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited. T1-runtime This PR/Issue is related to the topic “runtime”. B1-note_worthy Changes should be noted in the release notes labels Apr 20, 2023
@mustermeiszer
Copy link
Contributor Author

Cool. Let me know if you need anything for merging, but seems like it is up to you guys now.

@KiChjang
Copy link
Contributor

bot merge

@paritytech-processbot paritytech-processbot bot merged commit 887e38f into paritytech:master Apr 24, 2023
ordian added a commit that referenced this pull request Apr 26, 2023
* master:
  malus: dont panic on missing validation data (#6952)
  Offences Migration v1: Removes `ReportsByKindIndex` (#7114)
  Fix stalling dispute coordinator. (#7125)
  Fix rolling session window (#7126)
  [ci] Update buildah command and version (#7128)
  Bump assigned_slots params (#6991)
  XCM: Remote account converter (#6662)
  Rework `dispute-coordinator` to use `RuntimeInfo` for obtaining session information instead of `RollingSessionWindow` (#6968)
  Revert default proof size back to 64 KB (#7115)
ordian added a commit that referenced this pull request Apr 26, 2023
* master: (39 commits)
  malus: dont panic on missing validation data (#6952)
  Offences Migration v1: Removes `ReportsByKindIndex` (#7114)
  Fix stalling dispute coordinator. (#7125)
  Fix rolling session window (#7126)
  [ci] Update buildah command and version (#7128)
  Bump assigned_slots params (#6991)
  XCM: Remote account converter (#6662)
  Rework `dispute-coordinator` to use `RuntimeInfo` for obtaining session information instead of `RollingSessionWindow` (#6968)
  Revert default proof size back to 64 KB (#7115)
  update rocksdb to 0.20.1 (#7113)
  Reduce base proof size weight component to zero (#7081)
  PVF: Move PVF workers into separate crate (#7101)
  Companion for #13923 (#7111)
  update safe call filter (#7080)
  PVF: Don't dispute on missing artifact (#7011)
  XCM: Properly set the pricing for the DMP router (#6843)
  pvf: Update docs for PVF artifacts (#6551)
  Bump syn from 2.0.14 to 2.0.15 (#7093)
  Companion for substrate#13771 (#6983)
  Added Dwellir Nigeria bootnodes. (#7097)
  ...
librelois pushed a commit to moonbeam-foundation/polkadot that referenced this pull request May 11, 2023
* Draft remote account converter

* Tests and doc comments

* Adapt naming, tests fix

* Try with prefix in account

* Revert "Try with prefix in account"

This reverts commit 4617597.

* Adapt code and test to review suggestions

* adapt to take into account parent in conversion

* fix: docs

* fix: try doc fix v2
@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/multichain-friendly-account-abstraction/1298/19

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited. T1-runtime This PR/Issue is related to the topic “runtime”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants