Core Contracts

Regnum Aurum Acquisition Corp
HardhatReal World AssetsNFT
77,280 USDC
View results
Submission Details
Severity: high
Valid

Incorrect calculations in the `LendingPool` contract for checking whether a user has enough collateral.

Summary

The withdrawNFT functions have incorrect calculations in the if condition for collateral.

Vulnerability Details

withdrawNFT function :-

In this function, userDebt.percentMul(liquidationThreshold) is compared to collateralValue - nftValue, which is incorrect.

By withdrawing the NFT, the collateral value decreases. The debt should be lower than liquidationThreshold % of the new collateral value after withdrawing the NFT.

@>> if (collateralValue - nftValue < userDebt.percentMul(liquidationThreshold)) {
revert WithdrawalWouldLeaveUserUnderCollateralized();
}

https://github.com/Cyfrin/2025-02-raac/blob/89ccb062e2b175374d40d824263a4c0b601bcb7f/contracts/core/pools/LendingPool/LendingPool.sol#L302

Proof of code :-

lets take an example

liquidationThreshold = 80 %

collateralValue= 100

userDebt=70

Initially, the user has enough collateral for the debt.

Now follow the calculation for , nftValue=40

collateralValue - nftValue=60 anduserDebt.percentMul(liquidationThreshold)) =80% *70 =56

the new colletral amount = 60 , and the debt amount is userDebt=70

60 < 56 will be false , but the user has 70 debt and colletral = 60 , it should be UnderCollateralized.

Impact

The user cannot fully utilize the collateral value because userDebt.percentMul(liquidationThreshold) will be much lower than the actual liquidationThreshold of the collateral value.

The value of debt will be greater than the liquidationThreshold, which is incorrect.

Recommendations

withdrawNFT function :-

-if (collateralValue - nftValue < userDebt.percentMul(liquidationThreshold)) {
+if ((collateralValue - nftValue).percentMul(liquidationThreshold) < userDebt) {
revert WithdrawalWouldLeaveUserUnderCollateralized();
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 3 months ago
Submission Judgement Published
Validated
Assigned finding tags:

LendingPool::borrow as well as withdrawNFT() reverses collateralization check, comparing collateral < debt*0.8 instead of collateral*0.8 > debt, allowing 125% borrowing vs intended 80%

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.