If the payout criteria are not met, payoutLastPaid
should not be updated.
#180
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
edited-by-warden
🤖_14_group
AI based duplicate group recommendation
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-07-reserve/blob/main/contracts/p1/StRSR.sol#L594-L614
Vulnerability details
Impact
In function
_payoutRewards
, if the payout criteria are not met,payoutLastPaid
should not be updated. However, thepayoutLastPaid
is actually updated even if the payout criteria are not met, which leads subsequent payouts to be calculated incorrectly.Proof of Concept
In function
_payoutRewards
, the payout is done only if enough RSR (i.e. >= FIX_ONE) is staked. If not, the payout will not happen. ThepayoutLastPaid
records the last time when rewards are paid out. Thus if the payout does not happen,payoutLastPaid
should not be updated.However, in the function
_payoutRewards
, thepayoutLastPaid
is always updated regardless of whether a payout happens or not. This is problematic if thetotalStakes
of the previous stakes are less than FIX_ONE. When thetotalStakes
after a new stake is greater than FIX_ONE, a payout will happen. At this time, thepayoutLastPaid
will be smaller than it should be. This leads to thepayoutRatio
andpayout
being smaller than they should be.The
payoutRatio
is calculated as(1 - (1-rewardRatio)^numPeriods)
. AspayoutLastPaid
becomes larger,numPeriods
becomes smaller,(1-rewardRatio)^numPeriods
becomes larger, and therefore(1 - (1-rewardRatio)^numPeriods)
becomes smaller.https://github.com/code-423n4/2024-07-reserve/blob/main/contracts/p1/StRSR.sol#L594-L614
Tools Used
VS Code
Recommended Mitigation Steps
Update
payoutLastPaid
only iftotalStakes >= FIX_ONE
.Assessed type
Math
The text was updated successfully, but these errors were encountered: