Maple Finance V2 went through 3 audits during its development details of which you can find below. All relevant issues identified by auditors were addressed prior to the launch of V2.
Trail of Bits
Maple V2 has an active bug bounty to incentive whitehat hackers to report any issues discovered in the protocol to allow for the opportunity for a patch to be made before the exploit is performed by a malicious actor. For all information related to the ongoing bug bounty for these contracts run by Immunefi, please visit this site.
In order to discuss critical monitoring first its important to be clear on the invariants that are asserted which can be found below.
* Invariant A: collateral balance >= _collateral
* Invariant B: fundsAsset >= _drawableFunds
* Loan Manager (non-liquidating)
* Invariant A: domainStart <= domainEnd
* Invariant B: sortedPayments is always sorted
* Invariant C: outstandingInterest = ∑outstandingInterest(loan) (theoretical)
* Invariant D: totalPrincipal = ∑loan.principal()
* Invariant E: issuanceRate = ∑issuanceRate(payment)
* Invariant F: unrealizedLosses <= assetsUnderManagement()
* Invariant H: assetsUnderManagement == ∑loan.principal() + ∑outstandingInterest(loan)
* Invariant I: domainStart <= block.timestamp
* Invariant J: if (loanManager.paymentWithEarliestDueDate != 0) then issuanceRate > 0
* Invariant K: if (loanManager.paymentWithEarliestDueDate != 0) then domainEnd == paymentWithEarliestDueDate
* Invariant L: refinanceInterest[payment] = loan.refinanceInterest()
* Pool (non-liquidating)
* Invariant A: totalAssets > fundsAsset balance of pool
* Invariant B: ∑balanceOfAssets == totalAssets (with rounding)
* Invariant D: convertToAssets(totalSupply) == totalAssets (with rounding)
* Invariant E: convertToShares(totalAssets) == totalSupply (with rounding)
* Invariant G: ∑balanceOf[user] == totalSupply
* Invariant I: totalAssets == poolManager.totalAssets()
* Invariant J: unrealizedLosses == poolManager.unrealizedLosses()
* Invariant K: convertToExitShares == poolManager.convertToExitShares()
* PoolManager (non-liquidating)
* Invariant A: totalAssets == cash + ∑assetsUnderManagement[loanManager]
* Invariant B: hasSufficientCover == fundsAsset balance of cover > globals.minCoverAmount
* Withdrawal Manager
* Invariant A: WM LP balance == ∑lockedShares(user)
* Invariant B: totalCycleShares == ∑lockedShares(user)[cycle] (for all cycles)
* Invariant C: windowStart[currentCycle] <= block.timestamp
* Invariant D: initialCycleTime[currentConfig] <= block.timestamp
* Invariant E: initialCycleId[currentConfig] <= currentCycle
* Invariant F: getRedeemableAmounts.shares[owner] <= WM LP balance
* Invariant G: getRedeemableAmounts.shares[owner] <= lockedShares[user]
* Invariant H: getRedeemableAmounts.shares[owner] <= totalCycleShares[exitCycleId[user]]
* Invariant I: getRedeemableAmounts.assets[owner] <= fundsAsset balance of pool
* Invariant J: getRedeemableAmounts.assets[owner] <= totalCycleShares[exitCycleId[user]] * exchangeRate
* Invariant K: getRedeemableAmounts.assets[owner] <= lockedShares[user] * exchangeRate
* Invariant L: getRedeemableAmounts.partialLiquidity == (lockedShares[user] * exchangeRate < fundsAsset balance of pool)
* Invariant M: lockedLiquidity <= pool.totalAssets()
* Invariant N: lockedLiquidity <= totalCycleShares[exitCycleId[user]] * exchangeRate
Maple Finance makes use of a custom smart contract to check invariants on-chain, using data from both smart contracts and sub-graph to assert invariants on a Loan, Pool and LP level. This is all managed using Tenderly Web3 Actions. Every block, all invariants are checked atomically using the deployed contract. If any of the invariants fail, a critical Pager Duty incident is created. This will notify all on-call members of the incident response team immediately, and also includes a pre-defined escalation policy. In addition, Tenderly will use webhooks to send a message to the team's internal Slack channel with further information about how the invariant has failed.
Similarly to critical monitoring, Tenderly is used to notify the team whenever transactions are made against any of the protocols contracts in order to have real-time insights into protocol usage. Examples would include a Loan being funded or a Pool Delegate changing a withdrawal configuration.
Additionally all smart contracts get programmatically verified on Etherscan via the use of custom Tenderly web3 actions.
In the case of a critical incident, a multisig is able to trigger a protocol pause. This function can temporarily disable almost all functions in the Maple protocol. This will allow for the incident response team to address the situation and minimize any potential harm that would be done. More information on the Emergency Pause function is outlined on this page.
Maple Finance has implemented a number of protections to mitigate the risk of flash loans and front-running attacks. These protections are outlined below.
- 1.Chainlink Oracles - Maple Finance uses Chainlink oracles to provide price feeds for the protocol. Chainlink oracles are decentralized and provide a high level of security and reliability. In addition, Chainlink oracles are designed to be resistant to flash loan attacks since they provide price data from off-chain sources. More information on Chainlink oracles can be found here.
- 2.Oracle Wrappers - Maple Finance uses oracle wrappers to provide additional security and reliability to the Chainlink oracles. Oracle wrappers are designed to prevent oracle outages and oracle manipulation from causing issues in the protocol, specifically during liquidations.
- 3.Minimum Liquidation Price - The minimum liquidation price is a parameter that is set by the Pool Delegate. This parameter is used to prevent liquidations from occurring when the price of the collateral is too low. This is done to prevent flash loan attacks from being able to liquidate collateral at unfair prices.
- 4.Withdrawal Cooldowns - With withdrawal cooldowns, LPs are required to wait a certain amount of time before they can withdraw their funds. This is done to prevent flash loan attacks from being able to front-run LPs and deposit and withdraw funds to profit unfairly from discrete increases in pool value.
Every ERC-20 asset has a
bootstrapMintamount that is set by the Governor. This is to prevent attackers from front-running the first depositor in a Pool to get an unfair distribution of Pool value. Outlines of this exploit can be found here under finding 5.1.1.