-
Notifications
You must be signed in to change notification settings - Fork 14
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
358 handle delegation of brz token to automation pallet in xcm config #365
358 handle delegation of brz token to automation pallet in xcm config #365
Conversation
… Mock Moonbeam transfer of asset. Implement custom barrier for other runtimes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good overall, great job @gianfra-t 👍
I think it would be better if we don't add the same barrier on all runtimes though. For now I would only add it to the pendulum runtime and revert the changes for Foucoco and Amplitude. The reason is that the BRZ location only is correct like this on Pendulum. For testing purposes we will probably add a very similar barrier to Foucoco as well (but defining a different contract location instead of BRZ because we need to be the issuer of that contract for testing), so it's great that the barrier is implemented in the common
directory and re-usable. Adding the changes for Foucoco should be part of a different ticket once we know the details though.
Thus, I'd suggest we only focus on Pendulum for now and also change the added integration test to only target Pendulum and not the other runtimes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR. I have some general remarks.
- Is the Barrier really the right point to execute side effects? Just the name of the trait
ShouldExecute
indicates that this is just a pure function that returns Yes or No. Do we have examples from other parachains? - The xcm message can fail at a later point and we execute the side effect anyway (or am I wrong here?)
- The whole trait
MatcherConfig
feels overly generic to me. Let's please always just implement the minimum required and add features later if we need them, particularly:- why a fee system?
- why a vector of matcher pairs?
- why does is the
MatcherPair
a struct of functions instead of just a struct with an expected multilocation and, well, theDepositAssetMatcher
can probably not be simplified that much
To address some of the remarks (as far as I can!):
At first I actually chose the
I don't think it can fail really, since it is not going to be executed by the
This is true, it is not the "simplest" solution. The idea of using a vector is to allow for easily handling a new XC-20 token like BRZ that will go the same route (to the automation pallet). If this is not needed then we can simplify a bit. But fees was something that was discussed before and since the message will never reach the |
Wouldn't the I think that this is better and more flexible then reading the complete xcm message and trying to interpret what it does. Instead let the xcm executor execute the whole message and insert our special code only at the place where the real transaction happens.
I missed that and I would definitely advise against this. We put too many assumptions here on how messages sent by other parachains will look like in the future. I think we should definitely not skip the execution of the xcm executor pallet, particularly all the safety mechanisms built into it (and, e.g., fee payments, etc.)
If this is not a definition in the issue description, then we should use the normal fee mechanism of the xcm-executor and not start to build a custom solution here. The decision and discussion should happen in the issue instead. |
You are right that the
In this case, how could we prevent that another XC-20 token (BRZ_2) calls
This I agree until the fee extraction, after that (the deposit instruction left) will fail anyway since we will not map this special destination into a token. Update: |
Yes, it is exactly the Am I naive here? Could this be exploited? If that could be exploited, that means that another parachain would be able to send us an XCM message that we execute blindly that contains the But even if we can ensure that the xcm message originates at Moonbeam and is well formed: we do not know whether Moonbeam actually locked the respective amount of BRZ tokens or whether Moonbeam just sent this xcm message to us without any BRZ tokens being locked. We need to inherently trust that Moonbeam works correctly and not maliciously here (i.e., acting on XCM messages is not a trustless process). |
Then assuming we trust moonbeam and the other connected parachains which is probably a good assumption, and that we do not check for the parachain origin, the only dangerous scenario I see is another parachain that also implements pallet contracts or similar, where some user would be able to replicate this specific set of instructions.
In this case I think we do because it is reserved asset transfer as the ones here right? |
What do you mean, can you elaborate? I don't think that users are themselves able to generate these instructions. Users are not able to send arbitrary XCM messages to us from another parachain.
Sure, this is a reserved asset transfer. But just in principle: if Moonbeam implements malicious logic, they could just send us an XCM message that looks exactly like the one that results from a reserve asset transfer. Futhermore, I think that we need to use the |
For sure, I was thinking more about a parachain having a pallet contracts or equivalent that allowed their users to create tokens (like the XC-20) and send to a desired destination. I honestly don't know how it would look like, and it may be too far fetched. I also wasn't aware of the checking in |
I have greatly simplified the implementation as we discussed, also removing the generic capability of allowing multiple "pairs" and only defining one desired asset to intercept (in this case BRZ). We can later put back this capability easily once we are aware of how other asset may be bridged this way. |
Maybe it misses the point and you meant something else, but users actually are able to send arbitrary XCM messages to us from other parachains using the send() extrinsic of the xcm-pallet @TorstenStueber. |
But I think one can control that with |
@ebma I was not aware. I assume that in this case the origin MultiLocation will be different and not just |
No, I think it will be the correct |
@ebma I think you are correct that anyone can send a |
@gianfra-t the argument is that anyone could send exactly the same xcm message to us that would originate from a legitimate reserve asset transfer. But I doubt this. If everyone can send an xcm message to us from Moonbeam and we are not able to tell the difference, then this would be a clear flaw: the whole purpose of a reserve asset transfer is that such an xcm message only arrives at Pendulum when Moonbeam locked an amount of tokens before – like for every bridge. When we execute the xcm message, then we mint an equivalent amount of wrapped tokens. This should of course never happen when Moonbeam did not lock tokens before – otherwise this would be a flawed bridge design. |
I just checked this:
One more reason why we should not skip the normal VM execution (as you did originally @gianfra-t). |
If I understand correctly this does not hold because the origin of this |
I did not check what the xtokens pallet does. I only checked what pallet-xcm does when executing the I assume that xtokens works similarly but it might depends on the concrete extrinsic. What extrinsic do you have in mind? |
I was just curious as to why I wouldn't be able to execute a reserve transfer of assets with I checked the xtokens pallet and when doing a |
XCM is so complex and there are many different origins involved here:
The difference between sending an xcm message directly is that the there will always be this extra initial I find it confusing that there is pallet-xcm and xtokens, seems like there is a big overlap in their purpose. So it seems like the following two extrinsics basically have the same outcome:
Both of these extrinsics will ultimately call the function
So this xcm message with this one instruction will be executed on the source chain. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, looks good to me now 👍
What do you think @TorstenStueber?
Looks good so far. I want to check a few things and will give my final opinion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job @gianfra-t! Thanks.
A custom
MultiCurrencyAdapter
that is used asAssetTransactor
is re-defined in runtime-common which then can be used to specify on the xcm config of the runtimes theasset
andbeneficiary_location
that we want to "intercept", corresponding to theReserveAssetDeposited
'sasset
anDepositAsset
'sbeneficiary
instruction on the XCM message.Detailed Explanation
Any transfer from the
XTokens
pallet in moonbeam corresponding to the transfer of a nativeXC-20
token, will trigger the following instructions:ReserveAssetDeposited, ClearOrigin, BuyExecution, DepositAsset
See for instance this event which corresponds to the transfer of a local XC 20 with account key
0x931715fee2d06333043d11f658c8ce934ac61d0c
.The corresponding XCM message for this event can be found here where the
ReserveAssetDeposited
instructions reflects the multilocation of the XC-20 asset, andDepositAsset
that of the destination defined in theXTokens::transfer
.The call to the deposit_asset function will happen with the asset defined in
ReserveAssetDeposited
and the beneficiary location being that of the automation pallet.