Skip to content
Business logic Audit finding Intermediate

Dust amounts can cause payments to fail, leading to default

The repayment function requires the exact remaining loan amount; if a dust payment is sent first, the subtraction underflows and reverts. An attacker can front-run a borrower's final payment with a dust transfer, causing the borrower to default and lose collateral.

kiki_dev Follow with HollaDieWaldfee, IllIllI and 1 other

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-01-cooler-judging/issues/218

Found by

kiki_dev, HollaDieWaldfee, IllIllI, ak1

Summary

Dust amounts can cause payments to fail, leading to default

Vulnerability Detail

In order for a loan to close, the exact right number of wei of the debt token must be sent to match the remaining loan amount. If more is sent, the balance underflows, reverting the transaction.

Impact

An attacker can send dust amounts right before a loan is due, front-running any payments also destined for the final block before default. If the attacker's transaction goes in first, the borrower will be unable to pay back the loan before default, and will lose thier remaining collateral. This may be the whole loan amount.

Code Snippet

If the repayment amount isn't exactly the remaining loan amount, and instead is more (due to the dust payment), the subtraction marked below will underflow, reverting the payment:

Solidity
// File: src/Cooler.sol : Cooler.repay()   #1

108        function repay (uint256 loanID, uint256 repaid) external {
109            Loan storage loan = loans[loanID];
110    
111            if (block.timestamp > loan.expiry) 
112                revert Default();
113            
114            uint256 decollateralized = loan.collateral * repaid / loan.amount;
115    
116           if (repaid == loan.amount) delete loans[loanID];
117           else {
118 @>             loan.amount -= repaid;
119                loan.collateral -= decollateralized;
120            }
121    
122            debt.transferFrom(msg.sender, loan.lender, repaid);
123            collateral.transfer(owner, decollateralized);
124:       }

https://github.com/sherlock-audit/2023-01-cooler/blob/main/src/Cooler.sol#L108-L124

Tool used

Manual Review

Recommendation

Only collect and subtract the minimum of the current loan balance, and the amount specified in the repaid variable

Discussion

hrishibhat

Sponsor comment:

Good spot. Niche case.

The original report as published on Sherlock, by kiki_dev. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 repayment logic subtracts the repaid amount from the loan balance without checking if the repaid amount exceeds the remaining balance, causing an underflow.

Impact

An attacker could cause a borrower to default and lose their remaining collateral, which may be the whole loan amount.

What the attacker needed

Attacker can send dust to the contract; borrower repays near deadline; attacker front-runs the repayment

The fix

The repayment function should only collect and subtract the minimum of the current loan balance and the amount specified in the repaid variable.

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.

A smart contract loan requires you to pay back exactly what you owe. If someone sends a tiny amount (dust) to the contract just before you pay, your payment becomes too large and the contract rejects it. This can make you miss your deadline and lose your collateral.

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.

More from Cooler Update

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.