Thanks to Ruslan from the Nova Wallet team for the help throughout the process
Introduction
Kusama and AssetHub-Kusama (AH-K) Runtime 1001000 introduced a new XCM-delivery fee mechanism that caught all Parachain teams (and most ecosystem teams) off-guard.
In this post, I’ll try to explain the problem, the solution and what I’ll be proposing the MBF to help users whose funds are locked in Moonriver-owned accounts.
The Problem
To summarize what the delivery fee means. Now, when someone sends an XCM (for example, a token transfer) from Kusama or AH-K to Moonriver, the source chain charges an additional fee to the transaction fee for sending that XCM to the destination chain. This fee is obscured to the paymentInfo
endpoint in Polkadot.js SDK, which is the only way developers have to know the cost of a specific transaction in Kusama or AH-K.
So let’s go through a practical example. Alice wants to send 1 KSM from Kusama or 1 RMRK from AH-K to Bob in Moonriver. For practical reasons, let’s say the transaction fee in both chains I is 0.001 KSM. In addition, let’s say the new XCM delivery fee is 0.01 KSM. Consequently, Alice must hold at least 1.011 KSM in Kusama or 1 RMRK and 0.011 KSM in AH-K. Note that I’m not considering the existential deposit.
What happens if Alice has enough KSM to cover the transaction fee but not the XCM delivery fee? Well, that is where the problem lies! The transaction was actually executed in the origin chain, meaning that assets like KSM in Kusama or RMRK in AH-K went to a Moonriver-controlled account in each chain, but the XCM failed to be delivered. Consequently, users would not receive their transfer in Moonriver.
If the XCM can’t be delivered because of lack of funds, the call is not reverted.
Parachain to Parachain Transfers
Users also reported that their funds were stuck when doing KSM transfers from one Parachain to another Parachain. The issue here is similar to what was described above but slightly different.
Let’s say Alice in Bifrost-Kusama wants to transfer 1 KSM to Bob in Moonriver. What happens underneath is an XCM message that goes from Bifrost-Kusama to Kusama, which contains another XCM message that is then sent from Kusama to Moonriver. Do you see the problem?
The first XCM message executed in KSM was fine, as Bifrost-Kusama does not charge an XCM delivery fee. When that message is executed in Kusamam, the first part transfers the KSM from a Bifrost-owned account to the Moonriver-owned account (KSM that the user originally had in Bifrost Kusama).
The second part of that XCM actually sends another XCM message from Kusama to Moonriver to deliver the funds to Bob in Moonriver. But, who pays for the XCM-delivery fee there? Well, that is exactly the problem! There was no way to take the funds from the XCM message to pay the XCM delivery fee. Consequently, the XCM delivery failed.
The Solution
Understanding the problem is just one piece of the puzzle. Parity vaguely provided a methodology to calculate the XCM delivery fee generically. It was clear that for the problem to be solved, we needed to find a way to obtain the XCM delivery fee for each transfer and account for that at a dApp level.
Therefore, we set off to create some script that mocked an XCM message emulating the relevant token transfer, and calculating the fees. Moreover, instead of calculating an XCM delivery fee for each individual transfer, we calculated a single XCM delivery fee based on the worst-case scenario. For Kusama based transfers, the highest XCM delivery fee is when a user sends the maximum amount possible (which is U128::MAX
, or 340282366920938463463374607.431768211455
KSM). For AH-K-based transfers, the highest XCM delivery fee is when a user sends the maximum amount possible and the asset with the highest index (RMRK index is 8). In both instances, the maximum value is 340282366920938463463374607431768211455
). You can find the scripts in the following URLs:
From the scripts:
The Max Kusama XCM Delivery Fee in KSM is 0.001366666299
The Max AH XCM Delivery Fee in KSM is 0.001051999947
Consequently, the Moonriver dApp now checks if the user also has that balance to cover XCM delivery fees (it was actually bumped by around 10% and rounded off, so it is a bit higher).
The fix was pushed Jan 30th, and XCM transfers were reactivated.
What’s Next?
After understanding the problem and releasing a fix in the Moonriver dApp to ensure no other users were impacted, the logical next step was to find the affected users and devise a plan to unlock their funds.
Unfortunately, we can only help recover funds for transfers from Kusama to Moonriver, AssetHub Kusama to Moonriver, and parachains to Moonriver. If you transferred KSM from Moonriver to another parachain, please contact the team of the destination chain.
To find all the affected users, we created a Subsquid indexer to track all the XCM messages that failed in Kusama and AH-K, but where the funds were actually transferred to the Moonriver owned account. You can find the code of the indexer in the following URLs:
The result of the indexers is the following.
If you don’t see your account in the following list. Please respond in this forum post or contact a community moderator in Telegram or Discord.
Summary of Failed KSM Transfers - Funds Locked in Moonriver Owned Account in Kusama
Note that some transfers include a from
of a parachain and an account in that parachain.
[
{
"blockNumber": 21573927,
"amount": "193552087806000",
"from": "FcRfpcdqeViSYFHFRchnqpxktYMeNg8A9dxSE828QFWhhNZ",
"id": "0021573927-f94ef-000047",
"to": "F7fq1jSB3w59f8vMShxvP5eSu3wCJbL5Am5MQ6vP6VzYLWD"
},
{
"blockNumber": 21576212,
"amount": "21996150000",
"from": "FcW8WdrjoPdVLUFPWEyrRZA24bvS7Cx8PKCS3iiX7E1haGJ",
"id": "0021576212-d427e-000042",
"to": "F7fq1jSB3w59f8vMShxvP5eSu3wCJbL5Am5MQ6vP6VzYLWD"
},
{
"blockNumber": 21579329,
"amount": "107217134466000",
"from": "JFFw9RfZ6527u4mefZrE5hjzdB3NvV82Zfu44CJ3W3f6dnX",
"id": "0021579329-e64cc-000021",
"to": "F7fq1jSB3w59f8vMShxvP5eSu3wCJbL5Am5MQ6vP6VzYLWD"
},
{
"blockNumber": 21581683,
"amount": "9832709199",
"from": "Parachain 2001 - dgRUb8Nh6qA4ZxTHrhwMSGXjTzHaMwaFc8HsMCzpS9jjBoW - https://bifrost-kusama.subscan.io/extrinsic/5890904-2?event=5890904-9&tab=xcm_transfer",
"id": "0021581683-46921-000003",
"to": "F7fq1jSB3w59f8vMShxvP5eSu3wCJbL5Am5MQ6vP6VzYLWD"
},
{
"blockNumber": 21582439,
"amount": "11593960025",
"from": "Parachain 2001 - edjPQn1n8MDxGoFNtYEBvcxPRf6gE2S7BKgQxQu8gZknycs - https://bifrost-kusama.subscan.io/extrinsic/5891160-2?event=5891160-6&tab=xcm_transfer",
"id": "0021582439-2a20a-000003",
"to": "F7fq1jSB3w59f8vMShxvP5eSu3wCJbL5Am5MQ6vP6VzYLWD"
},
{
"blockNumber": 21583225,
"amount": "100290626722",
"from": "Parachain 2000 - r4SoBpxKYpUpXGTGtNpTzcP2L8faPD8xQExZG6vj55Q94SZ - https://karura.subscan.io/extrinsic/6138236-3?event=6138236-34&tab=xcm_transfer",
"id": "0021583225-81d24-000004",
"to": "F7fq1jSB3w59f8vMShxvP5eSu3wCJbL5Am5MQ6vP6VzYLWD"
},
{
"blockNumber": 21587554,
"amount": "9832709199",
"from": "Parachain 2001 - ffm75STKAACSqbnc6j16Nkm9h9i2VtjTvHXpkZy32QxsD2s - https://bifrost-kusama.subscan.io/extrinsic/5892906-2?event=5892906-5&tab=xcm_transfer",
"id": "0021587554-d471c-000004",
"to": "F7fq1jSB3w59f8vMShxvP5eSu3wCJbL5Am5MQ6vP6VzYLWD"
},
{
"blockNumber": 21588460,
"amount": "1517360819000",
"from": "JFFw9RfZ6527u4mefZrE5hjzdB3NvV82Zfu44CJ3W3f6dnX",
"id": "0021588460-202b6-000039",
"to": "F7fq1jSB3w59f8vMShxvP5eSu3wCJbL5Am5MQ6vP6VzYLWD"
},
{
"blockNumber": 21589429,
"amount": "154997802516000",
"from": "Dfi679UVN5LTQbPX5wT1brdrzAHthu4P3LgVSaC8dhvprk8",
"id": "0021589429-2b447-000046",
"to": "F7fq1jSB3w59f8vMShxvP5eSu3wCJbL5Am5MQ6vP6VzYLWD"
},
{
"blockNumber": 21590503,
"amount": "10174891000",
"from": "FcW8WdrjoPdVLUFPWEyrRZA24bvS7Cx8PKCS3iiX7E1haGJ",
"id": "0021590503-c3dde-000045",
"to": "F7fq1jSB3w59f8vMShxvP5eSu3wCJbL5Am5MQ6vP6VzYLWD"
},
{
"blockNumber": 21594113,
"amount": "22255803745000",
"from": "J6k9HwMJS2bxs3MNSwMmfYGUoqmX12g61nD46v1kdtLWj3V",
"id": "0021594113-ffa51-000042",
"to": "F7fq1jSB3w59f8vMShxvP5eSu3wCJbL5Am5MQ6vP6VzYLWD"
}
]
Summary of Failed RMRK Transfers - Funds Locked in Moonriver Owned Account in AssetHub Kusama
Only users transferring RMRK tokens to Moonriver were affected.
[
{
"blockNumber": 6284005,
"amount": "23630577378420",
"from": "EJkrJnW23UyTEkcfXpyAJ2zEtZepBTGbPh7z6ED4utyn1hd",
"id": "0006284005-f7c1c-000005",
"to": "FBeL7EFFn7yHFs4uSf432RThNjEuieS8pQWcMdRFpXZPqkW",
"assetID": 8
},
{
"blockNumber": 6285438,
"amount": "11000000000",
"from": "GUeNBTpyBDCGAFCPJnQuLwZT5zQnspygvD8czVzSBAe8HXe",
"id": "0006285438-b0a77-000010",
"to": "FBeL7EFFn7yHFs4uSf432RThNjEuieS8pQWcMdRFpXZPqkW",
"assetID": 8
},
{
"blockNumber": 6285596,
"amount": "3350000000000",
"from": "EtmtG8CwZfF6pm8Wf4pUqvPHJQKvi76cUZDKnVktBGMVbky",
"id": "0006285596-cca77-000004",
"to": "FBeL7EFFn7yHFs4uSf432RThNjEuieS8pQWcMdRFpXZPqkW",
"assetID": 8
},
{
"blockNumber": 6289790,
"amount": "30000000000",
"from": "EtmtG8CwZfF6pm8Wf4pUqvPHJQKvi76cUZDKnVktBGMVbky",
"id": "0006289790-79340-000005",
"to": "FBeL7EFFn7yHFs4uSf432RThNjEuieS8pQWcMdRFpXZPqkW",
"assetID": 8
}
]
The Plan to Recover Funds
We’ll propose to the Moonbeam Foundation to submit a governance proposal that will send an XCM message from Moonriver to Kusama and AH-K to unlock the funds and transfer them back to the original owners.
For KSMs locked in Kusama from another parachain, we’ll send an XCM to Kusama that executes an XCM call to transfer these funds back to the original account in the source parachain.
We’ll test everything in Chopsticks before submitting the governance proposal.