Skip to content
Business logic Audit finding Intermediate

Risk users are required to payout if the price of the pegged asset goes higher than underlying

The smart contract calculates the depeg ratio using the lower of the two asset prices, so a pegged asset trading above its underlying is treated as a depeg event. This means risk users (sellers of insurance) are required to pay out even though the pegged asset is worth more, which is not a real depeg.

0x52 Follow

Originally disclosed on Code4rena

Submitted by 0x52, also found by 0xDecorativePineapple, hyh, Jeiwan, Lambda, and PwnPatrol

Insurance is to protect the user in case the pegged asset drops significantly below the underlying but risk users are required to payout if the pegged asset is worth more than the underlying.

Proof of Concept

    if (price1 > price2) {
        nowPrice = (price2 * 10000) / price1;
    } else {
        nowPrice = (price1 * 10000) / price2;
    }

The above lines calculates the ratio using the lower of the two prices, which means that in the scenario, the pegged asset is worth more than the underlying, a depeg event will be triggered. This is problematic for two reasons. The first is that many pegged assets are designed to maintain at least the value of the underlying. They put very strong incentives to keep the asset from going below the peg but usually use much looser policies to bring the asset down to the peg, since an upward break from the peg is usually considered benign. The second is that when a pegged asset moves above the underlying, the users who are holding the asset are benefiting from the appreciation of the asset; therefore the insurance is not needed.

Because of these two reasons, it is my opinion that sellers would demand a higher premium from buyers as a result of the extra risk introduced by the possibility of having to pay out during an upward depeg. It is also my opinion that these higher premiums would push users seeking insurance to other cheaper products that don’t include this risk.

Recommended Mitigation Steps

The ratio returned should always the ratio of the pegged asset to the underlying (i.e. pegged/underlying).

MiguelBits (Y2K Finance) marked as duplicate and commented:

Duplicate of 26.

HickupHH3 (judge) commented:

Not a duplicate.

Pegged tokens go both ways: either valued more or less than the asset it’s pegging to (underlying token).

The warden is arguing that when the pegged token is worth more than the underlying (eg. worth > $1 for a stablecoin), the users are still eligible for a payout, which he argues shouldnt be the case.

I agree with the warden; from experience, most projects see it as a positive if their algo stablecoin is worth more than the underlying, and so, wouldn’t do nothing about it. In fact, they’d probably use it as a shilling point to attract more users to mint more of these tokens to help bring the price down. This scenario should not be covered by the insurers.


The original report as published on Code4rena, by 0x52. 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

Likely the ratio calculation always uses the lower price as the numerator, so it cannot distinguish between the pegged asset being below or above the underlying.

Impact

Risk users could be forced to pay out when the pegged asset appreciates above the underlying, which may lead to higher premiums and push users to cheaper products.

What the attacker needed

Pegged asset trades above underlying

The fix

The ratio should always be calculated as the pegged asset price divided by the underlying price, so that only downward depegs trigger a payout.

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 about a smart contract that acts like insurance for stablecoins. If a stablecoin loses its peg (drops below $1), the insurance pays out. But the code also pays out when the stablecoin goes above $1, which is not a problem for holders. The report says that is wrong because it makes sellers of insurance take unnecessary risk.

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 0x52

View all

211 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.