Skip to content
Business logic Audit finding Intermediate

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.

security Follow

Originally disclosed on Immunefi

Informational View original
  • 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

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:

Solidity
destConfig.adapter.getFee(
    toChain,
    destConfig.bridgeContract,
    toAddress,
    amount,
    new bytes(228)
);

Reference

However, in the implementation of CLAdapter::_buildCCIPMessage, the payload is ignored:

Solidity
function _buildCCIPMessage(
    bytes memory _receiver,
    uint256 _amount,
    bytes memory _payload
) private view returns (Client.EVM2AnyMessage memory) {
    // ...
    data: "",
    // ...
}

Reference

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:

Solidity
Client.EVM2AnyMessage memory message = _buildCCIPMessage(
    abi.encodePacked(_toAddress),
    _amount,
    _payload
);

Reference

The following comment in the code is misleading because the 228-byte payload is not actually bridged during deposit:

Solidity
// payload data doesn't matter for fee calculation, only length  

Reference

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:

Diff
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)
        );
}

Reference

Diff
function _buildCCIPMessage(
    bytes memory _receiver,
    uint256 _amount,
-   bytes memory _payload
+   bytes memory
) private view returns (Client.EVM2AnyMessage memory) {
    //...
}

Reference

The original report as published on Immunefi, by security. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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.

More by security

View all

2 more disclosed reports, best first.

More from Lombard

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.