Malicious user can make rolloverQueue never get processed
A single rollover queue is shared across all epochs, so a user can add many tiny entries that are never removed. This makes every round's rollover processing expensive and unprofitable for relayers, potentially stopping rollovers permanently.
Source: https://github.com/sherlock-audit/2023-03-Y2K-judging/issues/172
Found by
Ace-30, ElKu, Respx, ShadowForce, TrungOre, bin2chen, ck, evan, hickuphh3, immeas, minhtrng, nobody2018, twicek
Summary
rolloverQueue is shared by all epochs. For each round of epoch, mintRollovers will process rolloverQueue from the beginning. A normal user calls enlistInRollover to enter the rolloverQueue, and in the next round of epoch, he will call delistInRollover to exit the rolloverQueue. In this case, rolloverQueue.length is acceptable. However, malicious user can make the rolloverQueue.length huge, causing the relayer to consume a huge amount of gas for every round of epoch. Carousel will send relayerFee to relayer in order to encourage external relayer to call mintRollovers. Malicious user can make external relayer unwilling to call mintRollovers. Ultimately, rolloverQueue will never be processed.
Vulnerability Detail
Let's assume the following scenario:
relayerFee is 1e18. The current epochId is E1, and the next epochId is E2. At present, rolloverQueue has 10 normal user QueueItem. Bob has deposited 1000e18 assets before the start of E1, so balanceOf(bob, E1) = 1000e18.
-
Bob creates 1000 addresses, each address has
setApprovalForAllto bob. He calls two functions for each address:Carousel.safeTransferFrom(bob, eachAddress, E1, 1e18)Carousel.enlistInRollover(E1, 1e18, eachAddress), 1e18 equal to minRequiredDeposit. -
rolloverQueue.lengthequals to 1010(1000+10).
These 1000 addresses will never call delistInRollover to exit the rolloverQueue, so no matter whether these addresses win or lose, their QueueItem will always be in the rolloverQueue. In each round of epoch, the relayer has to process at least 1000 QueueItems, and these QueueItems are useless. Malicious users only need to do it once to cause permanent affects.
When a normal user loses in a certain round of epoch, he may not call delistInRollover to exit the rolloverQueue. For example, he left the platform and stopped playing. In this case, rolloverQueue.length will become larger and larger as time goes by.
Carousel contract will not send any relayerFee to the relayer, because these useless QueueItem will not increase the value of [executions](https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/Carousel/Carousel.sol#L447). Obviously, calling mintRollovers has no benefit for the relayer. Therefore, no relayer is willing to do this.
Impact
The relayer consumes a huge amount of gas for calling mintRollovers for each round of epoch. In other words, as long as the rolloverQueue is unacceptably long, it is a permanent DOS.
Code Snippet
Tool used
Manual Review
Recommendation
We should change the single queue to queue mapping. In this way, relayer only needs to process the queue corresponding to the epochId.
--- a/Earthquake/src/v2/Carousel/Carousel.sol
+++ b/Earthquake/src/v2/Carousel/Carousel.sol
@@ -23,7 +23,7 @@ contract Carousel is VaultV2 {
IERC20 public immutable emissionsToken;
mapping(address => uint256) public ownerToRollOverQueueIndex;
- QueueItem[] public rolloverQueue;
+ mapping(uint256 => QueueItem[]) public rolloverQueues;
QueueItem[] public depositQueue;
mapping(uint256 => uint256) public rolloverAccounting;
mapping(uint256 => mapping(address => uint256)) public _emissionsBalances;
Discussion
3xHarry
I would disagree with the feasibility of this attack.
- there is a non neglectable minDeposit which makes this attack much more expensive
- the queue can be processed in multiple transactoins and the relayerFee is supposed to be configured so much so that each processed item gas consumption is reimbursed with a profit
IAm0x52
Issue has been acknowledged by sponsor
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 design uses one global rollover queue instead of a per-epoch queue, so entries from many rounds accumulate and are all processed each time.
Impact
The relayer must spend a large amount of gas each round with no fee reward, so rollovers could be permanently blocked; a sponsor comment disputes feasibility because of the minimum deposit and multi-transaction processing.
What the attacker needed
Minimum deposit per entry; many addresses; approval for each address
The fix
The queue should be split per epoch so the relayer only processes the relevant epoch's entries.
How it was found
- Bob deposits assets before the epoch starts.
- Bob creates many addresses and approves Bob to transfer on their behalf.
- For each address, Bob transfers a minimum deposit and enlists it in the rollover queue.
- The queue length grows by the number of addresses created.
- Those addresses never delist, so their entries remain in every future round.
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 queue is a list of tasks processed in order. Here one list is used for every round, and anyone can add entries that stay forever. If the list grows very large, the person paid to process it spends too much effort for too little reward and stops, so the work never gets done.
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.