# The cycle payment due may span over approx. 2 cycles and block the borrower from paying

TellerV2 EMI repayment math charges ~2 cycles when payments are spaced near two cycles apart, reverting the borrower's minimum payment and risking liquidation.

- Payout: Contest reward
- Severity: medium
- Program: Teller
- Credited: CodeWasp
- Disclosed: 2024-04-18
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-04-teller-finance-judging/issues/285
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-04-teller-finance%3AM-16
- Tags: domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:business-logic

**Target:** TellerV2 repayLoan/repayLoanMinimum and V2Calculations.calculateAmountOwed
**Root cause:** calculateAmountOwed computes owedAmount as paymentCycleAmount * owedTime / paymentCycleDuration using elapsed time since lastRepaidTimestamp rather than the payment schedule, so a gap near two cycles demands ~two cycles' payment.
**Steps:**
1. Set bid: principal 30000, acceptedTimestamp 100, lastRepaidTimestamp 100+1 day, loanDuration 3 months, totalRepaid principal 10000/interest 200, paymentCycleAmount 10000, paymentCycle 30 days, APR 1200, EMI.
2. Borrower repays 10000 one day after acceptance (first cycle paid).
3. Warp to block.timestamp = 100 + 58 days.
4. Approve 10000+300 and call `repayLoan(bidId, 10300)`.
5. Observe revert `PaymentNotMinimum(1, 10300, 19000)` because owedTime ~57 days yields owedAmount ~19000.
**How found:** Reasoned about payment schedule vs. elapsed-time formula: noticed that paying early in cycle one then paying in cycle two makes owedTime approach two cycles, inflating the minimum due; confirmed with a Foundry unit test using TellerV2_Override.
**Insight:** When auditing amortized/EMI loan contracts, compare the minimum-payment formula against the intended schedule: any formula keyed on time-since-last-payment rather than cycle index will overcharge when a payment lands early in a cycle, so test early-payment-then-skip-a-cycle sequences.
