When the vault position is open(positionIsClosed == false
), deposits are processed through a deferred mechanism that involves off-chain signals and token swaps. During this process, the keeper-provided metadata triggers a GMX swap
and subsequent order execution. In the afterOrderExecution()
callback for MarketIncrease
orders, the vault calculates an “increased” amount
based on the deposited amount, fees, and a price impact factor before calling _mint()
. This formula can result in deposits minted with more (or less) shares compared to deposits when the position is closed(positionIsClosed == true
), leading to unfair distribution.
Users get different number of shares depending on position is open or closed(irrespective of same collateral amount).
if user deposits during position is closed then shares mints directly.
if user deposits during position is open then below flow is followed:
User calls deposit()
, payexecutionfee and set- NextActionSelector.INCREASE_ACTION
Now keeper runs- runNextAction()
with metadata.length==2, which makes a gmx swap.
After swap, now flow comes to afterOrderExecution()
in vault, here it mint shares with an increased amount:
In test case, one depositor received 1,000,000 shares while another received 1,003,806 shares for the same collateral deposit amount.
Unfair shares distribution: This unfair distribution may lead to one user eventually withdrawing more collateral than their fair share while diluting other depositors’ stakes.
High, particularly under volatile market conditions where GMX swaps occur frequently and price impacts are significant.
Most of test code is mimcked from protocol's test/PerpetualVault.t.sol::test_DepositIntoGmx()
.
Add test function into test/PerpetualVault.t.sol
:
Run by: forge test --match-test test_UnfairDistribution --rpc-url https://arb1.arbitrum.io/rpc -vvv --via-ir
Output:
it's clear that tom shares are 3806 more than alice
(even both deposits same amount of collateral (1e12) ).
Manual Review
Ensure that deposits—regardless of whether the position is open or closed—are valued consistently. This might involve recalculating the vault’s total collateral in a way that smooths out transient price impacts before minting shares.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.