Summary
KittyVault::getUserVaultMeowllateralInEuros implementation user's collateral for this vault in euros. The mulDiv(uint256(collateralToUsdPrice) * EXTRA_DECIMALS, PRECISION)
function in the KittyVault::getUserVaultMeowllateralInEuros where division occurs after multiplication causes precision loss.
Vulnerability Details
function getUserVaultMeowllateralInEuros(address _user) external view returns (uint256) {
(, int256 collateralToUsdPrice, , , ) = i_priceFeed.latestRoundData();
(, int256 euroPriceFeedAns, , ,) = i_euroPriceFeed.latestRoundData();
@> uint256 collateralAns = getUserMeowllateral(_user).mulDiv(uint256(collateralToUsdPrice) * EXTRA_DECIMALS, PRECISION);
@> return collateralAns.mulDiv(uint256(euroPriceFeedAns) * EXTRA_DECIMALS, PRECISION);
}
Impact
This results to lose of funds in the protocol when the KittyVault::getUserVaultMeowllateralInEuros function is implemented.
Tools Used
manual review
Recommendations
Avoiding unnecessary multiplication or division that could lead to inaccuracies. The function can be written better below
function getUserVaultMeowllateralInEuros(address _user) external view returns (uint256) {
uint256 userCollateralUsd = getUserMeowllateral(_user);
(, int256 collateralToUsdPrice, , , ) = i_priceFeed.latestRoundData();
(, int256 euroToUsdPrice, , ,) = i_euroPriceFeed.latestRoundData();
uint256 userCollateralInUsd = userCollateralUsd.mulDiv(uint256(collateralToUsdPrice), PRECISION);
uint256 userCollateralInEuros = userCollateralInUsd.mulDiv(uint256(euroToUsdPrice), PRECISION);
return userCollateralInEuros;
}