The getPendingRewards
function in the StabilityPool contract calculates a user's pending RAAC rewards based on the contract’s RAAC token balance (totalRewards = raacToken.balanceOf(address(this))
). However, this value does not get updated whenever new RAAC rewards are minted by the RaacMinter
contract. As a result, users may see incorrect pending rewards because the calculation does not account for newly minted RAAC tokens, potentially leading to lower-than-expected rewards.
Issue:
The getPendingRewards
function retrieves totalRewards
from the contract's RAAC token balance but does not ensure that newly minted rewards are included in this value.
The minting of new RAAC rewards occurs within _mintRAACRewards
, which is triggered through the tick()
function based on emissionRate
and block timestamps. However, since getPendingRewards
does not call this function, it relies on potentially outdated values.
This means that users checking their pending rewards may see stale reward amounts, leading to miscalculations.
Affected Code:
Root Cause:
The getPendingRewards
function does not update the RAAC rewards balance before performing calculations, leading to outdated or incorrect reward estimates.
Inaccurate Reward Calculation:
Users may see lower pending rewards than they are entitled to because the calculation does not include newly minted RAAC tokens.
Unequal Reward Distribution:
Users who frequently interact with the system (e.g., deposit, withdraw) may receive correct rewards, while those who only check their pending rewards without further interactions may get outdated values.
Manual Code Review
Ensure totalRewards
is Updated Before Calculating Pending Rewards:
Modify the getPendingRewards
function to refresh the RAAC rewards before performing calculations. This can be done by calling _mintRAACRewards()
or RaacMinter.tick()
to ensure the latest rewards are accounted for.
Example Fix:
Decouple Reward Calculation from Minting Logic:
Instead of minting new rewards every time getPendingRewards
is called (which could be inefficient), ensure that the contract updates totalRewards
at fixed intervals or upon specific triggers (e.g., when users deposit or withdraw funds).
Implement Automated Reward Updates:
Set up a mechanism where the minting of new RAAC rewards happens consistently at predetermined intervals or upon certain user interactions. This will prevent the accumulation of stale rewards and maintain fair and transparent reward distribution.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.