The borrow function in the lending contract contains a logic flaw in how it verifies collateral sufficiency. Instead of using the actual collateral value to determine whether a user can borrow, the function incorrectly applies the liquidation threshold check against the user's debt. This allows borrowers to extract more funds than they should be entitled to, leading to potential insolvency risks for the lending protocol.
The vulnerability exists in the following code segment:
The conditional check should ensure that collateralValue is sufficient to cover userTotalDebt based on the liquidation threshold. However, it erroneously uses userTotalDebt.percentMul(liquidationThreshold), which leads to an incorrect threshold calculation.
The issue arises because:
liquidationThreshold is set to 80% (80_00 in basis points)
The check compares if collateral value is less than (debt * 80%)
This effectively allows users to borrow up to 125% of their collateral value (100/80 = 1.25)
For example, with a collateral value of 100 crvusd
Correct implementation should allow borrowing up to 80 USDC (80% of collateral)
Current implementation allows borrowing up to 125 USDC because:
125 crvusd debt * 80% = 100 crvusd
100 crvusd collateral >= 100 crvusd (debt * threshold)
The check passes incorrectly
The PoC demonstrates this by:
Depositing an NFT worth 100 crvusd as collateral
Successfully borrowing 125 crvusd
Creating an undercollateralized position that should not be allowed
it allows users to borrow more than the protocol's intended limits
Users can mints NFTs and deposit it then borrow to gain the profit draining the lending pool.
Manual/Hardhat
##PoC
In LendingPool.test.js
Compare against the maximum allowed borrow amount:
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.