When a user deposits a long position into a 1x leverage market with a long open position, after the deposit flow is finalized, the flow stays in FLOW.DEPOSIT so the protocol gets stuck. This happens in PerpetualVault::runNextAction
Let`s consider the following scenario:
Alice deposits into a market with 1x leverage a long position (first deposit)
Bob deposits another long position in the same market after Alice
After Bob deposit, the protocol gets stuck in FLOW.DEPOSIT mode
Charlie tries to deposit but it reverts
Alice tries to withdraw but it reverts
See the following PoC showing this scenario:
Add this test to PerpetualVault.t.sol
I was hesitant whether to classify it as medium or high. I went for high because even though it can be “fixed” by the keeper, it makes the protocol practically unusable.
After the second deposit, no one can interact with the protocol.
The only fix would be for the keeper to invoke cancelFlow() which will swap the index token back to collateral and transfer it back to Bob in this case and cancel the deposit. By doing this, no more deposits are allowed in this market so all of them will have to be cancelled.
The other possible “fix” would be for the owner to invoke setVaultState() after every deposit to reset the flow.
As stated before, this makes the protocol impractical so I believe it is a high.
Foundry
Invoke _finalize()in runNextAction() after the swap is performed under the conditions : _nextAction.selector == NextActionSelector.INCREASE_ACTION => _isLongOneLeverage(_isLong):
Likelihood: Medium/High, - Leverage = 1x - beenLong = True - positionIsClosed = False - Metadata → 1 length and Dex Swap Impact: Medium/High, DoS on any new action before the admin uses setVaultState Since this seems to be the most probable path for a 1x PerpVault, this one deserves a High.
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.