Open howlbot-integration[bot] opened 3 months ago
kupermind (sponsor) confirmed
0xA5DF changed the severity to 2 (Med Risk)
0xA5DF marked the issue as satisfactory
0xA5DF marked the issue as selected for report
Regarding severity - I don't see how this can be med, given that only a small part of the staking-incentives are lost (only for the week where the nominee is removed)
Fixed
Lines of code
https://github.com/code-423n4/2024-05-olas/blob/3ce502ec8b475885b90668e617f3983cea3ae29f/tokenomics/contracts/Dispenser.sol#L393 https://github.com/code-423n4/2024-05-olas/blob/3ce502ec8b475885b90668e617f3983cea3ae29f/tokenomics/contracts/Dispenser.sol#L849 https://github.com/code-423n4/2024-05-olas/blame/3ce502ec8b475885b90668e617f3983cea3ae29f/tokenomics/contracts/Dispenser.sol#L774
Vulnerability details
Impact
If a nominee is removed in the ith epoch then they are eligible to receive staking incentives for the ith epoch if they had enough staking weight but due to current implementation the removed nominee would never receive staking incentives for the ith epoch thus causing loss of staking incentives for the nominee. It is evident from the code that it is intended that the nominee is eligible to receive staking incentives for the epoch when it was removed.Plus I have also asked from the sponsers and they have agreed too that nominee is eligible to receive incentives for that epoch.
Proof of Concept
Following is calculateStaking incentives function
From the above for loop it is visible that the staking incentives are calculated till lastClaimedEpoch-1.
Following function is used to check for which epoches is the nominee eligible to receive the staking incentives.
From the following if condition it is clear that nominee is also eligible to receive staking incentives for the epoch in which it was removed
So as initially for loop ran till lastClaimedEpoch -1 thus it is evident that removed nominnee is eligible for the staking incentives in which it was removed too.
Now lets see what happens when a nominee is removed Firstly it is removed in VoteWeighting.sol in removeNominee function which is as follows
Key thing to note is that if a nominee is removed in ith week then its weight/bias in the upcoming weeks is set to zero i.e from i+1 weeks it will have no weight
Also remove nominee in dispensor is also called which is as follows
Key thing to note here is the following condition
From the above condition it is clear that it is only allowed to remove a nominee if the time left to epoch end is greater than a week. In simpler terms if the epoch end time is scheduled to be at ith week then the nominee can only be removed in the weeks before the ith week(not inlcuding the ith week).
As we have seen from above that if a nominee is removed in ith week then its weight in the weeks starting from the i+1th week will be zero.
So now when the staking incentives are calculated for the removed nominee for the epoch in which they were removed it would always return zero as the weight of the nominee will always be zero.
In the current code base as it is intended that the removed nominee is eligible for the epoch in which they were removed and currently they are not receiving it thus it is a issue/bug.
Tools Used
Manual review
Recommended Mitigation Steps
The most easy way would be to not allow staking incentives for the epoch in which they were removed or you can do the following Allow removing a nominee only when there is less than a week time left before the epoch ends for that only change the following if condition https://github.com/code-423n4/2024-05-olas/blob/3ce502ec8b475885b90668e617f3983cea3ae29f/tokenomics/contracts/Dispenser.sol#L774 to if (block.timestamp < maxAllowedTime) { revert ; } But in this case too staking incentives can be lost if the epoch didn't end for few more weeks.
Assessed type
Context