paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.network/
1.8k stars 654 forks source link

PolkadotXCM Reserve Transfer Asset with Multiple Asset and FeeItem is Zero (0) #3661

Open albertov19 opened 6 months ago

albertov19 commented 6 months ago

Is there an existing issue?

Experiencing problems? Have you tried our Stack Exchange first?

Description of bug

We are testing doing a transfer from Polkadot AssetHub to Moonbeam (using Chopsticks), and we noticed the weirdest issue.

When transferring two assets (in this case, it was PINK and USDT, the latter to be used as the feeAssetItem), whenever USDT is set as an asset 0 and the feeAssetItem = 0, the call would fail with wasm: unreachable instructions....

Nevertheless, if you switch the asset order (leaving everything else the same, amounts, etc) and set feeAssetItem = 1, it works 🤯 .

Steps to reproduce

To replicate, you can run Asset-Hub, Moonbeam and Polkadot with Chopsticks using the following AssetHub configuration file:

endpoint: wss://statemint-rpc.dwellir.com
mock-signature-host: true
block: ${env.STATEMINT_BLOCK_NUMBER}
db: ./db.sqlite

import-storage:
  System:
    Account:
      -
        -
          - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
        - providers: 1
          data:
            free: 1000000000000000
  Assets:
    Account:
      - [[1984, 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY], { balance: 1000000000 }]
      - [[1337, 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY], { balance: 1000000000 }]
      - [[21, 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY], { balance: 1000000000 }]
      - [[23, 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY], { balance: "1000000000000000000" }]

The following call fails (Assets(0) = USDT, feeAssetItem = 0):

0x1f0801010100511f010001030098891e5fd24ef33a488a47101f65d212ff6e650e0108000002043205011f0002093d000000020432055c0002093d000000000000

The following call succeeds (Assets(1) = USDT, feeAssetItem = 1)

0x1f0801010100511f010001030098891e5fd24ef33a488a47101f65d212ff6e650e01080000020432055c0002093d00000002043205011f0002093d000100000000
acatangiu commented 6 months ago

Might be same underlying issue described in https://github.com/paritytech/polkadot-sdk/issues/2123?

Assets are sorted when going from vec<Asset> to Assets, so the order in which you add them in PJS might not be same final order and feeAssetItem = 0 might actually be pointing to the other asset.

The "asset idx" API is bad and we should just change it to explicitly specify the asset instead of an index in the list.

Still, that doesn't explain how it'd fail with wasm: unreachable instructions...

albertov19 commented 6 months ago

Yeah, I think the problem feels relatable to that described in #2123. Although I was reporting it from a more user-centric perspective, I could not find it when looking for it.

When will #2129 hit AssetHub?

Thanks for the quick answer

acatangiu commented 6 months ago

We should still investigate and see what is with the wasm error, afaict if the only problem is using wrong asset for paying fees, then transfer should fail with not enough fees not unreachable instructions