Part of CertiK’s series
CertiK reviewed Venus Protocol (Venus - Oracle) on 22 May 2023: 17 findings, 0 critical; 14 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 | 2 |
| Low | 1 | 0 | 12 |
The contract `BinanceOracle` does not inherit the `OracleInterface` and does not properly implement it. This is because it takes an input of type `VBep20Interface` as opposed to the interface that takes an input `address`. The `ResilientOracle` interacts with the oracles via the `OracleInterface`, so that because the `BinanceOracle` does not properly implement it, it cannot be used in the `ResilientOracle`.
When calling `feed.latestRoundData()`, the return `answer` is a `int256`, allowing it to possibly be a negative number. Currently it is only checked if the `answer` is zero, allowing for negative prices to be cast as a `uint256`. We understand there is a low chance of a negative price being reported, which is why we give it a medium severity. However, if negative numbers are returned it can instead return the maximum price possible.
In the function `getUnderlyingPrice()`, if the validation of the `mainPrice` vs. `pivotPrice` and `fallbackPrice` vs. `pivotPrice` fails. Then the `fallbackPrice` is tested against the `mainPrice` and if the validation passes, then the `mainPrice` is returned. However, if the `mainPrice` is being returned then it should be the price that is tested. Note that this goes against the comments at the beginning of the function that state the "fallback oracle against pivot oracle or main oracle".
In other audits you had clarified: "The convention for function signatures in ACM checks is to use the signature equivalent to the one used in the selector computation (e.g. f(uint, VToken) becomes `f(uint256,address)`) to avoid ambiguities where multiple type names are possible. An exception to this convention is struct parameters; instead of listing the struct contents as a tuple, which is a canonical EVM type name for structs, we just use the struct name." However the following do not seem to match this convention: - the access check in the contract `ChainlinkOracle` for the function `setUnderlyingPrice()` uses `setUnderlyingPrice(VBep20Interface,uint256)`; - the access check in the contract `PythOracle` for the function `setUnderlyingPythOracle()` uses `setUnderlyingPythOracle(IPyth)`; - the access check in the contract `ResilientOracle` for the function `setOracle()` uses `setOracle(address,address,OracleRole)`. Where `OracleRole` is an `enum` and according to the [solidity docs](https://docs.soliditylang.org/en/v0.8.0/abi-spec.html) should be `uint8`; - the access check in the contract `ResilientOracle` for the function `enableOracle()` uses `enableOracle(address,OracleRole,bool)`. Where `OracleRole` is an `enum` and according to the [solidity docs](https://docs.soliditylang.org/en/v0.8.0/abi-spec.html) should be `uint8`;
In the contract `PythOracle`: - the `initialize()` function checks that `underlyingPythOracle_` is not the zero address, when the `notNullAddress` modifier can be used to be more consistent and decrease the contracts deployment size. - the function `getUnderlyingPrice` also checks that `underlyingPythOracle` is not the zero address, when the `notNullAddress` modifier can be used to be more consistent and decrease the contracts deployment size. While this will increase the gas costs on function calls, we recommend remaining consistent throughout the codebase.
In the function `setMaxStalePeriod()`, instead of using `compare()` to determine if the input `symbol` is empty. The string can be converted to bytes and the length of the bytes checked. This will save around 809 gas on successful calls and 712 gas on calls that will revert due to this check. In the function `compare()`, the string can be cast into `bytes` directly as opposed to using `abi.encodePacked`, which costs more gas. In addition, `abi.encodePacked` may be removed in future solidity versions (see this issue: [https://github.com/ethereum/solidity/issues/11593](https://github.com/ethereum/solidity/issues/11593)).
In the function `setDirectPrice`, the `prices[asset]` is set to be equal to `price` before the event is emitted. This then emits the event so that all three of the parameters `previousPriceMantissa`, `requestedPriceMantissa`, and `newPriceMantissa` will be the same.
We understand that these are privileged functions and that these checks may be performed off chain, which is why we only mark this as informational. The `TwapOracle` is only designed to handle pools with WBNB or BUSD and it should be checked that any `pancakePool` has one of these in its pair along with the asset, and that the bools `isBnbBased` and `isReversedPool` are set properly. The `ChainlinkOracle` is designed to only use feeds for the assets it is assigned to along with USD. It should be checked that the feed assigned to an asset is for that asset and USD. The `PythOracle` is designed to only use the `pythId` for the assets that it is assigned to along with USD. It should be checked that the feed assigned to an asset is for that asset and USD. If the wrong values are used, then this can cause the wrong price to be returned by the oracle which may allow funds to be exploited from the protocol.
In the `constructor()` of the contract `ResilientOracle`, the input `vaiAddress` is not checked to not be `address(0)`.
In the contract `ChainlinkOracle`: - the comments above the function `_getChainlinkPrice()` uses "exit", when it should be "exist". In the contract `ResilientOracle`: - the comments above the function `setTokenConfigs()` misspells "length" as "lenght". - the comment in the function `updatePrice()`, only mentions if the pivot oracle is the `PythOracle` the call will revert and need to be caught. However, if the pivot oracle is any oracle that is not a `TwapOracle` the call will revert and need to be caught. In the contract `BoundValidator`: - a storage gap is added and the comment above it mentions that this contract is designed to be inherited, however, this contract is not inherited. We recommend having this contract be inherited, removing the storage gap, or providing more information on how this contract is to be implemented in future iterations. In the contract `PythOracle`: - the comments above `getUnderlyingPrice()` state "@return price Underlying price with a precision of 10 decimals", however the precision is with 18 not 10 decimals.
The following operations can be placed in unchecked blocks as they cannot overflow or underflow. --- In the contract `BinanceOracle`: ```solidity=109 uint256 deltaTime = block.timestamp - updatedAt; ``` can be placed in an unchecked block as the following check is made beforehand. ```solidity=107 if (block.timestamp < updatedAt) revert("updatedAt exceeds block time"); ``` This ensures that `block.timestamp >= updatedAt` so that the subtraction cannot underflow. --- In the contract `ChainlinkOracle`: ```solidity=209 int256 deltaTime = block.timestamp - updatedAt; ``` can be placed in an unchecked block as the following check is made beforehand. ```solidity=207 if (block.timestamp < updatedAt) revert("updatedAt exceeds block time"); ``` This ensures that `block.timestamp >= updatedAt` so that the subtraction cannot underflow. --- In the contract `TwapOracle`: ```solidity=217 uint256 timeElapsed = block.timestamp - oldTimestamp; ``` can be placed in an unchecked block as the following check is made beforehand. ```solidity=215 if (block.timestamp < oldTimestamp) revert("now must come after before"); ``` This ensures that `block.timestamp >= oldTimestamp` so that the subtraction cannot underflow. --- In general, `for` loops can have the increment placed in the body of the loop inside an unchecked block.
In the function `getUnderlyingPrice()`, the input `vToken` is an `address`. Thus when comparing it to the addresses `vBnb` and `vai` it does not need to be cast as an `address`.
In the contracts `ChainlinkOracle`, `PythOracle`, `TwapOracle`, and `ResilientOracle`: The function `setTokenConfigs()` checks that the `msg.sender` is allowed to call it. However, it then calls the function `setTokenConfig()` which will check that the `msg.sender` is allowed to call it. As permission was given to call `setTokenConfigs()` the permission does not need checked to call `setTokenConfig()`. Similarly this occurs in the contract `BoundValidator` for the function `setValidateConfigs()`. --- In the contract `TwapOracle`: The function `setTokenConfig()` makes the following checks: ```solidity if (config.baseUnit == 0) revert("base unit must be positive"); if (config.baseUnit != 10 ** IERC20Metadata(config.asset).decimals()) revert("base unit decimals must be same as asset decimals"); ``` However `10 ** IERC20Metadata(config.asset).decimals()` cannot be 0, so that checking if `config.baseUnit` is zero is unnecessary.
In the function `setUnderlyingPrice()`, the value of `prices[asset]` can be stored in a temporary variable before the input `underlyingPriceMantissa` and the temporary variable can be used as the `previousPriceMantissa` in the emitted event. This allows the event to be emitted after the assignment and saves a small amount of gas.
The report names a repository or files. Open the report to see its scope.
Repository and files the report names (13)
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