Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
code423n4 opened this issue Jun 19, 2022 · 4 comments
Closed

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

code423n4 opened this issue Jun 19, 2022 · 4 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax

Comments

@code423n4
Copy link
Contributor

Lines of code

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

Vulnerability details

Impact

  • _swapAssetOut() of AssetLogic.sol uses safeApprove() from openzeppelin's SafeERC20.
  • safeApprove() will revert when value != 0 and allowance to the spender != 0 .
  • When the _amountIn is > 0 and token.allowance(address(this), spender) > 0, the function will revert.

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().

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Jun 19, 2022
code423n4 added a commit that referenced this issue Jun 19, 2022
@ecmendenhall
Copy link

Duplicate of #154

@jakekidd jakekidd added the duplicate This issue or pull request already exists label Jun 24, 2022
@jakekidd
Copy link
Collaborator

dup of #154

@0xleastwood
Copy link
Collaborator

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

@0xleastwood
Copy link
Collaborator

Merging with #236.

@0xleastwood 0xleastwood added QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
Projects
None yet
Development

No branches or pull requests

4 participants