Introduction
We express our gratitude to the Venus team for the collaborative engagement that enabled the execution of this Smart Contract Security Assessment.
Venus is a decentralized finance (DeFi) algorithmic money market protocol on BNB Chain. Decentralized lending pools are very similar to traditional lending services offered by banks, except that they are offered by P2P decentralized platforms. Users can leverage assets by borrowing and lending assets listed in a pool. Lending pools help crypto holders earn a substantial income through interest paid on their supplied assets and access assets they don't currently own without selling any of their portfolio.
| title | content |
|---|---|
| Platform | EVM |
| Language | Solidity |
| Tags | Lending Platform, ERC20 |
| Timeline | 23/01/2023 - 03/04/2023 |
| Methodology | https://hackenio.cc/sc_methodology→ |
Review Scope | |
|---|---|
| Repository | https://github.com/VenusProtocol/isolated-pools→ |
| Commit | ddd4656d9221c29a7892c1c95a2e692ceb45d807 |
Review Scope
- Commit
- ddd4656d9221c29a7892c1c95a2e692ceb45d807
Audit Summary
9/10
73.87%
10/10
10/10
The system users should acknowledge all the risks summed up in the risks section of the report
Document Information
This report may contain confidential information about IT systems and the intellectual property of the Customer, as well as information about potential vulnerabilities and methods of their exploitation.
The report can be disclosed publicly after prior consent by another Party. Any subsequent publication of this report shall be without mandatory consent.
Document | |
|---|---|
| Name | Smart Contract Code Review and Security Analysis Report for Venus |
| Audited By | Hacken |
| Website | https://venus.io/→ |
| Changelog | 30/01/2023 - Initial Review |
| 07/03/2023 - Second Review | |
| 03/04/2023 - Third Review |
Document
- Name
- Smart Contract Code Review and Security Analysis Report for Venus
- Audited By
- Hacken
- Website
- https://venus.io/→
- Changelog
- 30/01/2023 - Initial Review
- 07/03/2023 - Second Review
- 03/04/2023 - Third Review
System Overview
Venus Protocol (“Venus”) is an algorithmic-based money market system designed to bring a complete decentralized finance-based lending and credit system.
Venus enables users to utilize their cryptocurrencies by supplying collateral to the network that may be borrowed by pledging over-collateralized cryptocurrencies. This creates a secure lending environment where the lender receives a compounded interest rate annually (APY) paid per block, while the borrower pays interest on the borrowed cryptocurrency.
The Venus Protocol has been designed to give platform users a decentralized and secure marketplace to take out loans, earn an interest, and mint synthetic stablecoins.
The files tested in the audit’s scope:
BaseJumpRateModelV2.sol - base contract for JumpRateModelV2.sol.
Comptroller.sol - the Comptroller contract is the central contract for each lending pool. It contains functionality central to the borrowing activity in the pool, such as supplying and borrowing assets and liquidations. Configuration values for the pool, such as the liquidation incentive, close factor, and collateral factor, can be set and retrieved from the Comptroller. Account liquidity and positions can be retrieved from the Comptroller.
ComptrollerInterface.sol - interface for Comptroller.sol.
ComptrollerStorage.sol - storage for Comptroller.sol.
ErrorReporter.sol - stores error codes for VToken.sol.
ExponentialNoError.sol - exponential module for storing fixed-precision decimals.
JumpRateModelFactory.sol - is a factory to deploy the jump rate interest rate model. When using this model, interest follows a linear curve until supply or demand reaches the kink, after which there is a steep increase in interest rates.
VTokenProxyFactory.sol - when adding a market to pools, VTokenProxyFactory is deployed for each market. It is the token that represents the underlying supplied asset.
WhitePaperInterestRateModelFactory.sol - is another interest rate model that can be deployed with a market. It is similar to the jump rate model but uses a base rate and does not include a kink.
AccessControlManager.sol - grants account access to call specific functions on contracts. This contract is responsible for granting and revoking those permissions. It provides a getter to check if an address is allowed to call a specific function.
InterestRateModel.sol - base interest rate model contract.
IPancakeswapV2Router.sol - interface for interacting with PancakeswapV2Router.
JumpRateModelV2.sol - compound's JumpRateModel Contract V2 for V2 vTokens.
PoolLens.sol - to make querying pool data easier, Isolated Pools contain a lens that queries and formats pool data. These calls can be gas intensive, so the general rule of thumb is that this contract should not be used in transactions.
PoolRegistry.sol - Creating and managing pools is done by PoolRegistry. It can add markets to pools, update pool metadata, and return pool information.
PoolRegistryInterface.sol - interface for PoolRegistry.sol.
UpgradeableBeacon.sol - used in conjunction with one or more instances of BeaconProxy to determine their implementation contract, which is where they will delegate all function calls;
RewardsDistributor.sol - users are rewarded for borrowing and lending activities with a rewards token. RewardsDistributor manages these distributions using a configurable rate.
IProtocolShareReserve.sol - interface for ProtocolShareReserve.sol.
IRiskFund.sol -
ProtocolShareReserve.sol - acts as a treasury where each isolated pool can transfer their revenue.
ReserveHelpers.sol - stores additional functionality for ProtocolShareReserve.sol and RiskFund.sol.
RiskFund.sol - lending comes with the inherent risk that borrowers will not be able to repay their loan, which is a threat to the protocol's insolvency. Venus V4 looks to mitigate this risk with a RiskFund. A percentage of the protocol’s revenues is transferred to the RiskFund. When bad debt is detected, this fund can be auctioned off and used to cover the bad debt.
Shortfall.sol - when bad debt is auctioned off the Shortfall contract is responsible for running the action and paying the winner.
VToken.sol - when a user supplies a token to the protocol, they are minted vTokens to represent their supply. The VToken contract contains methods that support lending activities for the asset including lending, borrowing and liquidating.
VTokenInterfaces.sol - stores interfaces and storage variables for VToken.sol.
WhitePaperInterestRateModel.sol - WhitePaperInterestRateModel is an interest rate model that can be deployed with markets . It is similar to JumpRateModel except it does not include a kink. Instead, it contains a fixed base rate.
AccessControlled.sol - access control manager contract.
MaxLoopsLimitHelper.sol - Limit for the loops to avoid the DOS.
Privileged roles
VToken.sol:
owner \- can set a new
AccessControlManagerand sweep accidental ERC-20 transfers to this contract.shortfall \- updates bad debt (Called only when bad debt is recovered from auction).
comptroller \- can call the method
healBorrow()which will repay a certain amount of debt, treat the rest of the borrow as bad debt, essentially "forgiving" the borrower andforceLiquidateBorrow()to liquidate the borrower's collateral.AccessControlManager privilege roles:
setProtocolSeizeShare()method caller - can set protocol share accumulated from liquidationssetReserveFactor()method caller - can set a new reserve factor for the protocol after accruing interestsetInterestRateModel()method caller - can update the interest rate model after accruing interest
Comptroller.sol:
owner \- can set the closeFactor to use when liquidating borrows, can add a new RewardsDistributor and initialize it with all markets, can set a new PriceOracle for the Comptroller.
vToken \- allowed to call the method
preBorrowHook()on borrows.poolRegistry \- can add the market to the markets mapping and set it as listed.
AccessControlManager privilege roles:
setCollateralFactor()method caller - can set collateralFactor for a market (collateralFactorMantissa - multiplier representing the most one can borrow against their collateral in this market and liquidationThresholdMantissa - multiplier representing the collateralization after which the borrow is eligible for liquidation)setLiquidationIncentive()method caller - can set liquidationIncentive (representing the discount on collateral that a liquidator receives)setMarketBorrowCaps()method caller - can set borrow caps for the given vToken marketssetMarketSupplyCaps()method caller - can set the given supply caps for the given vToken marketssetActionsPaused()method caller - can pause/unpause specified actionssetMinLiquidatableCollateral()method caller - can set the minimal collateral required for regular (non-batch) liquidations.
ProtocolShareReserve:
owner \- can release funds.
RiskFund:
owner \- can update pool registry address, can update convertible base asset, can update PancakeSwap router address and set min amount to convert
shortfall \- can transfer tokens for auction
AccessControlManager privilege roles:
swapPoolsAssets()method caller - can swap an array of pool assets into the base asset's tokens of at least a minimum amount.
PoolRegistry:
owner \- The owner of the PoolRegistry contract has the capability to create a new pool and add a market to an existing pool. The owner can set the pool name and update metadata information.
AccessControlManager:
owner \- The owner of the AccessControlManager can grant and revoke the role.
Shortfall:
owner \- The owner of the Shortfall contract has the authority to specify the convertible base assets and the minimum pool bad debt variables. They can also set the address for the Pool Registry. Furthermore, the owner has the ability to initiate a new auction.
Executive Summary
Documentation quality
The total Documentation quality score is 10 out of 10.
Functional requirements are provided.
Technical description is provided.
NatSpecs are generally satisfactory.
Code quality
The total Code quality score is 10 out of 10.
The development environment is configured.
Instead of using
onlyOwnermodifier, direct check is used.
Test coverage
Code coverage of the project is 73.87% (branch coverage).
Deployment and basic user interactions are covered with tests.
Negative cases coverage are partially missing.
Interactions with several users are not tested thoroughly.
Some contracts are not fully tested.
Security score
Upon auditing, the code was found to contain 0 critical, 9 high, 11 medium, and 13 low severity issues. Out of these, 29 issues have been addressed and resolved, leading to a security score of 9 out of 10.
All identified issues are detailed in the “Findings” section of this report.
Summary
The comprehensive audit of the customer's smart contract yields an overall score of 8.4. This score reflects the combined evaluation of documentation, code quality, test coverage, and security aspects of the project.
Risks
This protocol is divided into 3 repos. This audit only covers one of them (isolated-pools). The other repos (concerning Oracles and Governance) and their interactions are not covered in this audit. As the pools are interacting with the oracle part, any problem in the oracle repo will cause issues with the pools.
Reviewed contracts are upgradable but are supposed to be used as a first implementation.
In VToken.sol, on every mint function preMintHook of the Comptroller contract is called. As preMintHook is called before the actual amount of tokens transferred is calculated it will not allow it to reach the actual max supply limit for tokens with a fee on transfers.
The project uses OpenZeppelin’s AccessControl and its own access control implementation. It is recommended to use only one of them for the entire project.
Findings
Code ― | Title | Status | Severity | |
|---|---|---|---|---|
| F-2023-0767 | Highly Permissive Role Access | mitigated | High | |
| F-2023-0766 | Access Control Violation | fixed | High | |
| F-2023-0765 | Denial of Service - Loop Gas Limit | fixed | High | |
| F-2023-0764 | Undocumented Behavior | fixed | High | |
| F-2023-0763 | Race Condition | fixed | High | |
| F-2023-0762 | Requirements Violation | fixed | High | |
| F-2023-0761 | Requirements Violation | fixed | High | |
| F-2023-0760 | Access Control Violation | fixed | High | |
| F-2023-0759 | Highly Permissive Role Access | fixed | High | |
| F-2023-0778 | Contradiction - NatSpec Comments Contradiction | fixed | Medium |
Appendix 1. Severity Definitions
When auditing smart contracts, Hacken is using a risk-based approach that considers Likelihood, Impact, Exploitability and Complexity metrics to evaluate findings and score severities.
Reference on how risk scoring is done is available through the repository in our Github organization:
Severity | Description |
|---|---|
Critical | Critical vulnerabilities are usually straightforward to exploit and can lead to the loss of user funds or contract state manipulation. |
High | High vulnerabilities are usually harder to exploit, requiring specific conditions, or have a more limited scope, but can still lead to the loss of user funds or contract state manipulation. |
Medium | Medium vulnerabilities are usually limited to state manipulations and, in most cases, cannot lead to asset loss. Contradictions and requirements violations. Major deviations from best practices are also in this category. |
Low | Major deviations from best practices or major Gas inefficiency. These issues will not have a significant impact on code execution, do not affect security score but can affect code quality score. |
Severity
- Critical
Description
- Critical vulnerabilities are usually straightforward to exploit and can lead to the loss of user funds or contract state manipulation.
Severity
- High
Description
- High vulnerabilities are usually harder to exploit, requiring specific conditions, or have a more limited scope, but can still lead to the loss of user funds or contract state manipulation.
Severity
- Medium
Description
- Medium vulnerabilities are usually limited to state manipulations and, in most cases, cannot lead to asset loss. Contradictions and requirements violations. Major deviations from best practices are also in this category.
Severity
- Low
Description
- Major deviations from best practices or major Gas inefficiency. These issues will not have a significant impact on code execution, do not affect security score but can affect code quality score.
Appendix 2. Scope
The scope of the project includes the following smart contracts from the provided repository:
Scope Details | |
|---|---|
| Repository | https://github.com/VenusProtocol/isolated-pools→ |
| Commit | ddd4656d9221c29a7892c1c95a2e692ceb45d807 |
| Whitepaper | Provided |
| Requirements | Provided |
| Technical Requirements | Provided→ |
Scope Details
- Commit
- ddd4656d9221c29a7892c1c95a2e692ceb45d807
- Whitepaper
- Provided
- Requirements
- Provided
- Technical Requirements
- Provided→