Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

ShadowForce - unbounded loop in view function leads to a dos #313

Closed
sherlock-admin opened this issue Mar 27, 2023 · 4 comments
Closed

ShadowForce - unbounded loop in view function leads to a dos #313

sherlock-admin opened this issue Mar 27, 2023 · 4 comments
Labels
Escalation Resolved This issue's escalations have been approved/rejected Non-Reward This issue will not receive a payout

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Mar 27, 2023

ShadowForce

medium

unbounded loop in view function leads to a dos

Summary

unbounded loops in getRolloverTVL and getDepositQueueTVL functions will lead to a DOS

Vulnerability Detail

In the carousal contract we can see there are two unbounded loops. Because the rolloverQueue and depostiQueue are infinitely large, the function may encounter an Out of gas problem. the DOS issue can block external protocol integration that relies on these two functions to accurately retrieve the protocol TVL and also DOS the frontend website that relies on calling this function to display the protocol TVL.
the two unbounded loops can be viewed below.

  function getRolloverTVL(uint256 _epochId)
        public
        view
        returns (uint256 tvl)
    {
        for (uint256 i = 0; i < rolloverQueue.length; i++) {
            if (
                rolloverQueue[i].epochId == _epochId &&
                (previewWithdraw(
                    rolloverQueue[i].epochId,
                    rolloverQueue[i].assets
                ) > rolloverQueue[i].assets)
            ) {
                tvl += rolloverQueue[i].assets;
            }
        }
    }
    /** @notice returns the total value locked in the deposit queue
     * @return tvl total value locked in the deposit queue
     */
    function getDepositQueueTVL() public view returns (uint256 tvl) {
        for (uint256 i = 0; i < depositQueue.length; i++) {
            tvl += depositQueue[i].assets;
        }
    }

Impact

Because rolloverQueue and depositQueue can be infinitely large. These view functions wich are vital to the protocol may run out of gas and not work entirely leading to a Denial Of Service. Users funds will be locked up in queue, this is a loss of potential funds.

Code Snippet

https://github.com/Y2K-Finance/Earthquake/blob/736b2e1e51bef6daa6a5ecd1decb7d156316d795/src/v2/Carousel/Carousel.sol#L655-L671

https://github.com/Y2K-Finance/Earthquake/blob/736b2e1e51bef6daa6a5ecd1decb7d156316d795/src/v2/Carousel/Carousel.sol#L687-L694

Tool used

Manual Review

Recommendation

add running total or an accumulator variable and update the total TVL when request is added or removed to avoid unbounded loop.

@github-actions github-actions bot closed this as completed Apr 3, 2023
@github-actions github-actions bot added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Apr 3, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Apr 11, 2023
@twicek
Copy link

twicek commented Apr 11, 2023

Escalate for 10 USDC

This issue is not a duplicate of #174 and should not be medium severity since the issue is located in a view function that is not used in any state changing function.

As per the documentation:

  • Incorrect values in View functions are by default considered low.
    Exception: In case any of these incorrect values returned by the view functions are used as a part of a larger function which would result in loss of funds then it would be a valid medium/high depending on the impact.

@sherlock-admin
Copy link
Contributor Author

Escalate for 10 USDC

This issue is not a duplicate of #174 and should not be medium severity since the issue is located in a view function that is not used in any state changing function.

As per the documentation:

  • Incorrect values in View functions are by default considered low.
    Exception: In case any of these incorrect values returned by the view functions are used as a part of a larger function which would result in loss of funds then it would be a valid medium/high depending on the impact.

You've created a valid escalation for 10 USDC!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

@sherlock-admin sherlock-admin added the Escalated This issue contains a pending escalation label Apr 11, 2023
@hrishibhat
Copy link

Escalation accepted

Valid low
Not a duplicate of #174

@sherlock-admin
Copy link
Contributor Author

Escalation accepted

Valid low
Not a duplicate of #174

This issue's escalations have been accepted!

Contestants' payouts and scores will be updated according to the changes made on this issue.

@sherlock-admin sherlock-admin added Escalation Resolved This issue's escalations have been approved/rejected and removed Escalated This issue contains a pending escalation labels Apr 21, 2023
@hrishibhat hrishibhat removed Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Reward A payout will be made for this issue labels Apr 28, 2023
@sherlock-admin sherlock-admin added the Non-Reward This issue will not receive a payout label Apr 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Escalation Resolved This issue's escalations have been approved/rejected Non-Reward This issue will not receive a payout
Projects
None yet
Development

No branches or pull requests

3 participants