CertiK reviewed MetFi DAO (Metfi Audit 4) on 1 Feb 2024: 42 findings, 0 critical; 26 marked fixed, 4 acknowledged, 12 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 | 3 | 0 | 6 |
| Medium | 0 | 4 | 6 |
| Low | 9 | 0 | 14 |
### Lending Contract In the `Lending` contract, the following roles have authority over specific functions: - `LendingManager` - `setLendingConfiguration()`: Sets the lending configuration. - `setLendingManager()`: Assigns or removes the lending manager role from a given address. - `setBlackList()`: Allows the lending manager to manage the account blacklist. - `setApprovedCollateralCurrency()`: Allows the lending manager to add to or remove from the list of approved currencies for use as collateral in lending operations. - `setFailsafe()`: A safety switch that allows the Lending Manager to stop all lending activities until the issue is resolved. - `setFailsafePermanent()`: A safety feature that allows the Lending Manager to permanently stop all lending activities if a serious issue occurs. - `RealmGuardian` - `migrateToNewLendingContract()`: Migrates all active lending information and related assets to a new lending contract. - `Treasury` - `getLostTokens()`: Allows the Treasury contract to withdraw tokens from the contract. This will mostly be used to recover any lost or stuck tokens in the contract. Any compromise to the `LendingManager`, `Treasury`, `RealmGuardian` may allow the attacker to take advantage of their respective authorities and can potentially lead to security risks. ***The `LendingManager` role has the ability to manage lending configurations, manage the user blacklist, and halt all lending activities in the case of emergencies.*** ***The `Treasury` role has the authority to withdraw tokens from the contract. It is important to note that the `Treasury` role can only be designated by the `RealmGuardian` through the `ContractRegistry` contract. As a result, an attacker can use the `RealmGuardian` role to cause damage to the project through misuse of the `Treasury` role.*** ### LendingAuction Contract In the `LendingAuction` contract, the following roles have authority over specific functions: - `AuctionManager` - `setAuctionConfiguration()`: Sets the Auction configuration. - `setAuctionManager()`: Assigns or removes the auction manager role from a given address. - `setBlackList()`: Allows the auction manager to manage the account blacklist. - `setFailsafe()`: A safety switch that allows the Auction Manager to stop all lending activities until the issue is resolved. - `setFailsafePermanent()`: A safety feature that allows the Auction Manager to permanently stop all lending activities if a serious issue occurs. - `RealmGuardian` - `migrateToNewAuctionContract()`: Migrates all NFTs in this contract to a new Auction contract. - `Treasury` - `getLostTokens()`: Allows the Treasury contract to withdraw tokens from the contract. This will mostly be used to recover any lost or stuck tokens in the contract. Any compromise to the `LendingManager`, `Treasury`, `RealmGuardian` may allow the attacker to take advantage of their respective authorities and can potentially lead to security risks. ***The `AuctionManager` has the ability to manage auction configurations, manage the user blacklist, and halt all lending activities in the case of emergencies.*** ***The `Treasury` role has the authority to withdraw tokens from the contract. It is important to note that the `Treasury` role can only be designated by the `RealmGuardian` through the `ContractRegistry` contract. As a result, an attacker can use the `RealmGuardian` role to cause damage to the project through misuse of the `Treasury` role.*** --- **Potential Discrepancy Between Snapshot Voting Results and Executed Actions in DAO Governance** Despite using the Snapshot Platform for voting, the DAO's Multisig Manager contract includes a potential centralization risk. While Snapshot enables decentralized voting, the execution of the resulting actions is dependent on the `multiSigAccounts` assigned by the constructor. ```solidity constructor(ContractRegistry _contractRegistry, MultiSigAccount[] memory _multiSigAccounts, uint256 _signaturesRequired) EIP712("MultiSigMetFiManagerV4", "1") ContractRegistryAdmin(_contractRegistry) { for (uint256 x = 0; x < _multiSigAccounts.length; x++) { multiSigAccounts.push(_multiSigAccounts[x]); } require(_signaturesRequired < _multiSigAccounts.length, "You can't require 100% or more signatures"); signaturesRequired = _signaturesRequired; nextQueuedActionID.increment(); } ... function queueAction(Action memory action, bytes[] memory signatures, uint256 deadline) public { ... require(signatures.length >= signaturesRequired, "Not enough signatures"); require(block.timestamp < deadline, "Deadline exceeded"); verifySignatures(action.actionType, deadline, action.data, signatures, action.requestId); action.executionAvailableTime = block.timestamp + timeLockTime; action.executed = false; action.creator = msg.sender; allActions[actionId] =
In the `MetfiQuiz` contract, the following roles have authority over specific functions: - `RealmGuardian`: - `setAnswerOracle()`: Sets a new answer oracle and determines whether it is enabled or disabled. - `setSubscriptionId()`: Sets a new Chainlink VRF subscription ID. - `setConfig()`: Sets the configuration for the `MetFiQuiz` contract. - `endQuiz()`: Ends the quiz after the current round. - `AnswerOracles`: - `recordAnswer()`: Records the answer for a batch of tickets and whether the answer is correct or incorrect. - `Treasury` - `getLostTokens()`: Allows the Treasury contract to withdraw tokens from the contract. This will mostly be used to recover any lost or stuck tokens in the contract. Any compromise to the `RealmGuardian` and `AnswerOracles` may allow the attacker to take advantage of their respective authorities and can potentially lead to security risks. ***The `AnswerOracles` role has the ability to record answers for a group of tickets and whether the answer is correct or incorrect. This means that an attacker can take advantage of the authority of answer oracles to alter the outcome by determining the validity of answers submitted.*** ***The `Treasury` role has the authority to withdraw tokens from the contract. It is important to note that the `Treasury` role can only be designated by the `RealmGuardian` through the `ContractRegistry` contract. As a result, an attacker can use the `RealmGuardian` role to cause damage to the project through misuse of the `Treasury` role.*** ***The audit team strongly advises clients to mitigate this risk by applying decentralization and promoting transparency in future endeavors***.
The reliance on values extracted from liquidity pools, which can be manipulated by attackers, can potentially lead to project losses due to the inflation of collateral amounts allowing attackers to borrow more than normally allowed based on their underlying collateral of staked `METFI` tokens. The function `calculateLoanPercentageOfStakedMETFIValue()` determines the loan amount by comparing it to the value of staked `METFI` tokens. This value is obtained through `PancakeSwap.getAmountsOut()`, which means that an attacker could temporarily inflate the price of METFI in the same transaction using a flash loan, enabling them to bypass collateral checks and secure a larger loan than their collateral would normally permit. Moreover, it should be noted that the `checkLoanForInvalidation()` function within the `LendingCalculator` contract does not verify if the staked METFI meets the necessary collateral requirements. ```solidity function checkLoan(CreateLoanRequest calldata request, address msgSender) external view override { ... if ( getLendingCalculator().calculateLoanPercentageOfStakedMETFIValue(request.amount + interest, request.tokenId) > lendingConfiguration.creationLoanPercentageOfStakedValue ) { revert NotEnoughCollateral(); } ... } function calculateLoanPercentageOfStakedMETFIValue(uint256 outstandingLoanAmount, uint256 tokenId) external view override returns (uint256) { address[] memory path = new address[](2); path[0] = contractRegistry.getContractAddress(METFI_HASH); path[1] = address(getPrimaryStableCoin()); uint256 metfiValue = pancakeRouter.getAmountsOut( IStakingManagerV2(contractRegistry.getContractAddress(STAKING_MANAGER_HASH)).getAccountTokens(tokenId), path )[1]; if (metfiValue == 0) return 0; return ((outstandingLoanAmount * 1_000_000) / (metfiValue)); } ``` This attack could result in the protocol issuing undercollateralized loans, which could lead to insolvency if not addressed.
The contract utilizes a `liquidationGracePeriod`, a period after which a loan in danger of under-collateralization can be liquidated. While this allows borrowers time to add more collateral or repay a portion of their loan, it does not consider scenarios where the collateral's value could drastically drop during this grace period. In such cases, this could lead to the loan being severely under-collateralized by the time liquidation occurs, thus causing financial loss to the lender. If the value of the collateral falls significantly during the `liquidationGracePeriod`, the amount recovered from the liquidation might not cover the outstanding loan. This would lead to a financial loss for the lender. In an extreme case, a significant market crash could render the collateral valueless before liquidation, leading to a total loss of the loan amount.
The `addCollateral()` function is vulnerable to incorrect collateral amount calculations when deflationary tokens are used as collateral. Deflationary tokens are tokens that burn or reduce a certain percentage of the tokens involved in a transfer operation. As a result, the actual amount of tokens transferred from the borrower to the contract would be less than the `request.amount`. The current implementation assumes that the full `request.amount` of tokens are transferred to the contract, and this amount is used to update the loan collateral value. This is not always the case when dealing with deflationary tokens. Specifically, the line `currentLoan.additionalCollateralAmounts[i] += request.amount;` is responsible for adding the `request.amount` to the current collateral value of the loan. This could lead to an over-estimation of the collateral's value in case of deflationary tokens, which can create risk and instability for the entire loan system.
The `checkLendingConfig()` function lacks some validation checks for all fields in the `LendingConfiguration` struct. Consequently, several fields can contain invalid values that could lead to unexpected behavior or potential attacks. - `treasuryInterestPercentage` should be less than or equal to 10,000 (100%). - `foreignCurrencyExchangeFeePercentage` should be less than or equal to 1,000,000 (100%). - Maximum allowable value for `loanExtensionFeeInBNB` and `loanLiquidationFeeInSelectedStablecoin`. - `liquidationFeePayoutCurve` should have all values between 0 and 1000 (100%).
The `shareOfLoan` is calculated as `(fundedAmount * SHARE_MULTIPLIER) / currentLoan.amount`. This `calculation` may lead to an issue if `fundedAmount` is significantly less than `currentLoan.amount`. Given the nature of integer division in Solidity, this could lead to rounding issues and the resulting `shareOfLoan` may end up being zero.
In the current implementation of contract `Router`, `tx.origin` is frequently used in checks, which is used to prevent potential flashloan attacks and reentrancy issues. `tx.origin` check will be no longer be valid after EIP-3074 is added. EIP3074 introduces two EVM instructions `AUTH` and `AUTHCALL`. The first instruction `AUTH` sets a context variable authorized address based on an ECDSA signature. The second instruction `AUTHCALL` sends a call as the authorized address. This essentially delegates control of the EOA to a smart contract. This means there will be a way for malicious smart contracts to send transactions in the context of `owner`, thus bypassing this check. Also, `tx.origin` is widely discouraged as there are possible phishing attempts and may also block wallet contracts from using the products.
The `migrateToNewAuctionContract` function does not fully migrate all the necessary information associated with an auction when migrating active auctions to a new contract. Specifically, only the `tokenId` of the auction is transferred to the new contract, while critical information such as `currentBid` and `currentBidder` remain in the old contract. This could potentially lead to a loss of critical auction data during the migration, disrupting active auctions, and causing losses for bidders.
In the current implementation of the `invalidateLoan()` function, there is a potential for a loss of precision which could result in a minor amount of funds remaining locked in the contract. Similar issues are present in the `removeFund()` function. The issue lies in the calculation of the amount of stablecoin to be refunded to each lender during the loan invalidation process. ```solidity=840 // Return funded amounts to lenders for (uint256 i = 0; i < currentLoan.lenderInfo.length; i++) { selectedStableCoin.safeTransfer( currentLoan.lenderInfo[i].lender, (currentLoan.lenderInfo[i].shareOfLoan * currentLoan.amount) / SHARE_MULTIPLIER ); } ``` Due to the way integer division is handled in Solidity, if `shareOfLoan * currentLoan.amount` is not a multiple of `SHARE_MULTIPLIER`, the result of the division will be rounded down to the nearest integer. This may cause the actual amount transferred to be less than the intended amount, with the remainder becoming inaccessible within the contract.
The lack of access controls around functions executing swaps between the contract and decentralized liquidity pools can lead to the loss of funds through manipulation by attackers. The `QuizKeeperFinalizer` contract will be utilized to trigger the `finalizeRound()` once the `randomNumbersReceived` is `true`. Additionally, the `checkUpkeep()` function will calculate the `minPotSize` to prevent potential price slippage or sandwich attacks when calling `finalizeRound()`. ```solidity=13 function checkUpkeep(bytes calldata) external view override returns (bool upkeepNeeded, bytes memory performData) { (bool canBeEnded, uint256 minPotSize) = getMetFiQuiz().canRoundBeFinalizedWithMinPotSize(); return (canBeEnded, abi.encode(minPotSize)); } function performUpkeep(bytes calldata performData) external override { getMetFiQuiz().finalizeRound(abi.decode(performData, (uint256))); } ``` However, since there is no access control to the `performUpkeep()` function, everyone can call the `finalizedRound()` directly and set the `minPotSize` to any value. Therefore, in theory, when the `minPotSize` is set to zero and the `primaryStableCoin.balanceOf(address(this))` is large enough, attackers can perform a sandwich attack targeting the `pancakeRouter.swapTokensForExactTokens()` in the function, which is executed to exchange the primary stablecoin for the required `METFI` tokens. A sandwich attack typically targets decentralized exchanges (like PancakeSwap) and exploits the price slippage that occurs when placing a large trade. Attackers manipulate token prices by placing a large buy order (front-running the target transaction) and then a large sell order after the target transaction has executed. This results in the victim paying a higher price for the tokens, while the attacker profits from the price manipulation.
Depending on their level, users can use a certain defined percentage of METFI tokens in place of USDC to pay for the purchase of tickets which can potentially result in a decrease in their winning percentage. The `buyTickets()` function enables METFI NFT holders to use their METFI as a substitute for USDC when purchasing tickets. As a result, users will transfer a smaller amount of USDC to the contract. For instance, a level 9 NFT holder can pay for 10% of the ticket price using their METFI, and subsequently **transfers only 90% of the ticket price to the contract**. ```solidity if (useMETFIPercentage > (nftLevel + 1) * 1e3) { revert useMETFIPercentageTooHigh(useMETFIPercentage, (nftLevel + 1) * 1e3); } else if (useMETFIPercentage > 0) { uint256 metfiAmountOfPrice = totalTicketsPrice * useMETFIPercentage / 1e5; primaryStableCoinPrice -= metfiAmountOfPrice; IStakingManagerV3 stakingManager = getStakingManager(); uint256 metfiAmount = getPriceCalculator(contractRegistry.getContractAddress(METFI_HASH)).tokensForPrice(metfiAmountOfPrice); if (metfiAmount > stakingManager.getAccountTokens(nftId)) { revert NotEnoughMETFIInStaking(stakingManager.getAccountTokens(nftId), metfiAmount); } stakingManager.claimTokensFromAccount(nftId, metfiAmount, address(getBurnController())); getBurnController().burnExisting(); boughtTicketsInfo[newBatchId].spentMETFI = metfiAmount; } primaryStableCoin.safeTransferFrom(msg.sender, address(this), primaryStableCoinPrice); ``` A concern arises from the fact that winners receive a portion of all the USDCs transferred to the contract. Consequently, if fewer USDC is transferred to the contract, the winning expectation will decrease. This implies that using METFI as a substitute may actually lower the winning expectations. For example, let's assume the ticket price is 100 USDC each, and there are two level 9 players participating in the game. Both players buy a ticket using their METFI to substitute for 10% of the ticket price. Thus, each player spends assets worth 100 USDC, but only 180 USDC in total are transferred to the contract. The expected winnings for each player would be 180/2 = 90, which means they paid 100 USDC, but their winning expectation is only 90%. On the other hand, if they were to use 100 USDC without using METFI as a substitute, their winning expectation could be 100% instead.
The report names a repository or files. Open the report to see its scope.
Repository and files the report names (15)
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