Fujicracy / fuji-v2

Cross-chain money market aggregator
https://fuji-v2-frontend.vercel.app
15 stars 10 forks source link

Sender param in CrossTransferWithCall #530

Closed 0xdcota closed 1 year ago

0xdcota commented 1 year ago

While performing integration of the native token in the front-end during Beta testing, it was identified that there was a broken step to facilitate wrapping and unwrapping of the native assets while attempting to then perform further operations.

In the case of DEPOSIT_ETH + X_CALL_WITHCALLDATA, we should set the sender to be the router and then that should skip pulling the wnative from the user. This would be similar to how is done in BRIDGE + DEPOSIT. In such case the sender in the deposit action is again the router. In both instances described previously we don't need to pull anything from the user as the assets are already in the router.

In discussion it was suggested that we include a sender param when decoding args in function _crossTransferWithCalldata so that it's similar to function function _crossTransfer. This won't have any security impacts bc in function _safePullTokenFrom we can pull only if sender == msg.sender

Change as follows:

function _crossTransferWithCalldata(
    bytes memory params,
    address beneficiary
  )
    internal
    override
    returns (address beneficiary_)
  {
    (
      uint256 destDomain,
      uint256 slippage,
      address asset,
      uint256 amount,
      address delegate,
      address sender,
      bytes memory callData
    ) = abi.decode(params, (uint256, uint256, address, uint256, address, address, bytes));

    (Action[] memory actions, bytes[] memory args,) =
      abi.decode(callData, (Action[], bytes[], uint256));

    beneficiary_ = _checkBeneficiary(beneficiary, _getBeneficiaryFromCalldata(actions, args));

    _safePullTokenFrom(asset, sender, amount);
    _safeApprove(asset, address(connext), amount);