Skip to content
DoS Audit finding Intermediate

Attacker can fill merkle tree in `L2ToL1MessagePasser`, blocking any future withdrawals

The protocol uses a single fixed-size Merkle tree for all L2-to-L1 withdrawals, and an attacker can fill it by repeatedly sending cheap messages, after which any further withdrawal attempts revert. This permanently blocks all future withdrawals from L2 to L1.

mstpr-brainbot Follow with n4nika

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-08-morphl2-judging/issues/178

The protocol has acknowledged this issue.

Found by

mstpr-brainbot, n4nika

Summary

An attacker can fill the merkle tree used for withdrawals from L2 -> L1, preventing any withdrawals from L2 to L1.

Root Cause

The protocol uses one single merkle tree with a maximum of 2**32-1 entries for all ever happening withdrawals. Once that tree is full, any calls made to L2CrossDomainMessenger.sol::_sendMessage will fail, since Tree.sol::_appendMessageHash, called in L2ToL1MessagePasser.sol::appendMessage will revert.

Solidity
function _appendMessageHash(bytes32 leafHash) internal {
    bytes32 node = leafHash;

    // Avoid overflowing the Merkle tree (and prevent edge case in computing `_branch`)
    if (leafNodesCount >= _MAX_DEPOSIT_COUNT) {
        revert MerkleTreeFull();
    }
    // [...]
}

Internal pre-conditions

None

External pre-conditions

None

Attack Path

  • attacker deploys a contract with a function which initiates 200 withdrawals from L2 to L1 per transaction by calling l2CrossDomainMessenger.sendMessage(payable(0), 0, "", 0) 200 times
  • they then automate calling that contract as many times as it takes to fill the 2**32-1 entries of the withdrawal merkel tree in Tree.sol (~ 21_000_000 times)
  • this fills the merkle tree and once it is full, any withdrawals are blocked permanently

Cost for a DoS with the lowest gas cost: ~51152 USD at 2400 USD/ETH

Note that this exploit takes some time to execute. However with the low gas costs and block times on L2, it is absolutely feasible to do so causing massive damage to the protocol. Additionally, if the ether price goes down, this will cost even less to execute.

Impact

Permanent DoS of the rollup as no L2 -> L1 withdrawals/messages will be possible anymore.

PoC

The following exploit puts 200 calls into one transaction, using close to the block gas limit of 10_000_000 gas. To run it please add it to L2Staking.t.sol and execute it with forge test --match-test test_lowGasSendMessage.

Solidity
function test_lowGasSendMessage() public {
    for (uint256 i = 0; i < 200; ++i) {
        l2CrossDomainMessenger.sendMessage(payable(0), 0, "", 0);
    }
}

The forge output will show it costing about 9_924_957 gas with which the calculations in Attack Path were made.

Mitigation

Consider adding different handling for when a merkle tree is full, not bricking the rollup because of a filled merkle tree.

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

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 protocol uses a single Merkle tree with a hard cap on entries for all withdrawals, and the append function reverts when the cap is reached, with no alternative handling.

Impact

Permanent denial of service: no L2-to-L1 withdrawals or messages will be possible anymore.

What the attacker needed

Ability to send L2-to-L1 messages; enough funds for gas (~51152 USD at 2400 USD/ETH)

The fix

The protocol should handle a full Merkle tree differently so that a filled tree does not brick the rollup.

How it was found

  1. Deploy a contract that calls the cross-domain messenger to send 200 messages per transaction.
  2. Repeatedly call that contract until the Merkle tree reaches its maximum capacity.
  3. Once the tree is full, any further withdrawal attempts revert, blocking all withdrawals.

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 Merkle tree is a data structure that records many items in a fixed-size list. Here, every withdrawal from layer 2 to layer 1 adds one entry, and the tree has a maximum capacity. An attacker can send many tiny messages to fill the tree completely, and once it is full, the code refuses to add more entries, so no one can withdraw anymore.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by mstpr-brainbot

View all

43 more disclosed reports, best first.

More from MorphL2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.