The borrow
function in the LendingPool
contract is intended to enforce that users can borrow only up to a safe proportion of their collateral value. However, the current implementation of the collateralization check is flawed. In a scenario where a user has deposited an NFT valued at 100 ETH, the function allows the user to borrow 100 ETH even though the liquidation threshold is 80% (i.e. the maximum safe borrow should be 80 ETH). This means that the check does not properly enforce the intended risk management, compromising the protocol’s solvency.
Repo link:
https://github.com/Cyfrin/2025-02-raac/blob/89ccb062e2b175374d40d824263a4c0b601bcb7f/contracts/core/pools/LendingPool/LendingPool.sol#L344
The issue lies in the borrow function's collateralization check:
Current Check Analysis:
For example, if a user’s collateralValue is 100 ETH and they try to borrow an amount such that the total debt becomes 100 ETH:
userTotalDebt = 100 ETH
With a liquidation threshold of 80% (expressed as 8000 basis points), the check evaluates
collateralValue < userTotalDebt.percentMul(liquidationThreshold)
, which becomes:
100 ETH < 100 ETH * 0.8
100 ETH < 80 ETH
As this comparison is false, the function allows the borrow amount.
Intended Behavior:
In a correctly collateralized position, a user with 100 ETH of collateral should only be allowed to borrow 80 ETH. The check should ensure that the total debt does not exceed 80% of the collateral value. In other words, the condition should revert if:
userTotalDebt > collateralValue.percentMul(liquidationThreshold)
Because with 100 ETH collateral:
100 ETH > 100 ETH * 0.8
(which is true), the function should then revert.
Over-borrowing:
Users are able to borrow up to 100% of their collateral, far exceeding the intended safe borrow limit of 80%. This results in positions that are massively undercollateralized.
Increased Liquidation Risk:
Positions with 100% LTV are immediately at risk of liquidation, with little or no buffer to absorb price movements, potentially leading to rapid cascades of liquidations.
Protocol Solvency Concerns:
If borrowers take advantage of this flaw, the protocol might accumulate significant undercollateralized debt, risking insolvency and loss of funds.
Manual code review
Update the borrow function so that it properly compares the user’s total debt with the maximum allowable debt based on collateral:
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.