# Using original principal amount as due amount inside `liquidateDefaultedLoanWithIncentive` breaks contract accounting leading to lost assets/broken functionalities

liquidateDefaultedLoanWithIncentive used original principal instead of remaining principal as amount due, double-counting repayments and corrupting pool accounting.

- Payout: Audit contest
- Severity: high
- Program: Teller
- Found by: 0xeix
- Disclosed: 2024-11-16
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-11-teller-finance-update-judging/issues/43
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-teller-finance-update%3AH-3
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:high tech:solidity technique:source-review vuln:accounting-error vuln:liquidation

**Target:** LenderCommitmentGroup_Smart.sol liquidation logic
**Root cause:** _getAmountOwedForBid returns the bid's original principal from getLoanSummary rather than the remaining unpaid principal, so already-repaid principal is counted again in totalPrincipalTokensRepaid and tokenDifferenceFromLiquidations.
**Steps:**
1. Create loan with principal 100; totalPrincipalTokensLended=100, Repaid=0.
2. Repay 80 principal; totalPrincipalTokensRepaid=80, tokenBalance=80.
3. Loan defaults; auction settles at 50; liquidation sets amountDue=100 (original principal).
4. totalPrincipalTokensRepaid becomes 180 (>lended 100); tokenDifferenceFromLiquidations = 100-50 = -50.
5. Withdrawable amount computed as committed + difference = 50 while 130 tokens exist; getPrincipalAmountAvailableToBorrow underflows (100-180).
**How found:** Code review of liquidation path comparing amountDue source against repayLoanCallback accounting; noticed repaid principal already tracked separately yet liquidation reuses full principal.
**Exploitation:** No direct theft; the misaccounting causes lenders to be unable to withdraw full assets, underflow reverts blocking new bids, and possible division-by-zero on estimated value.
**Insight:** When a liquidation function reads 'amount owed' from a loan summary, verify whether that field is original principal or remaining principal — repaid amounts tracked elsewhere will be double-counted in pool-level accounting variables.

