Suboptimal gas usage and ambiguous behavior during fee estimation
The fee estimation function passes a fixed 228-byte payload that is ignored by the adapter, and it reverts when no adapter is configured instead of returning zero. This leads to suboptimal gas usage and ambiguous behaviour during fee estimation.
- Disclosed after under an hour
#38341 [SC-Insight] Suboptimal gas usage and ambiguous behavior during fee estimation
Submitted on Dec 31st 2024 at 13:10:15 UTC by @security for Audit Comp | Lombard
- Report ID: #38341
- Report Type: Smart Contract
- Report severity: Insight
- Target: https://github.com/lombard-finance/evm-smart-contracts/blob/main/contracts/bridge/Bridge.sol
- Impacts:
- Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol (not lower than $1K))
Description
Brief/Intro
The getAdapterFee function forwards 228 bytes as payload for fee estimation. However, these bytes are not included in the actual payload or fee calculation during the bridging process. Additionally, if no adapter is set for a destination, the function reverts instead of returning zero.
Vulnerability Details
When calculating the adapter fee via getAdapterFee, the function forwards new bytes(228) to destConfig.adapter.getFee for fee estimation:
destConfig.adapter.getFee(
toChain,
destConfig.bridgeContract,
toAddress,
amount,
new bytes(228)
);
However, in the implementation of CLAdapter::_buildCCIPMessage, the payload is ignored:
function _buildCCIPMessage(
bytes memory _receiver,
uint256 _amount,
bytes memory _payload
) private view returns (Client.EVM2AnyMessage memory) {
// ...
data: "",
// ...
}
Similarly, during deposits, the same _buildCCIPMessage is called, which skips the payload. As a result, the message used for fee estimation does not include the payload:
Client.EVM2AnyMessage memory message = _buildCCIPMessage(
abi.encodePacked(_toAddress),
_amount,
_payload
);
The following comment in the code is misleading because the 228-byte payload is not actually bridged during deposit:
// payload data doesn't matter for fee calculation, only length
Additionally, if no adapter is set in the destination configuration, getAdapterFee reverts. Instead, it should return zero for better handling.
Impact
These issues lead to suboptimal gas usage and ambiguous behavior during fee estimation and payload processing. Addressing them ensures clearer logic and better gas efficiency.
Proof of Concept
PoC
The payload length is not included in fee estimation or deposit processing, which is the correct behavior. However, for clarity and gas optimization, the following changes are recommended:
function getAdapterFee(
bytes32 toChain,
bytes32 toAddress,
uint64 amount
) external view returns (uint256) {
DestinationConfig memory destConfig = getDestination(toChain);
if (destConfig.bridgeContract == bytes32(0)) {
return 0;
}
+ if (destConfig.adapter == address(0)) {
+ return 0;
+ }
// payload data doesn't matter for fee calculation, only length
return
destConfig.adapter.getFee(
toChain,
destConfig.bridgeContract,
toAddress,
amount,
- new bytes(228)
+ new bytes(0)
);
}
function _buildCCIPMessage(
bytes memory _receiver,
uint256 _amount,
- bytes memory _payload
+ bytes memory
) private view returns (Client.EVM2AnyMessage memory) {
//...
}
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
Likely the fee estimation function passes a dummy payload that the adapter ignores, and it lacks a check for a zero adapter address.
Impact
These issues lead to suboptimal gas usage and ambiguous behavior during fee estimation and payload processing, with no direct security impact.
What the attacker needed
None
The fix
The report recommends returning zero when the adapter is not set and passing an empty payload to the fee estimation function.
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.
This is a smart contract code review finding, not an exploitable vulnerability. The fee estimation function sends extra data that is never used, wasting gas, and it crashes if no adapter is set instead of returning zero. These are code quality issues that make the contract less efficient and harder to understand.
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.