Skip to content
Audit finding Intermediate

Value of kerosene can be manipulated to force liquidate users

The price of kerosene tokens is calculated from the protocol's total value locked (TVL) and can be manipulated instantly by large depositors withdrawing their collateral. An attacker can drop the kerosene price to push other users' collateralization ratios below the liquidation threshold and liquidate them.

carrotsmuggler Follow with peanuts, pontifex and 28 others

Originally disclosed on Code4rena

Submitted by carrotsmuggler, also found by peanuts, pontifex, adam-idarrha, d3e4, Al-Qa-qa, amaron (1, 2), 0xblack_bird, foxb868, Infect3d, windhustler, 0xSecuri, jesjupyter, forgebyola, Ryonen, AM, KupiaSec, wangxx2026, SpicyMeatball, nnez, itsabinashb, cu5t0mpeo, zhuying, T1MOH, VAD37, darksnow (1, 2), Dudex_2004, Jorgect, 0xnev, AlexCzm, 0xAlix2, GalloDaSballo, and Egis_Security

The value of kerosene tokens is calculated according to the following formula:

Note: Please see scenario in warden’s original submission.

The price of kerosene changes based on user actions. If a user has a large amount of tokens in their vault, that adds to the TVL. Now if a user mints a bunch of dyad tokens with their deposit as collateral, or if a removes a bunch of their unused collateral, the price of kerosene tokens will drop instantaneously.

When calculating the collateralization ratio of a user’s position, the price of kerosene is essential. This is used in the getKeroseneValue function.

function getKeroseneValue(
    uint id
  )
    public
    view
    returns (uint) {
      uint totalUsdValue;
      uint numberOfVaults = vaultsKerosene[id].length();
      for (uint i = 0; i < numberOfVaults; i++) {
        Vault vault = Vault(vaultsKerosene[id].at(i));
        uint usdValue;
        if (keroseneManager.isLicensed(address(vault))) {
          usdValue = vault.getUsdValue(id);
        }
        totalUsdValue += usdValue;
      }
      return totalUsdValue;
  }

function getTotalUsdValue(
    uint id
  )
    public
    view
    returns (uint) {
      return getNonKeroseneValue(id) + getKeroseneValue(id);
  }

As seen above, thetotalUsdValue depends on the getKeroseneValue function, which calls getUsdValue on the kerosene vaults. So instantaneously dropping the price of kerosene tokens will also instantaneously drop the totalUSDValue of the user’s position, decreasing their collateralization ratio. This can be used to force users into liquidation, if their final ratio drops below the liquidation threshold.

Since this allows any user to affect the collateralization ratio of other user’s positions, this is a high severity issue.

Proof of Concept

Assume Alice has 1 million USDC tokens in her vault, and 0 minted dyad tokens. TVL is 10 million USD of exo collateral, dyad supply is 5.5 million. Assume total supply of kerosene is 100,000.

So the price of kerosene is:

kerosenePrice = {10,000,000 - 5,500,000}/{100,000} = 45 USD

Now assume Bob has an account with 1000 USDC tokens, and 20 kerosene tokens. They minted 1150 dyad tokens. These values were already included in the calculation above, so the minted amounts wont change. Their current collateralization ratio is:

CR = {1000 + 45 * 20}/{1150} = 1.65

Now, Alice decides to attack BOB’s position. She withdraws her 1 million USDC tokens from her vault. This drops the TVL to 9 million USD. Now the price of kerosene is:

kerosenePrice = {9,000,000 - 5,500,000}/{100,000} = 35 USD

Now the collateralization ratio of Bob’s position is:

CR = {1000 + 35 * 20}\{1150} = 1.48

Thus, Bob’s position is liquidatable.

Whales can set up traps by putting in large amounts of capital as TVL into the vault, propping up the price of kerosene. Then whenever a user opens a position which is moderately close to the liquidation threshold, the whale can immediately take out their liquidity, effectively doing a rug pull, and liquidate the users.

Since this gives high net worth users an easy way to manipulate the protocol at no loss, this is a high severity issue.

Recommended Mitigation Steps

Add a TWAP mechanism to calculate the price of kerosene. The price of kerosene being manipulatable instantaneously is a huge risk. By using a TWAP mechanism, the price of kerosene will be more stable, and users will have more time to react to changes in the price of kerosene.

Assessed type

Oracle

0xMax1 (DYAD) commented:

Kerosene can be very volatile. Especially in the early days. Users should act accordingly.

shafu0x (DYAD) acknowledged

Koolex (judge) decreased severity to Medium and commented:

Relying solely on the spot price makes users positions subject to liquidation which is a known issue in DeFi. Users should act to prevent their position from being liquidated, However, in this scenario, it is not possible since the price is manipulated in one block. Downgrading to medium since the price math is stated by the protocol.


The original report as published on Code4rena, by carrotsmuggler. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

The kerosene price is derived from the spot TVL, which can be changed instantly by large withdrawals, so the price is manipulable.

Impact

A large depositor can force other users into liquidation at no loss to themselves, potentially causing those users to lose collateral.

What the attacker needed

Attacker has large capital to deposit; victim has a position near liquidation threshold

The fix

The kerosene price should be calculated using a time-weighted average price (TWAP) mechanism to make it more stable and resistant to instant manipulation.

How it was found

  1. Alice deposits a large amount of USDC into her vault, raising the TVL and the kerosene price.
  2. Bob opens a position with some USDC and kerosene, minting dyad tokens, with a collateralization ratio above the liquidation threshold.
  3. Alice withdraws her large USDC deposit, instantly dropping the TVL and the kerosene price.
  4. Bob's collateralization ratio falls below the liquidation threshold, making his position liquidatable.

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 DeFi protocol, the value of a special token called kerosene depends on how much money is locked in the system. A big player can suddenly take their money out, making kerosene cheaper. That makes other people's borrowed positions look riskier, so they can be liquidated (forced to repay or lose collateral).

More by carrotsmuggler

View all

42 more disclosed reports, best first.

More from DYAD

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.