The msg.value - cost for multiple cross-chain bridges are not refunded to users
When users send more native currency than the bridge cost, the excess is not refunded and remains stuck in the contract. An attacker could cause users to lose funds by making them overpay.
Submitted by haxatron, also found by EV_om and ZanyBonzy
https://github.com/code-423n4/2024-05-olas/blob/main/tokenomics/contracts/staking/ArbitrumDepositProcessorL1.sol#L119-L192 https://github.com/code-423n4/2024-05-olas/blob/main/tokenomics/contracts/staking/WormholeDepositProcessorL1.sol#L59-L98
Vulnerability details
In multiple bridges, in _sendMessage there is a cost variable which is usually obtained by calling the bridge integration gas price estimator.
The problem is that when msg.value > cost, since cost is usually dynamic, the msg.value - cost will not be refunded to the transaction originator.
For instance, for the Wormhole integrator below:
WormholeTargetDispenserL2.sol#L89-L124
function _sendMessage(uint256 amount, bytes memory bridgePayload) internal override {
// Check for the bridge payload length
if (bridgePayload.length != BRIDGE_PAYLOAD_LENGTH) {
revert IncorrectDataLength(BRIDGE_PAYLOAD_LENGTH, bridgePayload.length);
}
// Extract refundAccount and gasLimitMessage from bridgePayload
(address refundAccount, uint256 gasLimitMessage) = abi.decode(bridgePayload, (address, uint256));
// If refundAccount is zero, default to msg.sender
if (refundAccount == address(0)) {
refundAccount = msg.sender;
}
// Check the gas limit values for both ends
if (gasLimitMessage < GAS_LIMIT) {
gasLimitMessage = GAS_LIMIT;
}
if (gasLimitMessage > MAX_GAS_LIMIT) {
gasLimitMessage = MAX_GAS_LIMIT;
}
// Get a quote for the cost of gas for delivery
(uint256 cost, ) = IBridge(l2MessageRelayer).quoteEVMDeliveryPrice(uint16(l1SourceChainId), 0, gasLimitMessage);
// Check that provided msg.value is enough to cover the cost
if (cost > msg.value) {
revert LowerThan(msg.value, cost);
}
uint64 sequence = IBridge(l2MessageRelayer).sendPayloadToEvm{value: cost}(uint16(l1SourceChainId),
l1DepositProcessor, abi.encode(amount), 0, gasLimitMessage, uint16(l1SourceChainId), refundAccount);
emit MessagePosted(sequence, msg.sender, l1DepositProcessor, amount);
}
A cost is returned from quoteEVMDeliveryPrice that reflects the gas cost of executing the cross-chain transaction for the given gas limit of gasLimitMessage. When this sendPayloadToEvm is called, cost amount will be sent for the cross-chain transaction, but the msg.value - cost will remain stuck and not refunded to the user.
This affects multiple areas of the codebase, see links to affected code.
Impact
msg.value - cost will remain stuck and not refunded to the user.
Recommended Mitigation Steps
Refund msg.value - cost to tx.origin.
Fixed.
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 contract does not refund the excess msg.value after paying the bridge cost.
What the attacker needed
User sends more than the bridge cost
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 money with a transaction, you might send more than needed to cover the bridge fee. The extra money should be returned to you, but here it stays stuck in the contract. This means users lose funds if they overpay.
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.