Venus Prime - al88nsk's results

Earn, borrow & lend on the #1 Decentralized Money Market on the BNB chain.

General Information

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

Venus Protocol

Findings Distribution

Researcher Performance

Rank: 56/115

Findings: 2

Award: $36.64

QA:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

32.2731 USDC - $32.27

Labels

2 (Med Risk)
satisfactory
duplicate-556

External Links

Judge has assessed an item in Issue #203 as 2 risk. The relevant finding follows:

L-1 Function updateScores spends all gas and reverts if a user has score updated Summary Function updateScores incorrectly handles case when a user’s score is already updated.

Vulnerability Details There is a for loop in the function updateScores that updates score for every user in users. If a user’s score is already updated, the user should be skipped and the next user should be updated. For this case there is an if statement (https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L208C1-L208C1):

if (isScoreUpdated[nextScoreUpdateRoundId][user]) continue; However, here is an issue. The variable i that is responsible for the current user in the loop is incremented in the end of the loop, but due to the continue statement, this code is not reached, the value of i remains and the current user is processed again and again until all the gas is spent, and then the function reverts.

Recommended Mitigation Steps When user’s score is updated, the i value must be incremented.

#0 - c4-judge

2023-11-03T16:43:47Z

fatherGoose1 marked the issue as satisfactory

#1 - c4-judge

2023-11-03T20:41:45Z

fatherGoose1 marked the issue as duplicate of #556

L-1 Function updateScores spends all gas and reverts if a user has score updated

Summary

Function updateScores incorrectly handles case when a user's score is already updated.

Vulnerability Details

There is a for loop in the function updateScores that updates score for every user in users. If a user's score is already updated, the user should be skipped and the next user should be updated. For this case there is an if statement (https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L208C1-L208C1):

 if (isScoreUpdated[nextScoreUpdateRoundId][user]) continue;

However, here is an issue. The variable i that is responsible for the current user in the loop is incremented in the end of the loop, but due to the continue statement, this code is not reached, the value of i remains and the current user is processed again and again until all the gas is spent, and then the function reverts.

When user's score is updated, the i value must be incremented.

L-2 Function getPendingInterests does not correctly handles VBNB market

Summary

Function getPendingInterests returns incorrect underlying token for VBNB market.

Vulnerability Details

VBNB market is specifically handled in function _getUnderlying (https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L930-L936):

function _getUnderlying(address vToken) internal view returns (address) { if (vToken == VBNB) { return WBNB; } else { return IVToken(vToken).underlying(); } }

So, when market is VBNB, the underlying token must be WBNB, otherwise the underlying() function result must be used. However, the function getPendingInterests uses IVToken(vToken).underlying() directly for all markets and has not special handling for VBNB market (https://github.com/code-423n4/2023-09-venus/blob/b11d9ef9db8237678567e66759003138f2368d23/contracts/Tokens/Prime/Prime.sol#L183-L186):

pendingInterests[i] = PendingInterest({
    market: IVToken(market).underlying(),
    amount: interestAccrued + accrued
});

So, the VBNB market is not handled correctly, _getUnderlying must be used instead.

Use function _getUnderlying to get underlying token in function getPendingInterests.

#0 - 0xRobocop

2023-10-07T02:17:15Z

L-01 dup of #556 L-02 dup of #101

#1 - c4-pre-sort

2023-10-07T15:22:47Z

0xRobocop marked the issue as sufficient quality report

#2 - c4-judge

2023-11-03T16:43:53Z

fatherGoose1 marked the issue as grade-b

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter