Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dandy Caramel Tortoise - EMI calculation is flawed #71

Open
sherlock-admin3 opened this issue Dec 10, 2024 · 0 comments
Open

Dandy Caramel Tortoise - EMI calculation is flawed #71

sherlock-admin3 opened this issue Dec 10, 2024 · 0 comments
Labels
Sponsor Confirmed The sponsor acknowledged this issue is valid Won't Fix The sponsor confirmed this issue will not be fixed

Comments

@sherlock-admin3
Copy link
Contributor

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
@sherlock-admin3 sherlock-admin3 added Won't Fix The sponsor confirmed this issue will not be fixed Sponsor Confirmed The sponsor acknowledged this issue is valid labels Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Sponsor Confirmed The sponsor acknowledged this issue is valid Won't Fix The sponsor confirmed this issue will not be fixed
Projects
None yet
Development

No branches or pull requests

1 participant