`Cooler.roll()` wouldn't work as expected when `newCollateral = 0`
The roll function transfers additional collateral, but when the calculated new collateral is zero, some tokens revert on zero-value transfers, causing roll to fail. This can also let a borrower extend the loan without cost, delaying the lender's ability to default.
hansfriese Follow with cccz, Allarious and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-01-cooler-judging/issues/320
Found by
hansfriese, cccz, Allarious, csanuragjain
Summary
Cooler.roll() is used to increase the loan duration by transferring the additional collateral.
But there will be some problems when newCollateral = 0.
Vulnerability Detail
function roll (uint256 loanID) external {
Loan storage loan = loans[loanID];
Request memory req = loan.request;
if (block.timestamp > loan.expiry)
revert Default();
if (!loan.rollable)
revert NotRollable();
uint256 newCollateral = collateralFor(loan.amount, req.loanToCollateral) - loan.collateral;
uint256 newDebt = interestFor(loan.amount, req.interest, req.duration);
loan.amount += newDebt;
loan.expiry += req.duration;
loan.collateral += newCollateral;
collateral.transferFrom(msg.sender, address(this), newCollateral); //@audit 0 amount
}
In roll(), it transfers the newCollateral amount of collateral to the contract.
After the borrower repaid most of the debts, loan.amount might be very small and newCollateral for the original interest might be 0 because of the rounding issue.
Then as we can see from this one, some tokens might revert for 0 amount and roll() wouldn't work as expected.
Impact
There will be 2 impacts.
- When the borrower tries to extend the loan using
roll(), it will revert with the weird tokens whennewCollateral = 0. - After the borrower noticed he couldn't repay anymore(so the lender will default the loan), the borrower can call
roll()again whennewCollateral = 0.
In this case, the borrower doesn't lose anything but the lender must wait for req.duration again to default the loan.
Code Snippet
https://github.com/sherlock-audit/2023-01-cooler/blob/main/src/Cooler.sol#L146
Tool used
Manual Review
Recommendation
I think we should handle it differently when newCollateral = 0.
According to impact 2, I think it would be good to revert when newCollateral = 0.
Discussion
hrishibhat
Sponsor comment:
Good spot. Niche case.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the roll function does not handle the case where the calculated new collateral is zero, leading to a zero-value token transfer that some tokens reject.
Impact
For tokens that revert on zero-value transfers, roll will fail; additionally, a borrower can call roll with zero new collateral to extend the loan without cost, delaying default and harming the lender.
What the attacker needed
Loan is rollable; newCollateral rounds to 0; token reverts on zero transfer
The fix
The roll function should revert when newCollateral is zero.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a borrower wants to extend a loan, the smart contract asks for more collateral. If the loan is almost paid off, the extra collateral needed can round down to zero. Some digital tokens refuse to transfer zero amounts, so the extension fails. Also, a borrower who cannot repay could keep extending the loan for free, making the lender wait longer.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.