`onCall` function has missing fee deduction update prior swap
The onCall function in GatewayTransferNative fails to deduct platform fees from the amount before swapping, causing the swap to attempt to pull the full amount and revert due to insufficient funds. If the contract holds refunds, an attacker could exploit this to steal those refunds.
0xEkko Follow with 0xiehnnkta, 0xlucky and 25 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2025-05-dodo-cross-chain-dex-judging/issues/626
Found by
0xEkko, 0xiehnnkta, 0xlucky, 10ap17, Abhan1041, AnomX, CoheeYang, Cybrid, EgisSecurity, Ocean_Sky, Yaneca_b, ZeroTrust, anirruth_, bladeee, cccz, elolpuer, hieutrinh02, hunt1, iamandreiski, malm0d, miracleworker0118, newspacexyz, roadToWatsonN101, rsam_eth, seeques, shivansh2580, tyuuu, wellbyt3
Summary
During zrc-20 depositAndCall operation, onCall function of GatewayTransferNative contract will revert due to missing update of amount to be used in swap in DODO Router. This amount is already deducted by platform fees, therefore need to be updated prior to the swap operation. The swap execution will always pull up a whole amount but in reality this is already deducted by fees, therefore guaranteed revert due to insufficient funds.
This can also be opportunity as attack vector for malicious attacker depending on situation like if the contract GatewayTransferNative has refund stored in it prior depositAndCall operation.
Root Cause
The real root cause is the missing update on the amount to be swapped in DODO Router. This amount should be deducted by platform fees prior to the swap operation to avoid revert. Look at line 370, the platform fees is already physically transferred to the protocol treasury, however this amount was never updated prior to the swap operation in line 395, this will cause guaranteed revert.
File: GatewayTransferNative.sol
357: function onCall(
358: MessageContext calldata context,
359: address zrc20, // this could be wzeta token
360: uint256 amount, // @audit this should be updated prior swap but no deduction happened
361: bytes calldata message
362: ) external override onlyGateway {
363: // Decode the message
364: // 32 bytes(externalId) + bytes message
365: (bytes32 externalId) = abi.decode(message[0:32], (bytes32));
366: bytes calldata _message = message[32:];
367: (DecodedNativeMessage memory decoded, MixSwapParams memory params) = SwapDataHelperLib.decodeNativeMessage(_message);
368:
369: // Fee for platform
370: uint256 platformFeesForTx = _handleFeeTransfer(zrc20, amount); // @audit , fees already transferred to treasury
371: address receiver = address(uint160(bytes20(decoded.receiver)));
372:
~ skip
392: );
393: } else {
394: // Swap on DODO Router
395: uint256 outputAmount = _doMixSwap(decoded.swapData, amount, params); //@audit amount here is not deducted by fees, therefore revert.
396:
Detail of _doMixSwap below
File: GatewayTransferNative.sol
425: function _doMixSwap(
426: bytes memory swapData,
427: uint256 amount, //@note, expected to be equal in line 438
428: MixSwapParams memory params
429: ) internal returns (uint256 outputAmount) {
430: if (swapData.length == 0) {
431: return amount;
432: }
433:
434: IZRC20(params.fromToken).approve(DODOApprove, amount);
435: return IDODORouteProxy(DODORouteProxy).mixSwap{value: msg.value}(
436: params.fromToken,
437: params.toToken,
438: params.fromTokenAmount, //@note amount to be used in swapping expected to be equal to amount in line 427
439: params.expReturnAmount,
440: params.minReturnAmount,
441: params.mixAdapters,
442: params.mixPairs,
443: params.assetTo,
444: params.directions,
445: params.moreInfo,
446: params.feeData,
447: params.deadline
448: );
449: }
Inside mixSwap function found in DODORouteProxy contract
_deposit(msg.sender, …, _fromTokenAmount);
…
IDODOApproveProxy.claimTokens(token, from, to, _fromTokenAmount); // _fromTokenAmount used in claiming tokens
Inside claimTokens function found in DODOApprove contract
File: DODOApprove.sol
72: function claimTokens(
73: address token,
74: address who,
75: address dest,
76: uint256 amount //@ note , this is the _fromTokenAmount
77: ) external {
78: require(msg.sender == _DODO_PROXY_, "DODOApprove:Access restricted");
79: if (amount > 0) {
80: IERC20(token).safeTransferFrom(who, dest, amount); //@audit, this will just revert due to insufficient funds
81: }
82: }
The protocol may argue that the fromTokenAmount in_doMixSwap parameters can easily be changed by the user in order for swap to be successful. This may be correct but there are two situations we need to emphasize here.
-
If the
GatewayTransgerNativehas no refunds stored. - User is expected to use thatfromTokenAmountis equal to theamountto be swap or transfer as the user is no longer expected to compute again the net remaining as this is expected for the logic contract to do its job for smooth experience of the users. The impact of this issue is just revert. If they want the swap to be successful, they will just changefromTokenAmountmanually but unnecessary computation burden for user. -
If the
GatewayTransferNativehas refunds stored. - This could be an attack vector by users who knows the vulnerability. They won't change thefromTokenAmountand allows to use the over-allowance given to the user. Over-allowance because the allowance given exceeded the amount that should be allowed to be transferred. For example , the whole amount is 100 which is given allowance however it should be 95 only (net of 5 fees) , because 5 for fees is already transferred to treasury. If they are able to transferred the whole 100, there is a tendency that they will be able to steal some refunds amounting 5 deposited there during that time.
Please be reminded that GatewayTransferNative is storing funds for refunds. This could be in danger to be stolen via this vulnerability. Look at the mapping variable storage below.
File: GatewayTransferNative.sol
32: mapping(bytes32 => RefundInfo) public refundInfos; // externalId => RefundInfo, storage for refund records
Internal Pre-conditions
- When cross-chain operation involves DODO router swap call in destination chain Zetachain.
External Pre-conditions
none
Attack Path
Scenario A:
This could be the scenario if the the GatewayTransferNative has no refunds stored.
| Step | Contract balance (zrc-20) | Allowance set | RouteProxy tries to pull | Outcome |
|---|---|---|---|---|
Deposited 1,000 zrc-20 amount from depositAndCall |
1 000 | – | – | – |
_handleFeeTransfer (0.5 %) |
995 | – | – | Treasury receives 5 |
_doMixSwap |
995 | approve 1 000 | – | approved the amount which still includes the fees transferred. |
_deposit → claimTokens |
995 | 1 000 | 1 000 | Revert (insufficient balance) |
| Swap aborted | – | – | – | onCall reverts, swap operation cancelled |
Scenario B:
This could be the scenario if the the GatewayTransferNative has refunds stored.
| Step | Contract balance (zrc-20) | Allowance set | RouteProxy tries to pull | Outcome |
|---|---|---|---|---|
| 5 zrc-20 tokens refund currently stored in contract | 5 | – | – | – |
Deposited 1,000 zrc-20 amount from depositAndCall |
1 005 | – | – | – |
_handleFeeTransfer (0.5 %) |
1000 | – | – | Treasury receives 5 |
_doMixSwap |
1000 | approve 1 000 | – | approved the amount which still includes the fees transferred. |
_deposit → claimTokens |
1000 | 1 000 | 1 000 | OK (sufficient balance) |
| Swap successful | – | – | – | onCall success, excess of 5 is pulled out from refund |
As you can see here, the refund of 5 zrc-20 tokens is pulled out from the last step (included in 1000 amount). This can be equivalent to stolen funds as the contract has no remaining funds left.
Impact
The onCall function will either revert or can cause loss of funds.
PoC
see attack path
Mitigation
Update the amount prior the swap operation.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Skyewwww/omni-chain-contracts/pull/29
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 amount passed to the swap function is not reduced by the platform fee that was already transferred to the treasury.
Impact
The onCall function will either revert or can cause loss of funds.
What the attacker needed
Cross-chain operation with DODO swap; contract holds refunds for fund loss
The fix
The amount should be updated to deduct the platform fees before the swap operation.
How it was found
- User calls depositAndCall with a zrc-20 token amount.
- onCall is triggered, which calls _handleFeeTransfer to deduct the platform fee and send it to the treasury.
- The remaining amount is not updated; _doMixSwap is called with the original amount.
- The swap attempts to pull the original amount from the contract, which now holds less, causing a revert.
- If the contract has refunds stored, the swap may succeed by pulling the extra amount from refunds, resulting in loss of funds.
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.
When a user deposits tokens and requests a cross-chain swap, the contract first takes a fee and sends it to the treasury. However, it then tries to swap the original full amount instead of the reduced amount, so the swap fails because the contract no longer has enough tokens. If the contract happens to hold extra tokens from previous refunds, an attacker could craft a swap that uses those extra tokens, effectively stealing them.
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.