Platform: Code4rena
Start Date: 03/05/2023
Pot Size: $60,500 USDC
Total HM: 25
Participants: 114
Period: 8 days
Judge: Picodes
Total Solo HM: 6
Id: 234
League: ETH
Rank: 27/114
Findings: 1
Award: $329.76
🌟 Selected for report: 1
🚀 Solo Findings: 0
🌟 Selected for report: cryptostellar5
Also found by: Bauchibred, ladboy233
329.7645 USDC - $329.76
https://github.com/code-423n4/2023-05-ajna/blob/main/ajna-core/src/RewardsManager.sol#L519-L541
This issue is similar to https://github.com/ajna-finance/audits/blob/main/sherlock/Contest1.md#issue-m-7-calculating-new-rewards-is-susceptible-to-precision-loss-due-to-division-before-multiplication which is not fixed properly. Still, the final multiplication is being performed after the division.
Rewards may be lost (0) due to division before multiplication precision issues.
The RewardsManager._calculateNewRewards
function calculates the new rewards for a staker by first multiplying interestEarned_
by totalBurnedInPeriod
and then dividing by totalInterestEarnedInPeriod
and then again multiplying by REWARD_FACTOR
Since the division is being performed before the final multiplication, this can lead to precision loss.
function _calculateNewRewards( address ajnaPool_, uint256 interestEarned_, uint256 nextEpoch_, uint256 epoch_, uint256 rewardsClaimedInEpoch_ ) internal view returns (uint256 newRewards_) { ( , // total interest accumulated by the pool over the claim period uint256 totalBurnedInPeriod, // total tokens burned over the claim period uint256 totalInterestEarnedInPeriod ) = _getPoolAccumulators(ajnaPool_, nextEpoch_, epoch_); // calculate rewards earned newRewards_ = totalInterestEarnedInPeriod == 0 ? 0 : Maths.wmul( REWARD_FACTOR, Maths.wdiv( Maths.wmul(interestEarned_, totalBurnedInPeriod), totalInterestEarnedInPeriod ) );
All the multiplication should be performed in step 1 and then division at the end.
Math
#0 - c4-judge
2023-05-18T17:41:15Z
Picodes marked the issue as primary issue
#1 - c4-sponsor
2023-05-19T19:37:31Z
MikeHathaway marked the issue as sponsor confirmed
#2 - c4-judge
2023-05-30T21:29:13Z
Picodes marked the issue as satisfactory
#3 - c4-judge
2023-05-30T21:29:55Z
Picodes marked the issue as selected for report