liquidateDefaultedLoanWithIncentive can be gamed to avoid paying loans interest
The liquidation function in the LenderCommitmentGroup contract calculates the amount due using only the principal, ignoring accrued interest. A malicious user could exploit this to avoid paying interest when liquidating a defaulted loan, shifting the loss to the lending pool.
0xDjango Follow with 0xrobsol, EgisSecurity and 2 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-04-teller-finance-judging/issues/121
Found by
0xDjango, 0xrobsol, EgisSecurity, jovi, no
Summary
The amountDue calculation at the liquidateDefaultLoanWithIncentive function at the LenderCommitmentGroup contract calls getAmountOwedForBid with a false argument, which means it considers the principal lent as owed but not the interest that was accrued during the borrow period. This can be gamed by malicious users to avoid paying loans interest.
Vulnerability Detail
Take a look at the getAmountOwedForBid function:
function getAmountOwedForBid(uint256 _bidId, bool _includeInterest)
public
view
virtual
returns (uint256 amountOwed_)
{
Payment memory amountOwedPayment = ITellerV2(TELLER_V2)
.calculateAmountOwed(_bidId, block.timestamp);
amountOwed_ = _includeInterest
? amountOwedPayment.principal + amountOwedPayment.interest
: amountOwedPayment.principal;
}
Notice it will only return the principal amount if a false boolean is passed as the second argument of a call to it.
At the liquidateDefaultedLoanWithIncentive function, this is exactly what happens:
function liquidateDefaultedLoanWithIncentive(
uint256 _bidId,
int256 _tokenAmountDifference
) public bidIsActiveForGroup(_bidId) {
uint256 amountDue = getAmountOwedForBid(_bidId, false);
...
}
This means the amountDue does not include interest.
However, this is not on par with TellerV2 contract, as its liquidation function does repay both the owed principal and the interest. This can be seen at the following code snippet:
function _liquidateLoanFull(uint256 _bidId, address _recipient)
internal
acceptedLoan(_bidId, "liquidateLoan")
{
...
_repayLoan(
_bidId,
Payment({ principal: owedPrincipal, interest: interest }),
owedPrincipal + interest,
false
);
...
}
Impact
Users can arbitrarily decide to liquidate repaying interest or not back to Teller lenders by liquidating via the TellerV2 contract or via LenderCommitmentGroups contracts. LenderCommitmentGroups's liquidation function spreads bad debt to the whole lending pool while benefitting the liquidator.
Code Snippet
Tool used
Manual Review
Recommendation
Ensure the calculation of amountDue accounts for interest when repaying a liquidated bid. The following change could be done at the code:
uint256 amountDue = getAmountOwedForBid(_bidId, true);
Discussion
ethereumdegen
Yes we will fix this - we can just set that to a 'true' and make sure we do not double count interest ( remove totalPrincipalTokensRepaid += ) as per the PR for that separate issue
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/teller-protocol/teller-protocol-v2-audit-2024/pull/34/files
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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
The liquidateDefaultedLoanWithIncentive function calls getAmountOwedForBid with a false argument for including interest, so the calculated amountDue excludes interest.
Impact
Liquidators could avoid paying interest, causing bad debt to be spread across the lending pool while benefiting the liquidator.
What the attacker needed
A defaulted loan in a LenderCommitmentGroup
The fix
The issue was fixed by changing the calculation to include interest and ensuring interest is not double-counted.
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 defaults, the lender can liquidate the loan to recover funds. Normally, the liquidator must repay both the principal (the original amount borrowed) and the interest that has built up. Here, a mistake in one contract meant the liquidator only had to repay the principal, so they could skip paying interest and leave the lenders short.
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.