# Wrong encoding of `BTC` receiver in revert options

BTC receiver address truncated to 20 bytes in revert options, so failed cross-chain withdrawals refund to a wrong EVM address, losing user funds.

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

**Target:** GatewayCrossChain / GatewayTransferNative withdraw revert handling
**Root cause:** withdraw() builds revertMessage as bytes.concat(externalId, bytes20(sender)), truncating the bech32 BTC receiver to 20 bytes; onRevert then interprets the 52-byte message as an EVM address and refunds there.
**Steps:**
1. Alice withdraws zBTC to BTC address `bc1q2whrmp2a6j46sxjjk3c7xqs7e7tr7u3348pghu` via GatewayCrossChain.onCall or GatewayTransferNative.withdrawToNativeChain
2. _handleBitcoinWithdraw calls withdraw() which sets revertMessage = `bytes.concat(externalId, bytes20(sender))` (52 bytes)
3. CCTX to BTC fails, gateway calls onRevert on the contract
4. onRevert sees revertMessage.length == 52, parses walletAddress = revertMessage[32:], casts to address(uint160(bytes20(walletAddress)))
5. safeTransfer sends refund to `0x029d71ec2aeea55d40d295a38f1810f67cb1fb91` instead of the BTC owner
**How found:** Code review of the withdraw/onRevert round-trip: noticed revertMessage length check of 52 bytes assumes a 20-byte EVM address, but BTC receivers are bech32 and longer, so bytes20 cast truncates.
**Exploitation:** No attacker action needed; any failed BTC withdrawal auto-refunds to an address derived from the truncated bech32 bytes, which is not controlled by the user, permanently losing the refunded funds.
**Insight:** When a contract encodes a receiver into a fixed-length revert/refund message, check that the length assumption matches every supported chain's address format (bech32 vs 20-byte EVM); the onRevert length branch is the tell.

