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.
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:
- call removeD3Pool(address) and force the pool into liquidation state. However, the vault call ID3MM(pool).startLiquidation() directly and skip setting liquidationTarget
- DODO team uses liquidationByDODO() to balance all tokens.
- 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
- Calculation liquidationTarget in removeD3Pool()
- 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
// 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:
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.
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
- Call removeD3Pool(address) to force the pool into liquidation state.
- The vault calls startLiquidation() directly, skipping setting liquidationTarget.
- The DODO team uses liquidationByDODO() to balance all tokens.
- 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.