Platform: Code4rena
Start Date: 28/09/2023
Pot Size: $36,500 USDC
Total HM: 5
Participants: 115
Period: 6 days
Judge: 0xDjango
Total Solo HM: 1
Id: 290
League: ETH
Rank: 78/115
Findings: 1
Award: $4.37
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: Bauchibred
Also found by: 0x3b, 0xDetermination, 0xMosh, 0xScourgedev, 0xTheC0der, 0xTiwa, 0xWaitress, 0xdice91, 0xfusion, 0xpiken, 0xprinc, 0xweb3boy, ArmedGoose, Aymen0909, Breeje, Brenzee, Daniel526, DavidGiladi, DeFiHackLabs, Flora, Fulum, HChang26, Hama, IceBear, J4X, Krace, KrisApostolov, Maroutis, Mirror, MohammedRizwan, Norah, PwnStars, SPYBOY, TangYuanShen, Testerbot, ThreeSigma, Tricko, al88nsk, alexweb3, ast3ros, berlin-101, bin2chen, blutorque, btk, d3e4, deth, e0d1n, ether_sky, ge6a, gkrastenov, glcanvas, hals, imare, inzinko, jkoppel, jnforja, joaovwfreire, josephdara, kutugu, lotux, lsaudit, mahdirostami, merlin, n1punp, nadin, neumo, nisedo, nobody2018, oakcobalt, orion, peanuts, pep7siup, pina, ptsanev, rokinot, rvierdiiev, said, santipu_, sashik_eth, seerether, squeaky_cactus, terrancrypt, tonisives, twicek, vagrant, xAriextz, y4y
4.3669 USDC - $4.37
https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L872-L897 https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L647-L664 https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L623-L639 https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L794-L802 https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L200-L230 https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L389-L392 https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L607-L617 https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L365-L382
Venus Prime uses the Cobb-Douglas function to determine how much of the available rewards each user with a Prime token should receive. This calculation relies on a user's score, which is based on their supply and borrow values for a specific token. The larger these values, the higher the score, but there are maximum limits for both. If these limits are exceeded, the upper boundary is used. The function _capitalForScore applies these limits and takes into account the prices of XVS and the underlying token, which can change due to market conditions. It turns out that users with the same supply and borrow values can have significantly different scores because of variations in token prices at the time of calculation. Additionally, users can update their scores to maximize rewards using one the functions xvsUpdated or accrueInterestAndUpdateScore. This behavior creates an unfair advantage and should not be possible.
First, it needs to be clarified when the score is recalculated and when the saved value is used. The function that calculates the score is _calculateScore.
It is called first when markets are initialized for a specific user and then only when there are changes in the user's balance. The functions that directly or indirectly update the saved values for the score are: _initializeMarkets, _updateScore, updateScores, accrueInterestAndUpdateScore, _accrueInterestAndUpdateScore, and xvsUpdated.
https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L623-L639 https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L794-L802 https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L200-L230 https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L389-L392 https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L607-L617 https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L365-L382
I won't describe in detail what each of them is used for, but it's important to see which of them can be called by the user without restrictions. These are accrueInterestAndUpdateScore and xvsUpdated, which are external and have no other limitations. Therefore, a user, when they decide that an appropriate moment has come, can call one of these functions and update their score.
Let's consider a possible scenario in the context of the _capitalForScore function.
We have two users, Alice and Bob, in the same market. Each of them has 1000 XVS and a supply of 1000 tokens. At the current moment, the price of XVS is $5, and the price of the underlying token is $10. The _capitalForScore function is executed for both users.
supplyCapUSD = 5 * 1000 = 5000 supplyUSD = 10 * 1000 = 10000 Since 10000 > 5000, the supply is calculated as 1000 * 5000 / 10000 = 500.
At this point, Alice and Bob have the same score. After some time, the price of the underlying token drops from $10 to $8. Alice sees an opportunity to increase her score and thereby receive a larger portion of the rewards fund. She calls one of the functions mentioned earlier and updates her score.
supplyCapUSD = 5 * 1000 = 5000 supplyUSD = 8 * 1000 = 8000 Since, 8000 > 5000, the supply is calculated as 1000 * 5000 / 8000 = 625.
At this point, Alice has a significantly higher score than Bob, even though they have the same assets and she could claim more rewards from the rewards fund.
Financial loss for legitimate users because their score is calculated at a wrong time. Financial gain for malicious users who exploit this behavior. About the severity i think that this issue is easy to exploit and very likely to happen.
Manual Review
2 ideas to mitigate it:
Other
#0 - 0xRobocop
2023-10-04T22:50:23Z
Design Decision
#1 - c4-pre-sort
2023-10-04T22:50:27Z
0xRobocop marked the issue as low quality report
#2 - c4-pre-sort
2023-10-05T04:45:32Z
0xRobocop marked the issue as duplicate of #148
#3 - c4-judge
2023-11-01T02:49:33Z
fatherGoose1 changed the severity to QA (Quality Assurance)
#4 - c4-judge
2023-11-03T02:48:40Z
fatherGoose1 marked the issue as grade-b