When DecentBridgeExecutor.execute fails, funds will be sent to a random address
When a cross-chain call's target execution fails on the destination chain, the bridge refunds the funds to the source-chain adapter address rather than the user, so the refund is lost. An attacker could cause a failed execution and the user's funds would be permanently lost.
DadeKuma Follow with NPCsCorp, MrPotatoMagic and 16 others
Originally disclosed on Code4rena
Submitted by DadeKuma, also found by NPCsCorp, MrPotatoMagic, SBSecurity, deth, nmirchev8, Tendency, ether_sky, Kow, haxatron, EV_om, 0xJaeger, ZdravkoHr, Giorgio, Soliditors, Aamir, Eeyore, Inference, and kutugu
When the DecentBridgeExecutor._executeWeth/_executeEth target call fails, a refund is issued to the from address.
However, this address is wrongly set, so those refunds will be permanently lost.
Proof of Concept
UTB.bridgeAndExecute (Link) calls DecentBridgeAdapter.bridge (Link), which calls DecentEthRouter.bridgeWithPayload (Link), where the payload is constructed (Link):
function _bridgeWithPayload(
uint8 msgType,
uint16 _dstChainId,
address _toAddress,
uint _amount,
uint64 _dstGasForCall,
bytes memory additionalPayload,
bool deliverEth
) internal {
(
bytes32 destinationBridge,
bytes memory adapterParams,
bytes memory payload
) = _getCallParams(
msgType,
_toAddress,
_dstChainId,
_dstGasForCall,
deliverEth,
additionalPayload
);
...
Inside _getCallParams the from address is the msg.sender, i.e. the DecentBridgeAdapter address on the source chain (Link):
function _getCallParams(
uint8 msgType,
address _toAddress,
uint16 _dstChainId,
uint64 _dstGasForCall,
bool deliverEth,
bytes memory additionalPayload
)
private
view
returns (
bytes32 destBridge,
bytes memory adapterParams,
bytes memory payload
)
{
uint256 GAS_FOR_RELAY = 100000;
uint256 gasAmount = GAS_FOR_RELAY + _dstGasForCall;
adapterParams = abi.encodePacked(PT_SEND_AND_CALL, gasAmount);
destBridge = bytes32(abi.encode(destinationBridges[_dstChainId]));
if (msgType == MT_ETH_TRANSFER) {
@> payload = abi.encode(msgType, msg.sender, _toAddress, deliverEth);
} else {
payload = abi.encode(
msgType,
@> msg.sender, //@audit 'from' address
_toAddress,
deliverEth,
additionalPayload
);
}
}
After the payload is constructed, DecentEthRouter sends the message:
dcntEth.sendAndCall{value: gasValue}(
address(this), // from address that has dcntEth (so DecentRouter)
_dstChainId,
destinationBridge, // toAddress
_amount, // amount
payload, //payload (will have recipients address)
_dstGasForCall, // dstGasForCall
callParams // refundAddress, zroPaymentAddress, adapterParams
);
Finally, on the destination chain, DecentEthRouter will receive the message (Link):
function onOFTReceived(
uint16 _srcChainId,
bytes calldata,
uint64,
bytes32,
uint _amount,
bytes memory _payload
) external override onlyLzApp {
//@audit from is the decentBridgeAdapter address on the source chain
(uint8 msgType, address _from, address _to, bool deliverEth) = abi
.decode(_payload, (uint8, address, address, bool));
...
}
At the end of this function, the executor is invoked with the same _from address:
} else {
weth.approve(address(executor), _amount);
executor.execute(_from, _to, deliverEth, _amount, callPayload);
}
Finally, this is the execute function in DecentBridgeExecutor (Link):
function execute(
address from,
address target,
bool deliverEth,
uint256 amount,
bytes memory callPayload
) public onlyOwner {
weth.transferFrom(msg.sender, address(this), amount);
if (!gasCurrencyIsEth || !deliverEth) {
_executeWeth(from, target, amount, callPayload);
} else {
_executeEth(from, target, amount, callPayload);
}
}
Both _executeWeth and _executeEth have the same issue and funds will be lost when the target call fails, for example _executeEth (Link):
function _executeEth(
address from,
address target,
uint256 amount,
bytes memory callPayload
) private {
weth.withdraw(amount);
(bool success, ) = target.call{value: amount}(callPayload);
if (!success) {
@> payable(from).transfer(amount); //@audit wrong address as it uses the source address, not destination
}
}
Now, DecentBridgeAdapter as a refund address seems wrong, as I disclosed in another issue, but let’s suppose that it isn’t, as it’s possible to prove both scenarios.
As proof by contradiction, funds should be sent to DecentBridgeAdapter, and this would be a non-issue if these contracts are deployed with CREATE2, as they would have the same address. But they are not deployed like that.
There is hard evidence that they have different addresses, for example, these are the addresses for DcntEth and DecentEthRouter in two different chains, which are already deployed:
lib/decent-bridge/actual-deployments/latest/arbitrumAddresses.json
{
"arbitrum_DcntEth": "0x8450e1A0DebF76fd211A03c0c7F4DdbB1eEF8A85",
"done": true,
"arbitrum_DecentEthRouter": "0x17479B712A1FE1FFaeaf155379DE3ad1440fA99e"
}
lib/decent-bridge/actual-deployments/latest/optimismAddresses.json
{
"DcntEth": "0x4DB4ea27eA4b713E766bC13296A90bb42C5438D0",
"done": true,
"DecentEthRouter": "0x57beDF28C3CB3F019f40F330A2a2B0e0116AA0c2"
}
If we take a look at the deploy script for DecentBridgeAdapter it also doesn’t use CREATE2, as there isn’t a factory:
function deployDecentBridgeAdapter(
address utb,
address decentEthRouter,
address decentBridgeExecutor
) internal returns (
DecentBridgeAdapter decentBridgeAdapter
) {
string memory chain = vm.envString("CHAIN");
bool gasIsEth = gasEthLookup[chain];
address weth = wethLookup[chain];
address bridgeToken = gasIsEth ? address(0) : weth;
@> decentBridgeAdapter = new DecentBridgeAdapter(gasIsEth, bridgeToken);
decentBridgeAdapter.setUtb(utb);
decentBridgeAdapter.setRouter(decentEthRouter);
decentBridgeAdapter.setBridgeExecutor(decentBridgeExecutor);
UTB(payable(utb)).registerBridge(address(decentBridgeAdapter));
}
So these funds will be sent to a random address in any case.
Recommended Mitigation Steps
The executor.execute call in DecentEthRouter.onOFTReceived should be changed to an appropriate address (e.g. the user refund address) instead of using _from:
} else {
weth.approve(address(executor), _amount);
executor.execute(_from, _to, deliverEth, _amount, callPayload);
}
The Warden has detailed how the encoding of the cross-chain payload will use an incorrect
_fromparameter under normal operating conditions, leading to failed transfers at the target chain refunding the wrong address.This submission was selected as the best given that it precisely details that the
_fromaddress is known to be incorrect at all times when the protocol is used normally.A high-risk rating is appropriate as any failed call will lead to full fund loss for the cross-chain call.
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 payload encodes msg.sender (the source-chain adapter address) as the refund address, and the destination executor uses that address for refunds even though it is not a valid destination-chain address.
Impact
Any failed target call on the destination chain leads to full loss of the bridged funds because the refund goes to an address that is not controlled on that chain.
What the attacker needed
User bridges funds via UTB; target call on destination fails
The fix
The executor.execute call in DecentEthRouter.onOFTReceived should pass an appropriate refund address, such as the user's refund address, instead of _from.
How it was found
- A user calls UTB.bridgeAndExecute, which calls DecentBridgeAdapter.bridge and then DecentEthRouter.bridgeWithPayload.
- The router builds the payload with msg.sender as the from address and sends it via dcntEth.sendAndCall.
- On the destination chain, onOFTReceived decodes the payload and calls executor.execute with the from address.
- If the target call fails, _executeEth or _executeWeth refunds the amount to the from address, which is the source-chain adapter 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.
A bridge moves funds between blockchains. If the final step on the destination chain fails, the contract tries to send the money back to the sender. But it uses the address of the bridge helper on the source chain, which does not exist on the destination chain, so the money goes to an address nobody controls and is lost.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.