Skip to content
Business logic Audit finding Intermediate

Interested calculated is ampliefied by multiple of 1000 in `_debt_interest_since_last_update`

The interest calculation function divides by a base with lower precision than the numerator, amplifying the result by a factor of 1000. This inflated interest corrupts debt calculations and could break leverage, liquidation, and share mechanisms.

BugBusters Follow with twicek

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-06-unstoppable-judging/issues/191

Found by

BugBusters, twicek

Summary

Interest calculated in the _debt_interest_since_last_update function is amplified by multiple of 1000, hence can completely brick the system and debt calculation. Because we divide by PERCENTAGE_BASE instead of PERCENTAGE_BASE_HIGH which has more precision and which is used in utilization calculation.

Vulnerability Detail

Following function calculated the interest accured over a certain interval :

Solidity
def _debt_interest_since_last_update(_debt_token: address) -> uint256:

    return (

        (block.timestamp - self.last_debt_update[_debt_token])* self._current_interest_per_second(_debt_token)
        * self.total_debt_amount[_debt_token]
        / PERCENTAGE_BASE 
        / PRECISION
    )

But the results from the above function are amplified by factor of 1000 due to the reason that the intrest per second as per test file is calculated as following:

Solidity
    # accordingly the current interest per year should be 3% so 3_00_000
    # per second that is (300000*10^18)/(365*24*60*60)
    expected_interest_per_second = 9512937595129375

    assert (
        expected_interest_per_second
        == vault_configured.internal._current_interest_per_second(usdc.address)
    )

So yearly interest has the precision of 5 as it is calculated using utilization rate and PERCENTAGE_BASE_HIGH_PRECISION is used which has precision of 5 .and per second has the precision of 18, so final value has the precision of 23.

Interest per second has precision = 23.

But if we look at the code:

Solidity
        (block.timestamp - self.last_debt_update[_debt_token])* self._current_interest_per_second(_debt_token)
        * self.total_debt_amount[_debt_token]
        / PERCENTAGE_BASE 
        / PRECISION

We divide by PERCENTAGE_BASE that is = 100_00 = precision of => 2 And than by PRECISION = 1e18 => precision of 18. So accumulated precision of 20, where as we should have divided by value precises to 23 to match the nominator.

Where is we should have divided by PERCENTAGE_BASE_HIGH instead of PERCENTAGE_BASE

Hence the results are amplified by enormous multiple of thousand.

Impact

Interest are too much amplified, that impacts the total debt calculation and brick whole leverage, liquidation and share mechanism.

Note: Dev confirmed that the values being used in the tests are the values that will be used in production.

Code Snippet

https://github.com/sherlock-audit/2023-06-unstoppable/blob/94a68e49971bc6942c75da76720f7170d46c0150/unstoppable-dex-audit/contracts/margin-dex/Vault.vy#L1069-L1076 https://github.com/sherlock-audit/2023-06-unstoppable/blob/94a68e49971bc6942c75da76720f7170d46c0150/unstoppable-dex-audit/tests/vault/test_variable_interest_rate.py#L314-L333

Tool used

Manual Review

Recommendation

Use PERCENTAGE_BASE_HIGH in division instead of PERCENTAGE_BASE.

Discussion

Unstoppable-DeFi

https://github.com/Unstoppable-DeFi/unstoppable-dex-audit/pull/8

Nabeel-javaid

Escalate for 10 USDC

This should be high as described impact in the given submission and the duplicate too.

sherlock-admin2

Escalate for 10 USDC

This should be high as described impact in the given submission and the duplicate too.

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

twicek

Escalate for 10 USDC The wrong calculation of interest rates will cause a direct loss of funds to users. This should definitely be high severity.

sherlock-admin2

Escalate for 10 USDC The wrong calculation of interest rates will cause a direct loss of funds to users. This should definitely be high severity.

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

141345

Recommendation: change the original judging, to high severity.

Escalate for 10 USDC

This should be high as described impact in the given submission and the duplicate too.

A magnitude of 1000 times of interest can be deemed as "material loss of funds".

141345

Escalate for 10 USDC The wrong calculation of interest rates will cause a direct loss of funds to users. This should definitely be high severity.

Same as above

hrishibhat

Result: High Has duplicates Considering this a valid high

sherlock-admin2

Escalations have been resolved successfully!

Escalation status:

maarcweiss

Fixed by calling PERCENTAGE_BASE_HIGH instead of PERCENTAGE_BASE for the interest calculation

The original report as published on Sherlock, by BugBusters. 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

Likely the interest calculation divides by PERCENTAGE_BASE (precision 2) instead of PERCENTAGE_BASE_HIGH (precision 5), while the numerator has precision 23, causing a 1000x amplification.

Impact

Interest is amplified by a factor of 1000, which impacts total debt calculation and could brick leverage, liquidation, and share mechanisms.

What the attacker needed

None

The fix

The fix was to use PERCENTAGE_BASE_HIGH instead of PERCENTAGE_BASE in the interest calculation.

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.

Smart contracts often use fixed-point arithmetic to handle decimals. If you multiply numbers with many decimal places and then divide by a number with fewer decimal places, the result can be much larger than intended. Here, the interest per second had 23 decimal places, but the code divided by a base with only 20 decimal places, making the interest 1000 times too big.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by BugBusters

View all

3 more disclosed reports, best first.

More from Unstoppable

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.