code-423n4 / 2022-06-connext-findings

1 stars 0 forks source link

Use of `SafeApprove()` while swapping may revert causing DoS #235

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Lines of code

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/libraries/AssetLogic.sol#L347

Vulnerability details

Impact

Proof of Concept

Snippet from SafeERC20

function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

Snippet from _swapAssetOut()

function _swapAssetOut(
    // .........
        // perform the swap
        SafeERC20.safeApprove(IERC20(_assetIn), address(pool), _amountIn);
        amountIn = pool.swapExactOut(_amountOut, _assetIn, _assetOut, _maxIn);
      }
      // slippage is too high to perform swap: success = false, amountIn = 0
      ......
    }

Tools Used

Manual Analysis

Recommended Mitigation Steps

Use safeIncreaseAllowance and safeDecreaseAllowance instead of safeApprove().

ecmendenhall commented 2 years ago

Duplicate of #154

jakekidd commented 2 years ago

dup of #154

0xleastwood commented 1 year ago

No mention of impact on how bridge transfers would fail under these circumstances and lock funds. Downgrading to QA.

0xleastwood commented 1 year ago

Merging with #236.