Skip to content
Business logic Audit finding Intermediate

`WooCrossChainRouterV4.crossSwap()` doesn't correctly check for slippage

charles__cheerful Follow with hals

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-03-woofi-swap-judging/issues/85

Found by

charles__cheerful, hals

Summary

WooCrossChainRouterV4.crossSwap() doesn't correctly check for slippage, as it deducts external swapping fees after checking for the minimum bridged amount determined by the user.

Vulnerability Detail

  • WooCrossChainRouterV4.crossSwap() function is meant to enable users from executing a cross-chain swap, where a cross chain swap transaction may include all or some of the following steps (as per the documentation):
  1. Swap asset A in the user's wallet to asset B in WOOFi on the source chain
  2. Then bridging asset B to asset C on the destination chain via Stargate (asset B and asset C are of the same value)
  3. Then swap asset C to asset D in WOOFi on the destination chain and send to the wallet instructed by the user.
  • So swapping from asset A to asset B on the source chain can be done either using a woofi pool (WooPPV2) via wooRouter.swap(), or this swap can be done via an external aggregater (where 1inch aggregator is going to be used) via wooRouter.externalSwap() that redirects the swap call to the external aggregator:

    JavaScript
    // Step 2: local swap by 1inch router
                if (srcInfos.fromToken != srcInfos.bridgeToken) {
                    TransferHelper.safeApprove(srcInfos.fromToken, address(wooRouter), srcInfos.fromAmount);
                    if (src1inch.swapRouter != address(0)) {
                        // external swap via 1inch
                         bridgeAmount = wooRouter.externalSwap(
                          src1inch.swapRouter,
                          src1inch.swapRouter,
                          srcInfos.fromToken,
                          srcInfos.bridgeToken,
                          srcInfos.fromAmount,
                          srcInfos.minBridgeAmount,
                          payable(address(this)),
                          src1inch.data
                      );
    
                        fee = (bridgeAmount * srcExternalFeeRate) / FEE_BASE;
                    } else {
                    //some code...
            }
    
            // Step 3: deduct the swap fee
            bridgeAmount -= fee;
    

    where the resulted bridgeAmount will be checked to be > srcInfos.minBridgeAmount in the wooRouter.externalSwap():

    JavaScript
    function externalSwap(
            address approveTarget,
            address swapTarget,
            address fromToken,
            address toToken,
            uint256 fromAmount,
            uint256 minToAmount,
            address payable to,
            bytes calldata data
        ) external payable override nonReentrant returns (uint256 realToAmount) {
            //some code...
    
            require(realToAmount >= minToAmount && realToAmount > 0, "WooRouter: realToAmount_NOT_ENOUGH");
    
            //some code...
        }
    

Impact

But as can be noticed, an external swap fee is deducted from the bridgeAmount after the swap is done via an external aggregator (1inch aggregator) and after checking that the bridgeAmount is sufficient as per detrmined by the user ( > srcInfos.minBridgeAmount), and this might result in the bridgeAmount being less than required by the user srcInfos.minBridgeAmount.

Code Snippet

WooCrossChainRouterV4.crossSwap function/L137-L138

JavaScript
   // Step 2: local swap by 1inch router
            if (srcInfos.fromToken != srcInfos.bridgeToken) {
                TransferHelper.safeApprove(srcInfos.fromToken, address(wooRouter), srcInfos.fromAmount);
                if (src1inch.swapRouter != address(0)) {
                    // external swap via 1inch
                    bridgeAmount = wooRouter.externalSwap(
                        src1inch.swapRouter,
                        src1inch.swapRouter,
                        srcInfos.fromToken,
                        srcInfos.bridgeToken,
                        srcInfos.fromAmount,
                        srcInfos.minBridgeAmount,
                        payable(address(this)),
                        src1inch.data
                    );

                    fee = (bridgeAmount * srcExternalFeeRate) / FEE_BASE;
                } else {

                //some code...
        }

        // Step 3: deduct the swap fee
        bridgeAmount -= fee;

Tool used

Manual Review

Recommendation

Update WooCrossChainRouterV4.crossSwap() to check for the bridgeAmount being greater than the amount determined by the user srcInfos.minBridgeAmount after deducting the fees:

Diff
    function crossSwap(
        uint256 refId,
        address payable to,
        SrcInfos memory srcInfos,
        DstInfos calldata dstInfos,
        Src1inch calldata src1inch,
        Dst1inch calldata dst1inch
    ) external payable whenNotPaused nonReentrant {

    //some code...

   // Step 2: local swap by 1inch router
            if (srcInfos.fromToken != srcInfos.bridgeToken) {
                TransferHelper.safeApprove(srcInfos.fromToken, address(wooRouter), srcInfos.fromAmount);
                if (src1inch.swapRouter != address(0)) {
                    // external swap via 1inch
                    bridgeAmount = wooRouter.externalSwap(
                        src1inch.swapRouter,
                        src1inch.swapRouter,
                        srcInfos.fromToken,
                        srcInfos.bridgeToken,
                        srcInfos.fromAmount,
                        srcInfos.minBridgeAmount,
                        payable(address(this)),
                        src1inch.data
                    );

                    fee = (bridgeAmount * srcExternalFeeRate) / FEE_BASE;
                } else {

                //some code...
        }

        // Step 3: deduct the swap fee
        bridgeAmount -= fee;

+       require(bridgeAmount >= srcInfos.minBridgeAmount, "insufficient bridged amount");

        //some code...

Discussion

sherlock-admin4

The protocol team fixed this issue in the following PRs/commits: https://github.com/woonetwork/WooPoolV2/pull/112/commits/151443bf3c780f4e45796312591c61e1bd188122

WangSecurity

Initially, it was selected as a duplicate of 141, but it's not. 141 is invalid and 85 is valid.

sherlock-admin2

Escalate.

Please think about the actual impact.

You've deleted an escalation for this issue.

sherlock-admin2

The Lead Senior Watson signed off on the fix.

The original report as published on Sherlock, by charles__cheerful. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is known

A medium-severity business logic bug in WOOFi Swap. Sherlock made it public on 6 April 2024. Found in the 277 audit contest (finding M-6), also found by 1 other warden.

About Business logic

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by charles__cheerful

View all

1 more disclosed report, best first.

More from WOOFi Swap

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.