Inability to perform partial liquidations allows huge positions to accrue bad debt in the system
The liquidate function only burns the entire DYAD amount minted by a DNft id, so a liquidator must cover the whole debt to liquidate a position. For very large positions this is impractical, so they stay undercollateralised and bad debt accrues in the system.
MrPotatoMagic Follow with Maroutis, peanuts and 13 others
Originally disclosed on Code4rena
Submitted by MrPotatoMagic, also found by Maroutis, peanuts, ArmedGoose, d3e4, OMEN, NentoR, 0xtankr, SpicyMeatball, KYP, Shubham, dimulski, Giorgio, Sabit, Egis_Security, and T1MOH
The liquidate() function allows liquidators to burn DYAD on behalf of an DNft id and receive collateral in return.
The issue is that the current functionality only allows burning of the whole DYAD amount minted by the DNft id. This means that partial liquidations cannot be performed and prevents liquidators from liquidating DYAD minted by whales that hold huge positions in the system. Since the liquidations cannot be performed unless the liquidator can match up to the collateral deposited and DYAD minted by the whale, the system will be undercollaterized causing bad debt to accrue.
The effect of this issue will increase as more such positions exist in the system that cannot be liquidated by the liquidators.
Proof of Concept
In the liquidate() function below, we can see on Line 235 that when the burn() function is called on the DYAD token contract, it burns the whole minted DYAD instead of allowing the liquidator to supply a specific amount they can burn to improve the collateral ratio of the id and the overall health of the system.
But since this is not allowed, liquidators trying to liquidate whales, who have minted a huge amount of DYAD, would fail due to the position being extremely big and the inability of partially liquidate.
File: VaultManagerV2.sol
225: function liquidate(
226: uint id,
227: uint to
228: )
229: external
230: isValidDNft(id)
231: isValidDNft(to)
232: {
233: uint cr = collatRatio(id);
234: if (cr >= MIN_COLLATERIZATION_RATIO) revert CrTooHigh();
235: dyad.burn(id, msg.sender, dyad.mintedDyad(address(this), id));
236:
237:
238: uint cappedCr = cr < 1e18 ? 1e18 : cr;
239: uint liquidationEquityShare = (cappedCr - 1e18).mulWadDown(LIQUIDATION_REWARD);
240: uint liquidationAssetShare = (liquidationEquityShare + 1e18).divWadDown(cappedCr);
241:
242: uint numberOfVaults = vaults[id].length();
243: for (uint i = 0; i < numberOfVaults; i++) {
244: Vault vault = Vault(vaults[id].at(i));
245: uint collateral = vault.id2asset(id).mulWadUp(liquidationAssetShare);
246:
247: vault.move(id, to, collateral);
248: }
249: emit Liquidate(id, msg.sender, to);
250: }
Recommended Mitigation Steps
Implement a mechanism to allow liquidators to partially liquidate positions. This would also require refactoring the collateral paid out to them based on the amount they cover.
Hmm, but can’t this be solved by flash loaning DYAD?
Not if loan exceeds market liquidity. Partial liquidations is a feature we should implement.
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 liquidate function hardcodes the full minted DYAD amount as the burn amount instead of accepting a partial amount from the liquidator.
Impact
Large positions cannot be liquidated unless a liquidator can source the full debt, so the system becomes undercollateralised and bad debt accrues; the team notes a flash loan could help only if it does not exceed market liquidity.
What the attacker needed
A position large enough to exceed available liquidity; position falls below the collateral ratio
The fix
Partial liquidations should be implemented, with the collateral paid to the liquidator recalculated based on the amount they cover.
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 this lending system, a position is healthy when the collateral is worth enough compared with the borrowed stablecoin. If the value drops, a liquidator repays the debt and takes some collateral as a reward. Here the code forces the liquidator to repay the entire debt at once, which is impossible for very large borrowers, so those positions cannot be rescued and the system loses money.
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.