Skip to content
DoS Audit finding Intermediate

Repayer can brick lending functionality of `LenderCommitmentGroup_Smart` by repaying excess

The smart contract function that calculates outstanding principal tokens performs a subtraction that can underflow if a borrower repays more than the total principal lent. An attacker can repay an excess amount, causing the function to always revert and thereby bricking the lending functionality.

OpaBatyo Follow with hash

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-11-teller-finance-update-judging/issues/46

Found by

OpaBatyo, hash

Summary

LenderCommitmentGroup_Smart doesn't handle excess repayments making it possible to brick the lending functionality

Root Cause

The getTotalPrincipalTokensOutstandingInActiveLoans function performs totalPrincipalTokensLended - totalPrincipalTokensRepaid without handling the underflow scenario. This is problematic as excess amount can be repaid for loans which will cause an underflow here

Solidity
    function getTotalPrincipalTokensOutstandingInActiveLoans()
        public
        view
        returns (uint256)
    {
        return totalPrincipalTokensLended - totalPrincipalTokensRepaid;
    }

on excess repayments, totalPrincipalTokensRepaid will become greater than totalPrincipalTokensLended

Solidity
    function repayLoanCallback(
        uint256 _bidId,
        address repayer,
        uint256 principalAmount,
        uint256 interestAmount
    ) external onlyTellerV2 whenForwarderNotPaused whenNotPaused bidIsActiveForGroup(_bidId) { 
        totalPrincipalTokensRepaid += principalAmount;
        totalInterestCollected += interestAmount;

function in TellerV2.sol contract to repay excess amount. User can specify any amount greater than minimum amount

Solidity
    function repayLoan(uint256 _bidId, uint256 _amount)
        external
        acceptedLoan(_bidId, "rl")
    {
        _repayLoanAtleastMinimum(_bidId, _amount, true);
    }

The function getTotalPrincipalTokensOutstandingInActiveLoans is invoked before every lending. Hence an underflow here will cause the lending functionality to revert

Another quirk regarding excess repayments is that the lenders of the pool won't obtain the excess repaid amount since it is not accounted anywhere. But this cannot be considered an issue since the lenders are only guarenteed the original lending amount + interest

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

  1. Attacker borrows 100 from the lender pool

totalPrincipalTokensLended == 100 totalPrincipalTokensRepaid == 0

  1. Attacker repays 101

totalPrincipalTokensLended == 100 totalPrincipalTokensRepaid == 101

Now getTotalPrincipalTokensOutstandingInActiveLoans will always revert

Impact

Bricked lending functionality

PoC

No response

Mitigation

In case repaid principal is more, return 0 instead

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/80

The original report as published on Sherlock, by OpaBatyo. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 function getTotalPrincipalTokensOutstandingInActiveLoans subtracts totalPrincipalTokensRepaid from totalPrincipalTokensLended without checking for underflow, which can occur if repayments exceed the total lent.

Impact

The lending functionality is bricked, preventing any new loans from being processed.

What the attacker needed

Attacker can borrow from the pool; attacker can repay more than borrowed

The fix

The function should return 0 if the repaid principal exceeds the lent principal, preventing underflow.

How it was found

  1. Attacker borrows 100 from the lender pool, setting totalPrincipalTokensLended to 100 and totalPrincipalTokensRepaid to 0.
  2. Attacker repays 101, making totalPrincipalTokensRepaid 101 while totalPrincipalTokensLended remains 100.
  3. Now getTotalPrincipalTokensOutstandingInActiveLoans will always revert due to underflow.

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 track of how much has been lent and how much has been repaid. If someone repays more than they borrowed, the 'repaid' number becomes larger than the 'lent' number. When the contract later subtracts the smaller from the larger, it crashes because it cannot handle negative numbers, and this stops all new loans from working.

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.

More by OpaBatyo

View all

3 more disclosed reports, best first.

More from Teller Lender Groups Update Audit

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.