Skip to content
Business logic Audit finding Intermediate

If RootBridgeAgent.lzReceiveNonBlocking reverts internally, the native token sent by relayer to RootBridgeAgent is left in RootBridgeAgent

When a cross-chain message fails inside the root bridge agent's non-blocking receive, the transaction does not revert for non-ARB senders, so the native token airdropped by the relayer stays in the contract. An attacker can then send a message with the fallback flag set and a deliberately failing call, causing the fallback to sweep the entire contract balance to them.

nobody2018 Follow with minhtrng, Arz and 9 others

Originally disclosed on Code4rena

Submitted by nobody2018, also found by minhtrng, Arz, gumgumzum (1, 2), windhustler, 0xnev, 0xStalin, 3docSec, Kow, perseverancesuccess, OMEN, Koolex, and rvierdiiev

v2 adapterParams are used to send messages, which means that the relayer will send native token to RootBridgeAgent before RootBridgeAgent.lzReceive is called. However, if an exception occurs inside lzReceiveNonBlocking, lzReceive will not revert (except for ARB branch). In this way, the native token sent to RootBridgeAgent will stay in RootBridgeAgent. Malicious users can steal these native tokens by sending some messages.

Proof of Concept

The messages discussed below are all sent using V2 (Airdrop):

When the cross-chain message reaches RootBridgeAgent, the relayer from layerZero will first send the native token to RootBridgeAgent and then call RootBridgeAgent.lzReceive which internally calls lzReceiveNonBlocking to process various messages.

File: src\RootBridgeAgent.sol
423:     function lzReceive(uint16 _srcChainId, bytes calldata _srcAddress, uint64, bytes calldata _payload) public {
424:         (bool success,) = address(this).excessivelySafeCall(
425:             gasleft(),
426:             150,
427:             abi.encodeWithSelector(this.lzReceiveNonBlocking.selector, msg.sender, _srcChainId, _srcAddress, _payload)
428:         );
429:
430:->       if (!success) if (msg.sender == getBranchBridgeAgent[localChainId]) revert ExecutionFailure();
431:     }

From the above code we can see that if lzReceiveNonBlocking returns false, as long as the sender is not from getBranchBridgeAgent[localChainId](ARB branch), then tx will not revert. This means that the native token previously sent by the relayer is left in this contract (RootBridgeAgent).

In lzReceiveNonBlocking, the functions used to process messages are two _execute functions: 1, 2. The difference between the former and the latter is whether Fallback can be triggered if a failure to process the message occurs.

File: src\RootBridgeAgent.sol
749:     function _execute(uint256 _depositNonce, bytes memory _calldata, uint16 _srcChainId) private {
750:         //Update tx state as executed
751:         executionState[_srcChainId][_depositNonce] = STATUS_DONE;
752:
753:         //Try to execute the remote request
754:         (bool success,) = bridgeAgentExecutorAddress.call{value: address(this).balance}(_calldata);
755:
756:         // No fallback is requested revert allowing for retry.
757:->       if (!success) revert ExecutionFailure();
758:     }

If the message is processed by _execute in L749, when bridgeAgentExecutorAddress.call returns false, the value sent is still in the current contract.

File: src\RootBridgeAgent.sol
768:     function _execute(
769:         bool _hasFallbackToggled,
770:         uint32 _depositNonce,
771:         address _refundee,
772:         bytes memory _calldata,
773:         uint16 _srcChainId
774:     ) private {
775:         //Update tx state as executed
776:         executionState[_srcChainId][_depositNonce] = STATUS_DONE;
777:
778:         //Try to execute the remote request
779:         (bool success,) = bridgeAgentExecutorAddress.call{value: address(this).balance}(_calldata);
780:
781:         //Update tx state if execution failed
782:         if (!success) {
783:             //Read the fallback flag.
784:             if (_hasFallbackToggled) {
785:                 // Update tx state as retrieve only
786:                 executionState[_srcChainId][_depositNonce] = STATUS_RETRIEVE;
787:                 // Perform the fallback call
788:                 _performFallbackCall(payable(_refundee), _depositNonce, _srcChainId);
789:             } else {
790:                 // No fallback is requested revert allowing for retry.
791:                 revert ExecutionFailure();
792:             }
793:         }
794:     }

_hasFallbackToggled is set when the user sends a message. When bridgeAgentExecutorAddress.call returns false:

Consider the following scenario:

  1. Alice wants to send the USDC of the ftm branch to the mainnet branch via BranchBridgeAgent.callOutSignedAndBridge. The _hasFallbackToggled argument is set to false, that is, fallback will be not triggered. This operation requires two cross-chain messages: ftm->arb and arb->mainnet. _gParams.remoteBranchExecutionGas is set to 1 ether.

  2. When the message reaches RootBridgeAgent, relayer sends 1 ether native token to RootBridgeAgent, then calls RootBridgeAgent.lzReceive. The processing flow is as follows:

    RootBridgeAgent.lzReceive
      (bool success,) = lzReceiveNonBlocking
        _execute	//_hasFallbackToggled = false
          (bool success,) = bridgeAgentExecutorAddress.call
          //if success = false
          revert ExecutionFailure()
      //success is false due to revert internally, msg.sender is not from arb, so tx will not revert
    

    This resulted in 1 ether native token being left in the RootBridgeAgent.

  3. Bob notices that RootBridgeAgent has ether and immediately calls via BranchBridgeAgent.callOutSignedAndBridge. The _hasFallbackToggled argument is set to true, that is, fallback will be triggered. The Call encoded in _params parameter intentionally triggers revert.

  4. When the message reaches RootBridgeAgent, the processing flow is as follows:

    RootBridgeAgent.lzReceive
      (bool success,) = lzReceiveNonBlocking
        _execute	//_hasFallbackToggled = true
          (bool success,) = bridgeAgentExecutorAddress.call
          //success = false due to intentionally revert
          _performFallbackCall
            //all native token held by RootBridgeAgent is taken away by this function
            ILayerZeroEndpoint(lzEndpointAddress).send{value: address(this).balance}
    
  5. Bob get all native token held by RootBridgeAgent because the excess gas will be returned to Bob by relayer.

Recommended Mitigation Steps

In lzReceive, if success is false and msg.sender is not an ARB branch, then the balance held by this should be returned to the sender address of the source message.

Assessed type

Context

alcueca (judge) decreased severity to Medium

0xLightt (Maia) confirmed via duplicate issue #464

0xBugsy (Maia) commented:

Addressed here.

Note: For full discussion, see here.


The original report as published on Code4rena, by nobody2018. 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

Likely the error path in lzReceive swallows the failure for non-ARB senders without refunding the attached native value, leaving it in the contract balance that the fallback path later sweeps.

Impact

Native tokens airdropped by the relayer for failed messages can be stolen by any user who sends a crafted message with the fallback flag enabled.

What the attacker needed

Cross-chain messaging enabled; attacker can send messages with fallback flag; contract holds stranded native token

The fix

The report recommends that when the inner call fails and the sender is not the ARB branch, the contract should return its balance to the source message sender; the project says it was addressed in a remediation commit.

How it was found

  1. Alice sends a cross-chain message with the fallback flag off and a remote execution gas value, so the relayer airdrops native token to the root bridge agent.
  2. The executor call fails, the inner function reverts, but the outer receive does not revert because the sender is not the ARB branch, leaving the native token in the contract.
  3. Bob notices the balance and sends a message with the fallback flag on and a call that intentionally reverts.
  4. The fallback path runs and sends the whole contract balance to Bob's refund 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 relayer delivers a small amount of the chain's native currency along with each cross-chain message. If processing the message fails, the code is supposed to undo everything, but here it quietly keeps the money in the contract instead. Anyone can later craft a message that fails on purpose with a 'send the money back to me' option, and the contract hands over everything it holds.

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 nobody2018

View all

7 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.