Venus - Token Converter

CertiKFiles named in the report

Audit

Part of CertiK’s series

CertiK reviewed Venus Protocol (Venus - Token Converter) on 7 Nov 2023: 26 findings, 0 critical; 19 marked fixed, 7 open.

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

Report hosted on skynet.certik.com.

Trustblock does not review code.

Findings26

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

SeverityOpenAcknowledgedFixed
Critical000
High201
Medium003
Low5015
HighRiskFundV2 Missing Or Improper ImplementationFixed

The interface of the `RiskFund` that will be upgraded is: ```solidity interface IRiskFund { function swapPoolsAssets( address[] calldata markets, uint256[] calldata amountsOutMin, address[][] calldata paths, uint256 deadline ) external returns (uint256); function transferReserveForAuction(address comptroller, uint256 amount) external returns (uint256); function updateAssetsState(address comptroller, address asset) external; function convertibleBaseAsset() external view returns (address); function getPoolsBaseAssetReserves(address comptroller) external view returns (uint256); } ``` However, not all of the functionality used in other contracts are implemented in `RiskFundV2`. In particular, the following functions are used in the contract `Shortfall`, but are not properly implemented by `RiskFundV2`: - `getPoolsBaseAssetReserves()` is not implemented. This is called in the `Shortfall` contract in the function `_startAuction()`, which will make it impossible to start or restart and auction without upgrading. - `transferReserveForAuction()` is implemented, but with a different amount of inputs. In particular, there is an added `bidder` input. This is called in the `Shortfall` contract in the function `closeAuction()`, which will make it impossible to close an auction without upgrading. In addition, the shortfall contract has logic to handle if the transfer to the bidder fails and instead of reverting tracking the debt to avoid potential DOS attacks. As such the funds should first be transferred to the shortfall contract and not sent directly to the bidder.

Medium`vXVS` Case Not Handled by `XVSVaultConverter`Fixed

Market `vXVS` is not fully handled by the `XVSVaultConverter`. Market `vXVS` has underlying asset `XVS` and is a market that is expected to be distributed by `ProtocolShareReserve` to `XVSVaultConverter` like all other markets. However, it is expected that asset `XVS` would not be a `tokenOut` option in the `XVSVaultConverter`, since it is the token to be accumulated and sent to the `XVSVaultTreasury`, so providing it as an asset to be converted at an incentive would be counter to the purpose of the contract. The only way `XVS` can be sent from the `XVSVaultConverter` to the `XVSVaultTreasury` is through the token converting functions that send the `tokenInAddress` token to the `destinationAddress`. Without any additional functionality, it appears the only method for retrieving sent `XVS` tokens from the `vXVS` market is through function `sweepToken()`.

MediumDifference Between `amountDiff` And Actual Sum OFixed

The amount that should be taken from each pool to account for the `amountDiff` is given by determining the percentage of the pools assets against the total reserves of the asset and taking that percentage of the amount. However, as these operations round down the sum of all the amounts may be slightly less than the amountDiff. Causing the reserves balance to be slightly higher than the balance of the contract. This can cause an issue when `transferReserveForAuction()` is called as in certain scenarios an auction cannot be closed when it should be. This can cause a delay in the closing of an auction and allow for more bids to be placed. --- A similar but less severe discrepancy occurs in `RiskFundConverter`.

MediumIssues With Functions Supporting Fee On TransferFixed

The functions supporting fee on transfer tokens do not perform any checks to ensure that the protocol does not lose an unexpected amount in a conversion. In particular, the amount converted is always based on the input amount and does not take into account the amount the destination address receives.

Low`for` Loop OptimizationFixed

In general, the counter in a for loop can be incremented or decremented in an unchecked block as it cannot overflow or underflow, saving gas as it will not perform a check for overflow or underflow. Additionally, it saves a small amount of gas to increment an index in a `for` loop from the left instead of from the right side as it performs fewer operations.

LowDivide Before MultiplyFixed

Performing integer division before multiplication truncates the low bits, losing the precision of calculation. ```solidity=433 uint256 tokenInToOutConversion = (tokenInUnderlyingPrice * conversionWithIncentive) / tokenOutUnderlyingPrice; ``` ```solidity=435 amountOutMantissa = (amountInMantissa * tokenInToOutConversion) / EXP_SCALE; ``` --- ```solidity=246 uint256 poolShare = (poolsAssetsReserves[pools[i]][tokenOutAddress] * EXP_SCALE) / assetReserve; ``` ```solidity=249 uint256 poolAmountInShare = (poolShare * amountIn) / EXP_SCALE; ``` ```solidity=182 uint256 poolShare = (poolAssetsFunds[pools[i]][tokenAddress] * EXP_SCALE) / assetReserves; ``` ```solidity=201 uint256 poolAmountShare = (poolShare * amount) / EXP_SCALE; ```

LowEnsure `convertConfigurations` Entries Do Not CreFixed

In general, it should be ensured before update that no combination of `convertConfigurations` entries creates a cycle where a user can input a token A and get token A as output through a sequence of conversions, where token conversion has been incentivized, causing the user to get more token A as output than they originally input. It is assumed, for instance, that any token configured as a `tokenInAddress` within the contract will never be set as a `tokenOutAddress`, and further, that only the base asset relevant to the Token Converter contract instance will be used as the `tokenInAddress`. However, we recommend including logic ensuring this is the case when configuring each Token Converter contract instance.

LowFunction `setPoolsAssetsDirectTransfer()` ShouldFixed

If function `setPoolsAssetsDirectTransfer()` is not called atomically with the `initialize()` function during initialization in order to directly transfer the base convertible asset to the `RiskFundV2` contract, then when `updateAssetsState()` is called, the value will be recorded in `poolsAssetsReserves[comptroller][asset]` for the `asset`. Consequently, since it is assumed that the convertible base asset will not be valid as a `tokenOut` address in a conversion, the amount recorded in the `poolsAssetsReserves` can only be removed through sweeping the token from the contract. While this may be the intended purpose of function `sweepToken()`, the action could be avoided for the initial convertible base asset by calling these functions atomically.

LowInaccurate Naming of `postSweepToken()`Fixed

Function `postSweepToken()` is called before token transfers in the `sweepToken()` function. It may be more descriptive to rename the function `preSweepToken()` since the function performs important checks and updates to state before transferring the specified token.

LowIncomplete NatSpec CommentsFixed

### XVSVaultTreasury - The `constructor()` does not have a NatSpec comment for the `xvsAddress_` parameter. - The function `initialize()` does not include comments for the `XVSVaultUpdated` event and the `ZeroAddressNotAllowed` error. ### RiskFundV2 - The comments above the functions `setConvertibleBaseAsset()`, `setRiskFundConverter()`, `setShortfallContractAddress()` do not mention their access is only governance. - The comments above the function `transferReserveForAuction()` do not reflect that it is only callable by `shortfall`. - The comments above the function `updatePoolState()` do not reflect that is is only callable by `riskFundConverter`. ### AbstractTokenConverter - The comments above the function `sweepToken()` do not include the parameters `to` and `amount`. - The comments above the function `postConversionHook()` do not include the parameter `tokenAddressOut`. - The comments above the function `balanceOf()` do not include the return parameter `tokenBalance`. - The comments above the function `_checkConversionPaused()` do not include the error `ConversionTokensPaused`. ### RiskFundConverter - The comments above the function `setPoolRegistry()` do not reflect it is only callable by governance. - The comments above the function `setPoolsAssetsDirectTransfer()` do not include the parameter `values`. - The comments above the function `balanceOf()` do not include the return parameter. - The comments above the function `getPools()` do not include the return parameter. - The comments above the function `ensureAssetListed()` do not include the return parameter. - The function `isAssetListedInCore()` is missing comments. - The comments above the function `postSweepToken()` do not include the error `InsufficientBalance`. ### XVSVaultConverter - The comments above the function `balanceOf()` do not include the return parameter `tokenBalance`.

Show 9 more
LowInconsistent Event Structure When Setting AddressFixed

Throughout the codebase, when an address is set the event is emitted prior to setting the new address in order to avoid needing a temporary variable to hold the old address to emit the event. However, in some places the event is emitted last and a temporary variable is used.

LowInsufficient Check to `isComptroller()`Fixed

Functions `getPoolAssetReserve()` and `updateAssetsState()` both make a check that `isComptroller()` returns true when called on the provided `comptroller` input address. However, this check only ensures that the user-provided input is a contract containing this function and that it returns the expected boolean. This check does not ensure that the address provided is a comptroller that is a legitimate part of protocol, or that the same expected logic is in the contract. Similarly, both functions check that the input `asset` is a nonzero address. However, this does not ensure that address provided is for a market existing within any of the Venus protocol pools. For function `updateAssetsState()`, both checks are unnecessary since the check to function `ensureAssetListed()` for the provided `comptroller` and `asset` is sufficient to ensure that the combination is either part of the core pool or isolated pools. For function `getPoolAssetReserve()`, since the function is for external viewing purposes only, it should be documented that if the `comptroller` and `asset` values provided are not a valid combination within the protocol, the return value will be zero. Alternatively, the check to `ensureAssetListed()` can be used as a replacement in the view function.

LowIssue With `PoolStateUpdated` EventFixed

The event `PoolStateUpdated` is emitted in the functions `updatePoolAssetsReserve()` and `updatePoolState()`. In the function `updatePoolState()` it indicates that the pools assets were incremented by the amount, however, in the function `updatePoolAssetsReserve()` it indicates that the pools assets were decremented by the amount. In addition, the comment above the event states "Emitted when pool states is updated with amount transferred to this contract" however it is also emitted when an amount of the reserve is swept.

LowMissing or Insufficient ChecksFixed

Missing or insufficient validation checks for function parameters can result in unexpected behavior and security vulnerabilities. ### RiskFundConverter - The function `postSweepToken()` is missing a check that the `amount` used as input is nonzero. Use of a zero amount may result in an ambiguous error message, since in that case, the `assetsReserves` value is not prevented from being nonzero, and can cause a division by zero. - The function `postConversionHook()` is missing a check that the `assetsReserves` value for the `tokenOutAddress` is nonzero. This may result in an ambiguous error message due to a division by zero. ### XVSVaultTreasury - The function `fundXVSVault()` is missing a check that `amountMantissa` is a nonzero value. ### RiskFundV2 - The function `postSweepToken()` is missing a check that the `amount` used as input is nonzero. Use of a zero `amount` may result in an ambiguous error message, since in that case, the `assetsReserves` value is not prevented from being nonzero, and can cause a division by zero. ### AbstractTokenConverter - The conversion functions are missing a check that `to` is neither the `tokenInAddress` nor `tokenOutAddress`.

LowPotential Issues With Added ChecksFixed

The following checks were added to the `setConversionConfig()` function: ```solidity if ( (tokenAddressIn == tokenAddressOut) || (tokenAddressIn != _getDestinationBaseAsset()) || conversionConfigurations[tokenAddressOut][tokenAddressIn].enabled ) { revert InvalidTokenConfigAddresses(); } ``` 1. First check ensures that `tokenAddressIn != tokenAddressOut`. 2. Second check ensures that `tokenAddressIn == _getDestinationBaseAsset()`. 3. Third check ensures that the reverse mapping is not enabled. However, there are scenarios where the third check can cause potential issues if the destination base asset is changed. Currently the only converter that allows for such a scenario is the `RiskFundConverter`. Please share the procedure that will be followed when there will be a change in the `convertibleBaseAsset` and updates to conversion configs in the `RiskFundConverter`.

LowPotential ReentrancyFixed

A reentrancy attack can occur when the contract creates a function that makes an external call to another untrusted contract before resolving any effects. If the attacker can control the untrusted contract, they can make a recursive call back to the original function, repeating interactions that would have otherwise not run after the external call resolved the effects. *This finding is considered informational because the reentrancy only causes out-of-order events and because the team has stated they do not currently support tokens with hooks.* ### External call(s) ```solidity=110 IERC20Upgradeable(convertibleBaseAsset).safeTransfer(bidder, amount); ``` * This function call executes the following external call(s). * In `SafeERC20Upgradeable._callOptionalReturn`, * `returndata = address(token).functionCall(data,"SafeERC20: low-level call failed")` * In `AddressUpgradeable.functionCallWithValue`, * `(success,returndata) = target.call{value: value}(data)` ### Events emitted after the call(s) ```solidity=111 emit TransferredReserveForAuction(comptroller, amount); ``` --- ### External call(s) ```solidity=81 IERC20Upgradeable(XVS_ADDRESS).safeTransfer(xvsStore, amountMantissa); ``` * This function call executes the following external call(s). * In `SafeERC20Upgradeable._callOptionalReturn`, * `returndata = address(token).functionCall(data,"SafeERC20: low-level call failed")` * In `AddressUpgradeable.functionCallWithValue`, * `(success,returndata) = target.call{value: value}(data)` ### Events emitted after the call(s) ```solidity=83 emit FundsTransferredToXVSStore(xvsStore, amountMantissa); ``` --- ### External call(s) ```solidity=188 token.safeTransfer(destinationAddress, balanceDifference); ``` * This function call executes the following external call(s). * In `SafeERC20Upgradeable._callOptionalReturn`, * `returndata = address(token).functionCall(data,"SafeERC20: low-level call failed")` * In `AddressUpgradeable.functionCallWithValue`, * `(success,returndata) = target.call{value: value}(data)` ### Events emitted after the call(s) ```solidity=191 emit AssetTransferredToDestination(comptroller, asset, balanceDifference); ```

LowSlots of Storage Placeholder in `AbstractTokenConFixed

The storage placeholder `__gap` variable in `AbstractTokenConverter`, along with the variables that are currently defined, take up a total of 51 storage slots.

LowTypos And InconsistenciesFixed

### RiskFundV2 - The comments above the function `setConvertibleBaseAsset()` state "ZeroAddressNotAllowed is thrown when risk fund converter address is zero", however, it should reference the convertible base asset as opposed to the risk fund converter. - The comments above the function `transferReserveForAuction()` state "param bidder Amount transferred to bidder address". However, bidder is an address not an amount. - The comments above the function `transferReserveForAuction()` state "@param amount Amount to be transferred to auction contract". However, this amount is transferred to the `bidder`. - The comments above the function `transferReserveForAuction()` state "@return Number reserved tokens.". This is not descriptive and may be misinterpreted. - The comments above the function `transferReserveForAuction()` state "@custom:error InvalidShortfallAddress is thrown on invalid shortfall address". However, this is thrown when the caller is not the `shortfall` address. - The comments above the function `sweepToken()` state "Tokens are sent to admin (timelock)", however, they are transferred to the input `to` address. - The comments above the function `updatePoolAssetsReserve()` state "@param amount Amount transferred to address(to)". However, the input amount is not necessarily the amount that will be transferred to `address(to)`. It is the amount of reserves that should be transferred to `address(to)`. ### AbstractTokenConverter - Throughout the file "convert" is used when "converted" or "conversion" should be used. - The comment above the variable `conversionPaused` states "Boolean of if convert is paused" which should be "Boolean for if convert is paused". - The comment above the variable `destinationAddress` states "Address at all incoming tokens are transferred to" which should be "Address that all incoming tokens are transferred to". - The comment above function `convertExactTokens()` contains typo "fater" which should be the word "after." - The comments above the functions to convert tokens state that they convert an exact amount. However, they only convert the exact amount if there is enough tokens held by the contract, otherwise the amount is adjusted. - In the function `postConversionHook()`, `tokenInAddress` is used, where everywhere else in the file `tokenAddressIn` is used. ### RiskFundConverter - The comments above immutable value `VBNB` state that the address is "used to exclude the BNB market while in the `getPools()` method", however, the market is not excluded in this function. - The comments above mapping `poolsAssetsDirectTransfer` states "this mapping would contain the assets for the pool which would be send to RiskFund directly." The comment can be modified to state "the mapping contains the assets for each pool which are sent to RiskFund directly."

LowUpgrade PlanningFixed

The contracts `XVSVaultConverter`, `RiskFundConverter`, and `XVSVaultTreasury` each include a storage placeholder variable, `__gap`, in the state of the child contract. Additionally, contract `XVSVaultTreasury` includes the `virtual` keyword. Please provide information on whether there is intention to ever use the child contracts listed as parent inheritances instead. If not, the placeholder variable in the child contracts and the `virtual` keyword may not be necessary.

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 (9)

  • contracts/TokenConverter/XVSVaultConverter.sol
  • contracts/TokenConverter/RiskFundConverter.sol
  • contracts/Utils/Constants.sol
  • contracts/ProtocolReserve/XVSVaultTreasury.sol
  • contracts/ProtocolReserve/RiskFundV2.sol
  • contracts/ProtocolReserve/RiskFundStorage.sol
  • contracts/TokenConverter/AbstractTokenConverter.sol
  • contracts/TokenConverter/IAbstractTokenConverter.sol
  • contracts/Utils/Validators.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