Inconsistent sequencer unexpected delay in DelayBuffer may harm users calling forceInclusion()
The delay buffer in Arbitrum's SequencerInbox does not always decrease when multiple delayed messages are force-included at once, so users may have to wait longer than necessary to force-include their own messages. An attacker could potentially exploit this to delay force inclusion, locking funds for some time.
Buffer unexpected delay due to sequencer outage is inconsistent.
Proof of Concept
When the sequencer is down, users may call SequencerInbox::forceInclusion() to get their message added to the inbox sequencerInboxAccs. However, there is an incosistency when the sequencer has been down and there is more than 1 message, or even if just 1 message.
The DelayBuffer is used to dynamically adjust how much delay a user has to wait to call SequencerInbox::forceInclusion(). The buffer increase mechanism is not relevant for this issue.
The buffer decrease consists of subtracting the last time the buffer was updated, self.prevSequencedBlockNumber, by the previous block number of the last delay buffer update, self.prevBlockNumber. This is done this way to ensure that the sequencer delay can not be double counted, as the delayed inbox may have more than 1 delayed message.
However, the approach taken as a way of protecting the sequencer and not depleting the buffer incorrectly as the drawback that it also means that the buffer will not always be decreased.
For example, if the sequencer is working at a block number A, a message is submited at block number A + 10 and another one at block number A + 110. If the sequencer is down, the user has to wait, for example, delay blocks of 100 (or the delay buffer, depending on the smallest). If 200 blocks have passed since A + 10 (the first message), both delayed messages may be force included, at block number A + 210.
The discrepancy is that, depending on how the delayed messages are included, the buffer delay will be reduced differently. If both messages are removed at once, by calling SequencerInbox::forceInclusion() with the id of the newest message, the buffer delay will not be decreased, as self.prevBlockNumber is A, the same as self.prevSequencedBlockNumber. This would harm users that want to force included messages as the buffer would be bigger and they would have to wait more time for their message to be force included.
If the oldest message is first force included, the buffer delay will not decreased, as above, but self.prevSequencedBlockNumber will be updated to A + 210 and self.prevBlockNumber to A + 10. Then, if the second message is force included, self.prevSequencedBlockNumber - self.prevBlockNumber == A + 210 - (A + 10) == 200, which means that the buffer would correctly decrease as the sequencer was offline (ignoring the fact that there is a threshold, but the issue is the same as long as the delay is bigger than the threshold).
As a proof of concept, add the following test to SequencerInbox.t.sol. It shows that given 2 messages, the delay buffer is only decreased if the first message is forcely included first and only after is the newest message included. If the given delayedMessagesRead is the if of the second message, without forcely including the first one first, the buffer will not decrease.
function test_POC_InconsistentBuffer_Decrease() public {
BufferConfig memory configBufferable = BufferConfig({
threshold: 600, //60 * 60 * 2 / 12
max: 14400, //24 * 60 * 60 / 12 * 2
replenishRateInBasis: 714
});
(SequencerInbox seqInbox, Bridge bridge) = deployRollup(false, true, configBufferable);
address delayedInboxSender = address(140);
uint8 delayedInboxKind = 3;
bytes32 messageDataHash = RAND.Bytes32();
(uint64 bufferBlocks, ,,,,) = seqInbox.buffer();
assertEq(bufferBlocks, 14400);
vm.startPrank(dummyInbox);
bridge.enqueueDelayedMessage(delayedInboxKind, delayedInboxSender, messageDataHash);
vm.roll(block.number + 1100);
bridge.enqueueDelayedMessage(delayedInboxKind, delayedInboxSender, messageDataHash);
vm.stopPrank();
vm.roll(block.number + 500);
uint256 delayedMessagesRead = bridge.delayedMessageCount();
// buffer is not decreased if the first and second messages are included at once
seqInbox.forceInclusion(
delayedMessagesRead,
delayedInboxKind,
[uint64(block.number - 500), uint64(block.timestamp)],
0,
delayedInboxSender,
messageDataHash
);
(bufferBlocks, ,,,,) = seqInbox.buffer();
assertEq(bufferBlocks, 14400);
// buffer is only decreased if the first message is included first
/*seqInbox.forceInclusion(
delayedMessagesRead - 6,
delayedInboxKind,
[uint64(block.number - 1600), uint64(block.timestamp)],
0,
delayedInboxSender,
messageDataHash
);
(bufferBlocks, ,,,,) = seqInbox.buffer();
assertEq(bufferBlocks, 14400);
seqInbox.forceInclusion(
delayedMessagesRead,
delayedInboxKind,
[uint64(block.number - 500), uint64(block.timestamp)],
0,
delayedInboxSender,
messageDataHash
);
(bufferBlocks, ,,,,) = seqInbox.buffer();
assertEq(bufferBlocks, 13478);*/
}
Tools Used
Vscode
Foundry
Recommended Mitigation Steps
A mitigation must be carefully taken as not to introduce double accounting of the buffer delay. One solution that would fix this issue is tracking the total unexpected delay separately and making it equal to the block.number minus the maximum between the previous sequenced block number and the oldest delayed message that was not yet included. This way, by doing the maximum with the last sequenced, we guarantee that no double accounting of delays takes place. By doing the maximum with the oldest delayed message, we guarantee that the delay is real and not that no message was submitted.
Note: the following discussion has been condensed for this report. To view the full discussion, please see the original submission.
This report shows how the delay buffer update could be nondeterministic and depend on how messages are included, but as shown by the sponsor fails to demonstrate why this would be important and how this fulfills the definition of Medium severity (function of the protocol or its availability could be impacted).
After further discussion, this issue is to me somewhere between “function incorrect as to spec, state handling”, and “availability issue”.
Considering:
that the impact of the end-user not being able to force-include a message as soon as possible is that its funds may be locked for some time.
that if the sequencer is down, there may be multiple messages to force-include, and that the depletion is advertised in various places but is non-deterministic and could be “manipulated” to delay the following message, I’ll upgrade to Medium.
that the impact of the end-user not being able to force-include a message as soon as possible is that its funds may be locked for some time
@Picodes - I’m not sure this is true. In the example @0x73696d616f gave with 3 messages (m1,m2,m3 at T1,T2,T3), m1 not being included right away does not cause funds to be locked since m1 is included when m2 is included at T2, and m1 could have been included at any time between T1 and T2.
If the same user (eg someone playing in an L3’s bold game) submits m2 and m3, and they force include only their own messages promptly (as in the example where there is a claimed bug) they are not affected. That user, the force includer, still can only experience some max amount of sequencer censorship over a given time period.
It is assumed … honest validators can react to malicious action broadcasted on-chain immediately in the same block unless the malicious party spend their censorship budget.
This is unless the function is designed to be non-admin permissioned, then we enforce straighter guarantee. e.g.
There is a correct fix that is applied in the delayProofImpl() but not in forceInclusion().
Batch poster’s delayProofImpl have the “correct fix” where permissionless forceInclusion do not. This is by design to limit the complexity of the contracts.
If anyone is concerned about the total delay of delayed message, it is assumed they SHOULD force include as soon as possible. If they do not call force include, there are no protocol guarantee their message will ever be included. Any delay in calling forceInclusion on parent chain can be modeled as part of the censorship budget of an attacker.
Here is a POC showing how the buffer is correctly depleted only if messages are included sequentially. The buffer gets depleted due to actively including messages sequentially. If the second message in the loop is included directly instead, the buffer is not correctly depleted, and instead of ending up being the minimum, is a much larger value (600 vs 7320). Thus, users have to wait 2000 blocks instead of 600. It can be confirmed that initially they have to wait 2000 blocks, but in the end only 600, if we include sequentially and fix this bug. If we don’t include sequentially, they still have to wait 2000 blocks.
We can play around with the numbers and observe different outcomes, but this is a real, proven risk. Here users have to wait 2000/600 = 3.3 times more to get their transaction force included. This issue will happen, how it happens depends on the conditions. The buffer being depleted is an expected scenario and the code is built to handle this situation, so arguments based on the fact that this will never happen do not stand. The impact depends on delayBlocks, threshold, max, replenishRate and user behaviour. We can find a lot of combinations showing very strong impact, as well as some showing less impact, but we know for sure this is a real risk. A list of parameters or user behavior that increase/decrease the impact can be made, but it does not erase the fact that this risk exists. It fits exactly in the definition of a medium severity issue:
with a hypothetical attack path with stated assumptions, but external requirements.
With the above PoC in a longer sequence the effect on the sequenced - start gets indeed neutralized and we’re back with a DoS issue. This is Medium severity.
The original report as published on Code4rena, by 0x73696d616f. 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.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the buffer decrease calculation uses the previous block number of the last buffer update rather than the oldest pending delayed message, so including multiple messages at once skips the decrease.
Impact
Users may have to wait up to several times longer to force-include their messages, potentially locking funds for some time; the effect depends on parameters and user behaviour.
What the attacker needed
Sequencer is offline; multiple delayed messages pending; user calls forceInclusion
The fix
The delay buffer should track the total unexpected delay separately, using the maximum of the previous sequenced block number and the oldest pending delayed message, to avoid double counting while ensuring real delays are accounted for.
How it was found
Deploy the SequencerInbox and Bridge with a buffer configuration.
Enqueue two delayed messages with a block gap between them.
Advance the block number so that force inclusion is allowed.
Call forceInclusion with the ID of the newest message only.
Observe that the buffer has not decreased.
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.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
When the sequencer (the service that orders transactions) is down, users can force their messages into the system after a waiting period. That waiting period is controlled by a 'delay buffer' that should shrink when the sequencer has been offline. This report shows that if several messages are waiting and a user includes the newest one first, the buffer does not shrink as it should, so everyone has to wait longer than necessary.
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.