CertiK reviewed MetFi DAO (Metfi) on 6 Feb 2023: 30 findings, 0 critical; 11 marked fixed, 19 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 | 1 | 0 | 1 |
| Medium | 1 | 0 | 0 |
| Low | 17 | 0 | 10 |
In `ContractRegistry`, the addresses with `realmGuardians` set to `true` have authority over the following functions: - `setContractAddress`: Change or set the address associated with `name` for the variable `contractAddress` - `setMatrixAddress`: Change or set the address associated with `level` for the variable `matrices` - `addMatrixLevel`: Add a matrix level to the variable `matrices` - `setLiquidityControllerAddress`: Change or set the address associated with `name` for the variable `liquidityControllers` - `setBuybackControllerAddress`: Change or set the address associated with `name` for the variable `buybackControllers` - `setPriceCalcAddress`: Change or set the address associated with `currencyAddress` for the variable `priceCalcAddresses` - `setRealmGuardian`: Change or set an address as a `realmGuardians` - `setCoinMaster`: Change or set an address as a `coinMasters` Furthermore, `ContractRegistry` serves as the access control for all contracts within the audit scope. The roles include `router`, `treasury`, `token_collector`, `reward_distributor`, `staking_manager`, `token_collector`, `treasury_extender`, `account_token`, and address in `coinMasters`. Any compromise to a `realmGuardians` account will allow the malicious actor to take advantage of this authority and change the value of sensitive state variables and addresses used across the platform for access control. The malicious actor can then call functions such as `getLostTokens` and/or `destroyContract` to steal all the tokens and ethers owned by the contracts.
According to the code implementation, the price of MFI is directly calculated via "reserves" from PancakeSwap Pair. i.e., `(uint256 reserve0, uint256 reserve1,) = pancakePair.getReserves();`, which can be affected by on-chain swapping. For example, the amount of MFI tokens that can be minted is calculated via the following code snippet: ```solidity=59 function getBonusTokens(uint256 busdPrice) public onlyRouter override returns (uint256) { IPriceCalculator priceCalc = IPriceCalculator(contractRegistry.getPriceCalculator(contractRegistry.getContractAddress(MFI_HASH))); IERC20 MFI = IERC20(contractRegistry.getContractAddress(MFI_HASH)); address to = contractRegistry.getContractAddress(STAKING_MANAGER_HASH); uint256 tokensForPrice = priceCalc.tokensForPrice(busdPrice); uint256 tokensFromSwap = (tokensForPrice * bonusTokenPercentageFromSwap) / 100; uint256 tokensToMint = tokensForPrice - tokensFromSwap; if (tokensToMint > 0) { MetFi(address(MFI)).mint(to, tokensToMint); } ... ``` The price of the MFI token is calculated via the function `tokensForPrice()`, whose logic is specified in the `PriceCalculator.sol`: ```solidity=87 function tokensForPrice(uint256 reserveTokenAmount) public override view returns (uint256) { if(!contractRegistry.contractAddressExists(PANCAKE_ROUTER_HASH)) return reserveTokenAmount; IPancakeRouter02 pancakeRouter = IPancakeRouter02(contractRegistry.getContractAddress(PANCAKE_ROUTER_HASH)); IPancakeFactory factory = IPancakeFactory(pancakeRouter.factory()); IPancakePair pancakePair = IPancakePair(factory.getPair(stableTokenAddress, calculatedToken)); if (address(pancakePair) == address(0)) { return reserveTokenAmount; } address token0 = pancakePair.token0(); (uint256 reserve0, uint256 reserve1,) = pancakePair.getReserves(); uint256 calculatedTokenReserve; uint256 reserveTokenReserve; (calculatedTokenReserve, reserveTokenReserve) = calculatedToken == token0 ? (reserve0, reserve1) : (reserve1, reserve0); require(calculatedTokenReserve > 0 && reserveTokenReserve > 0, 'No liquidity in pool'); uint256 amountInWithFee = reserveTokenAmount * 9975; uint256 numerator = amountInWithFee * calculatedTokenReserve; uint256 denominator = (reserveTokenReserve * 10000) + amountInWithFee; return numerator / denominator; } ``` As the code implementation shows above, the price of MFI is directly calculated via "reserves" from PancakeSwap Pair. i.e., `(uint256 reserve0, uint256 reserve1,) = pancakePair.getReserves();`. Therefore, the value of `reserve0` and `reserve1` can be updated by swapping, thus affecting the price of MFI. In this case, it will inflate the amount of MFI tokens that can be minted. The price calculation in the `PriceCalculator.sol` is based on reserves in the PancakeSwap and the affected functions are shown below: - `getPriceInUSD()` - `tokensForPrice()` - `priceForTokens()`
The order of external call/transfer and storage manipulation must follow the check-effect-interaction pattern. If an external call is made before storage is updated, it could potentially lead to a reentrancy attack.
The function `getTokensForCollector` transfers a specified amount of tokens to a specified address. Typically functions with function names starting from "get" are non-state modifying functions.
The following functions are declared as `public` despite not being invoked in any of the contracts contained within the project's scope. The functions that are never called internally should have `external` visibility. - `ERC20TreasuryFundsLock.returnFundsToTreasury` - `MetFiVoteCalculator.availableVotes` - `MetFiVoteCalculator.availableVotesForNFT` - `ContractRegistry.contractAddressExists` - `ContractRegistry.matrixExists` - `ContractRegistry.liquidityControllerExists` - `ContractRegistry.buybackControllerExists` - `ContractRegistry.priceCalculatorExists` - `ContractRegistry.getContractAddress` - `ContractRegistry.getMatrix` - `ContractRegistry.getLiquidityController` - `ContractRegistry.getBuybackController` - `ContractRegistry.getPriceCalculator` - `ContractRegistry.isCoinMaster` - `ContractRegistry.setContractAddress` - `ContractRegistry.setMatrixAddress` - `ContractRegistry.addMatrixLevel` - `ContractRegistry.setLiquidityControllerAddress` - `ContractRegistry.setPriceCalcAddress` - `ContractRegistry.setRealmGuardian` - `ContractRegistry.setCoinMaster` - `Treasury.getTotalRewardsPaid` - `Treasury.getValue` - `Treasury.onERC721Received` - `TokenCollector.getBonusTokens` - `TokenCollector.getTokens` - `TokenCollector.getCollectionType` - `TokenCollector.getPriceCalculationType` - `TokenCollector.getAdditionalTokensPercentage` - `TokenCollector.setCollectionType` - `TokenCollector.setPriceCalculationType` - `TokenCollector.setAdditionalTokensPercentage` - `TokenCollector.setBonusTokenPercentageFromSwap` - `TokenCollector.getLostTokens` - `TokenCollector.destroyContract` - `RewardDistributor.getAccountInfo` - `RewardDistributor.createAccount` - `RewardDistributor.accountUpgraded` - `RewardDistributor.liquidateAccount` - `RewardDistributor.distributeRewards` - `RewardDistributor.getLostTokens` - `RewardDistributor.setBonusActivationTimeOut` - `RewardDistributor.destroyContract` - `Router.createAccount` - `Router.createAccountWithReferral` - `Router.setReferralLink` - `Router.liquidateAccount` - `Router.cancelLiquidation` - `Router.stakeTokens` - `Router.buyTokens` - `Router.totalLevels` - `PancakeSwapBuybackController.buyBackMFI` - `PancakeSwapBuybackController.getLostTokens` - `PancakeSwapBuybackController.destroyContract` - `PancakeSwapLiquidityController.getLPTokenAddress` - `PancakeSwapLiquidityController.claimableTokensFromTreasuryLPTokens` - `PancakeSwapLiquidityController.mfiRequiredForProvidingLiquidity` - `PancakeSwapLiquidityController.provideLiquidity` - `PancakeSwapLiquidityController.removeLiquidity` - `PancakeSwapLiquidityController.destroyContract` - `EmptyTreasuryExtender.getValue` - `EmptyTreasuryExtender.getLostTokens` - `EmptyTreasuryExtender.destroyContract` - `PriceCalculator.exchangePairSet` - `PriceCalculator.getReserves` - `PriceCalculator.getPriceInUSD` - `PriceCalculator.tokensForPrice` - `PriceCalculator.priceForTokens` - `PriceCalculator.destroyContract` - `UnstakedNFTs.mintUnstakedTokens` - `UnstakedNFTs.tokenURI` - `UnstakedNFTs.supportsInterface` - `UnstakedNFTs.getLostTokens` - `PlatformView.getWalletData` - `PlatformView.getReferralCodeData` - `PlatformView.referralLinkExists` - `PlatformView.getMFIPrice` - `PlatformView.getPlatformData` - `PlatformView.getTreeData` - `PlatformView.stakedTokensForAddress` - `PlatformView.getLostTokens` - `PlatformView.destroyContract` - `Matrix.getUsersInLevels` - `Matrix.getDistributionNodes` - `Matrix.addNode` - `Matrix.getNode` - `Matrix.getSubtreeNode` - `Matrix.getSubNodesToLevel` - `Matrix.getLostTokens` - `Matrix.destroyContract` - `AccountToken.createAccount` - `AccountToken.setReferralLink` - `AccountToken.upgradeAccountToLevel` - `AccountToken.getAddressNFTs` - `AccountToken.getLiquidationInfo` - `AccountToken.requestLiquidation` - `AccountToken.liquidateAccount` - `AccountToken.cancelLiquidation` - `AccountToken.getAccountLevel` - `AccountToken.getAccountDirectlyEnrolledMembers` - `AccountToken.getAccountReferralLink` - `AccountToken.getAccountByReferral` - `AccountToken.referralLinkExists` - `AccountToken.getLevelMatrixParent` - `AccountToken.getDirectUplink` - `AccountToken.getAverageAPY` - `AccountToken.totalMembers` - `AccountToken.getLostTokens` - `AccountToken.destroyContract` - `AccountToken.setLiquidationPeriods` - `StakingManager.createStakingAccount` - `StakingManager.liquidateAccount` - `StakingManager.addTokensToStaking` - `StakingManager.upgradeStakingAccountToLevel` - `StakingManager.timeToNextRebase` - `StakingManager.nextRebaseAt` - `StakingManager.rebase` - `StakingManager.totalLevels` - `StakingManager.enterLiquidation` - `StakingManager.destroyContract` - `StakingManager.getLostTokens`
```solidity=131 uint256 valueFromSwap = (busdPrice * 85) / 100; uint256 minTokensOutSwap = (minTokensOut * 85) / 100; ``` ```solidity=153 uint256 tokensToMint = (receivedTokens * 15) / 85; //Mint 15% of tokens to staking manager MetFi(address(MFI)).mint(to, tokensToMint); ``` The amount to be minted to cover costs and rewards is a hard-coded percentage. In the case that this figure needs to be changed, the contract might need to be updated and re-deployed.
This issue is related to the implementation of the number of NFTs that a user can hold. Based on the assumption from the whitepapers that each user must purchase a certain level and all the NFT levels preceding that level, this would create a few issues. Firstly, this would mean that the function `availableVotesForNFT()` will be run for every level NFT that the user holds, compounding the weighted votes for each level. This could be an issue, especially for the few users who hold the relatively higher levels (especially in the earlier stages where there are fewer users). This could present a centralization issue where whales who hold the highest NFT levels and hold large amounts of MFI can possibly have more control over voting. Another issue that arises is checking for NFT levels that are purchased on secondhand markets. The current implementation for account creation and upgrading levels seems to only deem the latest and highest level as being valid. If this is the expected implementation, then users can purchase other levels from secondhand markets and effectively compound their votes as long as all the NFTs are categorized under the same address. This is another way users can artificially game the system to inflate their votes.
According to the documentation, there are 10 NFT levels. However, no input validation is available for the length of `_levelSettings`.
According to the documentation, there are 10 NFT levels. However, no input validation is available for the length of `_rebaseMultipliers`. Furthermore, if the multiplier is greater than 1000000000, line 161 will revert due to an underflow.
The value of `mfiTotalMembers` is not adjusted when an NFT is burnt. Although `mfiTotalMembers` is not used in any calculation, not having the value adjusted will only continue to increase the value of `mfiTotalMembers` and mislead users into believing that there are more active users than there really are.
The value of `totalAPY` is not adjusted when an NFT is burnt. As a result, the value returned by calling the function `getAverageAPY` will increase since the total supply will decrease after an NFT is burnt. Although `totalAPY` is not used in the calculation for any critical functionalities, it can mislead users to believe the APY is higher than it actually is.
`Treasury Extender` is created to manage any new tokens the `Treasury` wishes to add where the `EmptyTreasuryExtender.sol` acts as a template for the contracts of `Treasury Extenders`. Since the audit team does not know the actual detailed design of the Treasury Extenders, it is assumed that the developer can implement any logic in these extenders. The function `getValue()` in `EmptyTreasuryExtender.sol` can be used in `Treasury.sol` contract and will always return (0, 0) for the `riskFreeValue` and `totalValue`. Moreover, according to the function `manage()` in `Treasury.sol`, `Treasury Extender` can transfer any token to any address.
Since `parentLeg` is a `uint256` data type, checking `parentLeg >= 0` is unnecessary since it will always evaluate as true.
Although `ITreasuryExtender` is imported in `EmptyTreasuryExtender.sol` and `Treasury.sol`, the events are not used anywhere.
The following events are not used in `IRewardDistributor` are unused: - `AccountCreated` - `AccountUpgraded` - `AccountLiquidated`
`IMatrix.sol` is imported despite not being used.
`ITreasuryAllocator.sol` is imported despite not being used.
`Ownable.sol` is imported despite not being used.
Despite `SafeERC20` being imported and attached to `IERC20`, the functions are not used.
The report names a repository or files. Open the report to see its scope.
Repository and files the report names (42)
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