Submitted by Brenzee, also found by Testerbot, 0xDetermination, santipu_, ast3ros, ether_sky, sces60107, pep7siup, Breeje, tapir, 0xTheC0der (1, 2), and SpicyMeatball
Users earned rewards are calculated incorrectly because of the incorrect decimals value used to calculate users score and markets sumOfMembersScore, which impacts the delta that is added to markets rewardIndex when Prime.accrueInterest function is called.
All users rewards are calculated with the following formula:
This means that for user to earn rewards, markets rewardIndex needs to periodically increase.
markets[vToken].rewardIndex is updated (increased), when Prime.accrueInterest is called.
Prime.sol:L583-L588
From the code snippet above it is assumed that markets[vToken].sumOfMembersScore is precision of 18 decimals.
To ensure that users score and markets sumOfMemberScore are correctly calculated, in Prime._calculateScore function capital is adjusted to 18 decimals. After that capital is used in Scores.calculateScore function.
Note: capital precision from _capitalForScore function is in precision of underlying token decimals.
Prime.sol:660-L663
The mistake is made when vToken.decimals() is used instead of vToken.underlying().decimals().
To prove that this is the case, here are vTokens deployed on Binance Smart chain, their decimals and underlying token decimals:
Since vToken.decimals() is used, this means the precision of capital is 18 + (18 - 8) = 28 decimals instead of 18 decimals, which makes the score calculation from Score.calculateScore function incorrect, since the function expects capital to be in precision of 18 decimals.
As a result, delta for markets rewardIndex is incorrectly calculated and it can be 0 even though it shouldnt be, which means that users will not accrue any rewards.
Developers have made a mistake when writing the tests for Prime.sol - in the tests they have set vToken decimals to 18 instead of 8, which makes the tests pass, but on the Binance Smart Chain all of the vToken decimals are 8.
If the decimal value of vToken is set to 8 in the tests, then the tests will fail.
Change the vusdt, veth and vbnb decimals to 8 and run:
This will make the current tests fail.
Here is a test where it shows, that rewardIndex is still 0 after Prime.accrueInterest is called, even though it should be > 0.
Make sure that underlying token decimals are used instead of vToken decimals when calculating capital in Prime._calculateScore function.
chechu (Venus) confirmed via duplicate issue 588 and commented:
0xDjango (Judge) commented:
