Skip to content
DoS Audit finding Advanced

An attacker can overflow the count of messages in a bottom up message batch leading to bottom up checkpoint execution failure and halting

A bottom-up message batch could be overpopulated beyond the configured maximum of ten messages by committing many messages in one block, because the batch-cutting logic copies a full batch into a new batch keyed by the current block and then keeps appending. The resulting checkpoint always fails the message-count validation, so it can never be committed in the parent subnet, halting bottom-up checkpoint execution.

sin1st3r__ Follow

Originally disclosed on Code4rena

Submitted by sin1st3r__

https://github.com/code-423n4/2025-02-recall/blob/ab5f90b9b0322016ecce6dd71c528a935544bec5/contracts/contracts/lib/LibGateway.sol#L309

Overview of how commitBottomUpMsg() works

To understand the vulnerability, we need to first discuss how the function LibGateway::commitBottomUpMsg() which is used to commit bottom up msgs to be included in a bottom up msg batch. The created bottom up msg batch will then be included in a bottom up checkpoint to be sent to a parent subnet.

    function commitBottomUpMsg(IpcEnvelope memory crossMessage) internal {
        GatewayActorStorage storage s = LibGatewayActorStorage.appStorage();
        uint256 epoch = getNextEpoch(block.number, s.bottomUpCheckPeriod);

        .................

        // populate the batch for that epoch
        (bool exists, BottomUpMsgBatch storage batch) = LibGateway.getBottomUpMsgBatch(epoch);
        if (!exists) {
            batch.subnetID = s.networkName;
            batch.blockHeight = epoch;
            // we need to use push here to initialize the array.
            batch.msgs.push(crossMessage);
            emit QueuedBottomUpMessage({id: crossMessage.toTracingId()});
            return;
        }

        // if the maximum size was already achieved emit already the event
        // and re-assign the batch to the current epoch.
  ----> if (batch.msgs.length == s.maxMsgsPerBottomUpBatch) {
            // copy the batch with max messages into the new cut.
            uint256 epochCut = block.number;
            BottomUpMsgBatch memory newBatch = BottomUpMsgBatch({
                subnetID: s.networkName,
                blockHeight: epochCut,
                msgs: new IpcEnvelope[](batch.msgs.length)
            });

            uint256 msgLength = batch.msgs.length;
            for (uint256 i; i < msgLength; ) {
                newBatch.msgs[i] = batch.msgs[i];
                unchecked {
                    ++i;
                }
            }

            // emit event with the next batch ready to sign quorum over.
            emit NewBottomUpMsgBatch(epochCut);

            // Empty the messages of existing batch with epoch and start populating with the new message.
            delete batch.msgs;
            // need to push here to avoid a copy from memory to storage
            batch.msgs.push(crossMessage);

     -----> LibGateway.storeBottomUpMsgBatch(newBatch);
        } else {
            // we append the new message normally, and wait for the batch period
            // to trigger the cutting of the batch.
            batch.msgs.push(crossMessage);
        }

        emit QueuedBottomUpMessage({id: crossMessage.toTracingId()});
    }

How this function works is as follows:

It first retrieves the next epoch then it retrieves the currently stored bottom up message batch for that epoch. If a batch exists for the next epoch and it is full, a new bottom up msg batch will be created with a block height of the current epoch/block-number, and then the messages stored in the next epoch’s batch will be transferred to the newly created msg batch associated with the current block number.

The newly created bottom up msg batch will be stored by calling the function storeBottomUpMsgBatch():

    /// @notice stores bottom-up batch
    function storeBottomUpMsgBatch(BottomUpMsgBatch memory batch) internal {
        GatewayActorStorage storage s = LibGatewayActorStorage.appStorage();
        BottomUpMsgBatch storage b = s.bottomUpMsgBatches[batch.blockHeight];
        b.subnetID = batch.subnetID;
        b.blockHeight = batch.blockHeight;

        uint256 msgLength = batch.msgs.length;
        for (uint256 i; i < msgLength; ) {
            // We need to push because initializing an array with a static
            // length will cause a copy from memory to storage, making
            // the compiler unhappy.
            b.msgs.push(batch.msgs[i]);
            unchecked {
                ++i;
            }
        }
    }

This function retrieves the batch associated with the block height of the supplied batch, which would be the current block.number, and regardless or not of its existence, it will push the messages to it.

Finding description and impact

The vulnerability is that an attacker can overpopulate the newly created bottom up msg batch so that the batch has a number of messages which exceed the limit maxMsgsPerBottomUpBatch (which is a constant of 10). That can be achieved by simply committing a total of 21 bottom up messages at the same time (or less depending on the count of stored messages in batch associated with the next epoch).

The rationale behind the number 21 is that it takes 10 messages to make the batch of the next epoch full (if its empty), which triggers the code branch below, and it takes another 10 messages to re-populate the batch of the next epoch again after it was cleared, and 1 more message to overpopulate the bottom up message with the block height block.number so that it will contain a total of 11 messages which exceed the maxMsgsPerBottomUpBatch limit enforced.

  ----> if (batch.msgs.length == s.maxMsgsPerBottomUpBatch) {
            // copy the batch with max messages into the new cut.
            uint256 epochCut = block.number;
    ----->  BottomUpMsgBatch memory newBatch = BottomUpMsgBatch({
                subnetID: s.networkName,
                blockHeight: epochCut,
                msgs: new IpcEnvelope[](batch.msgs.length)
            });

            uint256 msgLength = batch.msgs.length;
     -----> for (uint256 i; i < msgLength; ) {
     ----->     newBatch.msgs[i] = batch.msgs[i];
                unchecked {
                    ++i;
                }
            }

This is problematic because when an attacker overpopulates the batch with more messages than its supposed to hold, the bottom up checkpoint holding the bottom up msg batch will always fail and the checkpoint will never be executable in the parent.

A checkpoint is submitted by calling the function SubnetActorCheckpointingFacet::submitCheckpoint():

    function submitCheckpoint(
        BottomUpCheckpoint calldata checkpoint,
        address[] calldata signatories,
        bytes[] calldata signatures
    ) external whenNotPaused {
 -----> ensureValidCheckpoint(checkpoint);

        .................................

        // Commit in gateway to distribute rewards
        IGateway(s.ipcGatewayAddr).commitCheckpoint(checkpoint);

        .................................
    }

Let’s take a look at the function ensureValidCheckpoint():

    function ensureValidCheckpoint(BottomUpCheckpoint calldata checkpoint) internal view {
        uint64 maxMsgsPerBottomUpBatch = s.maxMsgsPerBottomUpBatch;
 -----> if (checkpoint.msgs.length > maxMsgsPerBottomUpBatch) {
            revert MaxMsgsPerBatchExceeded();
        }

        .........................
    }

As it can be observed, the ensureValidCheckpoint checks if the count of messages stored in the checkpoint is more than maxMsgsPerBottomUpBatch (10), If that’s the case, then revert.

Exploit / PoC

  1. Attacker will deploy a malicious IPC smart contract on child subnet, which if called by an attacker, will commit 21 bottom up messages by calling the function sendContractXnetMessage() 21 times and supplying an appropriate IPC envelope struct.
  2. Bottom up batch will be overpopulated and now the checkpoint holding that batch will never be executed/committed leading to bottom up checkpoint halting.

Recommended mitigation steps

I believe this can be mitigated by ensuring that a single bottom up msg batch can not have more count of messages than maxMsgsPerBottomUpBatch.


The original report as published on Code4rena, by sin1st3r__. 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 batch-cutting logic copies a full batch into a new batch at the current block height and then continues pushing further messages into that same batch without re-checking the maximum size.

Impact

The oversized checkpoint will always fail validation, so bottom-up checkpoint execution halts and the checkpoint can never be committed in the parent subnet.

What the attacker needed

Ability to send bottom-up messages on child subnet; a deployed contract on the child subnet

The fix

The batch logic should ensure a single bottom-up message batch can never hold more messages than the configured maximum.

How it was found

  1. Deploy a malicious IPC smart contract on the child subnet.
  2. Call sendContractXnetMessage 21 times with suitable IPC envelope structs to commit 21 bottom-up messages.
  3. The bottom-up batch becomes overpopulated beyond the maximum.
  4. The checkpoint holding that batch fails validation and can never be committed in the parent.

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 subnet sends batches of messages up to its parent chain, and each batch is only allowed to hold a small number of messages. The code that starts a new batch did not stop adding messages once the batch was full, so a batch could end up with more messages than allowed. When the checkpoint carrying that oversized batch is submitted, a check rejects it, and the checkpoint can never be processed.

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 sin1st3r__

View all

11 more disclosed reports, best first.

More from Recall

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.