_repayLoan will fail if lender is blacklisted
The loan repayment function transfers tokens directly to the lender, so if the lender's address is blacklisted by the token (e.g., USDC), the transfer fails and repayment or liquidation is blocked. A lender can exploit this to prevent repayment and cause the borrower to default, potentially leading to loss of collateral.
T1MOH Follow with carrotsmuggler, cccz and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-03-teller-judging/issues/212
Found by
T1MOH, carrotsmuggler, cccz, cducrest-brainbot
Summary
The internal function that repays a loan _repayLoan attempts to transfer the loan token back to the lender. If the loan token implements a blacklist like the common USDC token, the transfer may be impossible and the repayment will fail.
This internal _repayLoan function is called during any partial / full repayment and during liquidation.
Vulnerability Detail
The function to repay the loan to the lender directly transfers the token to the lender:
function _repayLoan(...) internal virtual {
...
bid.loanDetails.lendingToken.safeTransferFrom(
_msgSenderForMarket(bid.marketplaceId),
lender,
paymentAmount
);
...
This function is called by any function that attemps to repay a loan (including liquidate): https://github.com/sherlock-audit/2023-03-teller/blob/main/teller-protocol-v2/packages/contracts/contracts/TellerV2.sol#L593 https://github.com/sherlock-audit/2023-03-teller/blob/main/teller-protocol-v2/packages/contracts/contracts/TellerV2.sol#L615 https://github.com/sherlock-audit/2023-03-teller/blob/main/teller-protocol-v2/packages/contracts/contracts/TellerV2.sol#L649 https://github.com/sherlock-audit/2023-03-teller/blob/main/teller-protocol-v2/packages/contracts/contracts/TellerV2.sol#L690
Any of these functions will fail if loan lender is blacklisted by the token.
During repayment the loan lender is computed by:
function getLoanLender(uint256 _bidId)
public
view
returns (address lender_)
{
lender_ = bids[_bidId].lender;
if (lender_ == address(lenderManager)) {
return lenderManager.ownerOf(_bidId);
}
}
If the lender controls a blacklisted address, they can use the lenderManager to selectively transfer the loan to / from the blacklisted whenever they want.
Impact
Any lender can prevent repayment of a loan and its liquidation. In particular, a lender can wait until a loan is almost completely repaid, transfer the loan to a blacklisted address (even one they do not control) to prevent the loan to be fully repaid / liquidated. The loan will default and borrower will not be able to withdraw their collateral.
This result in a guaranteed griefing attack on the collateral of a user.
If the lender controls a blacklisted address, they can additionally withdraw the collateral of the user.
I believe the impact is high since the griefing attack is always possible whenever lent token uses a blacklist, and results in a guaranteed loss of collateral.
Code Snippet
The function to withdraw collateral only works when loan is paid or transfer to lender when loan is defaulted:
function withdraw(uint256 _bidId) external {
BidState bidState = tellerV2.getBidState(_bidId);
if (bidState == BidState.PAID) {
_withdraw(_bidId, tellerV2.getLoanBorrower(_bidId));
} else if (tellerV2.isLoanDefaulted(_bidId)) {
_withdraw(_bidId, tellerV2.getLoanLender(_bidId));
emit CollateralClaimed(_bidId);
} else {
revert("collateral cannot be withdrawn");
}
}
Tool used
Manual Review
Recommendation
Use a push/pull pattern for transferring tokens. Allow repayment of loan and withdraw the tokens of the user into TellerV2 (or an escrow) and allow lender to withdraw the repayment from TellerV2 (or the escrow). This way, the repayment will fail only if TellerV2 is blacklisted.
Discussion
ethereumdegen
We feel as though this is technically a valid issue but
- hopefully it is extremely rare and edge-case
- it is so rare that it doesnt justify such a large change to the protocol and reducing UX flow for the entire system (an extra tx to withdraw funds)
- and finally, borrowers just have to be aware of the extra risk posed when using tokens which have 'denylists' in them or freezing capabilities and also should justify the risks of the particular party acting as the lender (if lender is likely to have assets frozen, do not borrow from them, etc.) .
IAm0x52
Sponsor has acknowledged this risk
ethereumdegen
Okay so after further review we did make a PR to make an option to pay into an escrow vault. This escrow vault is a new contract, a simple smart contract wallet to hold funds for a lender in the event that their account is not able to receive tokens. This way, borrowers can repay loans regardless.
PR: https://github.com/teller-protocol/teller-protocol-v2/pull/105
IAm0x52
Fix looks good. Contract now utilizes an escrow contract that will receive tokens in the event that the lender is unable to receive the repayment directly. This ensures that repayment is always possible.
jacksanford1
Teller decided to fix this issue, so changing label to "Will 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 repayment function uses a direct token transfer to the lender instead of a pull pattern, so a blacklisted lender address blocks repayment.
Impact
A lender can prevent loan repayment and liquidation, causing the borrower to default and lose collateral; if the lender controls a blacklisted address, they could also withdraw the collateral.
What the attacker needed
Loan token supports blacklisting; lender address is blacklisted
The fix
The protocol was fixed by adding an escrow contract that receives repayment if the lender cannot, ensuring repayment is always possible.
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.
Some tokens, like USDC, can blacklist addresses, meaning those addresses cannot send or receive the token. In this lending protocol, when a borrower repays, the tokens are sent directly to the lender. If the lender's address is blacklisted, the repayment fails, and the borrower cannot get their collateral back.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.