This repository has been archived by the owner on May 26, 2023. It is now read-only.
berndartmueller - Repaying loans with small amounts of debt tokens can lead to underflowing in the roll
function
#263
Labels
Has Duplicates
A valid issue with 1+ other issues describing the same vulnerability
Medium
A valid Medium severity issue
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
berndartmueller
medium
Repaying loans with small amounts of debt tokens can lead to underflowing in the
roll
functionSummary
Due to precision issues when repaying a loan with small amounts of debt tokens, the
loan.amount
can be reduced whereas theloan.collateral
remains unchanged. This can lead to underflowing in theroll
function.Vulnerability Detail
The
decollateralized
calculation in therepay
function rounds down to zero if therepaid
amount is small enough. This allows iteratively repaying a loan with very small amounts of debt tokens without reducing the collateral.The consequence is that the
roll
function can revert due to underflowing thenewCollateral
calculation once theloan.collateral
is greater thancollateralFor(loan.amount, req.loanToCollateral)
(loan.amount
is reduced by repaying the loan)As any ERC-20 tokens with different decimals can be used, this precision issue is amplified if the decimals of the collateral and debt tokens differ greatly.
Impact
The
roll
function can revert due to underflowing thenewCollateral
calculation if therepay
function is (iteratively) called with small amounts of debt tokens.Code Snippet
Cooler.sol#L114
Cooler.sol#L139
Calculating
newCollateral
in L139 can potentially revert due to underflowing ifloan.collateral
is greater than the required collateral (collateralFor(loan.amount, req.loanToCollateral)
).A malicious user can use the imprecision issue in the
repay
function in L114 to repay small amounts of debt tokens (loan.collateral * repaid
<loan.amount
), which leads to no reduction of loan collateral, whereas theloan.amount
is reduced.This will prevent the
roll
function from being called.Tool used
Manual Review
Recommendation
Consider preventing the loan from being repaid if the amount of returned collateral tokens is zero (i.e.,
decollateralized == 0
).The text was updated successfully, but these errors were encountered: