liquidateDefaultedLoanWithIncentive sends the collateral to the wrong account
The liquidation function sends collateral to the lender instead of the liquidator, so liquidators receive no incentive to liquidate. This can lead to missed liquidations and incorrect accounting in the lending pool.
0x3b Follow with 0x73696d616f, 0xAnmol and 15 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-04-teller-finance-judging/issues/46
Found by
0x3b, 0x73696d616f, 0xAnmol, 0xDjango, AuditorPraise, EgisSecurity, KupiaSec, Timenov, blockchain555, bughuntoor, cryptic, jovi, kennedy1030, merlin, no, pkqs90, samuraii77, y4y
Summary
liquidateDefaultedLoanWithIncentive sends the collateral to the Lender - LenderCommitmentGroup (LCG) instead of the liquidator. Liquidators will not be incentivized to liquidate.
Vulnerability Detail
liquidateDefaultedLoanWithIncentive is intended to liquidate bids, where liquidators pay off the debt and receive the collateral. However, currently the collateral is sent to the lender - LCG, because lenderCloseLoanWithRecipient includes msg.sender as its second parameter but does not utilize it:
function lenderCloseLoanWithRecipient(uint256 _bidId, address _collateralRecipient) external {
_lenderCloseLoanWithRecipient(_bidId, _collateralRecipient);
}
function _lenderCloseLoanWithRecipient(uint256 _bidId, address _collateralRecipient) internal acceptedLoan(_bidId, "lenderClaimCollateral") {
require(isLoanDefaulted(_bidId), "Loan must be defaulted.");
Bid storage bid = bids[_bidId];
bid.state = BidState.CLOSED;
address sender = _msgSenderForMarket(bid.marketplaceId);
require(sender == bid.lender, "Only lender can close loan");
//@audit we directly call `lenderClaimCollateral`
collateralManager.lenderClaimCollateral(_bidId);
}
lenderClaimCollateral in its place withdraws the collateral directly to the lender - LCG, without updating totalPrincipalTokensRepaid. Some effects:
- Liquidators will gain 0 profits, so they will not liquidate.
- LPs suffer losses as liquidations are not carried out, and returned collateral from liquidations is not accrued as
totalPrincipalTokensRepaid, increasing utilization, eventually bricking the contract.
Impact
Liquidators will not be incentivized to liquidate and incorrect accounting occurs inside LCG.
Code Snippet
function _lenderCloseLoanWithRecipient(
uint256 _bidId,
address _collateralRecipient // @audit never used
) internal acceptedLoan(_bidId, "lenderClaimCollateral") {
require(isLoanDefaulted(_bidId), "Loan must be defaulted.");
Bid storage bid = bids[_bidId];
bid.state = BidState.CLOSED;
address sender = _msgSenderForMarket(bid.marketplaceId);
require(sender == bid.lender, "Only lender can close loan");
collateralManager.lenderClaimCollateral(_bidId);
}
Tool used
Manual Review
Recommendation
Ensure _lenderCloseLoanWithRecipient sends the funds to _collateralRecipient.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/teller-protocol/teller-protocol-v2-audit-2024/pull/16/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
Likely the function _lenderCloseLoanWithRecipient ignores the _collateralRecipient parameter and always sends collateral to the lender.
Impact
Liquidators will not be incentivized to liquidate, leading to missed liquidations and incorrect accounting that could eventually brick the contract.
What the attacker needed
A defaulted loan; a liquidator willing to repay debt
The fix
The issue was fixed by ensuring the collateral is sent to the _collateralRecipient.
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.
In a lending system, if a borrower fails to repay, a liquidator can step in, pay off the debt, and receive the collateral as a reward. Here, a mistake in the code sends that collateral to the original lender instead of the liquidator, so no one is rewarded for liquidating. This can cause bad debt to pile up and break the system's accounting.
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.