`_repayLoan` now allows for overpaying of loan and could cause DoS within `LenderCommitmentGroup_Smart`
The `_repayLoan` function adjusts a local payment amount to the owed amount but passes the original payment struct to fund transfer, allowing overpayment. This overpayment can make `getTotalPrincipalTokensOutstandingInActiveLoans` revert, causing a permanent denial of service for borrows in `LenderCommitmentGroup_Smart`.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-04-teller-finance-judging/issues/32
The protocol has acknowledged this issue.
Found by
bughuntoor
Summary
_repayLoan now allows for overpaying of loan
Vulnerability Detail
Let's look at the code of _repayLoan
function _repayLoan(
uint256 _bidId,
Payment memory _payment,
uint256 _owedAmount,
bool _shouldWithdrawCollateral
) internal virtual {
Bid storage bid = bids[_bidId];
uint256 paymentAmount = _payment.principal + _payment.interest;
RepMark mark = reputationManager.updateAccountReputation(
bid.borrower,
_bidId
);
// Check if we are sending a payment or amount remaining
if (paymentAmount >= _owedAmount) {
paymentAmount = _owedAmount;
if (bid.state != BidState.LIQUIDATED) {
bid.state = BidState.PAID;
}
// Remove borrower's active bid
_borrowerBidsActive[bid.borrower].remove(_bidId);
// If loan is is being liquidated and backed by collateral, withdraw and send to borrower
if (_shouldWithdrawCollateral) {
// _getCollateralManagerForBid(_bidId).withdraw(_bidId);
collateralManager.withdraw(_bidId);
}
emit LoanRepaid(_bidId);
} else {
emit LoanRepayment(_bidId);
}
_sendOrEscrowFunds(_bidId, _payment); //send or escrow the funds
In the case where the user attempts to overpay, paymentAmount is adjusted to owedAmount. However, the _payment memory struct remains the same. Meaning that if the user has inputted more than supposed to, it will go through, causing an overpay.
To furthermore make it worse, this would allow for overpaying loans within LenderCommitmentGroup_Smart. This is problematic as it would make the following function revert.
function getTotalPrincipalTokensOutstandingInActiveLoans()
public
view
returns (uint256)
{
return totalPrincipalTokensLended - totalPrincipalTokensRepaid;
}
Since the function is called when a user attempts to borrow, this would cause permanent DoS for borrows within the LenderCommitmentGroup_Smart
Impact
Users accidentally overpaying
Permanent DoS within LenderCommitmentGroup_Smart
Code Snippet
Tool used
Manual Review
Recommendation
adjust the memory struct
Discussion
ethereumdegen
I dont think this is an issue ?
Look at this LOC :
paymentAmount = _owedAmount;
spacegliderrrr
@ethereumdegen yeah, but paymentAmount is no longer passed to the _sendOrEscrowFunds - the unchanged _payment struct is passed.
nevillehuang
This seems valid per computations here, but would have been good to see a poc if it actually goes through. Will be leaving valid medium. Seems like the only possible trigger is through here.
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 code updates a local variable for the payment amount but does not update the payment struct that is later used to transfer funds, so the overpayment is not prevented.
Impact
Users may accidentally overpay, and the overpayment could cause a permanent denial of service for borrows within `LenderCommitmentGroup_Smart`.
What the attacker needed
User repays more than owed
The fix
The payment struct should be adjusted to reflect the actual amount owed before funds are sent.
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 you repay a loan, the code checks if you sent too much and should only take what you owe. But it still sends the full amount you provided, so you accidentally pay extra. That extra payment messes up a calculation used to track outstanding loans, which can stop new loans from being taken out.
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.