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: 30/115
Findings: 1
Award: $198.48
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xDetermination
Also found by: DeFiHackLabs, Norah, Pessimistic, PwnStars, SpicyMeatball, Testerbot, ThreeSigma, bin2chen, blutorque, deadrxsezzz, dirk_y, ether_sky, hals, neumo, rokinot, said, seerether, turvy_fuzz
198.4834 USDC - $198.48
https://github.com/code-423n4/2023-09-venus/blob/main/contracts/Tokens/Prime/Prime.sol#L221
Update score breaks and reverts due to underflow caused by pendingScoreUpdates
variable.
updateScores()
:
function updateScores(address[] memory users) external { if (pendingScoreUpdates == 0) revert NoScoreUpdatesRequired(); if (nextScoreUpdateRoundId == 0) revert NoScoreUpdatesRequired(); for (uint256 i = 0; i < users.length; ) { address user = users[i]; if (!tokens[user].exists) revert UserHasNoPrimeToken(); if (isScoreUpdated[nextScoreUpdateRoundId][user]) continue; address[] storage _allMarkets = allMarkets; for (uint256 j = 0; j < _allMarkets.length; ) { address market = _allMarkets[j]; _executeBoost(user, market); _updateScore(user, market); unchecked { j++; } } pendingScoreUpdates--; isScoreUpdated[nextScoreUpdateRoundId][user] = true; unchecked { i++; } emit UserScoreUpdated(user); } }
In each iteration, pendingScoreUpdates
is decremented:
pendingScoreUpdates--;
This assumes pendingScoreUpdates is always >= length of users that has PrimeToken else it would always underflow, however this is not true, as it only directly updated in few places e.g in _burn()
but not updated when new users are issued prime tokens. Which means pendingScoreUpdates
could be lesser when possible number of users that PrimeToken exists for increases.
Manaul Review
Reconsider the pendingScoreUpdates
interactions. I suggest direactly updating pendingScoreUpdates in calling issue()
and maybe also check if the passed users array length matches the pendingScoreUpdates on the updateScores()
function
Under/Overflow
#0 - c4-pre-sort
2023-10-05T00:01:52Z
0xRobocop marked the issue as duplicate of #555
#1 - c4-judge
2023-11-01T02:09:26Z
fatherGoose1 marked the issue as satisfactory