You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.
sherlock-admin opened this issue
Mar 27, 2023
· 0 comments
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelHighA valid High severity issueRewardA payout will be made for this issue
Carousel: When a rollover is delisted it can prevent another rollover from being processed
Summary
Rollovers are removed from the queue using the Carousel.delistInRollover function.
When a rollover is removed from the queue, the rollover at the end of the queue is moved to the position where the rollover was removed.
Rollovers are minted from head to tail. This means that when a rollover is moved from the end of the queue to an earlier position in the queue, this earlier position might have already been processed.
This means that the rollover that was moved to an earlier position will not get processed.
I will show how this can just occur as part of normal operation and without the need for an attacker to deliberately make this happen.
Vulnerability Detail
First I show how removing an element from the queue works:
Let's say the queue contains the following elements:
head tail
1 2 3 4 5
Then element 2 is delisted and element 5 is moved to its position:
So say at a point in time all rollovers have been processed and the value in the rolloverAccounting mapping points to the next index where there is currently no element:
rolloverAccounting
|
head tail
1 2 3 4 5
Then a new rollover 6 is queued and before it can get executed the element 2 is removed from the queue such that element 6 is moved towards the front of the queue. The queue then looks like this:
rolloverAccounting
|
head tail
1 6 3 4 5
As you can see, the rollover 6 cannot get executed because rolloverAccounting is pointing to the end of the queue and rollover 6 has been moved to an earlier position within the queue.
Impact
Pending rollovers will not get executed if rollovers are delisted which just happens as part of normal operation.
This issue has been discussed with the sponsor but it was not possible to find a good solution with the current implementation of the queue.
It might be necessary to use a linked list implementation such that elements within the list can be removed without affecting the rest of the list.
Instead of pointing to an index, the rolloverAccounting mapping would then point to the next element to be processed directly or to a NULL element if the linked list is empty or all elements have been processed.
If the implementation is changed from a primitive array to a linked list there are further changes necessary to keep the state correctly updated so a broader refactoring would be necessary.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelHighA valid High severity issueRewardA payout will be made for this issue
roguereddwarf
medium
Carousel: When a rollover is delisted it can prevent another rollover from being processed
Summary
Rollovers are removed from the queue using the
Carousel.delistInRollover
function.When a rollover is removed from the queue, the rollover at the end of the queue is moved to the position where the rollover was removed.
Rollovers are minted from head to tail. This means that when a rollover is moved from the end of the queue to an earlier position in the queue, this earlier position might have already been processed.
This means that the rollover that was moved to an earlier position will not get processed.
I will show how this can just occur as part of normal operation and without the need for an attacker to deliberately make this happen.
Vulnerability Detail
First I show how removing an element from the queue works:
Let's say the queue contains the following elements:
Then element 2 is delisted and element 5 is moved to its position:
This occurs by executing the
else
block in thedelistInRollover
function:https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/Carousel/Carousel.sol#L292-L303
The issue comes about because the
mintRollovers
function makes use of arolloverAccounting
mapping which keeps track of the next index in the queue that needs to be rolled over:https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/Carousel/Carousel.sol#L453
So say at a point in time all rollovers have been processed and the value in the
rolloverAccounting
mapping points to the next index where there is currently no element:Then a new rollover 6 is queued and before it can get executed the element 2 is removed from the queue such that element 6 is moved towards the front of the queue. The queue then looks like this:
As you can see, the rollover 6 cannot get executed because
rolloverAccounting
is pointing to the end of the queue and rollover 6 has been moved to an earlier position within the queue.Impact
Pending rollovers will not get executed if rollovers are delisted which just happens as part of normal operation.
Code Snippet
https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/Carousel/Carousel.sol#L276-L304
https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/Carousel/Carousel.sol#L361-L459
Tool used
Manual Review
Recommendation
This issue has been discussed with the sponsor but it was not possible to find a good solution with the current implementation of the queue.
It might be necessary to use a linked list implementation such that elements within the list can be removed without affecting the rest of the list.
Instead of pointing to an index, the
rolloverAccounting
mapping would then point to the next element to be processed directly or to a NULL element if the linked list is empty or all elements have been processed.If the implementation is changed from a primitive array to a linked list there are further changes necessary to keep the state correctly updated so a broader refactoring would be necessary.
Duplicate of #72
The text was updated successfully, but these errors were encountered: