Prime#issue() call allows owner to issue prime tokens to a set of users, its takes isIrrevocable as a paramter which implies to mint revocable/Irrevocable tokens, the call also increases the count of totalRevocable and totalIrrevocable in an internal _mint call. If the scores of these accounts update via updateScores(), the txn will likely to be revert with underflow because the pendingScoreUpdates is not updated for the newly issued accounts above.
Consider, first, the owner makes updateAlpha call, it update value of alpha, and internally call the _startScoreUpdateRound() which update pendingScoreUpdates for the total number of accounts exist out there (pendingScoreUpdates perfectly sync here). Secondly, the issue() call happens after, which changes totalRevocable + totalIrrevocable count. Now the pendingScoreUpdates got out of sync with number of accounts there.
So if we try updateScores for all users, including accounts that are not accounted in pendingScoreUpdates, it will revert bc of the underflow here,
NOTE: The user can still update his score via accrueInterestAndUpdateScore for single market at a time. The purpose of report showing here, the updateScores() not working as it suppose to. And it will not be fixed, until alpha, market multipliers and new markets added.
Proof of Concept
Create a new file tests/hardhat/Prime/testPOC.ts, add the following script. And run npx hardhat test --grep "POC" on terminal.
Lines of code
https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L331-L359 https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L200-L230
Vulnerability details
Impact
Prime#issue() call allows owner to issue prime tokens to a set of users, its takes
isIrrevocable
as a paramter which implies to mint revocable/Irrevocable tokens, the call also increases the count oftotalRevocable
andtotalIrrevocable
in an internal_mint
call. If the scores of these accounts update viaupdateScores()
, the txn will likely to be revert with underflow because thependingScoreUpdates
is not updated for the newly issued accounts above.Prime.sol
Consider, first, the owner makes
updateAlpha
call, it update value of alpha, and internally call the_startScoreUpdateRound()
which updatependingScoreUpdates
for the total number of accounts exist out there (pendingScoreUpdates
perfectly sync here). Secondly, the issue() call happens after, which changestotalRevocable + totalIrrevocable
count. Now thependingScoreUpdates
got out of sync with number of accounts there.So if we try
updateScores
for all users, including accounts that are not accounted inpendingScoreUpdates
, it will revert bc of the underflow here,NOTE: The user can still update his score via
accrueInterestAndUpdateScore
for single market at a time. The purpose of report showing here, the updateScores() not working as it suppose to. And it will not be fixed, until alpha, market multipliers and new markets added.Proof of Concept
Create a new file
tests/hardhat/Prime/testPOC.ts
, add the following script. And runnpx hardhat test --grep "POC"
on terminal.Tools Used
Manual review
Recommended Mitigation Steps
Assessed type
DoS