Skip to content
Business logic Audit finding Intermediate

Any user can avoid paying most of the protocol fees on short positions, and can unknowingly pay very high fee on long positions

The protocol fee for LIMIT orders is calculated from the user-supplied limit price rather than the actual execution price. For short positions, a user can set a very low limit price to pay almost no fee, and for long positions, a user can set a very high limit price and unknowingly pay an inflated fee.

panprog Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-06-symmetrical-judging/issues/139

Found by

panprog

Summary

Protocol fee paid by the user for LIMIT orders is calculated based on the LIMIT price provided by the user. For short positions, a very low LIMIT price allows to basically open short position close to MARKET order (using current market price). However, the fee paid will be based on very low LIMIT price, which is far below current market price, allowing the user to pay very low fee (close to 0), which is the funds lost by the protocol (the user steals his fee from the protocol).

For long positions, if the LIMIT price provided is very high (which basically equals a MARKET long order), the user will unknowningly overpay the fee due to the same bug.

Vulnerability Detail

For LIMIT orders, the protocol fee user pays is calculated as percentage of quantity * requestedOpenPrice, which is a price provided by the user in the quote.

https://github.com/sherlock-audit/2023-06-symmetrical/blob/main/symmio-core/contracts/libraries/LibQuote.sol#L126-L130

For short positions, a user can provide very low price (for example, if current ETH price is $1000, user can provide $1) and be charged a very low fee ($0.01 instead of $10). Since the provided price is very low, the order will basically be equal to MARKET order. This allows users to avoid paying the protocol fee, which is a loss of fees funds for the protocol.

For long positions, if a user uses a high limit price (which basically equals long MARKET order), he will unknowingly pay very large fee (for example, if current ETH price is $1000, user provides a $10000 LIMIT price, paying $100 fee instead of $10). This is a loss of funds for the user, which he didn't expect to pay.

Impact

For short positions, users can avoid paying protocol fees for opened positions, resulting in protocol fee loss.

For long positions, users can pay very large fee, resulting in user funds loss.

Code Snippet

Add this to any test, for example to ClosePosition.behavior.ts

TS
  it("1. Paying very low fees", async function () {
    const context: RunContext = this.context;

    this.user_allocated = decimal(500);
    this.hedger_allocated = decimal(4000);

    this.user = new User(this.context, this.context.signers.user);
    await this.user.setup();
    await this.user.setBalances(this.user_allocated, this.user_allocated, this.user_allocated);

    this.hedger = new Hedger(this.context, this.context.signers.hedger);
    await this.hedger.setup();
    await this.hedger.setBalances(this.hedger_allocated, this.hedger_allocated);

    // Quote1 SHORT opened
    await this.user.sendQuote(limitQuoteRequestBuilder().positionType(PositionType.SHORT).quantity(decimal(500)).build());
    await this.hedger.lockQuote(1);
    await this.hedger.openPosition(1, limitOpenRequestBuilder().filledAmount(decimal(500)).build());

    var feeCollectorAddress = await context.viewFacet.getFeeCollector();
    var feeBalance = await context.viewFacet.balanceOf(feeCollectorAddress);

    console.log("Fee collected (LIMIT SHORT 500 @ 1.0, filled at 1.0): " + feeBalance/1e18);

    // Quote2 SHORT opened
    await this.user.sendQuote(limitQuoteRequestBuilder().positionType(PositionType.SHORT).quantity(decimal(500)).price(decimal(2, 17)).build());
    await this.hedger.lockQuote(2);
    await this.hedger.openPosition(2, limitOpenRequestBuilder().filledAmount(decimal(500)).build());

    feeBalance = await context.viewFacet.balanceOf(feeCollectorAddress) - feeBalance;

    console.log("Fee collected (LIMIT SHORT 500 @ 0.2, filled at 1.0): " + feeBalance/1e18);

  });

Tool used

Manual Review

Recommendation

There are a couple of options depending on team preference:

  1. Always calculate fee based on market price (quote.marketPrice), both for MARKET and LIMIT orders. Upside is very easy fix, downside is that for LIMIT orders which are on the market for a long time (aiming for prices away from current market), the fees will be wrong (the market price at openPosition time can be very different from the price at the sendQuote time).

  2. The fee should be taken based on actual position openPrice (at the time of opening the position), rather than any price at the sendQuote time. Upside is completely correct fees in any conditions, downside is more difficult fix (and slight differences from the preliminary fees paid at sendQuote time). It will require returning the fees before opening a position, and taking it again (but based on openPrice) after the position is opened.

Discussion

panprog

Escalate

This is at least a valid medium. If long quote is opened with very high limit price, but is executed at the current market price, then fee is taken using user-specified limit price, not the execution price. For example:

  1. ETH is trading at about $1000, fee is 1%
  2. PartyA send a quote long 1 ETH at LIMIT price = $100000, the fee locked is 1 * $100000 * 1% = $1000
  3. PartyB locks the quote and opens position with the current market price ($1000).
  4. Fee taken is $1000 instead of expected $10, which is an unexpected loss of funds for the PartyA

It can be argued that user sending a long quote with LIMIT price = $100000 risks having his position opened at this extremely high price, however this is still possible (so a valid scenario, even if not very likely) and this also requires partyB to act maliciously risking its reputation (a fair partyB should open positions with its market price, not with the best price it can get). If partyB behaves this way, it risks being banned from the platform or users starting to blacklist it (or rather not including in whitelist in the current implementation) due to such story getting public attention.

Additionally, #225 is a valid medium with a very similar requirement (user specifying very low LIMIT price), but a different core reason and impact.

Due to the scenario of user losing significant amount possible (even if not very likely), this should be at least a valid medium.

sherlock-admin2

Escalate

This is at least a valid medium. If long quote is opened with very high limit price, but is executed at the current market price, then fee is taken using user-specified limit price, not the execution price. For example:

  1. ETH is trading at about $1000, fee is 1%
  2. PartyA send a quote long 1 ETH at LIMIT price = $100000, the fee locked is 1 * $100000 * 1% = $1000
  3. PartyB locks the quote and opens position with the current market price ($1000).
  4. Fee taken is $1000 instead of expected $10, which is an unexpected loss of funds for the PartyA

It can be argued that user sending a long quote with LIMIT price = $100000 risks having his position opened at this extremely high price, however this is still possible (so a valid scenario, even if not very likely) and this also requires partyB to act maliciously risking its reputation (a fair partyB should open positions with its market price, not with the best price it can get). If partyB behaves this way, it risks being banned from the platform or users starting to blacklist it (or rather not including in whitelist in the current implementation) due to such story getting public attention.

Additionally, #225 is a valid medium with a very similar requirement (user specifying very low LIMIT price), but a different core reason and impact.

Due to the scenario of user losing significant amount possible (even if not very likely), this should be at least a valid medium.

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

MoonKnightDev

This isn't a bug. It's not a free workaround that users can employ to pay less in fees. In fact, by doing this, they are taking a substantial risk. We cannot guarantee that Party B will open the position at the market price. Consequently, Party B could open that short position at the lowest possible price, potentially causing the user to suffer a significant loss.

panprog

This isn't a bug. It's not a free workaround that users can employ to pay less in fees. In fact, by doing this, they are taking a substantial risk. We cannot guarantee that Party B will open the position at the market price. Consequently, Party B could open that short position at the lowest possible price, potentially causing the user to suffer a significant loss.

I agree that not paying fee is connected with a high risk, although this is still possible, like some partyB can let people pay less fees this way by promising to fill them at market price if they specify a LIMIT price close to 0.

It is, however, possible for the user to unexpectedly pay substantially more in fees (for long position with limit price much higher than market) than he should like in example in previous comment. Yes, he risks being filled at that inflated price, but if he's filled at the market price (which can happen, not all partyBs will fill at the price very far from the market), the fees will still be paid from the limit price, so he'll pay much higher fees than he should, effectively protocol will steal a large amount from user. Yes, not very likely, but possible, so should be valid medium.

Also, I want to repeat that #225 is a valid medium and the requirements for it to happen are the same.

Evert0x

  1. ETH is trading at about $1000, fee is 1%
  2. PartyA send a quote long 1 ETH at LIMIT price = $100000, the fee locked is 1 * $100000 * 1% = $1000
  3. PartyB locks the quote and opens position with the current market price ($1000).
  4. Fee taken is $1000 instead of expected $10, which is an unexpected loss of funds for the PartyA

@panprog why is this an unexpected loss for PartyA? It is a known fact the fee will be $1000 at step 2), right?

panprog

@panprog why is this an unexpected loss for PartyA? It is a known fact the fee will be $1000 at step 2), right?

The fee is 1% of notional. Notional = size * price. Position is opened at a price = $1000, so Notional = 1 * 1000 = $1000. So the fee should be $1000 * 1% = $10. IF the quote was executed at the requested price of $100000, then yes, notional would be $100000 and fee would be $1000.

But the quote was opened at a price of $1000. Why does the protocol charge such high fee (equal to position notional) when the real position notional is just $1000? The fact that user requested a price $100000 doesn't mean that protocol should charge the fee off this price regardless of real open price.

Another example: imagine you open long 1 ETH position at a LIMIT price of $1.000.000 at Binance. Since the orderbook is deep, you get executed close to current price of $1000, so a notional of $1000. The fee (0.1%) would be $1. Do you expect that binance will charge you off $1.000.000 notional for a fee of $1000 just because you specified LIMIT price of $1.000.000?

panprog

For comparison, if the user requested a price of $100.000 with a MARKET order, but is filled at the current price of $1000, he's charged a $10 fee, not $1000, although it's also possible that he's filled at the requested price of $100.000. So why charge $10 for a MARKET order, but $1000 for the same LIMIT order?

And regarding - if it's a known fact that fee is $1000 for such LIMIT order. I don't think it's specified anywhere, but it's just common sense and how all the other protocols work - charging fee based on actual executed price, not based on requested price.

panprog

If you mean that the fee is already taken at the sendQuote time, this is preliminary fee based on the current data and it can change. For example, if quote is canceled, the fee is refunded. So I don't think that preliminary fee can serve as a "known fact" of the final fee. As a user, I'd expect the fee to be refunded if quote is canceled, and the fee to be adjusted if the actual price differs from the requested one, like the locked values are adjusted.

hrishibhat

Sponsor comment:

when someone places a short limit order at a low price, they indeed pay reduced fees. However, they also accept the potential risk of unfavorable opening prices for their position. Ideally, fees should be charged at the position's opening, but due to certain complexities, we plan to implement this in upcoming versions.

panprog

As I understand, sponsor confirms this is a valid issue. I want to note that the report talks both about lower or higher fees (although POC supplied is about lower fees):

  1. For SHORT quotes, partyA will pay reduced fees (loss of funds for the protocol)
  2. For LONG quotes, partyA will pay inflated fees (loss of funds for the user)

While the sponsor only mentions the 1st impact (user can pay lower fees), I think the higher impact is the 2nd, where user pays inflated fees, which can be orders of magnitude higher than the user should pay. And the fact that the users bears the risk of unfavorable opening prices shouldn't influence the validity of this issue. Still, I think both impacts make this a valid medium.

hrishibhat

Result: Medium Unique After reviewing the comments above and further discussion, agree with the points in the escalation, considering this issue a valid medium although unlikely there are situations where this would have an impact.

sherlock-admin2

Escalations have been resolved successfully!

Escalation status:

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

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

Impact

For short positions, users can avoid paying protocol fees, causing fee loss for the protocol; for long positions, users may pay a much higher fee than expected, causing user fund loss.

What the attacker needed

A limit order with a price far from market; the position is opened at market price

The fix

The fee should be based on the actual position open price at the time of opening, not the limit price from the quote.

How it was found

  1. Send a LIMIT quote with a very low price for a short position.
  2. Have the quote locked and the position opened at the current market price.
  3. Observe that the fee collected is based on the low limit price, not the market 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.

When you place a limit order, you set the price you are willing to trade at. This protocol charges its fee based on that price, not the price at which the trade actually happens. So if you set a very low price for a short, you pay almost no fee, and if you set a very high price for a long, you pay a much larger fee than expected.

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 panprog

View all

66 more disclosed reports, best first.

More from Symmetrical Update

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.