Skip to content
Business logic Audit finding Intermediate

`partyA` can inflate the uPnL with no cost

A partyA could open a long limit position with an openedPrice of 0, causing no locked values and inflating its unrealised profit (uPnL) at no cost. This could let partyA avoid liquidation and wait for favourable price movements.

shaka Follow

Originally disclosed on Sherlock

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

Found by

shaka

Summary

partyA can inflate the uPnL with no cost by opening a long position of order type limit with an openedPrice of 0, using a partyB account that is also controlled by partyA.

Vulnerability Detail

In the PartyBFacetImpl:openPosition function, when the position type is long there is no minimum for the openedPrice. Also, if the openedPrice is lower than the requestedOpenPrice, the proportional locked values are unlocked. This means that for a long position of order type limit party B can send an openedPrice of 0 and result in no locked values.

This could be done by a partyA to inflate the uPnL with no cost. See the following example:

  1. Party A creates a quote with the following parameters:

    • partyBsWhiteList: [bob]
    • positionType: LONG
    • orderType: LIMIT
    • price: 100e18
    • quantity: 1e18
    • cva: 22e18,
    • mm: 75e18
    • lf: 3e18
  2. Party A also controls the bob account and uses it to open a position with the following parameters:

    • filledAmount: 1e18
    • requestedOpenPrice: 0
  3. As a result, there is no locked values and the uPnL of party A is inflated by (currentPrice - 0) * 1e18.

This temporary inflation of the uPnL will be corrected when party B is liquidated. However, there are two things to consider:

  • There is no incentive for liquidators to liquidate the position, since the liquidation fee is 0. So it will have to be done by the liquidator bot.
  • There is a liquidation timeout that will delay the liquidation process. Currently this value is set to 1 day in the Fantom mainnet.

Party A can also repeat the process with different accounts to keep the uPnL inflated.

Impact

Party A can inflate the uPnL with no cost, which could be used to avoid liquidations and wait until the prices on other positions are favorable.

Code Snippet

https://github.com/sherlock-audit/2023-06-symmetrical/blob/main/symmio-core/contracts/facets/PartyB/PartyBFacetImpl.sol#L136-L167

Tool used

Manual Review

Recommendation

A possible solution would be checking that the openedPrice is inside a certain range.

Discussion

shaka0x

Escalate.

The issue has been marked incorrectly as a duplicate of #350. That issue is about how submitting a very large value for openPrice can cause overflow/underflow in forward calculations.

This issue shows how passing an openPrice of 0 can be used to inflate the uPnL of another account. So I think this one should be considered as a valid issue.

sherlock-admin2

Escalate.

The issue has been marked incorrectly as a duplicate of #350. That issue is about how submitting a very large value for openPrice can cause overflow/underflow in forward calculations.

This issue shows how passing an openPrice of 0 can be used to inflate the uPnL of another account. So I think this one should be considered as a valid issue.

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.

hrishibhat

@ctf-sec

panprog

This looks like a duplicate of #225 to me. The core reason is the same (scaled balances for LIMIT orders). The impact, as I see it, is that due to lockedBalances = 0, any market price change will make either party liquidatable with bad debt, meaning that the profit for the other party will be slightly reduced due to bad debt. I see no other benefit to either party: PartyA upnl is inflated by PartyB loss: PartyB will not be allowed to openPosition if it doesn't have enough allocatedBalance to cover PartyA profit. So in the example from the report:

  • PartyA will have unrealized profit of 100
  • PartyB will have unrealized loss of -100, and it can only openPosition if it has allocatedBalance = 100

So it's not like PartyA has unrealized profit for free - partyB must have the same amount allocated to open the position. I'm not sure if this impact is high enough to be medium. It's hard to use this self-inflicted bad debt. So either this is duplicate of #225 or low impact.

shaka0x

This looks like a duplicate of #225 to me. The core reason is the same (scaled balances for LIMIT orders). The impact, as I see it, is that due to lockedBalances = 0, any market price change will make either party liquidatable with bad debt, meaning that the profit for the other party will be slightly reduced due to bad debt. I see no other benefit to either party: PartyA upnl is inflated by PartyB loss: PartyB will not be allowed to openPosition if it doesn't have enough allocatedBalance to cover PartyA profit. So in the example from the report:

  • PartyA will have unrealized profit of 100
  • PartyB will have unrealized loss of -100, and it can only openPosition if it has allocatedBalance = 100

So it's not like PartyA has unrealized profit for free - partyB must have the same amount allocated to open the position. I'm not sure if this impact is high enough to be medium. It's hard to use this self-inflicted bad debt. So either this is duplicate of #225 or low impact.

This issue differs completely from #255. Neither the root cause, nor the impact or the fix are similar.

PartyA does have an unrealized profit for free. Once partyB is liquidated, the 100 will go to partyA so, as both accounts are controlled by the same person and there is no liquidation fee involved, there is no cost to perform the operation. Until the liquidation process for partyB is completed (remember that there is a minimum delay and that there are no economic incentives for liquidators) partyA has managed to inflate his global uPnL, avoiding a potential liquidation.

panprog

@shaka0x I don't understand why you call this inflated upnl if it's just funds of the user. Can you describe better? Scenario 1: User has $200. He deposits and allocates all $200 into partyA account. He has allocated balance of 200 + 0 (unrealized pnl) - total of 200 available for the positions.

Scenario 2: User has $200. He deposits and allocates 100 to partyA and 100 to controlled partyB account. He then opens the position described in this report between partyA and partyB. Now partyA has 100 (balance) + 100 (upnl) = 200 available for positions, while partyB has 100 (balance) - 100 (upnl) = 0 available. If partyB is liquidated, the situation will be exactly as in scenario 1: PartyA balance will be 200, upnl 0, PartyB balance will be 0.

So what's the difference between scenario 1 and 2? Why partyA needs to deposit funds to partyB and create upnl with it, when it can simply deposit these funds directly to partyA account?

shaka0x

@shaka0x I don't understand why you call this inflated upnl if it's just funds of the user. Can you describe better? Scenario 1: User has $200. He deposits and allocates all $200 into partyA account. He has allocated balance of 200 + 0 (unrealized pnl) - total of 200 available for the positions.

Scenario 2: User has $200. He deposits and allocates 100 to partyA and 100 to controlled partyB account. He then opens the position described in this report between partyA and partyB. Now partyA has 100 (balance) + 100 (upnl) = 200 available for positions, while partyB has 100 (balance) - 100 (upnl) = 0 available. If partyB is liquidated, the situation will be exactly as in scenario 1: PartyA balance will be 200, upnl 0, PartyB balance will be 0.

So what's the difference between scenario 1 and 2? Why partyA needs to deposit funds to partyB and create upnl with it, when it can simply deposit these funds directly to partyA account?

In scenario 1 uPnL is 0, as uPnL is calculated based on the open positions. In the difference between the opened price and the current price to be more precise.

hrishibhat

Sponsor comment:

the auditor has identified a valid bug. We must verify locked values at the time of opening. While we do check it for partial fillings, we overlooked it for complete fillings.

panprog

Sponsor's response implies the fix is to verify that locked values are not less than minAcceptableQuoteValue and this can only happen due to lockedValues being scaled.

  • The fix for #225 is adding solvency check after lockedValues are scaled
  • The fix for this issue is adding lockedValues > minAcceptableQuoteValue check after lockedValues are scaled
  • The impact of both #225 and this one are probably medium (scenarios are completely different, but the impact is still medium)

I still think this is duplicate of #225 because core reason is that scaled lockedValues are not accounted for. However, since the condition which should be checked is different, this might be a separate issue.

MoonKnightDev

Fixed code PR link: https://github.com/SYMM-IO/symmio-core/pull/25

hrishibhat

@shaka0x Let me know what you think of this comment: https://github.com/sherlock-audit/2023-06-symmetrical-judging/issues/181#issuecomment-1685204613

shaka0x

@hrishibhat this are my thoughts

Sponsor's response implies the fix is to verify that locked values are not less than minAcceptableQuoteValue and this can only happen due to lockedValues being scaled.

Agree, the fix is different, as seen in the PRs shown by the sponsor.

Agree that the impact scenarios are different (instant liquidation of user vs user avoiding liquidation by inflating his uPnL). However, I do think that a user being able to avoid liquidation by manipulating his uPnL is a high severity issue.

I still think this is duplicate of #225 because core reason is that scaled lockedValues are not accounted for. However, since the condition which should be checked is different, this might be a separate issue.

I do not see the root cause of the issues to be the same at all. #255 's is that the check for solvency is done before the adjustment on lockedValues. The root cause of this issue is that a party B can inflate the uPnL of party A, and if they are the same person, this will have no cost, as lockedValue = 0.

In fact, although the fix https://github.com/SYMM-IO/symmio-core/pull/25 is a good addition, I would argue that is still not enough to mitigate the issue. By checking that lockedValue is above minAcceptableQuoteValue, the uPnL manipulation is not free anymore. But depending on the value of minAcceptableQuoteValue, the amount subject to liquidation for party A and the liquidation timeout, a user might still be incentiviced to inflate his uPnL though this operation. That is why my recommendation was checking that the openedPrice is inside a certain range.

panprog

However, I do think that a user being able to avoid liquidation by manipulating his uPnL is a high severity issue.

The scenario presented uses controlled partyB account which is whitelisted by the protocol and any malicious actions with it are at most medium (as seen from many other issues with partyBs).

the amount subject to liquidation for party A and the liquidation timeout, a user might still be incentiviced to inflate his uPnL though this operation.

Liquidation timeout doesn't delay the liquidation process, it's just the time acceptable between liquidation steps, so it has nothing to do with this issue here. I can only see the impact of user inflating his upnl via partyB when the locked values = 0: then as soon as the price moves, the one side (partyB) will have bad debt and once liquidated, the other side (partyA) will have it's unrealized profit reduce immediately by bad debt, which can in turn make partyA liquidatable with bad debt (highly unlikely scenario, but still possible). Additionally, liquidators are not incentivized to liquidate such partyB due to locked balance = 0 and no profit for the liquidator.

If locked balances are enforced to be minAcceptableQuoteValue: what is the impact that the user can make his partyA account in large profit? I don't see any impact here. If partyB is liquidated, partyA will realize its profit (+cva), so no other party can lose funds due to this. And unrealized profit by itself is not an issue: it can happen naturally as well, what's the benefit for the user to have unrealized profit rather than balance? The original issue was exactly due to locked balance = 0.

shaka0x

However, I do think that a user being able to avoid liquidation by manipulating his uPnL is a high severity issue.

The scenario presented uses controlled partyB account which is whitelisted by the protocol and any malicious actions with it are at most medium (as seen from many other issues with partyBs).

Message 1 for partyB it can also be assumed that anyone can be one (eventually that is the goal)

Message 2 the system will be permissionless (anyone can become a counterparty), so consider them not trusted neither party should have any special privileges in the system

the amount subject to liquidation for party A and the liquidation timeout, a user might still be incentiviced to inflate his uPnL though this operation.

Liquidation timeout doesn't delay the liquidation process, it's just the time acceptable between liquidation steps, so it has nothing to do with this issue here.

You are right. I was mistakenly interpreting it as a cooldown period.

I can only see the impact of user inflating his upnl via partyB when the locked values = 0: then as soon as the price moves, the one side (partyB) will have bad debt and once liquidated, the other side (partyA) will have it's unrealized profit reduce immediately by bad debt, which can in turn make partyA liquidatable with bad debt (highly unlikely scenario, but still possible). Additionally, liquidators are not incentivized to liquidate such partyB due to locked balance = 0 and no profit for the liquidator.

If locked balances are enforced to be minAcceptableQuoteValue: what is the impact that the user can make his partyA account in large profit? I don't see any impact here. If partyB is liquidated, partyA will realize its profit (+cva), so no other party can lose funds due to this. And unrealized profit by itself is not an issue: it can happen naturally as well, what's the benefit for the user to have unrealized profit rather than balance? The original issue was exactly due to locked balance = 0.

From the moment party B opens the position until the moment party B is liquidated, party A manages to avoid liquidation. So basically party A is buying time for his positions to recover (the market prices can change in his favor). It is true that being an incentive for liquidators (lockedValue not zero) it is likely that this time window will not be as long as in the case when there is not such incentive. But depending on the amount party A has at risk of liquidation and his expectations about the market, might still be interested in paying the cost of the lockedValue in order to freeze his liquidation process for longer.

Anyway, that comment was just about my thoughts of the sponsor's fix. With the current code I think that the potential damage is clear.

hrishibhat

Result: Medium Unique Based on the above discussion considering its a valid medium

sherlock-admin2

Escalations have been resolved successfully!

Escalation status:

The original report as published on Sherlock, by shaka. 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

Root cause

Likely, the contract does not enforce a minimum openedPrice for long limit orders, allowing a zero price that unlocks all locked values.

Impact

Party A could inflate its uPnL at no cost, potentially avoiding liquidation and waiting for favourable price movements; however, the inflation is temporary and corrected upon liquidation of party B, and liquidators lack incentive due to zero liquidation fee.

What the attacker needed

PartyA controls a partyB account; partyB is whitelisted; partyA has sufficient allocated balance

The fix

The code was fixed by adding a check that locked values are not less than minAcceptableQuoteValue after scaling, as shown in the sponsor's PR.

How it was found

  1. Party A creates a quote with a whitelisted partyB, long position, limit order, and specified price, quantity, cva, mm, and lf.
  2. Party A, controlling the partyB account, opens the position with a filledAmount equal to the quantity and a requestedOpenPrice of 0.
  3. As a result, no locked values remain and party A's uPnL is inflated by the difference between current price and zero times the quantity.

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 trading system, a user (partyA) can create a position with a counterparty (partyB). The bug lets partyA set the opening price to zero, so no collateral is locked, and partyA's profit appears artificially high. This fake profit can help partyA dodge liquidation.

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 shaka

View all

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