Skip to content
Business logic Audit finding Intermediate

Calls to liquidate don't write down totalBorrows which breaks exchange rate

The liquidate function does not decrement the totalBorrows state variable for the debt token, so the exchange rate of the corresponding pToken remains artificially high. This causes depositors to receive more interest than they should, and the last withdrawer may be unable to redeem their pTokens due to insufficient underlying tokens.

dirk_y Follow with seeques

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-06-dodo-judging/issues/46

Found by

dirk_y, seeques

Summary

When a pool is liquidated, the totalBorrows storage slot for the token in question should be decremented by debtToCover in order to keep the exchange rate of the corresponding pToken correct.

Vulnerability Detail

When users call liquidate to liquidate a pool, they specify the amount of debt they want to cover. In the end this is used to write down the borrow amount of the pool in question:

Solidity
record.amount = borrows - debtToCover;

However, the totalBorrows of the token isn't written down as well (like it should be). The finishLiquidation method correctly writes down the totalBorrows state.

Impact

When a user calls liquidate to liquidate a pool, the exchange rate of the token (from its pToken) remains high (because the totalBorrows for the token isn't decremented). The result is that users that have deposited this ERC20 token are receiving a higher rate of interest than they should. Because this interest is not being covered by anyone the end result is that the last withdrawer from the vault will not be able to redeem their pTokens because there isn't enough of the underlying ERC20 token available. The longer the period over which interest accrues, the greater the incentive for LPs to withdraw early.

Code Snippet

https://github.com/sherlock-audit/2023-06-dodo/blob/main/new-dodo-v3/contracts/DODOV3MM/D3Vault/D3VaultLiquidation.sol#L57

Tool used

Manual Review

Recommendation

The liquidate method should include the following line to write down the total borrow amount of the debt token being liquidated:

Solidity
info.totalBorrows = info.totalBorrows - debtToCover;

Discussion

djb15

Escalate

This is not a duplicate of #211. I believe this and #157 should be grouped together separately.

#211 is about the vault token balance not being updated during liquidations which allows users to claim more dTokens than they should with new deposits.

This issue (and #157) is about the exchange rate for the token being broken during liquidations due to a different variable not being updated. The solution for this issue is different to the solution to #211. The only similarity is that both issues occur during calls to liquidate.

sherlock-admin2

Escalate

This is not a duplicate of #211. I believe this and #157 should be grouped together separately.

#211 is about the vault token balance not being updated during liquidations which allows users to claim more dTokens than they should with new deposits.

This issue (and #157) is about the exchange rate for the token being broken during liquidations due to a different variable not being updated. The solution for this issue is different to the solution to #211. The only similarity is that both issues occur during calls to liquidate.

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.

maarcweiss

Agree with escalation. #157 and #211 do not describe the same issue as #46 and should be duped together

djb15

@maarcweiss Just to confirm, I'm suggesting #46 and #157 are duped together, and #211 is duped with #68, #122 and #156. I.e.

Issue A: #46, #157 Issue B: #211, #68, #122, #156

Just thought I'd check as the above message seems to suggest the opposite :)

hrishibhat

Result: High Has duplicates Agree with the above escalation and comments and two separate sets of issues that should be valid issues

sherlock-admin2

Escalations have been resolved successfully!

Escalation status:

The original report as published on Sherlock, by dirk_y. 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 liquidate function updates the individual borrow record but fails to decrement the totalBorrows state variable for the debt token.

Impact

Depositors receive inflated interest, and the last withdrawer may be unable to redeem their pTokens because the pool lacks sufficient underlying tokens; the longer interest accrues, the greater the incentive for early withdrawal.

What the attacker needed

A liquidation occurs in the pool

The fix

The liquidate method should decrement totalBorrows by the debtToCover amount.

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 pool, the exchange rate between deposit tokens and receipt tokens (pTokens) depends on total borrows. If a liquidation reduces a borrower's debt but the total borrows variable is not updated, the exchange rate stays too high, meaning depositors earn more interest than they should. Over time, this can leave the pool short of funds, so the last person to withdraw may not get their money back.

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 dirk_y

View all

17 more disclosed reports, best first.

More from DODO V3 update

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.