This repository has been archived by the owner on Jan 12, 2025. It is now read-only.
0xboriskataa - Owner will not be able to change the weight of one of the old pools or remove it #384
Labels
Non-Reward
This issue will not receive a payout
0xboriskataa
High
Owner will not be able to change the weight of one of the old pools or remove it
Summary
Voter.sol: setTopPoolIdsWithWeights()
can be used by the owner to set the weight for each pool. If old pools are present it removes them and resets their weight to 0. However due to incorrect array itteration a revert can happen which will prevent the owner from overwriting the weight of one of the old pools. It also prevents him from removing it.Vulnerability Detail
Here is part of the code for the
setTopPoolIdsWithWeights()
:First, if old pools are present it itterates through them in order to remove each one from
_topPids
and set their weight to 0. The issue is that the loop doesn't itterate through the element with index 0:As we can see if
i > 0
it will get into the for loop and remove the element with index ofi
. However ifi = 0
it will not get inside the body of the loop and thus the 0th element will not be removed from_topPids
.This can cause an issue in the second for loop where we itterate through the new pools and try to add them in
_topPids
:As you can see there is an if check and its purpose is to not allow duplicate pools.
Imagine this scenario:
_topPids
with their weights._topPids
because it cannot be removed from it as it has an index of 0. The transaction will simply revert because the if statement will catch duplicate pools.Impact
Owner will not be able to change the weight of the first pool in the
_topPids
or remove it._topPids
represent farms that users can deposit in. The weight of each pool/farm affects how many rewards a user will get from it.Code Snippet
https://github.com/sherlock-audit/2024-06-magicsea/blob/main/magicsea-staking/src/Voter.sol#L271-L276
Tool used
Manual Review
Recommendation
The text was updated successfully, but these errors were encountered: