Skip to content
Business logic Audit finding Intermediate

In de-peg scenario, forcing full exit from every derivative & immediately re-entering can cause big losses for depositors

The protocol's rebalancing function fully exits all derivative positions and then re-enters them according to new weights, rather than making only marginal adjustments. In a de-peg scenario, this forces unnecessary trades that increase slippage and cause losses for depositors.

0Kage Follow with Co0nan, deliriusz and 5 others

Originally disclosed on Code4rena

Submitted by 0Kage, also found by Co0nan, deliriusz, yac, Tricko, IgorZuk, adriro, and Bahurum

In a de-peg scenario, there will be a general flight to safety (ETH) from users across the board. All pools will have a uni-directional sell-pressure where users prefer to exchange derivative token for WETH.

There are 3 sources of losses in this scenario

  • Protocol currently doesn’t localize exit & force-exits all positions. So even non de-pegged assets are forced to exit causing further sell-side pressure that can further widen slippages
  • Protocol immediately tries to re-enter the position based on new weights. Since de-peg in one asset can trigger de-peg in another (eg. USDT de-pegged immediately after UST collapse), immediately entering into another position after exiting one might cause more. A better approach would be to simply exit stressed positions & waiting out for the market/gas prices to settle down. Separating exit & re-entry functions can save depositors from high execution costs.
  • Protocol is inefficiently exiting & re-entering the positions. Instead of taking marginal positions to rebalance, current implementation first fully exits & then re-enters back based on new weights (see POC below). Since any slippage losses are borne by depositors, a better implementation can save losses to users

Proof of Concept

  • Assume positions are split in following ratio by value: 10% frax-Eth, 70% stEth and 20% rEth
  • Now frax-Eth starts to de-peg, forcing protocol to exit frax-Eth and rebalance to say, 80% stEth and 20% rEth
  • Current rebalancing first exits 70% stEth, 20% rEth and then re-enters 80% stEth and 20% rEth
  • A marginal re-balancing would have only needed protocol to exit 10% frax-Eth and divert that 10% to stEth

By executing huge, unnecessary txns, protocol is exposing depositors to high slippage costs on the entire pool.

Recommended Mitigation Steps

Consider following improvements to rebalanceToWeights:

  • Separate exits & entries. Split the functionality to exit and re-enter. In stressed times or fast evolving de-peg scenarios, protocol owners should first ensure an orderly exit. And then wait for markets to settle down before re-entering new positions
  • Localize exits, ie. if derivative A is de-pegging, first try to exit that derivative position before incurring exit costs on derivative B and C
  • Implement a marginal re-balancing - for protocol’s whose weights have increased, avoid exit and re-entry. Instead just increment/decrement based on marginal changes in net positions

toshiSat (Asymmetry) acknowledged and commented:

This is definitely valid, it would require a black swan event. We have thought about this, and might implement this for v2.

This should be half confirmed, because I think we will implement the marginal rebalancing. I’m not sure if this is High severity, I will leave that up to judge.

Picodes (judge) decreased severity to Medium and commented:

The report shows how in case of a black swan event, the protocol could take a significant loss when calling rebalanceToWeights that could easily be avoided by implementing at least marginal re-balancings.

However, considering that there is no need to call rebalanceToWeights even in the case of a black swan event unless there is a governance decision to do so, I think Medium Severity is appropriate.

Note that even without black swan event, calling rebalanceToWeights would likely lead to a significant loss due to the current ineffective implementation. But there is no specific need to call this action unless the owner or the DAO wants to force the rebalancing.

Asymmetry commented:

Out of scope for mitigation review. Will need a black swan event to happen and will upgrade rebalanceToWeights later to handle this.


The original report as published on Code4rena, by 0Kage. 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 rebalancing function exits all positions entirely and then re-enters them based on new weights, instead of adjusting only the positions that need to change.

Impact

In a de-peg scenario, calling the rebalancing function could cause significant losses for depositors due to unnecessary slippage, though the function only runs if governance decides to call it.

What the attacker needed

A de-peg event occurs; governance calls rebalanceToWeights

The fix

The rebalancing function should be changed to separate exits and entries, localise exits to only the de-pegged asset, and use marginal rebalancing instead of full exit and re-entry.

How it was found

  1. Assume positions are split by value: 10% frax-Eth, 70% stEth, and 20% rEth.
  2. frax-Eth starts to de-peg, forcing the protocol to exit frax-Eth and rebalance to 80% stEth and 20% rEth.
  3. The current rebalancing first exits 70% stEth and 20% rEth, then re-enters 80% stEth and 20% rEth.
  4. A marginal rebalancing would have only needed to exit 10% frax-Eth and divert that to stEth.

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 a token loses its peg to the dollar (de-pegs), many people rush to sell it, which pushes prices around. This protocol, when it rebalances, sells all its holdings and then buys them back in new amounts, even if only one token de-pegged. That creates extra trading fees and price slippage, and those costs are paid by the people who deposited money.

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

View all

7 more disclosed reports, best first.

More from Asymmetry Finance afETH Invitational

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.