Part of CertiK’s retainer series
CertiK reviewed WEMIX (Wemix Retainer 103 KLEVA Omni) on 2 Apr 2024: 23 findings, 0 critical; 14 marked fixed, 9 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 | 3 |
| Medium | 1 | 0 | 2 |
| Low | 6 | 0 | 9 |
In the `EarnRouter` contract, the outcome of `getConvertedFeeRate` rises over time, which means that after a year, the `protocolShare` will represent an equivalent portion of the `protocolFeeRate` within the `totalShare`. As the `protocolShare` is a component of the `totalShare`, the latter also grows in tandem. ```solidity=234 function getProtocolShare(uint256 pid_) public view override returns (uint256) { PoolInfo memory poolInfo_ = _poolInfos[pid_]; if (block.timestamp <= poolInfo_.lastUpdateTime) { return poolInfo_.protocolShareStored; } uint256 timeElapse_ = block.timestamp - poolInfo_.lastUpdateTime; uint256 protocolShare_ = poolInfo_.protocolShareStored + (timeElapse_ * getConvertedFeeRate(pid_) * (poolInfo_.totalShareStored - poolInfo_.protocolShareStored)) / 1e18; return protocolShare_; } ``` When the user calls the `withdrawAll()` function, the protocol fee will be taken in the `userBalance_` due to the increment of the `totalShare_`. ```solidity=346 function withdrawAll(string calldata poolName_) external override nonReentrant { ... uint256 userBalance_ = getBalance(msg.sender, pid_); _withdrawInternal(pid_, userBalance_); } function getBalance(address account_, uint256 pid_) public view override returns (uint256) { if (_poolInfos[pid_].totalShareStored == 0) return 0; uint256 totalBalance_ = getTotalBalance(pid_); uint256 totalShare_ = getTotalShare(pid_); return (totalBalance_ * _userShare[account_][pid_]) / totalShare_; } ``` The `EarnRouter` will execute a withdrawal using less liquidity than what was initially deposited(deduct fee), and the shares converted from this smaller amount of liquidity might still surpass the user's recorded `_userShare`. As a result, the `_userShare` is updated to 0 and the remaining liquidity value is still in the `KlevaDistributor`. Additionally, it allows users to repeatedly claim rewards from the KlevaDistributor due to the presence of residual liquidity. ```solidity=407 function _withdrawInternal(uint256 pid_, uint256 withdrawAmount_) private { ... if (_userShare[msg.sender][pid_] < share_ + 1000) { share_ = _userShare[msg.sender][pid_]; _userPidSet[msg.sender].remove(pid_); } ... _userShare[msg.sender][pid_] -= share_; ... IKlevaDistributor(klevaDistributor).notifyWithdraw( msg.sender, poolInfo.distributorId, removedLiquidity_ ); } ```
In the contract `Ownable2StepUpgradeable`, if an owner wants to transfer ownership to another, the owner calls the function `transferOwnership()` to update the `_pendingOwner` to the new owner. Then the new owner calls the function `acceptOwnership()` to become the new owner. However, the `_pendingOwner` is not updated to `address(0)`. If the new owner renounces ownership, they can still regain ownership using the `acceptOwnership()` function.
A protocol fee will be applied when the user deposits funds into the `EarnRouter`. ```solidity function getBalance(address account_, uint256 pid_) public view override returns (uint256) { if (_poolInfos[pid_].totalShareStored == 0) return 0; uint256 totalBalance_ = getTotalBalance(pid_); uint256 totalShare_ = getTotalShare(pid_); return (totalBalance_ * _userShare[account_][pid_]) / totalShare_; } ``` The existing check within the `EarnRouter` does not prevent an user from withdrawing all of their liquidity, ie. including the fee. ```solidity function _withdrawInternal(uint256 pid_, uint256 withdrawAmount_) private { PoolInfo storage poolInfo = _poolInfos[pid_]; bytes memory data_ = abi.encode(poolInfo.target, withdrawAmount_); bytes memory res_ = _delegate(poolInfo.implementation, Selector.IMPL_WITHDRAW, data_); uint256 removedLiquidity_ = abi.decode(res_, (uint256)); uint256 share_ = _liquidityToShare(pid_, removedLiquidity_); if (_userShare[msg.sender][pid_] < share_ + 1000) { share_ = _userShare[msg.sender][pid_]; _userPidSet[msg.sender].remove(pid_); } poolInfo.totalLiquidity -= removedLiquidity_; poolInfo.totalShareStored -= share_; _userShare[msg.sender][pid_] -= share_; _transferOut(poolInfo.baseToken, msg.sender, withdrawAmount_); IKlevaDistributor(klevaDistributor).notifyWithdraw( msg.sender, poolInfo.distributorId, removedLiquidity_//CertiK: check exists here ); emit Withdrawn(pid_, poolInfo.baseToken, withdrawAmount_, removedLiquidity_); } ``` The check is located in the `KlevaDistributor`; users must make sure that the `removedLiquidity_` does not exceed the previously `addedLiquidity_`. Users can enter the calculated maximum profit amount when calling the `withdraw()` function to bypass the protocol fee.
The function `harvest()` relies on the `KlevaToken` to mint reward tokens to the `KlevaDistributor`. However, the `KlevaToken` can only mint tokens when the contract is not paused.
Users deposit their ERC20 tokens or native tokens to the `EarnRouter`, which then transfers them to another pool(such as Wemixfi) to receive liquidity value and converts them to shares for recording. Then, it calls `notifyDeposit()` to deposit the liquidity value to the `KlevaDistributor` to receive rewards. In the `KlevaDistributor` contract, the function `harvest()` is invoked when depositing, withdrawing or claiming rewards, causing the `KlevaToken` to be minted. However, the total supply cannot exceed the cap. Once the cap is exceeded, users cannot withdraw their tokens if the `MinterRole` does not call the function `burn()`. ```solidity function mint( address account_, uint256 amount_ ) external virtual whenNotPaused onlyMinterRole returns (bool) { require(totalSupply() + amount_ <= cap(), "KlevaToken: Cap exceeded"); _mint(account_, amount_); mintedBy[msg.sender] += int256(amount_); return true; } ```
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.
As mentioned above the function in Openzeppelin's contract is `AccessControl`. The function `_setupRole()` is deprecated in favor of `_grantRole`. The contract `KlevaConfig` is using the deprecated `_setupRole()` function. Reference: [OpenZeppelin Documentation](https://docs.openzeppelin.com/contracts/4.x/api/access#AccessControl-_setupRole-bytes32-address-)
Low level call on EOA or non-existing address will always succeed even if no smart contract code is executed at all. If parameter is EOA or non-existing address, the function will malfunction: it returns true even if no contract code is executed. See https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/v4.8.3/contracts/utils/AddressUpgradeable.sol#L180
In the contract `EarnRouter`, the function `sync()` can only be called by the contract `KlevaConfig`. However, the function `sync()` in the contracts `KlevaLocker`, `KlevaDistributor`, and `Dashboard` can be called by anyone as it has no access restriction. ```solidity =94 function sync() external { require(msg.sender == klevaConfig, "EarnRouter: Only klevaConfig"); klevaDistributor = IKlevaConfig(klevaConfig).getKlevaDistributor(); feeBox = IKlevaConfig(klevaConfig).getFeeBox(); } ``` ```solidity =43 function sync() external { klevaToken = IKlevaConfig(klevaConfig).getKlevaToken(); } ```
In the contract `KlevaConfig`, the function `setFeeBox()` checks that the input address is not `address(0)`. However, the other functions check whether the input address is a contract address. ```solidity=110 function setFeeBox(address feeBox_) external onlyOwner { require(feeBox_ != address(0), "KlevaConfig: Invalid feeBox address"); _feeBox = feeBox_; } ```
In the function `addPool()`, the input parameter `distributorId_` only checks that it should be less than or equal to the `lastPoolId` of the contract `KlevaDistributor`. However, in the contract `KlevaDistributor`, the minimum pool id is 1. If the `distributorId_` is 0, the check will pass and the correct pool cannot be found in the contract `KlevaDistributor`.
The following contracts contain the `receive()` function, yet the contract does not utilize forwarded ETH, and the contract is missing functionality to withdraw ETH from the contract. This means that funds may become trapped in the contract indefinitely.
In the function `addPool()`, there are two incorrect `require` statements: ```solidity require( target_ == address(0) || AddressUpgradeable.isContract(target_), "EarnRouter: Invalid target" ); require( implementation_ == address(0) || AddressUpgradeable.isContract(implementation_), "EarnRouter: Invalid implementation" ); ``` If `target_ == address(0)`, the code in L132 will revert. The same issue exists in the next `require` statement.
SafeTransfer should be used in place of Transfer for Solidity contracts to ensure robust security and error handling. Unlike the basic Transfer function, SafeTransfer incorporates safeguards against potential smart contract vulnerabilities, such as unexpected token loss. By automatically validating the recipient's ability to receive tokens and reverting transactions in case of failures.
The report names a repository or files. Open the report to see its scope.
Repository and files the report names (43)
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