Venus Prime - e0d1n'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: 107/115

Findings: 1

Award: $4.37

QA:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Lines of code

https://github.com/code-423n4/2023-09-venus/blob/main/contracts/Tokens/Prime/PrimeLiquidityProvider.sol#L216-L225

Vulnerability details

Summary

The sweepToken function lacks a crucial check to determine whether a token is being tracked and has pending accruals, which can lead to discrepancies in the tokenAmountAccrued mapping and subsequent issues in the accrueTokens and releaseFunds functions.

Vulnerability Details

The sweepToken function allows the contract owner to transfer a specified amount of any token from the contract to another address. However, it does not verify whether the token is being tracked or has pending accruals by the contract. Consequently, if sweepToken is used to withdraw tokens that are pending to be accrued, it can create a situation where the tokenAmountAccrued mapping reflects an amount greater than the actual token balance of the contract. This discrepancy can lead to an underflow in the accrueTokens function and cause the releaseFunds function to revert due to insufficient balance.

function sweepToken(IERC20Upgradeable token_, address to_, uint256 amount_) external onlyOwner { uint256 balance = token_.balanceOf(address(this)); if (amount_ > balance) { revert InsufficientBalance(amount_, balance); } emit SweepToken(address(token_), to_, amount_); token_.safeTransfer(to_, amount_); }

Impact

The absence of a check for tracked tokens in the sweepToken function can disrupt the normal operation of the contract by creating a mismatch between the actual token balance and the tokenAmountAccrued mapping. This can lead to underflows in arithmetic operations within the accrueTokens function and reverts in the releaseFunds function due to insufficient funds, thereby potentially locking funds and halting the normal operation of the contract.

Proof of Concept

If sweepToken is utilised to withdraw tokens that are being tracked and have pending accruals, the actual balance of the contract for that token will be reduced without updating the tokenAmountAccrued mapping. This will create a situation where tokenAmountAccrued[token_] is greater than the actual balance, causing the subtraction in accrueTokens to underflow and the ERC20 transfer in releaseFunds to revert due to insufficient funds.

Tools Used

Manual analysis was performed.

Introduce a check in the sweepToken function to prevent the withdrawal of tokens that are being tracked and have pending accruals. This could be achieved by maintaining a mapping of tracked tokens and checking against it in the sweepToken function. Alternatively, directly check whether tokenAmountAccrued[token_] is greater than 0, and if it is, revert the transaction to prevent the sweeping of tokens that are pending accrual.

Example mitigation in sweepToken function:

function sweepToken(IERC20Upgradeable token_, address to_, uint256 amount_) external onlyOwner { require(tokenAmountAccrued[address(token_)] == 0, "Cannot sweep tracked token with pending accruals"); uint256 balance = token_.balanceOf(address(this)); require(amount_ <= balance, "Insufficient balance"); emit SweepToken(address(token_), to_, amount_); token_.safeTransfer(to_, amount_); }

This mitigation ensures that tokens with pending accruals cannot be swept, thereby preventing the described vulnerability. Ensure to thoroughly test the contract after implementing changes to validate that the solution works as intended and does not introduce new issues.

Assessed type

Invalid Validation

#0 - c4-pre-sort

2023-10-05T01:10:22Z

0xRobocop marked the issue as duplicate of #42

#1 - c4-judge

2023-10-31T17:09:53Z

fatherGoose1 changed the severity to QA (Quality Assurance)

#2 - c4-judge

2023-11-03T01:42:42Z

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