Funds can be stolen because of incorrect update to `ownerToRollOverQueueIndex` for existing rollovers
The contract incorrectly updates the ownerToRollOverQueueIndex to the last queue index even when a user already has an existing rollover, causing the notRollingOver check to validate the wrong queue item. This allows a depositor to withdraw funds that should have been locked for the rollover.
Source: https://github.com/sherlock-audit/2023-03-Y2K-judging/issues/2
Found by
0Kage, 0x52, 0xMojito, 0xPkhatri, 0xRobocop, 0xnirlin, AlexCzm, Aymen0909, Bauer, Ch_301, Dug, ElKu, Emmanuel, HonorLt, Junnon, Respx, TrungOre, VAD37, ast3ros, auditor0517, berndartmueller, bin2chen, cccz, charlesjhongc, ck, climber2002, csanuragjain, datapunk, evan, hickuphh3, holyhansss, iglyx, immeas, jasonxiale, joestakey, kenzo, libratus, ltyu, minhtrng, mstpr-brainbot, ne0n, pfapostol, roguereddwarf, shaka, sinarette, spyrosonic10, toshii, twicek, volodya, warRoom, yixxas, zeroknots
Summary
In the case where the owner has an existing rollover, the ownerToRollOverQueueIndex incorrectly updates to the last queue index. This causes the notRollingOver check to be performed on the incorrect _id, which then allows the depositor to withdraw funds that should've been locked.
Vulnerability Detail
In enlistInRollover(), if the user has an existing rollover, it overwrites the existing data:
if (ownerToRollOverQueueIndex[_receiver] != 0) {
// if so, update the queue
uint256 index = getRolloverIndex(_receiver);
rolloverQueue[index].assets = _assets;
rolloverQueue[index].epochId = _epochId;
However, regardless of whether the user has an existing rollover, the ownerToRolloverQueueIndex points to the last item in the queue:
ownerToRollOverQueueIndex[_receiver] = rolloverQueue.length;
Thus, the notRollingOver modifier will check the incorrect item for users with existing rollovers:
QueueItem memory item = rolloverQueue[getRolloverIndex(_receiver)];
if (
item.epochId == _epochId &&
(balanceOf(_receiver, _epochId) - item.assets) < _assets
) revert AlreadyRollingOver();
allowing the user to withdraw assets that should've been locked.
Impact
Users are able to withdraw assets that should've been locked for rollovers.
Code Snippet
https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/Carousel/Carousel.sol#L252-L257 https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/Carousel/Carousel.sol#L268 https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/Carousel/Carousel.sol#L755-L760
Tool used
Manual Review
Recommendation
The ownerToRollOverQueueIndex should be pointing to the last item in the queue in the else case only: when the user does not have an existing rollover queue item.
} else {
// if not, add to queue
rolloverQueue.push(
QueueItem({
assets: _assets,
receiver: _receiver,
epochId: _epochId
})
);
+ ownerToRollOverQueueIndex[_receiver] = rolloverQueue.length;
}
- ownerToRollOverQueueIndex[_receiver] = rolloverQueue.length;
Discussion
3xHarry
good catch
3xHarry
fix PR: https://github.com/Y2K-Finance/Earthquake/pull/128
IAm0x52
Fix looks good. Assigning index has been moved inside else block
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
The code unconditionally sets ownerToRollOverQueueIndex to the new queue length after updating an existing rollover, instead of only doing so when adding a new rollover.
Impact
Users are able to withdraw assets that should've been locked for rollovers.
What the attacker needed
Existing rollover; depositor role
The fix
The ownerToRollOverQueueIndex should only be updated in the else case when the user does not have an existing rollover; the fix was confirmed by the auditor.
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.
When a user signs up to roll over their deposit to the next period, the contract records their place in a queue. If they sign up again, the contract mistakenly updates their queue position to the end instead of keeping their original spot. This means a safety check looks at the wrong entry and lets the user take out money that was supposed to stay locked.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.