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: 59/115
Findings: 1
Award: $32.27
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xDetermination
Also found by: 0xblackskull, 0xweb3boy, ADM, Breeje, Pessimistic, PwnStars, SBSecurity, Satyam_Sharma, ThreeSigma, al88nsk, blutorque, debo, dethera, maanas, neumo, oakcobalt, pina, said, sces60107, tapir, tsvetanovv, xAriextz
32.2731 USDC - $32.27
https://github.com/code-423n4/2023-09-venus/blob/main/contracts/Tokens/Prime/Prime.sol#L200-L230
The odds of an infinite loop happening are high. This will result in reaching the maximum block gas limit and the inability to execute the function.
In Prime.sol
we have updateScores()
function:
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); Â Â Â Â } Â Â }
This function iterates over a list of user addresses and updates their scores.
The possibility of an infinite loop comes from the following code:
208: if (isScoreUpdated[nextScoreUpdateRoundId][user]) continue;
This line of code checks whether a user's score has already been updated during the present update round. If so it is expected to pass to the next user.
But this will not happen because i
is incremented at the end of the function. This puts us in a situation where we will check the same user continuously until we reach the maximum gass limit of the block.
Why I think the report is valid Medium:
for
loops that call external calls. That means there may be a problem, but there may not be.Visual Studio Code
To solve this problem, it is best to move the increase of i
in the normal way:
204: for (uint256 i = 0; i < users.length; i++) {
DoS
#0 - c4-pre-sort
2023-10-04T22:20:52Z
0xRobocop marked the issue as duplicate of #556
#1 - c4-judge
2023-11-01T19:51:29Z
fatherGoose1 marked the issue as satisfactory