Skip to content
Smart contracts Audit finding Advanced

liquidationTarget is not set when removing pool

When removing a pool, the vault's startLiquidation function is called directly without setting liquidationTarget, so later the team cannot finish liquidation and balance the vault's borrow recording. This may prevent the pool from being removed successfully.

Protocol Team Follow

Originally disclosed on Sherlock

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

Found by

Protocol Team Remove pool has 3 steps:

  1. call removeD3Pool(address) and force the pool into liquidation state. However, the vault call ID3MM(pool).startLiquidation() directly and skip setting liquidationTarget
  2. DODO team uses liquidationByDODO() to balance all tokens.
  3. call finishPoolRemove() and finish removing.

The bugs could happen in step 2. During liquidationByDODO, liquidator only rebalance tokens in pool. It can't update vault borrow recording. If dodo team want to call finishLiquidation(), they will find liquidationTarget wasn't set and they could not balance vault borrow recording.

Impact

It may not remove pool successfully.

Tool Used

Manual Review

Recommandation

  1. Calculation liquidationTarget in removeD3Pool()
  2. call finishLiquidation() to finish pool balance and then call finishPoolRemove()

Thinking of balance > debt situation, it could transfer realDebt into vault: https://github.com/sherlock-audit/2023-06-dodo/blob/a8d30e611acc9762029f8756d6a5b81825faf348/new-dodo-v3/contracts/DODOV3MM/D3Vault/D3VaultLiquidation.sol#L141C1-L145C67

Solidity
            // note: During liquidation process, the pool's debt will slightly increase due to the generated interests. 
            // The liquidation process will not repay the interests. Thus all dToken holders will share the loss equally.
            uint256 realDebt = borrows.div(record.interestIndex == 0 ? 1e18 : record.interestIndex).mul(info.borrowIndex);
            IERC20(token).transferFrom(pool, address(this), debt);

change into:

Solidity
IERC20(token).transferFrom(pool, address(this), realDebt);

Discussion

hrishibhat

Please note: This issue is not part of the contest submissions and is not eligible for contest rewards.

The original report as published on Sherlock, by Protocol Team. 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 removeD3Pool function calls startLiquidation without first calculating and setting liquidationTarget, so finishLiquidation cannot complete.

Impact

The pool may not be removed successfully because finishLiquidation cannot balance the vault borrow recording.

What the attacker needed

Pool in liquidation state; team calls liquidationByDODO; team calls finishLiquidation

The fix

The fix should calculate liquidationTarget in removeD3Pool() and call finishLiquidation() before finishPoolRemove(); also, when balance exceeds debt, transfer realDebt instead of debt.

How it was found

  1. Call removeD3Pool(address) to force the pool into liquidation state.
  2. The vault calls startLiquidation() directly, skipping setting liquidationTarget.
  3. The DODO team uses liquidationByDODO() to balance all tokens.
  4. Call finishPoolRemove() to finish removing the pool.

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.

A smart contract pool is being shut down. The shutdown process has steps, and one step skips recording a key value (liquidationTarget). Later, when the team tries to finish the shutdown, the missing value stops them from balancing the books, so the pool might not be removed.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Protocol Team

View all

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

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.