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.
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
Assume strike price of vault is 1 and current price of pegged asset is also 1
User calls triggerDepeg function which calls isDisaster modifier to check the depeg eligibility
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
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
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
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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
Assume the strike price of the vault is 1 and the current price of the pegged asset is also 1.
A user calls the triggerDepeg function, which invokes the isDisaster modifier.
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.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.