A user can get more dTokens than they should get via `D3VaultFunding.userDeposit()`, due to accounting issues in `D3VaultLiquidation.liquidate()`
The vault's recorded balance of a debt token is not updated when a liquidation transfers that token into the vault. A user who deposits the same token immediately after can receive more dTokens than they should, diluting existing LP holders.
Source: https://github.com/sherlock-audit/2023-06-dodo-judging/issues/211
Found by
0xkaden, dirk_y, lemonmon, seeques
Summary
The vault token balance (assetInfo[debt].balance) is not updated during liquidation (D3VaultLiquidation.liquidate()).
Thus, a user who calls D3VaultFunding.userDeposit() can get more dTokens than they should get.
Vulnerability Detail
When D3VaultLiquidation.liquidate() is called, the debt is transferred to the vault:
But assetInfo[debt].balance is not updated, even though the debt tokens were received.
This leads to the issue that if a user deposits this debt token right after the liquidation, they will receive more dTokens in return than they should, because D3VaultFunding.userDeposit() is using the wrongly tracked value of assetInfo[debt].balance:
As a result, the protocol will mint more dTokens for the user than they should receive:
Impact
A user can call D3VaultFunding.userDeposit() right after a token got liquidated by D3VaultLiquidation.liquidate(), resulting in that the user will receive more dToken than they should receive, due to accounting issues in D3VaultLiquidation.liquidate().
All LP holders will suffer from inflated dTokens.
Code Snippet
Tool used
Manual Review
Recommendation
After D3VaultLiquidation.liquidate() is transferring the debt tokens to the vault, update the assetInfo[debt].balance of the vault.
If the repaid debt in D3VaultLiquidation.liquidate() was meant to be sent to the pool, like in the function D3VaultLiquidation.liquidateByDODO(), the ID3MM(pool).updateReserveByVault(debt) should be called at the end of D3VaultLiquidation.liquidate(). Otherwise a very similar problem can occur since the state.balances[debtToken] is not being updated. state.balances[debtToken] is used in a similar way in the D3Trading.sol contract to determine the actual balance received.
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 liquidation function transfers debt tokens into the vault without updating the vault's internal accounting variable `assetInfo[debt].balance`.
Impact
A user could receive more dTokens than they should, and all LP holders would suffer from the inflated dToken supply.
What the attacker needed
A liquidation has occurred; user deposits the same debt token
The fix
The vault's `assetInfo[debt].balance` should be updated after the debt tokens are transferred in liquidation; if the repaid debt is meant for the pool, `updateReserveByVault` should also be called.
How it was found
- A liquidation occurs and debt tokens are transferred to the vault.
- The vault's recorded balance for that debt token is not updated.
- A user calls `D3VaultFunding.userDeposit()` with the same debt token.
- The deposit function uses the stale recorded balance, so the user receives more dTokens than they should.
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 vault keeps a record of how many tokens it holds. When a liquidation sends tokens into the vault, that record is not updated, so the vault thinks it has fewer tokens than it really does. If someone deposits that token right after, the vault gives them too many shares (dTokens) based on the wrong record, which harms existing share holders.
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.