Skip to content

Latest commit

 

History

History
56 lines (30 loc) · 1.9 KB

File metadata and controls

56 lines (30 loc) · 1.9 KB

Steep Rose Rattlesnake

Medium

Vault.sol when market closed, minPosition is calculated incorrectly, which may cause allocated assets to remain unreleased

Summary

The Vault.sol calculation of minPosition doesn't take into account market closed, which can lead to values that are too large and funds never get released.

Root Cause

in StrategyLib.sol#L205

We will calculate marketContext.minPosition to avoid MarketOverCloseError/MarketInsufficientLiquidityError error when decreasing Position

Use formula: minPosition = user.maker - min( (global.maker - | global.long - global.short | ) , user.closable )

The current code doesn't take into account market closed, which may result in global.maker - | global.long - global.short | being very small, resulting in minPosition being too large.

note: when market closed , don't check MarketInsufficientLiquidityError

It should use : minPosition = user.maker - user.closable when the market closed.

        marketContext.minPosition = marketContext.currentAccountPosition.maker
            .unsafeSub(marketContext.currentPosition.maker
                .unsafeSub(marketContext.currentPosition.skew().abs()).min(marketContext.closable));

Internal pre-conditions

  1. market.marketParameter.closed = true

External pre-conditions

No response

Attack Path

No response

Impact

marketContext.minPosition is too large will cause that can't reduce position=0, even if weight=0, collateral can't be released, closed markets are not profitable, this part funds fails to generate revenue

PoC

No response

Mitigation

when market closed:marketContext.minPosition = marketContext.currentAccountPosition.maker .unsafeSub(marketContext.closable);