Borrowers can brick the commitment group pool
A borrower can set a repayment listener on a bid they borrowed directly from TellerV2, causing the commitment group's repayment counters to increase without a matching lending counter. This underflows the outstanding principal calculation and can brick the commitment group contract.
Source: https://github.com/sherlock-audit/2024-04-teller-finance-judging/issues/42
The protocol has acknowledged this issue.
Found by
0x3b, 0xLogos, 0xadrii, EgisSecurity, bughuntoor, merlin, samuraii77
Summary
Borrowers can setRepaymentListenerForBid after directly borrowing from TellerV2. Upon repayment, totalPrincipalTokensRepaid will increase without a corresponding increase in totalPrincipalTokensLended. This discrepancy causes getTotalPrincipalTokensOutstandingInActiveLoans to underflow, which will brick commitment group contract.
Vulnerability Detail
When borrowing from LenderCommitmentGroup (LCG), the acceptFundsForAcceptBid function increases totalPrincipalTokensLended and calls _acceptBidWithRepaymentListener to log the bid as borrowed from LCG. Later, the _repayLoan function, having made repaymentListenerForBid[_bidId] = _listener, triggers _sendOrEscrowFunds which will call the repayLoanCallback inside LCG. This increases both totalPrincipalTokensRepaid and totalInterestCollected.
The flow balances totalPrincipalTokensLended on borrowing with totalPrincipalTokensRepaid on repayment, equalizing them.
However, borrowers can directly borrow from TellerV2 and call setRepaymentListenerForBid. Upon repayment, totalPrincipalTokensRepaid and totalInterestCollected will increase without a corresponding increase in totalPrincipalTokensLended (because the borrowing was direct from TellerV2).
- The inflation of
totalInterestCollectedcauses share values to increase, generating unbacked profits. - The inflation of
totalPrincipalTokensRepaidleads togetTotalPrincipalTokensOutstandingInActiveLoansunderflowing, potentially bricking the contract.
Note that user can even make custom tokens with infinite liquidity and use them to borrow / repay to maximize the damage.
Impact
Loss of funds.
Code Snippet
function setRepaymentListenerForBid(uint256 _bidId, address _listener) external {
address sender = _msgSenderForMarket(bids[_bidId].marketplaceId);
require(sender == bids[_bidId].lender, "Only the bid lender may set the repayment listener");
repaymentListenerForBid[_bidId] = _listener;
}
Tool used
Manual Review
Recommendation
Make sure setRepaymentListenerForBid is callable only by the LCG.
- function setRepaymentListenerForBid(uint256 _bidId, address _listener) external
+ function setRepaymentListenerForBid(uint256 _bidId, address _listener) onlyCommitmentGroup external
{
address sender = _msgSenderForMarket(bids[_bidId].marketplaceId);
require( sender == bids[_bidId].lender,"Only bid lender may set repayment listener");
repaymentListenerForBid[_bidId] = _listener;
}
Discussion
ethereumdegen
I think this is already fixed by
require(
sender == bids[_bidId].lender,
"Only bid lender may set repayment listener"
);
since the group IS the lender . correct ?
meaning this is a non issue
nevillehuang
@ethereumdegen I believe what the watsons are trying to say here is that a malicious user can act as both the borrower and the lender, and can artificially inflate totalPrincipalTokensRepaid and totalInterestCollected which ultimately affects share computations. Perhaps issue #225 gives a better indepth description and a potential fix would be to only allow setting listener for active bids.
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 listener setter lacks an access check restricting it to the commitment group, so any lender (including a borrower acting as lender) can register a listener that updates group accounting without a matching lend.
Impact
The commitment group contract could be bricked and funds lost, though the text hedges with 'potentially'.
What the attacker needed
Ability to borrow directly from TellerV2; ability to act as lender on the same bid
How it was found
- Borrow directly from TellerV2 while acting as both borrower and lender.
- Call setRepaymentListenerForBid to point the bid at the commitment group.
- Repay the loan so the group's repayment callback runs.
- Observe totalPrincipalTokensRepaid and totalInterestCollected increase without totalPrincipalTokensLended increasing.
- The outstanding principal calculation underflows and the commitment group contract is bricked.
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 keeps running totals of money lent and money repaid. If someone can make the repaid total go up without the lent total going up, the subtraction used to work out what is still owed goes negative, which crashes the contract. Here a borrower could trigger that by telling the contract to notify a group about a repayment that the group never lent.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.