Submitted by LokiThe5th, also found by Koolex (1, 2, 3), Limbooo, ast3ros, QiuhaoLi, windhustler (1, 2), Tendency, DevABDee, peakbolt (1, 2), lsaudit, 33BYTEZZZ, 3docSec, 0xadrii, kodyvim, Kow, neumo, ihtishamsudo, and Bauchibred
The communication channel between a branch chain and a destination chain can be blocked by exploiting the ability to specify arbitrary gas parameters for the destination chain function calls. As Ulysses implements a non-blocking pattern, forcing the destination chain calls to revert creates an undesirable in blocking state.
In addition, as the requisite functions to clear the blocked channel were not implemented, the channel will remain blocked until a successful manual call to the blocked endpoints retryPayload (with appropriate gas parameters).
As this vulnerability is created by the confluence of multiple underlying issues these have been split into three Root Causes for clarity:
It should also be noted that this can be exploited to cause economic damage to the protocol. In its current state the manual call to Endpoint::retryPayload() is the only way to clear the channel. If the griefer were to initiate a high payload size call on a low-cost branch like Polygon zkEVM or Optimism, then the team will need to pay the gas fees to process the griefing payload at the higher gas cost on Arbitrum.
Due to the ability to consistently (and at a low cost) block communication between the root chain and branch chain (which can only be unblocked through a manual intervention) the issue has been evaluated to high.
Bob deploys an ERC20 to the local chain, for example, Polygon. Bob now adds the token via the CoreBranchRouter by calling addLocalToken. Importantly, Bob sets the gasParams as gasLimit: 1 (Issue A). This should not be allowed, as Layer Zero explicitly advises:
The branch hToken is created and these poisoned gas parameters are now encoded and sent to the local BridgeAgent for a system callout.
In the local BaseBridgeAgent the callOutSystem function is called at Lines 180-193. This passes on the poisoned _gParams to _performCall at Lines 766-779.
In _performCall the poisoned params are passed through to the local chain LayerZeroEndpoint via send:
In the Endpoint contract the outboundNonce is incremented, and the _getSendLibrary(uaConfig).send() is called.
The call now passes through to the nodes and relayers and this finally passes the call through to the try/catch block in the receivePayload() function of the Endpoint contract on Arbitrum.
Here, the Endpoint contract must make a call to the destination address via alzReceve call. Such calls to lzReceive is should not fail in the Ulysses protocol (i.e. it is supposed to be non-blocking). We can see this in the lzReceive code implemented in the RootBridgeAgent.sol contract at Lines 424-433. It should never revert a call which originates from the Endpoint contract (Issue B).
Crucially, the _gasLimit used here for the lzReceive call is the _gasLimit that was provided by Bob. But because Bob has specified a gasLimit of 1, they force the call from the Endpoint contract to RootBridgeAgent::lzReceive() to revert due to an out-of-gas error. This causes the Endpoint contract to store the payload. This blocks any subsequent cross-chain messages for that chain which will revert with LayerZero: in message blocking.
The message channel is now blocked. The channel can only be unblocked through a manual call to Endpoint::retryPayload(); crucially, the Maia protocol team will need to bear the costs of this transaction.
Layer Zero provides a get-out-of-jail-card for these cases through its forceResumeReceive functionality. Unfortunately, because of Issue C, the protocol doesnt implement forceResumeReceive and thus, has no other way to clear the channel without bearing the execution cost. This results in blocking the channel and communication loss.
To accurately demonstrate the proof of concept we will use the below code, testProofOfConcept, and paste it into the file RootForkTest.t.sol in the audit repo. This provides us with a fork test environment which uses the actual Endpoint contract from Layer Zero.
The test uses the example of using CoreBranchRouter::addLocalToken() to demonstrate Issue A, where a user-supplied gasParams can lead to an OutOfGas revert on the destination chain call to RootBridgeAgent:lzReceive. It then demonstrates Issue B by showing how subsequent messages to the same chain fail (even when done with valid gas parameters) due to the blocking nature of Endpoint. This, combined with issue C, where there is no implementation of forceResumeReceive(), creates a situation where a channel between the source chain and the root chain can be blocked permanently.
Instructions:
Foundry
As this submission demonstrates a high severity impact stemming from multiple root causes, the recommendations will be provided for each.
Issue A:
Layer Zero acknowledges that a cross-chain call can use more or less gas than the standard 200k. For this reason it allows the passing of custom gas parameters. This overrides the default amount of gas used. By allowing users to directly set these custom gas parameters (without validation) it opens the Ulysses implementation up to vulnerabilities related to cross-chain gas inequalities.
Consider adding input validation within the BridgeAgents before a cross-chain call is commenced that ensures the gasLimit supplied is sufficient for the lzReceive call on the root chain. This can be expanded by calculating sufficient minimums for the various functions which are implemented (e.g. adding a token, bridging). An alternative would be to deny the user the ability to modify these params downward. The BranchBridgeAgent::getFeeEstimate() is already implemented, but never used in the contracts - this would be perfect for input validation.
Issue B:
The current implementation is designed to never allow failures from the Layer Zero Endpoint, as it implements a non-blocking pattern. Due to Issue A, the lzReceive call from Endpoint can be forced to fail. This blocks the message channel, violating the intended non-blocking pattern (and giving rise to this issue).
Consider inheriting from the Layer Zero non-blocking app example.
Issue C:
It is highly recommended to implement the ILayerZeroApplicationConfig, as it provides access to forceResumeReceive in the case of a channel blockage and allows the protocol to resume communication between these two chains. Most importantly, it will allow the team to resume messaging at a fraction of what it might cost to call retryPayload.
DoS
alcueca (judge) decreased severity to Medium and commented:
lokithe5th (warden) commented:
0xLightt (Maia) confirmed
alcueca (judge) commented:
0xBugsy (Maia) commented:
