Boost _ Folks Finance 33870 - [Smart Contract - Low] convToRepayBorrowAmount calculation is incorrec
Description
Description
File: /contracts/hub/logic/LiquidationLogic.sol
function calcLiquidationAmounts(
DataTypes.LiquidationLoansParams memory loansParams,
mapping(bytes32 => LoanManagerState.UserLoan) storage userLoans,
mapping(uint16 => LoanManagerState.LoanType) storage loanTypes,
IHubPool collPool,
IOracleManager oracleManager,
uint256 maxRepayBorrowValue,
uint256 maxAmountToRepay
) external view returns (DataTypes.LiquidationAmountParams memory liquidationAmounts) {
LoanManagerState.UserLoan storage violatorLoan = userLoans[loansParams.violatorLoanId];
uint8 collPoolId = loansParams.collateralPoolId;
uint8 borrPoolId = loansParams.borrowPoolId;
LoanManagerState.UserLoanCollateral storage violatorLoanCollateral = violatorLoan.collaterals[collPoolId];
LoanManagerState.LoanPool storage borrowLoanPool = loanTypes[violatorLoan.loanTypeId].pools[borrPoolId];
LoanManagerState.UserLoanBorrow storage violatorLoanBorrow = violatorLoan.borrows[borrPoolId];
DataTypes.PriceFeed memory borrPriceFeed = oracleManager.processPriceFeed(borrPoolId);
DataTypes.PriceFeed memory collPriceFeed = oracleManager.processPriceFeed(collPoolId);
uint256 repayBorrowAmount;
{
uint256 maxRepayBorrowAmount = MathUtils.calcAssetAmount(
maxRepayBorrowValue * MathUtils.ONE_10_DP,
borrPriceFeed.price,
borrPriceFeed.decimals
);
repayBorrowAmount = Math.min(maxAmountToRepay, Math.min(maxRepayBorrowAmount, violatorLoanBorrow.balance));
}
{
highliight #1 -->@ uint256 seizeUnderlyingCollateralAmount = repayBorrowAmount.convToSeizedCollateralAmount(
collPriceFeed.price,
collPriceFeed.decimals,
borrPriceFeed.price,
borrPriceFeed.decimals,
borrowLoanPool.liquidationBonus
);
uint256 collDepositInterestIndex = collPool.getUpdatedDepositInterestIndex();
uint256 violatorUnderlingCollateralBalance = violatorLoanCollateral.balance.toUnderlingAmount(
collDepositInterestIndex
);
highliight #2 -->@ if (seizeUnderlyingCollateralAmount > violatorUnderlingCollateralBalance) {
seizeUnderlyingCollateralAmount = violatorUnderlingCollateralBalance;
repayBorrowAmount = seizeUnderlyingCollateralAmount.convToRepayBorrowAmount(
collPriceFeed.price,
collPriceFeed.decimals,
borrPriceFeed.price,
borrPriceFeed.decimals,
borrowLoanPool.liquidationBonus
);
}
liquidationAmounts.repayBorrowAmount = repayBorrowAmount;
liquidationAmounts.repayBorrowToCollateralFAmount = repayBorrowAmount.convToCollateralFAmount(
collPriceFeed.price,
collPriceFeed.decimals,
borrPriceFeed.price,
borrPriceFeed.decimals,
collDepositInterestIndex
);
liquidationAmounts.seizeCollateralFAmount = seizeUnderlyingCollateralAmount.toFAmount(
collDepositInterestIndex
);
}
}
File: /contracts/hub/libraries/MathUtils.sol
function convToSeizedCollateralAmount(
uint256 borrowAmount,
uint256 collPrice,
uint8 collDecimals,
uint256 borrPrice,
uint8 borrDecimals,
uint256 liquidationBonus
) internal pure returns (uint256) {
return
Math.mulDiv(
convertAssetAmount(borrowAmount, borrPrice, borrDecimals, collPrice, collDecimals),
(MathUtils.ONE_4_DP + liquidationBonus),
MathUtils.ONE_4_DP
);
}
function convToRepayBorrowAmount(
uint256 collAmount,
uint256 collPrice,
uint8 collDecimals,
uint256 borrPrice,
uint8 borrDecimals,
uint256 liquidationBonus
) internal pure returns (uint256) {
return
Math.mulDiv(
convertAssetAmount(collAmount, collPrice, collDecimals, borrPrice, borrDecimals),
(MathUtils.ONE_4_DP + liquidationBonus),
MathUtils.ONE_4_DP
);
}Impact
Rationale for Severity
Proof of concept
Proof-of-Concept
PreviousBoost _ Folks Finance 33869 - [Smart Contract - Medium] loanIds are easy to reproduce and front-runnNextBoost _ Folks Finance 33880 - [Smart Contract - Medium] Front-Running Vulnerability in createUserLoa
Last updated
Was this helpful?