Skip to content
DoS Audit finding Intermediate

`Gateway.withBatch()` lacks message count validation enabling permanent DOS via an excessive number of messages in a batch

The Gateway.withBatch() function lacks validation on the number of messages in a batch, allowing an attacker to create batches with hundreds of messages that exceed the block gas limit on the receiving chain. This causes the batch to become permanently unprocessable, blocking critical cross-chain messages such as pool accounting updates.

0x52 Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-10-centrifuge-protocol-v3-1-audit-judging/issues/560

Found by

0x52

Summary

An attacker can permanently DOS cross-chain message processing by creating batches with excessive numbers of messages that collectively exceed the block gas limit on the receiving chain. The protocol lacks validation on the number of messages when batches are created on the sending side via Gateway.withBatch(), allowing attackers to construct batches with hundreds of messages. Even if each individual message wastes only a small amount of gas, the sheer volume of messages makes the batch unprocessable on the receiving chain, causing permanent DOS of critical pool accounting synchronization.

Root Cause

Gateway.sol#L230-L256 - Gateway.withBatch() has no validation on message count before accepting messages into a batch

Vulnerability Detail

The vulnerability lies in Gateway.withBatch()'s complete lack of validation on the number of messages in a batch. While this function is designed to enable legitimate multi-message operations, there is no check to limit how many messages can be included.

Gateway.sol#L230-L256

Solidity
function withBatch(bytes memory data, uint256 callbackValue, address refund) public payable {
    require(callbackValue <= msg.value, NotEnoughValueForCallback());

    bool isNested = isBatching;
    isBatching = true;

    _batcher = msg.sender;
    (bool success, bytes memory returnData) = msg.sender.call{value: callbackValue}(data);
    if (!success) {
        uint256 length = returnData.length;
        require(length != 0, CallFailedWithEmptyRevert());

        assembly ("memory-safe") {
            revert(add(32, returnData), length)
        }
    }

    // Force the user to call lockCallback()
    require(address(_batcher) == address(0), CallbackWasNotLocked());

    if (isNested) {
        _refund(refund, msg.value - callbackValue);
    } else {
        uint256 cost = _endBatching(msg.value - callbackValue, refund);
        _refund(refund, msg.value - callbackValue - cost);
    }
}

The function accepts the batch and sends it to the destination chain without any validation on message count. This allows attackers to create batches with hundreds of messages, where the cumulative gas requirement exceeds the block gas limit (30M on Ethereum).

One example would be using spoke.updateContract():

Spoke.sol#L159-L172

Solidity
function updateContract(
    PoolId poolId,
    ShareClassId scId,
    bytes32 target,
    bytes calldata payload,
    uint128 extraGasLimit,
    address refund
) external payable {
    emit UntrustedContractUpdate(poolId.centrifugeId(), poolId, scId, target, payload, msg.sender);

    sender.sendUntrustedContractUpdate{
        value: msg.value
    }(poolId, scId, target, payload, msg.sender.toBytes32(), extraGasLimit, refund);
}

This function allows anyone to create UntrustedContractUpdate messages targeting any contract. An attacker can use gateway.withBatch() to bundle hundreds of these messages together with critical system messages like UpdateHoldingAmount.

When the batch reaches the receiving chain and Gateway.handle() attempts to process it, each message consumes gas for processing overhead, contract execution, and storage operations. With enough messages, the total gas requirement exceeds the block gas limit.

When Gateway.handle() attempts to process this batch on the receiving chain, it runs out of gas and reverts with NotEnoughGasToProcess(). The batch becomes permanently stuck because:

  1. The batch cannot be processed (exceeds block gas limit)
  2. The protocol has no mechanism to skip or split oversized batches
  3. Critical messages bundled in the same batch (like UpdateHoldingAmount) cannot execute
  4. Pool accounting synchronization breaks permanently

The vulnerability exists because batch creation has no message count validation. The batch is accepted and sent to the destination chain where it becomes unprocessable.

Impact

Critical system messages batched with excessive numbers of gas-wasting messages become permanently stuck and cannot be processed. When the batch executes on the receiving chain, it reverts at the Gateway.handle() level due to exceeding the block gas limit, making the entire batch unrecoverable.

Affected message types include UpdateHoldingAmount messages that synchronize pool accounting state between hub and spoke chains, and ExecuteTransferShares messages used in spoke-to-spoke share transfers. When these messages are blocked, pools cannot update their holding amounts and users cannot transfer shares between spoke chains, breaking core cross-chain functionality.

Code Snippet

Gateway.sol#L258-L277

Tool Used

Manual Review

Recommendation

Implement a configurable maximum message count limit on the sending side to prevent creation of batches with excessive numbers of messages. The fix requires two components:

  1. Add a configurable maxBatchMessages parameter that can be set by governance
  2. Count messages in the batch and validate the count before sending
Diff
contract Gateway {
+   uint256 public maxBatchMessages; // Configurable max messages per batch

    function _endBatching(uint256 fuel, address refund) internal returns (uint256 cost) {
        require(isBatching, NoBatched());
        bytes32[] memory locators = TransientArrayLib.getBytes32(BATCH_LOCATORS_SLOT);

        TransientArrayLib.clear(BATCH_LOCATORS_SLOT);

        for (uint256 i; i < locators.length; i++) {
            (uint16 centrifugeId, PoolId poolId) = _parseLocator(locators[i]);
            bytes32 outboundBatchSlot = _outboundBatchSlot(centrifugeId, poolId);
            uint128 gasLimit = _gasLimitSlot(centrifugeId, poolId).tloadUint128();
            bytes memory batch = TransientBytesLib.get(outboundBatchSlot);

+           // Validate batch doesn't exceed message count limit
+           uint256 messageCount = _countMessages(batch);
+           require(messageCount <= maxBatchMessages, TooManyMessages());

            cost += _send(centrifugeId, batch, gasLimit, refund, fuel - cost);

            TransientBytesLib.clear(outboundBatchSlot);
            _gasLimitSlot(centrifugeId, poolId).tstore(uint256(0));
        }

        isBatching = false;
    }

+   function _countMessages(bytes memory batch_) internal view returns (uint256 count) {
+       bytes memory remaining = batch_;
+       while (remaining.length > 0) {
+           uint256 length = processor.messageLength(remaining);
+           remaining = remaining.slice(length, remaining.length - length);
+           count++;
+       }
+   }
}

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/centrifuge/protocol-internal/pull/43

The original report as published on Sherlock, by 0x52. 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

Likely, the batch creation function does not check how many messages are included, so an attacker can create a batch that is too large to process on the destination chain.

Impact

Critical system messages batched with excessive numbers of gas-wasting messages become permanently stuck and cannot be processed, breaking core cross-chain functionality such as pool accounting synchronization and share transfers.

What the attacker needed

Attacker can call Gateway.withBatch(); Attacker can create many messages

The fix

The protocol team fixed this issue by implementing a configurable maximum message count limit on the sending side.

How it was found

  1. Call Gateway.withBatch() with a large number of messages, including many UntrustedContractUpdate messages and critical messages like UpdateHoldingAmount.
  2. The batch is sent to the destination chain.
  3. On the receiving chain, Gateway.handle() attempts to process the batch but runs out of gas and reverts.
  4. The batch remains stuck permanently, and critical messages cannot execute.

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 batch is a group of messages sent together to another blockchain. If a batch is too large, it cannot be processed because it needs more gas (computing power) than a single block allows. This means the messages get stuck forever, and important updates like pool balances cannot happen.

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 0x52

View all

211 more disclosed reports, best first.

More from Centrifuge Protocol V3.1

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.