Wrong encoding of `BTC` receiver in revert options
The contract truncates Bitcoin addresses to 20 bytes when constructing revert options, so if a cross-chain withdrawal to Bitcoin fails, the refund is sent to an incorrect Ethereum-style address derived from the truncated bytes. This results in loss of user funds.
Source: https://github.com/sherlock-audit/2025-05-dodo-cross-chain-dex-judging/issues/916
Found by
0xEkko, 0xShoonya, Aenovir, AnomX, EgisSecurity, Goran, Ob, PolarizedLight, elolpuer, fromeo_016, montecristo, oxch0w, pyk, rsam_eth, shushu
Summary
BTC addresses are casted to 20 bytes resulting in incorrect addresses
Root Cause
When gateway calls GatewayCrossChain::onCall or user calls GatewayTransferNative::withdrawToNativeChain to withdraw zBTC (BTC to native chain), the _handleBitcoinWithdraw constructs the revertOtions with decoded.receiver but casts the decoded.receiver to 20 bytes which is wrong for BTC wallets (BTC addresses are bech32):
https://github.com/sherlock-audit/2025-05-dodo-cross-chain-dex/blob/main/omni-chain-contracts/contracts/GatewayCrossChain.sol#L363-L377
function _handleBitcoinWithdraw(
bytes32 externalId,
DecodedMessage memory decoded,
uint256 outputAmount,
uint256 gasFee
) internal {
if (gasFee >= outputAmount) revert NotEnoughToPayGasFee();
IZRC20(decoded.targetZRC20).approve(
address(gateway),
outputAmount + gasFee
);
withdraw( //==> call withdraw here
externalId,
decoded.receiver, //==> second parameter is decoded.receiver which is the BTC wallet to receive funds
decoded.targetZRC20,
outputAmount - gasFee
);
}
function withdraw(
bytes32 externalId,
bytes memory sender, //==> second parameter is decoded.receiver which is the BTC wallet to receive funds
address outputToken,
uint256 amount
) internal {
gateway.withdraw(
sender,
amount,
outputToken,
RevertOptions({
revertAddress: address(this),
callOnRevert: true,
abortAddress: address(0),
//==> cast sender to a bytes20 which results in a wrong address
revertMessage: bytes.concat(externalId, bytes20(sender)),
onRevertGasLimit: gasLimit
})
);
}
function onRevert(RevertContext calldata context) external onlyGateway {
// 52 bytes = 32 bytes externalId + 20 bytes evmWalletAddress
bytes32 externalId = bytes32(context.revertMessage[0:32]);
bytes memory walletAddress = context.revertMessage[32:];
if(context.revertMessage.length == 52) { //==> revertMessage length is 52 bytes in the BTC revert options
address receiver = address(uint160(bytes20(walletAddress))); //==> wrong receiver
TransferHelper.safeTransfer(context.asset, receiver, context.amount); //==> lost funds
This results in user refunds being sent to a wrong address
Internal Pre-conditions
decoded.receiveris bytes representation of a valid BTC address
External Pre-conditions
- CCTX to send funds to BTC chain fails
onRevertis called onGatewayCrossChainorGatewayTransferNative
Attack Path
- Alice withdraws funds to BTC address 'bc1q2whrmp2a6j46sxjjk3c7xqs7e7tr7u3348pghu'
RevertOptions.walletAddressis set to029d71ec2aeea55d40d295a38f1810f67cb1fb91(used www.bech32converter.com to convertbc1q2whrmp2a6j46sxjjk3c7xqs7e7tr7u3348pghuto029d71ec2aeea55d40d295a38f1810f67cb1fb91)- onRevert function is called and funds are sent to
0x029d71ec2aeea55d40d295a38f1810f67cb1fb91
Impact
- Broken refund logic
- Loss of user refunds
PoC
No response
Mitigation
Do not cast walletAddress to 20 bytes:
function withdraw(
bytes32 externalId,
bytes memory sender,
address outputToken,
uint256 amount
) public {
gateway.withdraw(
sender,
amount,
outputToken,
RevertOptions({
revertAddress: address(this),
callOnRevert: true,
abortAddress: address(0),
- revertMessage: bytes.concat(externalId, bytes20(sender)),
+ revertMessage: bytes.concat(externalId, sender),
onRevertGasLimit: gasLimit
})
);
}
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Skyewwww/omni-chain-contracts/pull/27
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 code casts a Bitcoin address (which is longer than 20 bytes) to bytes20 when building the revert message, truncating it and causing the refund to be sent to an incorrect address.
Impact
User refunds for failed Bitcoin withdrawals are sent to an incorrect address, resulting in loss of funds.
What the attacker needed
A cross-chain withdrawal to a Bitcoin address; The cross-chain transaction fails, triggering onRevert
The fix
The issue was fixed by not casting the sender address to bytes20 when constructing the revert message.
How it was found
- Alice initiates a withdrawal to a Bitcoin address.
- The revert options are constructed with the Bitcoin address truncated to 20 bytes.
- The cross-chain transaction fails and onRevert is called.
- The refund is sent to the truncated address instead of the original Bitcoin 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.
When you send cryptocurrency across chains, sometimes the transaction fails and the system tries to refund you. This report shows that for Bitcoin refunds, the system mistakenly shortened your Bitcoin address to 20 bytes, which is the length of an Ethereum address, and then sent the refund to that wrong address. As a result, the refund went to an address you don't control, and your money was lost.
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.