Venus - Diamond Comptroller (Subscription Audit 5)

CertiKFiles named in the report

Audit

Part of CertiK’s series

CertiK reviewed Venus Protocol (Venus - Diamond Comptroller (Subscription Audit 5)) on 3 Aug 2023: 10 findings, 0 critical; 7 marked fixed, 3 open.

No open critical findings
Open the reportOpen Venus Protocol’s security record

Report hosted on skynet.certik.com.

Trustblock does not review code.

Findings10

Statuses are the security firm’s own, from its report.

SeverityOpenAcknowledgedFixed
Critical000
High200
Medium000
Low107
Low`Diamond.sol` Does Not Implement the `DiamondLoupFixed

One requirement of the EIP-2535 specification on Diamond proxies is that the Diamond contract in use must implement the DiamondLoupe interface, either through inheritance or inclusion in a facet of the Diamond. References: https://eips.ethereum.org/EIPS/eip-2535#implementation-points https://eips.ethereum.org/EIPS/eip-2535#a-note-on-implementing-interfaces The `Diamond.sol` file of the project implements some view functions which are similar to those listed in the outlined `IDiamondLoupe` interface, but these functions do not have the same name: - `getFacetFunctionSelectors()` in `Diamond.sol` performs the same actions as what is specified for the function `facetFunctionSelectors()` in the `IDiamondLoupe` interface; - `getAllFacetAddresses()` in `Diamond.sol` performs the same actions as what is specified for the function `facetAddresses()` in the `IDiamondLoupe` interface; - `getFacetAddressAndPosition()` in `Diamond.sol` performs some of the same actions as what is specified for the function `facetAddress()` in the `IDiamondLoupe` interface; Additionally, there is one function of the `IDiamondLoupe` interface which is not implemented by `Diamond.sol`, that is function `facets()`, which is supposed to return an array of `Facet` structs for all facet addresses used within `Diamond.sol`. The `Facet` struct is not currently used within the project.

LowImmutable Functions of `Diamond.sol`Fixed

EIP-2535 contains specifications for how [*immutable*](https://eips.ethereum.org/EIPS/eip-2535#terms) functions should be handled. Namely, "any attempt to replace or remove an immutable function must revert." Reference: https://eips.ethereum.org/EIPS/eip-2535#addingreplacingremoving-functions There are no requirements within the specification for which functions are required to be made immutable, and a Diamond contract may not hold any immutable functions. Please specify whether any of the functions within `Diamond.sol` are intended to be considered as immutable for the project. If so, we recommend including logic within the logical path of `diamondCut()` to ensure that these functions cannot be replaced or removed, as the specification requires.

LowNo Initializing Logic When Functions are Added, RFixed

It is noted that there is no logic to handle the potential need to initialize any new states that may be introduced through upgrades to Comptroller when new functions are added, removed, or replaced. Please state the plan for initialization when updates necessitate this.

LowPotential Difficulty in Accommodating UpgradesFixed

Contract `Diamond.sol` does not meet all of the required specifications of [EIP-2535](https://eips.ethereum.org/EIPS/eip-2535). One of the main distinctions is that EIP-2535 specifies that a `Diamond` contract should be the proxy contract, holding its own state, while the facets it associates with are its stateless logic contracts. Instead, the intention of the protocol is to keep the already deployed `Unitroller` contract as the stateful proxy, and use the new `Diamond` contract as a logic contract that outsources the main Comptroller logic to various facets. Additionally, each facet and the `Diamond` contract inherit the eternal storage pattern held in the `Unitroller` in order to facilitate the retention of the old logic patterns implemented in the Comptroller logic contract that is currently being used. This difference in set up could potentially cause difficulty in future upgrades. 1. Any time an upgrade is made to the logic of any facet that introduces a new state variable, every facet may need to be updated in order to keep a consistent reference to the eternal storage of the `Unitroller`. It is noted that the update of each facet to reflect all current state variables in the `Unitroller` would not necessarily need to be immediate if the facet does not use the new state variable in its current logic. However, if each facet does not maintain a consistent reference to the `Unitroller` storage, this could cause issues with the storage variables referenced in updated logic. An effort to maintain a consistent storage reference throughout all facets would mean that each facet contract address would have to be updated every time there is any update to storage. 2. The difficulty presented in necessitating the replacement/removal of every old facet during upgrade could lead to vulnerabilities if the update is not handled atomically. Adding, replacing, or removing one function or facet at a time could allow for unexpected points of failure in the code, or unintended entry points. 3. Additionally the `Diamond.sol` contract only currently inherits `ComptrollerV12Storage`. If new state variables are added, it appears that it is necessary to implement a new `Diamond` contract for the implementation used in the `Unitroller`.

LowPotential for OverflowFixed

Potential for overflow with `selectorPosition` is technically possible if more than $ 2^{96} - 1 $ function selectors are added to the `Diamond` contract for a given facet address. It is recognized that the occurrence is unlikely without malicious takeover of the privileged `admin` account since this number of functions exceeds what is practical for any given deployed contract. If the value of `selectorPosition` for a given `_facetAddress` exceeds $2^{96}-1$ then - overflow to a value of 0 may cause `addFacet()` to be called on a `_facetAddress` which is already included in `facetAddresses` array - the selector's recorded `functionSelectorPosition` in mapping `selectorToFacetAndPosition` may not accurately record its actual position in the `functionSelectors` array of the `_facetAddress` in `facetFunctionSelectors`.

LowUnnecessary Remnant CastingFixed

Function `getMintableVAI()` of contract `VAIController` uses the following structure for calling `markets()`: ```solidity (, uint collateralFactorMantissa) = ComptrollerInterface(address(comptroller)).markets( ``` This casting structure is unnecessary since `comptroller` is already of type `ComptrollerInterface` and can be use directly to call `markets()`.

LowUnprotected Direct Updates to State of `Diamond.sFixed

EIP-2535 specifies that the `Diamond` contract should act as stateful proxy, and that its included facets should be stateless. However, in the upgrade to the new logic pattern employed by this project, the `Diamond` contract also acts as a logic contract, keeping the originally deployed `Unitroller` as the stateful proxy. Even so, both the `Diamond` and the included facets inherit the Comptroller's eternal storage, and, as a result, are both technically stateful, where some storage variables can be updated directly within each contract, outside of the use of the `Unitroller`. It is noted that addresses such as `admin` and `accessControl` cannot be updated directly within these contracts. Moreover, many user-facing endpoints contain a check to `ensureListed()` which will always return false. Thus, in most cases, the state cannot be updated. The only function that was found to successfully update the state of these contracts directly was function `updateDelegate()` which can be called directly in the `Diamond` or `MarketFacet` contract to update the state of either contract. A malicious user may update the state of either the `Diamond` or `MarketFacet` directly in an attempt to feed other users false information about the protocol.

Contracts in scope

No deployed address is recorded for this audit.

The report names a repository or files. Open the report to see its scope.

Repository and files the report names (18)

  • contracts/Comptroller/Diamond/interfaces/IMarketFacet.sol
  • contracts/Comptroller/Diamond/facets/MarketFacet.sol
  • contracts/Comptroller/Diamond/facets/XVSRewardsHelper.sol
  • contracts/Comptroller/Diamond/interfaces/IRewardFacet.sol
  • contracts/Comptroller/Diamond/Diamond.sol
  • contracts/Comptroller/ComptrollerInterface.sol
  • contracts/Comptroller/Diamond/interfaces/IDiamondCut.sol
  • contracts/Lens/SnapshotLens.sol
  • contracts/Comptroller/Diamond/facets/PolicyFacet.sol
  • contracts/Lens/ComptrollerLens.sol
  • contracts/Tokens/VAI/VAIController.sol
  • contracts/Comptroller/Diamond/facets/RewardFacet.sol
  • contracts/Tokens/VAI/VAIControllerStorage.sol
  • contracts/Comptroller/Diamond/facets/FacetBase.sol
  • contracts/Comptroller/Diamond/facets/SetterFacet.sol
  • contracts/Comptroller/Diamond/interfaces/ISetterFacet.sol
  • contracts/Comptroller/ComptrollerStorage.sol
  • contracts/Comptroller/Diamond/interfaces/IPolicyFacet.sol

Part of Venus Protocol’s security record

Venus Protocol
Audits67 audits by 7 firmsLast audit Sep 2025, by Quantstamp.
Critical findingsNo open critical findingsAcross the 67 reports, 4 critical findings were reported. Each is marked fixed by the firm that reported it.
IncidentIncident 12 May 2022Source: De.Fi incident database.
Open Venus Protocol’s security record

Security firm

CertiK

1,045 projects reviewed · 1,376 reports · latest May 2025

See CertiK’s audits

Something wrong on this page? A missing report, a wrong date, a finding that was fixed since. Tell us and we check it against its source.

Tell us