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` labelMediumA valid Medium severity issueRewardA payout will be made for this issue
Unbounded size of rolloverQueue will eventually cause the mintRollovers function to revert
Summary
In Carousel contract, the items in the array rolloverQueue , doesnt get deleted after a listed item is minted by the mintRollovers function. And in every call to mintRollovers function, the whole array is copied to memory. This means eventually we will hit the gas limit of the block, making the function revert and thus resulting in the funds being stuck.
Vulnerability Detail
When a user wants to use his leftover funds from a previous epoch to the upcoming epoch, he/she calls the enlistInRollover function. This pushes the details required for the roll over to an array structure called rolloverQueue.
The only case where these pushed items are popped from the array is when the user itself wants to cancel the rollover using the delistInRollover function.
Otherwise a relayer would call the mintRollovers function before the new epoch starts.
In the mintRollovers function, the whole rolloverQueue array is read into memory, irrespective of how many operations the relayer want to perform. Each element in this array requires at least 300 gas, as its a storage read(3 uint's per read).
Assuming that each user creates a rollover request at least once, there will be one entry for each user in the array. If n is the total number of users in a market then the call to mintRollovers function will cost a minimum of n*300 gas.
Impact
As the time goes, and the number of users of a particular market increases the gas cost of minting a rollover increases. Beyond a threshold this will break the entire market(as the 3 million gas limit of a block is approached) resulting in loss of funds, and a lot and lot of inconvenience for everyone involved.
Code Snippet
The enlistInRollover function has this part:
if (ownerToRollOverQueueIndex[_receiver] !=0) { //ownerToRollOverQueueIndex is derived from length of array// if so, update the queueuint256 index =getRolloverIndex(_receiver); //ownerToRollOverQueueIndex[_receiver] - 1;
rolloverQueue[index].assets = _assets;
rolloverQueue[index].epochId = _epochId;
} else {
// if not, add to queue
rolloverQueue.push(
QueueItem({
assets: _assets,
receiver: _receiver,
epochId: _epochId
})
);
}
And mintRollovers has this line, reading the entire array into memory:
QueueItem[] memory queue = rolloverQueue;
Tool used
Manual Review, VSCode.
Recommendation
Remove the struct element from the array when a rollover is minted. Or change the logic so that only elements which need to be minted are read from storage.
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` labelMediumA valid Medium severity issueRewardA payout will be made for this issue
ElKu
medium
Unbounded size of rolloverQueue will eventually cause the mintRollovers function to revert
Summary
In
Carousel
contract, the items in the arrayrolloverQueue
, doesnt get deleted after a listed item is minted by the mintRollovers function. And in every call tomintRollovers
function, the whole array is copied to memory. This means eventually we will hit the gas limit of the block, making the function revert and thus resulting in the funds being stuck.Vulnerability Detail
enlistInRollover
function. This pushes the details required for the roll over to an array structure calledrolloverQueue
.delistInRollover
function.relayer
would call themintRollovers
function before the new epoch starts.mintRollovers
function, the wholerolloverQueue
array is read into memory, irrespective of how many operations therelayer
want to perform. Each element in this array requires at least 300 gas, as its a storage read(3 uint's per read).n
is the total number of users in a market then the call tomintRollovers
function will cost a minimum of n*300 gas.Impact
As the time goes, and the number of users of a particular market increases the gas cost of minting a rollover increases. Beyond a threshold this will break the entire market(as the 3 million gas limit of a block is approached) resulting in loss of funds, and a lot and lot of inconvenience for everyone involved.
Code Snippet
The
enlistInRollover
function has this part:And
mintRollovers
has this line, reading the entire array into memory:Tool used
Manual Review, VSCode.
Recommendation
Remove the struct element from the array when a rollover is minted. Or change the logic so that only elements which need to be minted are read from storage.
Duplicate of #172
The text was updated successfully, but these errors were encountered: