Skip to content

Latest commit

 

History

History
72 lines (45 loc) · 1.87 KB

File metadata and controls

72 lines (45 loc) · 1.87 KB

Dandy Caramel Tortoise

Medium

EMI calculation is flawed

Summary

Taking min when calculating EMI repayment amount is flawed

Root Cause

The amount due in case of EMI repayment is calculated as: https://github.com/sherlock-audit/2024-11-teller-finance-update/blob/0c8535728f97d37a4052d2a25909d28db886a422/teller-protocol-v2-audit-2024/packages/contracts/contracts/libraries/V2Calculations.sol#L124-L138

        } else {
            // Default to PaymentType.EMI
            // Max payable amount in a cycle
            // NOTE: the last cycle could have less than the calculated payment amount


            //the amount owed for the cycle should never exceed the current payment cycle amount  so we use min here 
            uint256 owedAmountForCycle = Math.min(  ((_bid.terms.paymentCycleAmount  * owedTime)  ) /
                    _paymentCycleDuration , _bid.terms.paymentCycleAmount+interest_ ) ;


            uint256 owedAmount = isLastPaymentCycle
                ? owedPrincipal_ + interest_
                : owedAmountForCycle  ;


            duePrincipal_ = Math.min(owedAmount - interest_, owedPrincipal_);
        }

This is incorrect and leads to lowered payments since _bid.terms.paymentCycleAmount+interest_ will be taken instead of the ratio wise amount

Eg: Principal (P) = 100 Annual Rate (r) = 12% = 0.12 Number of Monthly Payments (n) = 12 monthly EMI = 8.84

But if the repayment occurs after 2 months, this formula calculates the amount due as 8.84 + 2 == 10.84 instead of 8.84 * 2

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

No response

Impact

Incorrectly lowered payments in case of EMI repayments

PoC

No response

Mitigation

Dont take the min. Instead use

 ((_bid.terms.paymentCycleAmount  * owedTime)  ) /
                    _paymentCycleDuration