Skip to content
Business logic Audit finding Intermediate

Attacker can transfer all SUSD’s balance of LiquidityPool as margin to Synthetix perpetual market, and break the actions of users until the pool is rebalanced by the authority

The LiquidityPool contract always transfers a positive margin to the Synthetix perpetual market for every trade, even when reducing position size. An attacker can repeatedly open and close a position in one transaction to drain the pool's SUSD balance into margin, preventing users from withdrawing or trading until the pool is rebalanced.

KIntern_NA Follow

Originally disclosed on Code4rena

Submitted by KIntern_NA

Contract LiquidityPool will transfer margin of size delta for every trade, and this margin is always > 0. Then attacker can repeat open and close a position in 1 transaction, to make the pool transfer all its SUSD tokens to Synthetix perpetual market as margin, even the perpetual size of LiquidityPool will not change after that. Then many actions of users which need SUSD of the pool such as withdrawing liquidity tokens, opening short positions, closing long positions… can’t be executed until the pool is rebalanced by the authority.

Proof of concept

Let’s take a look at function _hedge in contract LiquidityPool:

function _hedge(int256 size, bool isLiquidation) internal returns (uint256 hedgingFees) {
    ...
    uint256 marginRequired = _calculateMargin(hedgingSize) + hedgingFees;
    usedFunds += int256(marginRequired);
    require(usedFunds <= 0 || totalFunds >= uint256(usedFunds));

    perpMarket.transferMargin(int256(marginRequired));
    ...

In this function, marginRequired is always > 0, since it is the required margin for the independant hedgingSize.

Even the size of pool’s perpetual position increases or decreases (sometimes it doesn’t need to transfer more positive margin), it always transfer this amount of SUSD as margin to Synthetix perpetual market.

Then attacker can make the pool transfer all its SUSD tokens as margin by repeating open and close a position, although it will not change the pool’s perpetual size after that. It leads to users’ actions can be broken because of the lack of SUSD in LiquidityPool, until the pool is rebalanced by the authority. Furthermore, the attacker can front-run to break the actions of important specific users.

Recommended Mitigation Steps

Calculate marginRequired (can be positive or negative) from the new perpetual size and the remaining margin. I advise you to use the similar calculation from the function rebalanceMargin.

mubaris (Polynomial) disagreed with severity and commented:

The entire action of the pool will be watched by a keeper bot to call rebalanceMargin() anytime required. I disagree with the severity of this issue.

Dravee (judge) decreased severity to Low/Non-Critical and commented:

Furthermore, the attacker can front-run to break the actions of important specific users.

Optimism, no front-running.

Assets aren’t at risk and this can’t really be considered a real grief attack either if this is just a random act.

Lack of coded POC too to prove that this could actually be done for cheap or not by the attacker. Hand-waved arguments.

Will downgrade to QA.

duc (warden) commented:

This issue highlights the problem that the LiquidityPool contract always adds margin for every trade, even if sizeDelta is decreased. The marginRequired should be calculated correctly, similar to the rebalanceMargin function, to prevent the transferred margin from growing too high.

Therefore, the attacker can conduct a grief attack by repeatedly opening and closing a position in 1 transaction, causing the LiquidityPool to transfer more margin than it actually needs. I am aware that a keeper bot will be used to call rebalanceMargin() whenever necessary, but bot’s action can’t guarantee flawless performance indefinitely. So within the scope of the smart contract, I think this issue deserves to be considered a valid medium.

Dravee (judge) increased severity to Medium and commented:

Talked with the sponsor. This issue can indeed be considered valid, but will be a no-fix. Still a nice-to-have on the final report.


The original report as published on Code4rena, by KIntern_NA. 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 margin calculation always returns a positive value regardless of whether the position size is increasing or decreasing, so the pool transfers excess margin on every trade.

Impact

Users cannot withdraw liquidity, open short positions, or close long positions until the pool is manually rebalanced; the attacker could also front-run to target specific users, though the judge noted no front-running on Optimism and assets are not at risk.

What the attacker needed

Attacker has funds to trade; pool has SUSD balance

The fix

Calculate marginRequired from the new perpetual size and remaining margin, similar to the rebalanceMargin function, so that margin can be positive or negative as needed.

How it was found

  1. Attacker calls a function to open a position, causing the pool to transfer margin to the perpetual market.
  2. Attacker immediately closes the position in the same transaction, but the pool still transfers margin again.
  3. Attacker repeats open and close many times in one transaction until the pool's SUSD balance is depleted.

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.

A liquidity pool holds funds that users can withdraw or use for trading. The pool also trades on another market and must post collateral (margin) for those trades. Because the pool always adds margin even when it shouldn't, an attacker can make many quick trades to lock up all the pool's funds as margin, so users cannot withdraw or trade until someone manually fixes the pool's balance.

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 KIntern_NA

View all

21 more disclosed reports, best first.

More from Polynomial Protocol 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.