bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 14쪽
mart 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](https://docs.tenderly.co/web3-actions/intro-to-web3-actions). Every block, all invariants are checked atomically using the deployed contract. If any of the invariants fail, a critical [Pager Duty incident](https://support.pagerduty.com/docs/incidents) 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.
## Informational Monitoring
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.
## Emergency Pause Function
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](/technical-resources/security/emergency-protocol-pause).
## Oracle/Flash Loan Protections
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](https://docs.chain.link/).
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. 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.
## Front-Running Protections
Every ERC-20 asset has a `bootstrapMint` amount 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](https://docs.google.com/viewer?url=https://github.com/maple-labs/maple-v2-audits/files/10223545/Maple.Finance.v2.-.Spearbit.pdf) under finding 5.1.1.
# List of Assumptions
This page outlines all assumptions that have been made by the smart contracts team in relation to smart contract security and trust models.
#### 1. All external calls to contracts that are part of the Maple Protocol System can be assumed to be non-reentrant.
Since all contracts that are deployed as part of the Maple protocol are developed by the Maple smart contracts team and are externally audited before deployment, it can be assumed that the contracts are both non-reentrant and non-malicious.
#### 2. All external calls to ERC-20 contracts can be assumed to be non-reentrant.
This assumption is made since all tokens that are used in the Maple protocol have to be added to the protocol allowlist, in the MapleGlobals contract. This means that the smart contracts team will audit the ERC-20 contracts and ensure that reentrancy is impossible.
#### 3. Pool Delegates are trusted actors.
Pool Delegates have to go through a KYC process and have to get onboarded to the Maple protocol by the Governor. They have a public reputation to protect, and are incentivized to act in the protocol's best interest to grow their pool's size. Liquidity Providers and Stakers are inherently trusting a Pool Delegate with their funds when they enter a Maple Pool. This means that they are trusting the Pool Delegate to handle funds and liquidation proceedings in a trusted manner.
#### 4. Oracle prices from Chainlink are considered to be reasonably accurate and frequently updated.
Since the oracle price is used in the liquidation module, it is assumed that these prices are accurate and cannot be exploited (e.g., flash loan oracle manipulation is impossible with an offchain oracle source).
#### 5. The Governor & Operational Admin are trusted actors.
Governor control is exercised via the on‑chain `GovernorTimelock`, whose controlling roles (e.g., proposer, executor, role admin) are held by Maple managed multisigs.
The Operational Admin is also a multisig controlled by Maple managed multisigs.
#### 6. Loans are expected to be instantiated with reasonable terms.
During the fuzz testing process, it was discovered that certain overflow conditions can occur in the amortization calculation of the loan, but only at "unreasonable" upper bounds (E.g., 100-year loans with 1 year payment intervals at 100% APR, for >$10b).
#### 7. Pool Delegates don't try to prevent withdrawals.
It's known that, in theory, withdrawal managers can be configured to unreasonable terms, for example, making the withdrawal window 1 second, or the cycle duration to be large,or pool delegates can set the withdrawal manager address to an invalid address. However, it's understood that pool delegates are trusted actors and they are working to making the pool well functioning.
# External Entry Points
## Overview
There are many actors that can interact with Maple's contracts, so this page serves the purpose to outline all possible entry points for each actor.
## Public Callable Functions
#### Pool
**Enter and Exit Functions**
* `Deposit`
* `DepositWithPermit`
* `Mint`
* `MintWithPermit`
* `Redeem`
* `Remove Shares`
* `RequestRedeem`
* `RequestWithdraw`
* `Withdraw`
**ERC20 functions**
* `approve`
* `transfer`
* `transferFrom`
#### FixedTermLoan
* `closeLoan`
* `makePayment`
* `postCollateral`
* `returnFunds`
* `skim`
#### OpenTermLoan
* `makePayment`
#### Globals
* `scheduleCall` - Although publicly callable, only calls scheduled by Governor and PoolDelegates can have state changing capabilities.
* `unscheduleCall`
#### Liquidator
* `liquidatePortion` - Used to perform liquidations.
#### PoolManager
* `depositCover`
## Permissioned Functions
#### FixedTermLoan
**Factory Permissioned Functions**
* `migrate`
* `setImplementation`
**Security Admin Permissioned Functions**
* `upgrade`
**Borrower Permissioned Functions**
* `acceptBorrower`
* `drawdownFunds`
* `proposeNewTerms`
* `rejectNewTerms`
* `removeCollateral`
* `setPendingBorrower`
**Lender Permissioned Functions**
* `acceptLender`
* `acceptNewTerms`
* `fundLoan`
* `impairLoan`
* `rejectNewTerms`
* `removeLoanImpairment`
* `repossess`
* `setPendingLender`
#### Globals
**Governor Permissioned Functions**
* `acceptGovernor`
* `activatePoolManager`
* `setBootstrapMint`
* `setCanDeployFrom`
* `setContractPause`
* `setDefaultTimelockParameters`
* `setFunctionUnpause`
* `setManualOverridePrice`
* `setMapleTreasury`
* `setMaxCoverLiquidationPercent`
* `setMigrationAdmin`
* `setMinCoverAmount`
* `setPendingGovernor`
* `setPlatformManagementFeeRate`
* `setPlatformOriginationFeeRate`
* `setPlatformServiceFeeRate`
* `setPriceOracle`
* `setProtocolPause`
* `setSecurityAdmin`
* `setTimelockWindow`
* `setTimelockWindows`
* `setValidBorrower`
* `setValidCollateralAsset`
* `setValidInstanceOf`
* `setValidPoolAsset`
* `setValidPoolDelegate`
* `setValidPoolDeployer`
* `unscheduleCall`
**Security Admin Permissioned Functions**
* `setContractPause`
* `setFunctionUnpause`
* `setProtocolPause`
**Pool Manager Permissioned Functions**
* `transferOwnedPoolManager`
#### PoolPermissionManager
**Governor Permissioned Functions**
* `configurePool`
* `setLenderAllowlist`
* `setLenderBitmaps`
* `setPermissionAdmin`
* `setPoolBitmaps`
* `setPoolPermissionLevel`
**Operational Admin Permissioned Functions**
* `configurePool`
* `setLenderAllowlist`
* `setLenderBitmaps`
* `setPermissionAdmin`
* `setPoolBitmaps`
* `setPoolPermissionLevel`
**Permission Admin Permissioned Functions**
* `setLenderBitmaps`
**Pool Delegate Permissioned Functions**
* `configurePool`
* `setLenderAllowlist`
* `setPoolBitmaps`
* `setPoolPermissionLevel`
#### PoolManager
**Factory Permissioned Functions**
* `migrate`
* `setImplementation`
**Governor Permissioned Functions**
* `finishCollateralLiquidation`
* `triggerDefault`
**Security Admin Permissioned Functions**
* `upgrade`
**Deployer Permissioned Functions**
* `addStrategy`
* `completeConfiguration`
* `setDelegateManagementFeeRate`
* `setLiquidityCap`
* `setWithdrawalManager`
**Pool Delegate Permissioned Functions**
* `acceptPoolDelegate`
* `addStrategy`
* `finishCollateralLiquidation`
* `setAllowedLender`
* `setDelegateManagementFeeRate`
* `setIsStrategy`
* `setLiquidityCap`
* `setOpenToPublic`
* `setPendingPoolDelegate`
* `triggerDefault`
* `withdrawCover`
**Globals Permissioned Functions**
* `setActive`
**Loan Manager Permissioned Functions**
* `requestFunds`
**Pool Permissioned Functions**
* `processRedeem`
* `removeShares`
* `requestRedeem`
**Disabled Functions**
* `processWithdraw`
* `requestWithdraw`
#### FixedTermLoanManager
**Factory Permissioned Functions**
* `migrate`
* `setImplementation`
**Governor Permissioned Functions**
* `impairLoan`
* `removeLoanImpairment`
* `setAllowedSlippage`
* `setMinRatio`
* `updateAccounting`
**Security Admin Permissioned Functions**
* `upgrade`
**Pool Delegate Permissioned Functions**
* `acceptNewTerms`
* `fund`
* `impairLoan`
* `rejectNewTerms`
* `removeLoanImpairment`
* `setAllowedSlippage`
* `setMinRatio`
* `updateAccounting`
**Pool Manager Permissioned Functions**
* `finishCollateralLiquidation`
* `triggerDefault`
**Loan Permissioned Functions**
* `claim`
#### WithdrawalManager (Queue)
**Factory Permissioned Functions**
* `migrate`
* `setImplementation`
**Governor Permissioned Functions**
* `processRedemptions`
* `removeRequest`
* `setManualWithdrawal`
**Operational Admin Permission Functions**
* `processRedemptions`
* `removeRequest`
* `setManualWithdrawal`
**Pool Delegate Permissioned Functions**
* `upgrade`
* `processRedemptions`
* `removeRequest`
* `setManualWithdrawal`
**Pool Manager Permissioned Functions**
* `addShares`
* `processExit`
* `removeShares`
**Redeemer Permissioned Functions**
* `processRedemptions`
* `removeShares`
**Security Admin Permissioned Functions**
* `upgrade`
**User Callable Functions**
* `removeSharesById`
#### OpenTermLoan
**Factory Permissioned Functions**
* `migrate`
* `setImplementation`
**Governor Permissioned Functions**
* `skim`
**Security Admin Permissioned Functions**
* `upgrade`
**Borrower Permissioned Functions**
* `acceptBorrower`
* `acceptNewTerms`
* `rejectNewTerms`
* `setPendingBorrower`
* `skim`
**Lender Permissioned Functions**
* `acceptLender`
* `callPrincipal`
* `fund`
* `impair`
* `proposeNewTerms`
* `rejectNewTerms`
* `removeCall`
* `removeImpairment`
* `repossess`
* `setPendingLender`
#### OpenTermLoanManager
**Factory Permissioned Functions**
* `migrate`
* `setImplementation`
**Governor Permissioned Functions**
* `impairLoan`
* `removeLoanImpairment`
**Security Admin Permissioned Functions**
* `upgrade`
**Pool Delegate Permissioned Functions**
* `callPrincipal`
* `fund`
* `impairLoan`
* `proposeNewTerms`
* `rejectNewTerms`
* `removeCall`
* `removeLoanImpairment`
**Pool Manager Permissioned Functions**
* `triggerDefault`
**Loan Permissioned Functions**
* `claim`
#### Aave Strategy
**Factory Permissioned Functions**
* `migrate`
* `setImplementation`
**Security Admin Permissioned Functions**
* `upgrade`
**Governor Permissioned Functions**
* `claimRewards`
* `deactivateStrategy`
* `impairStrategy`
* `reactivateStrategy`
* `setStrategyFeeRate`
**Operational Admin Permissioned Functions**
* `claimRewards`
* `deactivateStrategy`
* `impairStrategy`
* `reactivateStrategy`
* `setStrategyFeeRate`
**Pool Delegate Permissioned Functions**
* `claimRewards`
* `deactivateStrategy`
* `impairStrategy`
* `reactivateStrategy`
* `setStrategyFeeRate`
#### Basic Strategy
**Factory Permissioned Functions**
* `migrate`
* `setImplementation`
**Security Admin Permissioned Functions**
* `upgrade`
**Governor Permissioned Functions**
* `deactivateStrategy`
* `impairStrategy`
* `reactivateStrategy`
* `setStrategyFeeRate`
**Operational Admin Permissioned Functions**
* `deactivateStrategy`
* `impairStrategy`
* `reactivateStrategy`
* `setStrategyFeeRate`
**Pool Delegate Permissioned Functions**
* `deactivateStrategy`
* `impairStrategy`
* `reactivateStrategy`
* `setStrategyFeeRate`
#### Sky Strategy
**Factory Permissioned Functions**
* `migrate`
* `setImplementation`
**Security Admin Permissioned Functions**
* `upgrade`
**Governor Permissioned Functions**
* `deactivateStrategy`
* `impairStrategy`
* `reactivateStrategy`
* `setPsm`
* `setStrategyFeeRate`
**Operational Admin Permissioned Functions**
* `deactivateStrategy`
* `impairStrategy`
* `reactivateStrategy`
* `setPsm`
* `setStrategyFeeRate`
**Pool Delegate Permissioned Functions**
* `deactivateStrategy`
* `impairStrategy`
* `reactivateStrategy`
* `setPsm`
* `setStrategyFeeRate`
# Emergency Protocol Pause
### Pre-Upgrade Pausing
In the previous version of the protocol, there was a single switch that determined whether the protocol was paused. This switch had a global effect on all functions within the protocol. The security admin was responsible for triggering the global pause.
However, while effective as an emergency shut down, this architecture posed limitations for recovery strategies to return the system to normal operations from a paused state. To illustrate this limitation, consider a scenario where a pool delegate misconfigured a parameter that affects a pool, such as setting an inappropriate liquidation rate, which allows collateral to be traded at an unwanted discount.
In such a situation, the security admin would trigger a pause, which stops all operations. However, the fix requires either the governor or the pool delegate to reset the minimum ratio, which cannot be done in a paused state. Full recovery requires the following atomic actions to be performed:
```
1. The security admin calls unpause.
2. The governor or pool delegate calls setMinRatio.
```
Even in this simple scenario, the fix is an operational challenge, as there is no native way to ensure the atomicity of operations and it involves multiple parties and time-sensitive procedures. Therefore, the mechanism has been redesigned to address these issues.
### Granular Pausing
Addressing the flaws described above, the pausing has 3 separate setters that control the status.
1. Global pause
2. Per contract pause
3. Per function un-pause.
#### Global Pause
This structure is the same as the previous one, meaning a single switch that turns on or off the pause for the whole system, with the difference that now it can be called by either the `governor` or the `security admin`.
#### Per-Contract Pause
Additionally, a flag is added to pause specific contract instances. This way, if there's a problem in an isolated contract, there's no need to lock the whole protocol while a fix is underway. This granularity allows, for example, to have a specific loan paused, but not any of the others.
#### Per-Function Unpause
To help with the recovery, there's a third lever which indicates which function in a paused contract can be manually un-paused. This handles the case of "unknown unknowns", which is hard to know upfront which functions might need to be called as part of the solution.
With these three variables, the governor and security admin have a greater flexibility in dealing with emergencies, and also allows for the protocol to return to a functioning state sooner.
Back to the example where the ratio of a collateral asset is misconfigured in a pool, the new way of handling the issue:
```
1. Pause the whole protocol for investigation.
2. Turn on the `setMinRatio` function to be callable and adjust the parameter.
3. Once the fix is assured to be comprehensible, unpause the protocol.
```
Using the new pausing mechanism, the operational complexity is reduced and it becomes impossible to exploit the system while the fix is underway.
# Protocol Invariants
```
* Fixed Term Loan
* Invariant A: collateral balance >= _collateral`
* Invariant B: fundsAsset >= _drawableFunds`
* Invariant C: `_collateral >= collateralRequired_ * (principal_ - drawableFunds_) / principalRequested_`
* Fixed Term 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 G: unrealizedLosses == 0
* 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()
* Invariant M: paymentDueDate[payment] = loan.paymentDueDate()
* Invariant N: startDate[payment] <= loan.paymentDueDate() - loan.paymentInterval()
* Open Term Loan
* Invariant A: dateFunded <= datePaid, dateCalled, dateImpaired (if not zero)
* Invariant B: datePaid <= dateImpaired (if not zero)
* Invariant C: datePaid <= dateCalled (if not zero)
* Invariant D: calledPrincipal <= principal
* Invariant E: dateCalled != 0 -> calledPrincipal != 0
* Invariant F: paymentDueDate() <= defaultDate()
* Invariant G: getPaymentBreakdown == theoretical calculation
* Open Term Loan Manager
* Invariant A: accountedInterest + accruedInterest() == ∑loan.getPaymentBreakdown(block.timestamp) (minus fees)
* Invariant B: if no payments exist: accountedInterest == 0
* Invariant C: principalOut = ∑loan.principal()
* Invariant D: issuanceRate = ∑payment.issuanceRate
* Invariant E: unrealizedLosses <= assetsUnderManagement()
* Invariant F: if no impairments exist: unrealizedLosses == 0
* Invariant G: block.timestamp >= domainStart
* Invariant H: payment.startDate == loan.dateFunded() || loan.datePaid()
* Invariant I: payment.issuanceRate == theoretical calculation (minus management fees)
* Invariant J: payment.impairedDate >= payment.startDate
* Invariant K: assetsUnderManagement - unrealizedLosses - ∑outstandingValue(loan) ~= 0
* Invariant L: fundsAsset.balanceOf(OTLM) == 0
* Invariant M: fundsAsset.allowance(OTLM, address(loan)) == 0
* Pool (non-liquidating)
* Invariant A: totalAssets > fundsAsset balance of pool
* Invariant B: ∑balanceOfAssets == totalAssets (with rounding)
* Invariant C: totalAssets >= totalSupply (in non-liquidating scenario)
* Invariant D: convertToAssets(totalSupply) == totalAssets (with rounding)
* Invariant E: convertToShares(totalAssets) == totalSupply (with rounding)
* Invariant F: balanceOfAssets[user] >= balanceOf[user]
* Invariant G: ∑balanceOf[user] == totalSupply
*프로젝트로 돌아가기