Skip to content
DoS Audit finding Intermediate

`Carousel.mintRollovers` potentially mints `0` shares and can grief rollover queue

The Carousel.mintRollovers function can mint zero shares when a user's deposited assets equal the relayer fee, and if this is the only deposit for an epoch, the vault's total value locked (TVL) remains zero. This causes previewWithdraw to revert due to division by zero, permanently blocking the rollover queue unless the affected user delists their item.

berndartmueller Follow with evan and kenzo

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-03-Y2K-judging/issues/418

Found by

berndartmueller, evan, kenzo

Summary

If the deposited assets for a queued rollover item are equal to the relayer fee, the rollover will be minted with 0 shares, potentially leading to zero TVL and hence finalTVL[_id] = 0. This will cause the previewWithdraw call to revert due to division by zero and the rollover queue will be stuck forever.

Vulnerability Detail

Minting rollovers in the carousel vault iterates over all items in the rolloverQueue queue. Each item is processed, and the entitled shares (entitledShares) are calculated using previewWithdraw. If the entitled shares are greater than the deposited assets), the rollover is minted.

However, if the deposited assets for the queued item are equal to the relayer fee, the assets to mint (assetsToMint) calculated in line 436 will be 0.

If this happens to be the only deposit (mint) for the epoch and the vaults TVL remains zero, the previewWithdraw call in line 396 will revert due to division by zero.

Impact

Once there is a rollover minted with 0 shares for an epoch and the vaults TVL (i.e., finalTVL) remains zero, the rollover queue will be stuck forever unless the owner of this queue item delists it.

Code Snippet

src/v2/Carousel/Carousel.mintRollovers

Solidity
361: function mintRollovers(uint256 _epochId, uint256 _operations)
362:     external
363:     epochIdExists(_epochId)
364:     epochHasNotStarted(_epochId)
365:     nonReentrant
366: {
...      // [...]
392:
393:     while ((index - prevIndex) < (_operations)) {
394:         // only roll over if last epoch is resolved
395:         if (epochResolved[queue[index].epochId]) {
396: @>          uint256 entitledShares = previewWithdraw( // @audit-info reverts if epoch's `finalTVL` == 0
397:                 queue[index].epochId,
398:                 queue[index].assets
399:             );
400:             // mint only if user won epoch he is rolling over
401:             if (entitledShares > queue[index].assets) {
402:                 // skip the rollover for the user if the assets cannot cover the relayer fee instead of revert.
403:                 if (queue[index].assets < relayerFee) {
404:                     index++;
405:                     continue;
406:                 }
407:                 // @note we know shares were locked up to this point
408:                 _burn(
409:                     queue[index].receiver,
410:                     queue[index].epochId,
411:                     queue[index].assets
412:                 );
413:                 // transfer emission tokens out of contract otherwise user could not access them as vault shares are burned
414:                 _burnEmissions(
415:                     queue[index].receiver,
416:                     queue[index].epochId,
417:                     queue[index].assets
418:                 );
419:                 // @note emission token is a known token which has no before transfer hooks which makes transfer safer
420:                 emissionsToken.safeTransfer(
421:                     queue[index].receiver,
422:                     previewEmissionsWithdraw(
423:                         queue[index].epochId,
424:                         queue[index].assets
425:                     )
426:                 );
427:
428:                 emit Withdraw(
429:                     msg.sender,
430:                     queue[index].receiver,
431:                     queue[index].receiver,
432:                     _epochId,
433:                     queue[index].assets,
434:                     entitledShares
435:                 );
436: @>              uint256 assetsToMint = queue[index].assets - relayerFee; // @audit-info `assetsToMint` can potentially become 0
437:                 _mintShares(queue[index].receiver, _epochId, assetsToMint);
438:                 emit Deposit(
439:                     msg.sender,
440:                     queue[index].receiver,
441:                     _epochId,
442:                     assetsToMint
443:                 );
444:                 rolloverQueue[index].assets = assetsToMint;
445:                 rolloverQueue[index].epochId = _epochId;
446:                 // only pay relayer for successful mints
447:                 executions++;
448:             }
449:         }
450:         index++;
451:     }
452:
...      // [...]
459: }

src/v2/VaultV2.previewWithdraw

Solidity
357: function previewWithdraw(uint256 _id, uint256 _assets)
358:     public
359:     view
360:     override(SemiFungibleVault)
361:     returns (uint256 entitledAmount)
362: {
363:     // entitledAmount amount is derived from the claimTVL and the finalTVL
364:     // if user deposited 1000 assets and the claimTVL is 50% lower than finalTVL, the user is entitled to 500 assets
365:     // if user deposited 1000 assets and the claimTVL is 50% higher than finalTVL, the user is entitled to 1500 assets
366:     entitledAmount = _assets.mulDivDown(claimTVL[_id], finalTVL[_id]);
367: }

Tool used

Manual Review

Recommendation

Consider checking the total assets of the epoch queue[index].epochId to be greater than 0 before calling previewWithdraw in line 396.

Discussion

3xHarry

will move check from line 403 up before previewWithdraw, also considering implementing rollover delisting if assetsToMint is less than relayerFee

3xHarry

in general delisting of stale rollovers (not enough to pay for relayer, or not won prev epoch) should be delisted by smart contract.

3xHarry

fix PR: https://github.com/Y2K-Finance/Earthquake/pull/133

IAm0x52

Needs additional changes. This still doesn't address the issue of minting 0 because if assets == relayerFee then it will still mint 0. Should instead be:

if (queue[index].assets <= relayerFee) {

IAm0x52

Fix looks good. Suggested change above has been added

jacksanford1

Note: 0x52 referenced this commit in their second message from PR #133:

https://github.com/Y2K-Finance/Earthquake/pull/133/commits/9edaa8a5da96edf7c61bef4a8847f7c107f2b630

The original report as published on Sherlock, by berndartmueller. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 does not check that the assets to mint after subtracting the relayer fee are greater than zero, and it also does not ensure the epoch's total value locked (TVL) is non-zero before calling previewWithdraw, which divides by TVL.

Impact

The rollover queue can become permanently stuck, preventing any further rollovers for that epoch, unless the owner of the zero-share item delists it.

What the attacker needed

User queues a rollover with assets equal to relayer fee; this is the only deposit for the epoch

The fix

The code was fixed by moving the relayer fee check before previewWithdraw and changing the condition to skip rollovers when assets are less than or equal to the relayer fee.

How it was found

  1. A user queues a rollover with deposited assets exactly equal to the relayer fee.
  2. The mintRollovers function processes the queue and calls previewWithdraw for that item.
  3. Since the user's assets equal the relayer fee, assetsToMint becomes zero and zero shares are minted.
  4. If this is the only deposit for the epoch, the vault's TVL remains zero.
  5. A subsequent call to previewWithdraw for any item in that epoch reverts due to division by zero.
  6. The rollover queue becomes stuck and cannot be processed further unless the affected user delists their item.

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.

In a vault, users can queue up their deposits to automatically roll over to the next epoch. When processing these rollovers, the code subtracts a relayer fee from the user's assets to determine how many new shares to mint. If the user's assets exactly equal the fee, zero shares are minted. If that was the only deposit for the epoch, the vault's total assets become zero, and a later calculation that divides by total assets fails, causing the whole rollover process to get stuck.

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.

More by berndartmueller

View all

97 more disclosed reports, best first.

More from Y2K

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.