Skip to content
Business logic Audit finding Intermediate

ArbitrumBranchBridgeAgent::_performFallbackCall function does not refund users their excess native gas deposit

The ArbitrumBranchBridgeAgent's fallback function does not refund the excess native gas deposit to the user, unlike other branch bridge agents. An attacker could cause users to lose their excess gas fees when a settlement fails and fallback is triggered.

Tendency Follow with QiuhaoLi, peakbolt and 1 other

Originally disclosed on Code4rena

Submitted by Tendency, also found by QiuhaoLi, peakbolt, and rvierdiiev

When a user calls the RootBridgeAgent::retrySettlement function, to retry a failed settlement call to a root chain branch bridge agent (ArbitrumBranchBridgeAgent contract), msg.value (sent in native token) is passed as parameter in the internal call to the _performRetrySettlementCall function.

    function retrySettlement(
        uint32 _settlementNonce,
        address _recipient,
        bytes calldata _params,
        GasParams calldata _gParams,
        bool _hasFallbackToggled
    ) external payable override lock {

                       //SNIP

        // Perform Settlement Retry
        _performRetrySettlementCall(
            _hasFallbackToggled,
            settlementReference.hTokens,
            settlementReference.tokens,
            settlementReference.amounts,
            settlementReference.deposits,
            _params,
            _settlementNonce,
            payable(settlementReference.owner),
            _recipient,
            settlementReference.dstChainId,
            _gParams,
            msg.value // <-- HERE
        );
    }

In the _performRetrySettlementCall function, native gas tokens are sent to the local branch bridge agent (Arbitrum branch bridge agent contract):

    function _performRetrySettlementCall(
        bool _hasFallbackToggled,
        address[] memory _hTokens,
        address[] memory _tokens,
        uint256[] memory _amounts,
        uint256[] memory _deposits,
        bytes memory _params,
        uint32 _settlementNonce,
        address payable _refundee,
        address _recipient,
        uint16 _dstChainId,
        GasParams memory _gParams,
        uint256 _value
    ) internal {

                // SNIP

            // Check if call to local chain
        } else {
            //Send Gas to Local Branch Bridge Agent
            callee.call{value: _value}("");
            //Execute locally
            IBranchBridgeAgent(callee).lzReceive(0, "", 0, payload);
        }
    }

Assuming the execution fails at a point in ArbitrumBranchBridgeAgent, where fallback is toggled to true, ArbitrumBranchBridgeAgent::_performFallbackCall function is called.

https://github.com/code-423n4/2023-09-maia/blob/f5ba4de628836b2a29f9b5fff59499690008c463/src/BranchBridgeAgent.sol#L747

The problem here is, on fallback, the _performFallbackCall function does not refund the excess/remaining native gas deposit to the user:

    function _performFallbackCall(address payable, uint32 _settlementNonce) internal override {
        //Sends message to Root Bridge Agent
        IRootBridgeAgent(rootBridgeAgentAddress).lzReceive(
            rootChainId, "", 0, abi.encodePacked(bytes1(0x09), _settlementNonce)
        );
    }

It’s important to note that in other branch bridge agents, users do receive a refund of their excess native gas deposit from Layer Zero when a similar situation occurs.

https://github.com/code-423n4/2023-09-maia/blob/f5ba4de628836b2a29f9b5fff59499690008c463/src/BranchBridgeAgent.sol#L785-L795

Proof of Concept

https://github.com/code-423n4/2023-09-maia/blob/f5ba4de628836b2a29f9b5fff59499690008c463/src/ArbitrumBranchBridgeAgent.sol#L112-L118

Recommended Mitigation Steps

Consider refunding users their native gas tokens when performing a fallback call due to a prior failed execution in ArbitrumBranchBridgeAgent:

    function _performFallbackCall(address payable refundee, uint32 _settlementNonce) internal override {
        //perform a refund
  ++    require(refundee.call{value: address(this).balance}(""), "Refund failed");
        IRootBridgeAgent(rootBridgeAgentAddress).lzReceive(
            rootChainId, "", 0, abi.encodePacked(bytes1(0x09), _settlementNonce)
        );
    }

Assessed type

ETH-Transfer

0xBugsy (Maia) confirmed

alcueca (judge) decreased severity to Medium and commented:

With the losses limited to the gas refunds, this can’t be High.

0xBugsy (Maia) commented:

Addressed here.


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

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 _performFallbackCall function in ArbitrumBranchBridgeAgent does not include logic to refund the excess native gas deposit to the user, unlike other branch bridge agents.

Impact

Users could lose their excess native gas deposit when a settlement fails and fallback is triggered, but the loss is limited to gas refunds.

What the attacker needed

User calls retrySettlement with native gas; Execution fails and fallback is toggled

The fix

The issue was fixed by adding a refund of the native gas tokens in the _performFallbackCall function.

How it was found

  1. User calls RootBridgeAgent::retrySettlement with native gas deposit.
  2. The call is forwarded to ArbitrumBranchBridgeAgent.
  3. Execution fails and fallback is toggled to true.
  4. ArbitrumBranchBridgeAgent::_performFallbackCall is called.
  5. The excess native gas deposit is not refunded to the user.

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 a transaction on a blockchain, you pay a fee (gas) in the native token. If you send more than needed, you usually get the extra back. Here, in a specific fallback situation, the extra gas is not returned to the user, so they lose it.

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 Tendency

View all

2 more disclosed reports, best first.

More from Maia DAO - Ulysses

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.