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.
Report hosted on skynet.certik.com.
Trustblock does not review code.
Statuses are the security firm’s own, from its report.
| Severity | Open | Acknowledged | Fixed |
|---|---|---|---|
| Critical | 0 | 0 | 0 |
| High | 2 | 0 | 0 |
| Medium | 0 | 0 | 0 |
| Low | 1 | 0 | 7 |
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.
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.
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.
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`.
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`.
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()`.
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.
The report names a repository or files. Open the report to see its scope.
Repository and files the report names (18)
1,045 projects reviewed · 1,376 reports · latest May 2025
See CertiK’s auditsSomething 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