The Standard

The Standard
DeFiHardhat
20,000 USDC
View results
Submission Details
Severity: medium
Valid

Incorrect Comparison in SmartVaultV3's `canRemoveCollateral()`

Summary

canRemoveCollateral() checks for determining whether collateral can be removed based on the vault's minted EUROs and deposited collateral. This could result in incorrect outcomes when attempting to remove collateral.

Vulnerability Details

127 function canRemoveCollateral(ITokenManager.Token memory _token, uint256 _amount) private view returns (bool) {
128 if (minted == 0) return true;
129 uint256 currentMintable = maxMintable();
130 uint256 eurValueToRemove = calculator.tokenToEurAvg(_token, _amount);
//@audit invalid comparison as both terms represent different things
131 return currentMintable >= eurValueToRemove &&
132 minted <= currentMintable - eurValueToRemove;
133 }

https://github.com/Cyfrin/2023-12-the-standard/blob/main/contracts/SmartVaultV3.sol#L127

A user wants to remove collateral, calls removeCollateralNative() and removeCollateral which further execute above mentioned canRemoveCollateral() to check if vaults have enough tokens corresponding to minted

minted- total minted euros from the vault
currentMintable- max number of euros that can be minted which depends on the totalcollateral and collateralRate i.e ((totalcollateral * HUNDRED_PC) / collateralRate )

eurValueToRemove- collateral value that user want to remove.

As eurValueToRemove does not represent the same unit as of minted and currentMintable. it will give incorrect results (Generally false)

suppose for a vault

If
minted = 0
currentMintable = 100USD
eurValueToRemove = 110USD
The condition (100 - 110 >= 0) will return false, erroneously denying the removal of collateral despite over-collateralization.

Impact

The incorrect logic within canRemoveCollateral() may cause the removeCollateral() function to revert even when the vault is overcollateralized

Tools Used

Manual

Recommendations

Instead of eurValueToRemove use ((eurValueToRemove * HUNDRED_PC) / collateralRate )

Updates

Lead Judging Commences

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

canRemoveCollateral

Support

FAQs

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