plane-arrivaldApp Security Guidelines: Lending

Threat 1: Vicious Cycle of Mass Liquidation Leading to Collateral Price Drops and Triggering Further Liquidations

A large-scale liquidation triggers a sharp drop in the price of collateral assets, which in turn causes a chain reaction that triggers more position liquidations. This vicious cycle results in the loss of users' collateral assets and the creation of bad debt for the protocol.

Impact

Medium

It forces excessive collateral losses on users and, in severe cases, can leave the protocol with unrecoverable bad debt, leading to system insolvency. The probability of occurrence exists depending on market conditions, and past cases37 show that the damage can be fatal, so it is rated Medium.

Guideline

  • Chain Reaction39 Prevention Mechanism

    • Restrict collateral repayment in Recovery Mode.

      function _requireValidAdjustmentInCurrentMode(...) {...
           // Collateral repayment is not allowed in recoveryMode
           if (_isRecoveryMode) {
              require(_collWithdrawal == 0, "BorrowerOps: Collateral withdrawal not permitted in Recovery Mode");
              if (_isDebtIncrease) {
                  _requireICRisAboveCCR(newICR);
                  _requireNewICRisAboveOldICR(newICR, oldICR);
              }
              ...
      }
      
      // Closing a loan position is not allowed in recoveryMode
      function closeDen(...) {
      ...
      require(!isRecoveryMode, "BorrowerOps: Operation not permitted during Recovery Mode");
      }
  • Dynamic Risk Parameters

    • Mechanism to lower the liquidation threshold during recoveryMode.

      function liquidateDens(..) {
      
      // In normal mode
      if (ICR <= _LSP_CR_LIMIT) {
          singleLiquidation = _liquidateWithoutSP(denManager, account);
          _applyLiquidationValuesToTotals(totals, singleLiquidation);
      } else if (ICR < applicableMCR) {
          singleLiquidation = _liquidateNormalMode(
              denManager,
              account,
              debtInStabPool,
              denManagerValues.sunsetting
          );
          debtInStabPool -= singleLiquidation.debtToOffset;
          _applyLiquidationValuesToTotals(totals, singleLiquidation);
      } else break; // break if the loop reaches a Den with ICR >= MCR
      
      // In recoveryMode
      // Check recoveryMode (CCR > TCR) && check if it's a liquidation target (ICR < TCR)
      
      {
          uint256 TCR = BeraborrowMath._computeCR(entireSystemColl, entireSystemDebt);
          if (TCR >= borrowerOperations.BERABORROW_CORE().CCR() || ICR >= TCR)
              break;
      }
      
      // If recoveryMode is on and the Den's ICR is less than TCR, proceed with liquidation
      singleLiquidation = _tryLiquidateWithCap(
          denManager,
          account,
          debtInStabPool,
          _getApplicableMCR(account, denManagerValues),
          denManagerValues.price
      );

Best practice

LiquidationManager.solarrow-up-right

BorrowOperations.solarrow-up-right


Threat 2: ERC-4626 Inflation34 Attack

When the total supply of an ERC-4626 vault is nearly zero, an attacker deposits a very small amount of shares and then directly transfers assets to the vault to inflate the value of their shares. Subsequent users who deposit will receive far fewer shares due to the inflated share price, effectively having their assets stolen by the attacker. Similar past casesarrow-up-right exist.

https://docs.openzeppelin.com/contracts/5.x/erc4626#defending_with_a_virtual_offsetarrow-up-right

Impact

Low

If it occurs, it would have a significant impact, but the likelihood of the LSP supply being zero, the attacker inflating the share value, and a subsequent user depositing tokens is low, so it is rated Low.

Guideline

Best Practice

LiquidStabilityPool.solarrow-up-right

LiquidStabilityPool.solarrow-up-right

BaseCollateralVault.solarrow-up-right

Custom Code


Threat 3: Incompleteness of Recovery Mode Status Judgment and Transition Mechanism

An error in the logic for judging or transitioning into Recovery Mode can make the system appear to be functioning normally when it is actually in a dangerous state, allowing for additional bad loans and magnifying losses.

If an attacker bypasses the collateral ratio (ICR/TCR) verification logic and takes out an excessive loan while the system is in Recovery Mode36, that loan is at very high risk of becoming bad debt.

Impact

Low

A failure in the Recovery Mode transition logic can lead to bad loans, causing potential losses for the protocol. There have been cases of errorsarrow-up-right during Recovery Mode entry in MakerDAO's MCD system. However, strong safeguards such as a ban on collateral withdrawal and multiple collateral ratio (ICR/TCR) verifications are already in place, making the probability of a successful attack low. Therefore, it is rated Low.

Guideline

  • Simultaneous verification of individual ICR (Individual Collateral Ratio) and system TCR (Total Collateral Ratio) for all position changes.

  • Mode Transition Stability35

    • Ensure the latest prices and interest are reflected when calculating TCR.

    • Bulk update all position states during a mode transition.

Best Practice

BorrowerOperations.solarrow-up-right

BeraborrowOperations.solarrow-up-right


Threat 4: System Integrity Violation due to Owner Privilege Abuse

If the Owner abuses their authority to maliciously change the protocol's critical parameters, users will suffer direct economic losses, such as paying unexpected excessive fees and facing increased risks of asset liquidation.

Impact

Low

Malicious parameter changes by the Owner are a serious threat that can cause direct financial loss to users. As seen in past DeFi casesarrow-up-right, this includes not only technical vulnerabilities but also 'governance risks37' where a trusted core group turns malicious. However, since these privileges are controlled by multi-signature and Timelock mechanisms, the actual probability of success is low, so it is rated Low.

Guideline

  • Decentralization of Governance Authority

  • Parameter Change Restrictions

    • Limit the maximum increase/decrease when changing MCR and CCR

    • Limit the number of monthly fee changes

    • Require community vote for system address changes

  • Interest Rate Governance Protection

    • Apply a 7-day timelock for interest rate changes

    • Limit the range of interest rate changes

    • Require community vote for interest rate changes

  • Interest Calculation Transparency

    • Make all interest calculations publicly verifiable on-chain

    • Prevent overflow in the interest accrual logic

    • Ensure traceability and auditability of interest rate change history

Best Practice

DenManager.solarrow-up-right

DenManager.solarrow-up-right


Last updated