# Attacker can overwrite legitimate refundsInfo by triggering `GatewayTransferNative::onRevert`

Attacker overwrites victim's refundInfo by triggering onRevert with crafted revertMessage, redirecting refund to attacker's address.

- Payout: Audit contest
- Severity: medium
- 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/855
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-05-dodo-cross-chain-dex%3AM-7
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium technique:source-review vuln:access-control vuln:business-logic

**Target:** GatewayTransferNative contract on ZetaChain
**Root cause:** onRevert does not validate if a RefundInfo already exists for the given externalId before overwriting it with attacker-controlled revertMessage data.
**Steps:**
1. Victim's cross-chain tx fails, onAbort stores RefundInfo with externalId VICTIM_EXTERNAL_ID and refund amount.
2. Attacker deploys contract on destination EVM chain that reverts in onCall.
3. Attacker calls GatewayZEVM::withdrawAndCall with receiver=attackerContract, amount=1 wei zUSDC, revertOptions.revertMessage=bytes.concat(VICTIM_EXTERNAL_ID, bytes32(uint256(123456789))), callOnRevert=true, abortAddress=GatewayTransferNative.
4. Destination call reverts, triggering GatewayTransferNative::onRevert.
5. onRevert overwrites refundInfo[VICTIM_EXTERNAL_ID].walletAddress with attacker's address (123456789).
6. Victim cannot withdraw refund; attacker may claim it.
**How found:** Code review of onRevert revealed lack of check for existing RefundInfo, allowing overwrite via untrusted revertMessage.
**Exploitation:** Attacker monitors for failed transactions, then triggers onRevert with victim's externalId and attacker's address in revertMessage, overwriting the refund recipient at cost of 1 wei.
**Insight:** When refund accounting relies on user-supplied revertMessage, always check for existing records before overwriting to prevent griefing/theft.

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

**withdrawAndCall with victim externalId in revertMessage**

```
function withdrawAndCall(
        bytes memory receiver, // attackerContract
        uint256 amount, // 1
        address zrc20,// zUSDC
        bytes calldata message,
        CallOptions calldata callOptions,
        //CallOptions({
        //        isArbitraryCall: false,
        //        gasLimit: 100_000
        //    }),
        RevertOptions calldata revertOptions 
        // RevertOptions({
        //     revertAddress: address(GatewayTransferNatie)
        //     callOnRevert: true,
        //     abortAddress: address(GatewayTransferNative)
        //     revertMessage: bytes.concat(VICTIM_EXTERNAL_ID, bytes32(uint256(123456789)),
        //     onRevertGasLimit: 100_000
        // })
    )
```

