Missing enough exogenous collateral check in VaultManagerV2::liquidate makes the liquidation revert even if (DYAD Minted > Non Kerosene Value)
The liquidation function in VaultManagerV2 lacks a check that the vault's non-kerosene collateral value is at least the DYAD minted, so when a position's total collateral ratio remains at or above 150% due to kerosene but its exogenous collateral falls below the minted DYAD, liquidation reverts. This prevents liquidators from acting, allowing the protocol's core invariant (TVL > DYAD supply) to be broken and potentially causing DYAD to depeg.
shikhar229169 Follow with Honour, Circolors and 11 others
Originally disclosed on Code4rena
Submitted by shikhar229169, also found by Honour, Circolors, Maroutis, KupiaSec, 3th, ke1caM, 0xfox, 0xSecuri, Sancybars, Strausses, kennedy1030, Stormreckson, and 0x486776
The vulnerability is present in the VaultManagerV2::liquidate function where it doesn’t have any check for whether the vault has enough exogenous collateral leading to no liquidation even if the non-kerosene value is less than DYAD minted.
It is intended that the position of user’s DNFT has enough exogenous collateral and should be 150% overcollateralized. But there will arise a case when a position is no doubt 150% collateralized by the support of kerosene value, but the non-kerosene value is reduced below the DYAD token minted. As a result of which the vault doesn’t have enough required exogenous collateral. But due to the missing check for enough non-kerosene value collateral in liquidate function, the liquidation will never happen and reverts.
Impact
The position will never be liquidated, for the above discussed case. As a result of which the (DYAD Minted > Non Kerosene Value), making the value of DYAD to fall.
Proof of Concept
Add the below test file in test/fork/v2.t.sol, and add the imports:
import {DNft} from "../../src/core/DNft.sol";
import {ERC20} from "@solmate/src/tokens/ERC20.sol";
import {OracleMock} from "../OracleMock.sol";
import {IVaultManager} from "../../src/core/VaultManagerV2.sol";
Run the test (Replace the $ETH_MAINNET_RPC_URL by your eth mainnet rpc url):
forge test --mt test_LiquidationReverts_EvenIfVaultHasNotEnoughExoCollateral --fork-url $ETH_MAINNET_RPC_URL
function test_LiquidationReverts_EvenIfVaultHasNotEnoughExoCollateral() public {
address user = makeAddr("user");
vm.deal(user, 100 ether);
Licenser licenser = Licenser(MAINNET_VAULT_MANAGER_LICENSER);
vm.prank(MAINNET_OWNER);
licenser.add(address(contracts.vaultManager));
DNft dnft = DNft(MAINNET_DNFT);
vm.startPrank(user);
uint256 id = dnft.mintNft{value: 10 ether}(user);
// user adds vault
contracts.vaultManager.add(id, address(contracts.ethVault));
contracts.vaultManager.addKerosene(id, address(contracts.wstEth));
// user adds weth to the vault
deal(MAINNET_WETH, user, 10 ether); // get 10 weth to the user
ERC20(MAINNET_WETH).approve(address(contracts.vaultManager), 10 ether);
contracts.vaultManager.deposit(id, address(contracts.ethVault), 10 ether);
// user adds wsteth to the vault
deal(MAINNET_WSTETH, user, 10 ether); // get 10 wsteth to the user
ERC20(MAINNET_WSTETH).approve(address(contracts.vaultManager), 10 ether);
contracts.vaultManager.deposit(id, address(contracts.wstEth), 10 ether);
// user mints DYAD token
uint256 nonKeroseneValue = contracts.vaultManager.getNonKeroseneValue(id);
// user mints DYAD equal to the usd value of their non-kerosene collateral
uint256 dyadToMint = nonKeroseneValue;
contracts.vaultManager.mintDyad(id, dyadToMint, user);
// now the value of weth falls to 90%
_manipulateWethPrice();
// now get the nonKeroseneValue
uint256 newNonKeroseneValue = contracts.vaultManager.getNonKeroseneValue(id);
// non kerosene usd value reduced, as weth price reduced
assert(newNonKeroseneValue < dyadToMint);
// now it is intended that the user should be liquidated by a liquidator
// but due to missing exogenous collateral check, the liquidation will not happen
vm.stopPrank();
address liquidator = makeAddr("liquidator");
vm.deal(liquidator, 100 ether);
vm.startPrank(liquidator);
uint256 liquidatorId = dnft.mintNft{value: 10 ether}(liquidator);
// the liquidation reverts as mentioned, even if (dyadMinted > nonKeroseneValue)
// thus shows unintended behaviour
vm.expectRevert(IVaultManager.CrTooHigh.selector);
contracts.vaultManager.liquidate(id, liquidatorId);
vm.stopPrank();
}
function _manipulateWethPrice() internal {
(, int256 ans, , , ) = contracts.ethVault.oracle().latestRoundData();
OracleMock oracleMock = new OracleMock(uint256(ans));
vm.etch(address(contracts.ethVault.oracle()), address(oracleMock).code);
vm.warp(1);
OracleMock(address(contracts.ethVault.oracle())).setPrice(uint256(ans) * 90e18 / 100e18);
}
Tools Used
Unit Test in Foundry
Recommended Mitigation Steps
Update the line 214 in VaultManagerV2.sol:
- if (cr >= MIN_COLLATERIZATION_RATIO) revert CrTooHigh();
+ if (cr >= MIN_COLLATERIZATION_RATIO && getNonKeroseneValue(id) >= dyad.mintedDyad(address(this), id)) revert CrTooHigh();
Assessed type
Context
Kerosene should be included in the transfer upon liquidation.
@shafu0x - Could you please help with the severity assessment here?
The impact is obviously high, However, I’m not sure about the likelihood.
Here is an example, the user added extra kerosene (i.e. above 50%):
- A user added 110% value of non-kerosene
+60% value of kerosene=>CR 170% .- Non-kerosene value drops below 100%, let’s say 90%.
- Now, we have 90% value of non-kerosene
+60% value of kerosene=>CR 150%.- Liquidation is reverting.
Another scenario, would be that the kerosene added by the user is equal or less than 50%, and the price of kerosene goes up enough to cover 150% as CR.
So, likelihood depends on two events:
- Amount of kerosene has to be above 50%.
- Price of kerosene going up.
Given the info above, would you say the likelihood is low, medium or high?
As @0xMax1 mentioned, we fix this by also moving kerosene in the case of a liquidation. I think this should fix it.
The liquidation will revert if CR
>=1.5 but the non-kerosene collateral value is less than 100%. So, minted dyad is not backed by (at least) 100% of non-kerosene collateral.After discussing the likelihood of this with the sponsor, I believe the issue stands as high.
adam-idarrha (warden) commented:
This issue should be invalid. The issue is about the state where positions have exogenous collateral less than the DYAD minted, suggesting such positions should be liquidated. However, the protocol specifications do not mandate liquidation under these circumstances if the position remains overall sufficiently collateralized with kerosene.
Protocol docs state:
If a Note’s collateral value in USD drops below 150% of its DYAD minted balance, it faces liquidation.
There is no mention that position is subject to liquidation when
exogenous collateral < DYAD minted. Yes there is that check inwithdraw()andmintDyad(), but from reviewer’s perspective it is no more than sanity check. Because bypassing this check as it is doesn’t harm protocol due to the nature of Kerosine price (it has valuation of surplus collateral). That’s because if someone has say 90% of exogenous collateral and 60% of Kerosine, then somebody else has more than 100% in exogenous collateral and protocol is totally fine. As noted before, Kerosine has value only if there is surplus collateral in protocol. I think submission is invalid.
The core invariant of the protocol is
TVL (which is measured as the non Kerosene collateral) > DYAD total supplyPositions being able to fall below a 1:1 exogenous collateral to dyad minted ratio allows for the protocol to break it’s core invariant meaning this is a valid issue regardless of the sponsors intentions.
As pointed out in issue #1027, as the value of the collateral in the protocol is all significantly correlated (to the price of ETH), a significant drop in ETH price can cause a large % of open positions to drop below this 1:1 ratio; meaning it becomes very likely this core invariant is broken.
Abdessamed (warden) commented:
The confusion around this issue is that it didn’t succeed in combining two findings. There are two invariants related to minting/liquidating DYAD:
- When minting DYAD, the ratio 1:1 of exogenous value with dyad minted should hold.
- When liquidating DYAD, the 150% ratio of USD collateral value (not exogenous collaterals only) should hold.
This issue does not highlight the first invariant. It only talks about liquidation and it assumes that if the USD value of exogenous collateral drops below a 1:1 ratio, liquidation should happen, while this is a wrong assumption. Liquidation should happen if the total collateral USD value (including both exogenous and kerosene tokens) drops below 150%
However, the first invariant (when minting DYAD, a 1:1 ratio should hold) is a valid finding as it demonstrates a core invariant break, but it is not highlighted in this issue.
The core invariant of the whole protocol is that total TVL does not drop below total Dyad minted. Being able to liquidate positions that have fallen below the 1:1 ratio is merely a mitigation to protect the protocol from this happening.
Given there is no option to post collateral in non-ETH sources (other stable coins), if ETH price were to drop & TVL to fall below DYAD minted it would lead to the stablecoin to depegging as it would no longer be backed 1:1. Being able to liquidate positions with less than a 1:1 ratio is more a mitigation to protect the health of the entire protocol rather than a bug in itself.
This issue stays as a valid high since the core invariant in the protocol can be broken leading to DYAD’s depeg.
Note: For full discussion, see here.
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 check uses only the total collateral ratio (including kerosene) and omits a condition that the non-kerosene collateral value must be at least the DYAD minted.
Impact
Positions whose non-kerosene collateral falls below the DYAD minted cannot be liquidated, which can break the protocol's core invariant and cause DYAD to lose its peg.
What the attacker needed
A user position with kerosene collateral; non-kerosene value falls below DYAD minted; total collateral ratio stays at or above 150%
The fix
The liquidation logic should also transfer kerosene when a liquidation occurs, as confirmed by the sponsor.
How it was found
- A user mints a DNFT and adds an ETH vault and a kerosene vault.
- The user deposits WETH and wstETH as collateral.
- The user mints DYAD equal to the USD value of their non-kerosene collateral.
- The price of WETH is manipulated to fall to 90% of its previous value.
- The non-kerosene value becomes less than the DYAD minted.
- A liquidator attempts to liquidate the position but the transaction reverts with CrTooHigh.
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 stablecoin system, users lock collateral (like ETH) and also receive a second token called kerosene that counts toward their collateral ratio. The liquidation function only checks the total ratio (including kerosene) and not whether the real, non-kerosene collateral alone is enough to cover the stablecoins minted. So if the real collateral drops below the minted amount but kerosene keeps the total ratio above 150%, nobody can liquidate the position, which can make the stablecoin undercollateralised.
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.