Skip to content
Business logic Audit finding Intermediate

Vault: `_update_debt` does not accrue interest

The `_update_debt` function updates the last debt update timestamp before calculating interest, causing the interest calculation to always return zero. As a result, no interest accrues on debt, leading to lost revenue for the protocol and liquidity providers.

0x00ffDa Follow with 0xDjango, 0xStalin and 8 others

Originally disclosed on Sherlock

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

Found by

0x00ffDa, 0xDjango, 0xStalin, 0xpinky, Bauer, BugBusters, Dug, GimelSec, kutugu, n33k, pengun

Summary

_update_debt call _debt_interest_since_last_update to accrue interest but _debt_interest_since_last_update always return 0 in _update_debt.

Vulnerability Detail

_update_debt sets self.last_debt_update[_debt_token] to block.timestamp and then calls _debt_interest_since_last_update.

Python
def _update_debt(_debt_token: address):
    ....
    self.last_debt_update[_debt_token] = block.timestamp
    ....
    self.total_debt_amount[_debt_token] += self._debt_interest_since_last_update(
        _debt_token
    )

_debt_interest_since_last_update always returns 0. because block.timestamp - self.last_debt_update[_debt_token] is always 0.

Python
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
    )

Impact

Debt fee is not accrued.

Code Snippet

https://github.com/sherlock-audit/2023-06-unstoppable/blob/main/unstoppable-dex-audit/contracts/margin-dex/Vault.vy#L1050-L1076

Tool used

Manual Review

Recommendation

Call _debt_interest_since_last_update then update last_debt_update.

Discussion

Unstoppable-DeFi

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

0x00ffDa

Escalate for 10 USDC.

I believe this should be high severity. This flaw results in definite loss of funds for the protocol and LP providers: zero revenue from all debts, no special circumstances needed.

sherlock-admin2

Escalate for 10 USDC.

I believe this should be high severity. This flaw results in definite loss of funds for the protocol and LP providers: zero revenue from all debts, no special circumstances needed.

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: keep the original judging.

Escalate for 10 USDC.

I believe this should be high severity. This flaw results in definite loss of funds for the protocol and LP providers: zero revenue from all debts, no special circumstances needed.

The loss is on interest, not big loss in principal, the amount might not be considered "material loss of funds".

I think medium is appropriate.

Nabeel-javaid

IMO, high is appropriate is it is bricking the core functionality of interest. There is no point of lending when there is no interest on it.

0xpinky

interest is core concept in lend and borrow, flawed interest updates would brick one of the core functions. when we look at this over a period of time, the loss would have incurred is huge.. High is appropriate.

hrishibhat

Result: High Has duplicates Considering this issue a valid high for two reasons:

  • It breaks the core functionality of accruing interest on debt.
  • Leading loss of revenue for protocol and LP.

sherlock-admin2

Escalations have been resolved successfully!

Escalation status:

maarcweiss

Fixed by calling last_debt_update after _debt_interest_since_last_update

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

The function updates the last debt update timestamp before calling the interest calculation, so the elapsed time is always zero.

Impact

Debt interest is never accrued, causing a loss of revenue for the protocol and liquidity providers.

What the attacker needed

None

The fix

The fix was to call `_debt_interest_since_last_update` before updating `last_debt_update`.

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.

In a lending system, interest is charged over time. The code records the current time before calculating how much time has passed since the last update, so the time difference is always zero. This means borrowers are never charged interest, and the protocol earns nothing.

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 0x00ffDa

View all

8 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.