-
Notifications
You must be signed in to change notification settings - Fork 44
RFC: ExecuteWithOrigin instruction #38
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
Merged
franciscoaguirre
merged 5 commits into
polkadot-fellows:master
from
franciscoaguirre:with-pushed-origin
Aug 9, 2023
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1e96eb4
RFC: WithPushedOrigin instruction
franciscoaguirre 6b8a331
Address feedback
franciscoaguirre 3247d21
Rephrase summary
franciscoaguirre f4690ee
Rename WithPushedOrigin instruction and bump version
franciscoaguirre 6875af3
Fix XCM version
franciscoaguirre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| --- | ||
| Title: WithPushedOrigin instruction | ||
| Number: 0 | ||
| Status: Draft | ||
| Version: 0 | ||
| Authors: | ||
| - Francisco Aguirre | ||
| Created: 2023-06-21 | ||
| Impact: Low | ||
| Requires: | ||
| Replaces: | ||
| --- | ||
|
|
||
| ## Summary | ||
|
|
||
| The proposed change is the introduction of a `WithPushedOrigin` instruction. | ||
| The instruction allows the XCVM to "push" a new origin for just a few instructions and then return to the original origin when those instructions are done. | ||
| It can be seen as pushing a new origin on a stack for the execution of a block of instructions and then popping it back when the block is done. | ||
| The new origin can only be empty (clear the origin) or a child of the current origin. | ||
|
|
||
| The goal is to give developers more flexibility and a better experience when handling origins in their messages. | ||
|
|
||
| ## Motivation | ||
|
|
||
| Right now, XCM has two instructions for modifying the origin: `ClearOrigin` and `DescendOrigin`. | ||
| These work for manipulating the origins in safe ways. | ||
| However, these instructions are final, once you use them, there's no standard way of going back to the original origin. | ||
| This results in a complicated developer experience, where the order of operations needs to be highly taken into account to perform the operations needed, with the correct origins for each. | ||
|
|
||
| This new instruction, `WithPushedOrigin`, provides a way of pushing an origin and popping to return to the original one. | ||
| It makes scenarios where multiple operations need to be performed by multiple origins much easier to do. | ||
| It gives a standard way of doing things like buying execution from a user's account and then returning to the previous origin to perform other operations that require the priviledges associated with it. | ||
| It also allows for previously impossible scenarios like acting on behalf of many sibling origins. | ||
|
franciscoaguirre marked this conversation as resolved.
|
||
|
|
||
| ## Specification | ||
|
franciscoaguirre marked this conversation as resolved.
|
||
|
|
||
| The instruction looks like this: | ||
|
|
||
| ```rust | ||
| WithPushedOrigin { origin: Option<InteriorMultiLocation>, xcm: Xcm } | ||
| ``` | ||
|
|
||
| If the `pushed_origin` is `None`, then `ClearOrigin` will be called before executing the inner `xcm`. | ||
| The previous origin will be restored once the inner `xcm` has finished executing. | ||
|
|
||
| If the `pushed_origin` is `Some(interior_location)`, then `DescendOrigin(interior_location)` will be called before executing the inner `xcm`. | ||
| The previous origin will be restored once the inner `xcm` has finished executing. | ||
|
franciscoaguirre marked this conversation as resolved.
|
||
|
|
||
| ### Examples | ||
|
|
||
| #### Clearing the origin | ||
|
|
||
| ```rust | ||
| // Withdraw assets from the origin | ||
| WithdrawAsset(/* ...snip... */); | ||
| WithClearOrigin { | ||
|
franciscoaguirre marked this conversation as resolved.
Outdated
|
||
| origin: None, | ||
| xcm: Xcm(vec![ | ||
| // Deposit assets without an origin | ||
| DepositAsset { /* ...snip... */ } | ||
| ]), | ||
| } | ||
| ``` | ||
|
|
||
| #### Buying execution with an account | ||
|
|
||
| ```rust | ||
| /* Origin: ../Parachain(1000) */ | ||
|
|
||
| WithClearOrigin { | ||
|
franciscoaguirre marked this conversation as resolved.
Outdated
franciscoaguirre marked this conversation as resolved.
Outdated
|
||
| origin: Some(AccountId32 { /* ...snip... */ }), | ||
| xcm: Xcm(vec![ | ||
| BuyExecution { /* ...snip... */ }, | ||
| ].into()), | ||
| } | ||
| // Transact with the parachain origin | ||
| Transact { | ||
| origin_kind: OriginKind::SovereignAccount, | ||
| /* ...snip... */ | ||
| } | ||
| ``` | ||
|
|
||
| ## Security considerations | ||
|
|
||
| This instruction does not allow for arbitrary origin manipulation, which would be a serious issue. | ||
| It only mixes the current `DescendOrigin` and `ClearOrigin` instructions in an easier-to-use way. | ||
|
|
||
| ## Impact | ||
|
|
||
| The impact is Low since it introduces a new instruction. XCVM implementations would need to be updated. | ||
|
|
||
| ## Alternatives | ||
|
|
||
| The alternative right now is to use `ClearOrigin` or `DescendOrigin` by themselves, which depends on the order of operations, which is subject to barriers. | ||
| There are some situations that are impossible to express without this new instruction, like dealing with multiple sibling origins. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.