Skip to content
Business logic Audit finding Intermediate

Depeg event can happen at incorrect price

The depeg trigger condition in the smart contract used a strict less-than comparison, so a depeg event could be triggered when the asset price was exactly equal to the strike price, contrary to the documented requirement that it be below. An attacker could call the trigger function at the equal price to cause the vaults to swap assets prematurely.

Anurag Jain Follow

Originally disclosed on Code4rena

Submitted by csanuragjain, also found by bin2chen, datapunk, Lambda, R2, rbserver, and unforgiven

Depeg event can still happen when the price of a pegged asset is equal to the strike price of a Vault which is incorrect.

This docs clearly mentions:

“When the price of a pegged asset is below the strike price of a Vault, a Keeper(could be anyone) will trigger the depeg event and both Vaults(hedge and risk) will swap their total assets with the other party.” - https://code4rena.com/contests/2022-09-y2k-finance-contest

Proof of Concept

  1. Assume strike price of vault is 1 and current price of pegged asset is also 1
  2. User calls triggerDepeg function which calls isDisaster modifier to check the depeg eligibility
  3. Now lets see isDisaster modifier
modifier isDisaster(uint256 marketIndex, uint256 epochEnd) {
        address[] memory vaultsAddress = vaultFactory.getVaults(marketIndex);
        if(
            vaultsAddress.length != VAULTS_LENGTH
            )
            revert MarketDoesNotExist(marketIndex);

        address vaultAddress = vaultsAddress[0];
        Vault vault = Vault(vaultAddress);

        if(vault.idExists(epochEnd) == false)
            revert EpochNotExist();

        if(
            vault.strikePrice() < getLatestPrice(vault.tokenInsured())
            )
            revert PriceNotAtStrikePrice(getLatestPrice(vault.tokenInsured()));

        if(
            vault.idEpochBegin(epochEnd) > block.timestamp)
            revert EpochNotStarted();

        if(
            block.timestamp > epochEnd
            )
            revert EpochExpired();
        _;
    }
  1. Assume block.timestamp is at correct timestamp (between idEpochBegin and epochEnd), so none of revert execute. Lets look into the interesting one at
        if(
            vault.strikePrice() < getLatestPrice(vault.tokenInsured())
            )
            revert PriceNotAtStrikePrice(getLatestPrice(vault.tokenInsured()));
  1. Since in our case price of vault=price of pegged asset so if condition does not execute and finally isDisaster completes without any revert meaning go ahead of depeg
  2. But this is incorrect since price is still not below strike price and is just equal

Recommended Mitigation Steps

Change the isDisaster modifier to revert when price of a pegged asset is equal to the strike price of a Vault

if(
            vault.strikePrice() <= getLatestPrice(vault.tokenInsured())
            )
            revert PriceNotAtStrikePrice(getLatestPrice(vault.tokenInsured()));

MiguelBits (Y2K Finance) disputed and commented:

After discussion, the docs clearly state only below the strike Price

This docs clearly mentions:

"When the price of a pegged asset is below the strike price of a Vault, a Keeper(could be anyone) will trigger the depeg event and both Vaults(hedge and risk) will swap their total assets with the other party." - https://code4rena.com/contests/2022-09-y2k-finance-contest

csanuragjain (warden) commented:

@MiguelBits Exactly when it is below the strike price but in this case depeg is happening when price is equal and not below. Can you please suggest?

MiguelBits (Y2K Finance) confirmed and commented:

Oh I see what you mean, need to correct it!

HickupHH3 (judge) commented:

Ah, a matter of when the equality sign matters a lot. Critically, in this case. Agree with warden that it should be <= and not < only.


The original report as published on Code4rena, by csanuragjain. 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 isDisaster modifier used a strict less-than comparison instead of less-than-or-equal, allowing the depeg event when the price equals the strike price.

What the attacker needed

Price equals strike price; block timestamp within epoch

The fix

The condition should be changed to revert when the strike price is less than or equal to the latest price, i.e., use <= instead of <.

How it was found

  1. Assume the strike price of the vault is 1 and the current price of the pegged asset is also 1.
  2. A user calls the triggerDepeg function, which invokes the isDisaster modifier.
  3. The isDisaster modifier checks that the strike price is less than the latest price; since they are equal, the condition is false and no revert occurs.
  4. The depeg event proceeds even though the price is not below the strike price.

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.

This is a smart contract bug where a check for 'price below strike' was written as 'price less than strike', so it also allowed 'price equal to strike'. That meant someone could trigger a payout event when the price was only equal, not actually below, which could cause the vaults to swap assets at the wrong time.

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.

More by Anurag Jain

View all

63 more disclosed reports, best first.

More from Y2k Finance contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.