Skip to content
This repository has been archived by the owner on Dec 13, 2019. It is now read-only.

[node] Ordering on uninstall for MULTI_ASSET_MULTI_PARTY_COIN_TRANSFER outcome #2085

Open
LayneHaber opened this issue Aug 1, 2019 · 0 comments

Comments

@LayneHaber
Copy link
Collaborator

In the handleMultiAssetMultiPartyCoinTransfer function within get-outcome-increments.ts, there is a strong assumption on the ordering of arguments supplied to the coinTransfer object in the state of the app.

For instance, this initial state supplied to SimpleSwapApp will result in an incorrect transfer:

  {
      coinTransfers: [
        [
          {
            amount: swappedAmount,
            to: fromExtendedKey(this.connext.nodePublicIdentifier).derivePath("0").address,
          },
        ],
        [
          {
            amount,
            to: fromExtendedKey(this.connext.publicIdentifier).derivePath("0").address,
          },
        ],
      ],
    };

Sample logs from this error:

// swap request
Installing swap app. Swapping 10000000000000000 of 0x0000000000000000000000000000000000000000 for 2162250000000000000 of 0xdDA6327139485221633A1FcD65f4aC932E60A2e1

// after app install -- correct decrementing
info: [SwapController] Free balance after swap install
info: [SwapController] Channel's free balance of 0xdDA6327139485221633A1FcD65f4aC932E60A2e1:
info: [SwapController] 0xd6e78115B145E6A988159Cc80483E7e6Bcfa12B0 0.0
info: [SwapController] 0xF80fd6F5eF91230805508bB28d75248024E50F6F 7.83775
info: [SwapController] Channel's free balance of 0x0000000000000000000000000000000000000000:
info: [SwapController] 0xd6e78115B145E6A988159Cc80483E7e6Bcfa12B0 0.09
info: [SwapController] 0xF80fd6F5eF91230805508bB28d75248024E50F6F 0.0

// after uninstalling -- incorrect merging
Channel's free balance of 0x0000000000000000000000000000000000000000:
0xd6e78115B145E6A988159Cc80483E7e6Bcfa12B0 2.25225
0xF80fd6F5eF91230805508bB28d75248024E50F6F 0.0
Channel's free balance of 0xdDA6327139485221633A1FcD65f4aC932E60A2e1:
0xd6e78115B145E6A988159Cc80483E7e6Bcfa12B0 0.0
0xF80fd6F5eF91230805508bB28d75248024E50F6F 7.84775

Whereas this initial state will result in a correct swap:

     {
      coinTransfers: [
       [
          {
            amount,
            to: fromExtendedKey(this.connext.publicIdentifier).derivePath("0").address,
          },
        ],
        [
          {
            amount: swappedAmount,
            to: fromExtendedKey(this.connext.nodePublicIdentifier).derivePath("0").address,
          },
        ],
      ],
    };

This comes from the following code:

return interpreterParams.tokenAddresses.reduce(
    (acc, tokenAddress, index) => ({
        ...acc,
        [tokenAddress]: convertCoinTransfersToCoinTransfersMap(
            decodedTransfers[index]
        )
    }),
    {}
)```

where the assumption is the `tokenAddress` in the interpreter parameters will have the same ordering as the tokens resulting from the decoded state.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant