Skip to content
Business logic Audit finding Intermediate

Executing withdrawToNativeChain with Zeta as fromToken will not be possible

When a user calls withdrawToNativeChain with ZETA as the fromToken and a non-zero fee is set, the full msg.value is passed to mixSwap instead of deducting the fee, causing a mismatch with fromTokenAmount and a revert. This prevents swapping ZETA for ZRC20 tokens whenever the fee is non-zero.

10ap17 Follow with AnomX, Cybrid and 3 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-05-dodo-cross-chain-dex-judging/issues/660

Found by

10ap17, AnomX, Cybrid, farismaulana, newspacexyz, rsam_eth

Summary

Executing withdrawToNativeChain with ZETA as fromToken will fail when a non-zero fee is set, due to a mismatch between msg.value and fromTokenAmount passed to mixSwap.

Root Cause

When a user wants to execute withdrawToNativeChain with ZETA as fromToken, they send some ZETA with msg.value, set the zrc20 variable to the native token, and specify the same amount of ZETA as sent via msg.value. After that, the fee gets paid (let's imagine that the issue where it's not possible to pay the fee when ZETA is the zrc20 is fixed), and now _doMixSwap is called and the full msg.value is sent to the mixSwap, even though the fee was paid with a fraction of that value. The swap will fail because there will be a mismatch between msg.value and fromTokenAmount (the value sent to mixSwap should be mixSwap{value: msg.value-fee}(...)), which would be adjusted to account for the fee that was transferred to EddyTreasurySafe.

Solidity
function mixSwap(
        address fromToken,
        address toToken,
        uint256 fromTokenAmount,
        uint256 expReturnAmount,
        uint256 minReturnAmount,
        address[] memory mixAdapters,
        address[] memory mixPairs,
        address[] memory assetTo,
        uint256 directions,
        bytes[] memory moreInfos,
        bytes memory feeData,
        uint256 deadLine
    ) external payable judgeExpired(deadLine) returns (uint256) {
        require(mixPairs.length > 0, "DODORouteProxy: PAIRS_EMPTY");
        require(mixPairs.length == mixAdapters.length, "DODORouteProxy: PAIR_ADAPTER_NOT_MATCH");
        require(mixPairs.length == assetTo.length - 1, "DODORouteProxy: PAIR_ASSETTO_NOT_MATCH");
        require(minReturnAmount > 0, "DODORouteProxy: RETURN_AMOUNT_ZERO");

        address _fromToken = fromToken;
        address _toToken = toToken;
        uint256 _fromTokenAmount = fromTokenAmount;
        uint256 _expReturnAmount = expReturnAmount;
        uint256 _minReturnAmount = minReturnAmount;
        address[] memory _mixAdapters = mixAdapters;
        address[] memory _mixPairs = mixPairs;
        address[] memory _assetTo = assetTo;
        uint256 _directions = directions;
        bytes[] memory _moreInfos = moreInfos;
        bytes memory _feeData = feeData;
        
        uint256 toTokenOriginBalance;
        if(_toToken != _ETH_ADDRESS_) {
            toTokenOriginBalance = IERC20(_toToken).universalBalanceOf(address(this));
        } else {
            toTokenOriginBalance = IERC20(_WETH_).universalBalanceOf(address(this));
        }

        // transfer in fromToken
        bool isETH = _fromToken == _ETH_ADDRESS_;
        _deposit(
            msg.sender,
            _assetTo[0],
            _fromToken,
            _fromTokenAmount,
            isETH
        );
.
.
.
}

If we check the _deposit() function where the isEth flag and amount are passed (amount is equal to fromTokenAmount), we can spot that the msg.value and amount have to be equal.

Solidity
function _deposit(
        address from,
        address to,
        address token,
        uint256 amount,
        bool isETH
    ) internal {
        if (isETH) {
            if (amount > 0) {
                require(msg.value == amount, "ETH_VALUE_WRONG");
                IWETH(_WETH_).deposit{value: amount}();
                if (to != address(this)) SafeERC20.safeTransfer(IERC20(_WETH_), to, amount);
            }
        } else {
            IDODOApproveProxy(_DODO_APPROVE_PROXY_).claimTokens(token, from, to, amount);
        }
    }

Since they will not be equal, the attempt to swap ZETA to a certain ZRC20 will fail.

https://github.com/sherlock-audit/2025-05-dodo-cross-chain-dex/blob/main/omni-chain-contracts/contracts/GatewayTransferNative.sol#L435

Internal Pre-conditions

/

External Pre-conditions

/

Attack Path

  1. User calls withdrawToNativeChain intending to swap ZETA (native token) to some ZRC20 token (sets zrc20 to native address and amount equal to msg.value).
  2. The fee is paid (assuming the inability to transfer fee when native token is zrc20 is fixed).
  3. _doMixSwap is called.
  4. Inside _doMixSwap, mixSwap is called and msg.value is passed without deducting the fee.
  5. Inside mixSwap, the _deposit function is called. Since isEth is true, a check is performed to verify if msg.value == amount.
  6. Since the values are not equal, the function reverts.

This behavior will prevent ZETA token swaps whenever the transfer fee is different from 0.

Impact

Attempts to swap ZETA for some other ZRC20 will fail since the msg.value passed to the mixSwap function will differ from the fromTokenAmount value (fromTokenAmount should be equal to msg.value - fee, but also mixSwap call should be mixSwap{value: msg.value- fee}(...)). This will break the contract’s ability to swap ZETA for ZRC20 whenever the fee is set to a non-zero value.

PoC

No response

Mitigation

Consider deducting the fee from msg.value when calling mixSwap ( msg.value - fee).

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/Skyewwww/omni-chain-contracts/pull/28

The original report as published on Sherlock, by 10ap17. 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.

How it worked

Root cause

The contract passes the full msg.value to mixSwap without deducting the fee, so the amount parameter does not match msg.value, causing the deposit check to fail.

Impact

Attempts to swap ZETA for some other ZRC20 will fail since the msg.value passed to the mixSwap function will differ from the fromTokenAmount value, breaking the contract’s ability to swap ZETA for ZRC20 whenever the fee is set to a non-zero value.

What the attacker needed

Fee set to non-zero value; user calls withdrawToNativeChain with ZETA as fromToken

The fix

The protocol team fixed this issue by deducting the fee from msg.value when calling mixSwap.

How it was found

  1. User calls withdrawToNativeChain intending to swap ZETA (native token) to some ZRC20 token (sets zrc20 to native address and amount equal to msg.value).
  2. The fee is paid (assuming the inability to transfer fee when native token is zrc20 is fixed).
  3. _doMixSwap is called.
  4. Inside _doMixSwap, mixSwap is called and msg.value is passed without deducting the fee.
  5. Inside mixSwap, the _deposit function is called. Since isEth is true, a check is performed to verify if msg.value == amount.
  6. Since the values are not equal, the function reverts.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

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

This is a smart contract bug where a function that swaps one token for another fails because the amount of cryptocurrency sent with the transaction does not match the amount the swap function expects. The contract sends the full amount to the swap but also takes a fee, so the numbers don't add up and the transaction is rejected.

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 10ap17

View all

2 more disclosed reports, best first.

More from DODO Cross-Chain DEX

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.