The LendingPool
contract allows users to borrow up to 100% of their collateral value. This completely bypasses the concept of a liquidation threshold, which is designed to protect the protocol from bad debt. By allowing borrowing up to 100%, the protocol becomes extremely vulnerable to even small price drops in the collateral asset, as there is no buffer to absorb losses before the debt becomes undercollateralized.
The core function of a lending protocol is to ensure that borrowed amounts are always sufficiently collateralized. The liquidation threshold represents the percentage of the collateral value below which a loan is considered undercollateralized and can be liquidated. This threshold provides a safety margin to protect the protocol against losses in case the collateral value decreases.
The borrow
function in the LendingPool
contract calculates the user's total debt and checks if it's less than the user's collateral value multiplied by the liquidationThreshold
. However, the liquidationThreshold
is not being enforced correctly. Users are able to borrow up to 100% of their collateral.
The crucial flaw is that the userTotalDebt
calculation includes the amount the user is about to borrow. The check against liquidationThreshold
happens after the debt has already been increased by the borrow amount. This means the borrow amount is already added to the user debt when the collateral is checked. As a result, the user can borrow the full amount of the collateral. The collateral is checked against the debt after the borrow has been added to the debt. Since it is added, the check will always pass.
Bad Debt: The most significant impact is the increased risk of bad debt. Even small price drops in the collateral can leave the protocol holding undercollateralized loans.
Loss of Funds: If the collateral value drops significantly, the protocol may not be able to recover the full borrowed amount during liquidation, leading to a loss of funds for the protocol and its lenders.
System Instability: The lack of a liquidation threshold makes the protocol highly susceptible to market volatility and can lead to rapid erosion of the protocol's reserves.
Alice deposits 50_000 USD worth of NFT collateral.
The LendingPool
allows Alice to borrow up to 50_000 USD worth of a crvUSD.
Alice borrows 50_000 USD worth of a crvUSD.
The price of NFT drops by even a small percentage (e.g., 5%).
Alice's loan is now undercollateralized. Alice has no incentive to repay, as the value of her collateral is now less than her debt.
The protocol is left with bad debt.
Use this guide to intergrate foundry into your project: foundry
Create a new file FortisAudits.t.sol
in the test
directory.
Add the following gist code to the file: Gist Code
Run the test using forge test --mt test_FortisAudits_BorrowingUpTo100Percent -vvvv
.
Manual code review.
The borrow
function should be modified to enforce the liquidation threshold before the borrow amount is added to the user's debt. The check should be against the current debt plus the requested borrow amount. This corrected logic will ensure that users cannot borrow beyond the liquidation threshold, protecting the protocol from undercollateralized debt and making all the loans overcollateralized.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.