CancelFlow
ia added as a glass breaking function which will help to revert the current flow in case of any accident from Gamma side or GMX side , how ever in case of deposit flow it sent the collateral back and delete the user record but does not update the totalShare.
The vault can enter a state where it cannot proceed to the next flow and may become stuck due to an accident. To handle such scenarios, the Gamma team has implemented the cancelFlow
function as a glass-breaking mechanism. This function allows the team to reset the flow and restore the vault to a normal state. If the flow is in a deposit state, cancelFlow
will return the collateral tokens to the user and reset the vault's state.
From the above code, it can be observed that cancelFlow
sends back the collateralToken
, updates totalDepositAmount
, refunds the fee, and deletes the depositInfo
. However, there is an edge case where virtual shares are minted to the user, but totalShare
is not updated accordingly. This issue can lead to incorrect share calculations for other users, ultimately impacting withdrawals.
Add following test case to PerpetualVault.t.sol
and run with command forge test --mt test_CancelFlow_Deposit_Case -vvv --rpc-url arbitrum
:
For this test case we need that the positionIsClosed = false;
so inside PerpetualVault::initialize()
function.
Failing to update totalShare
affects how users withdraw their funds. Since withdrawals rely on dividing shares by totalShare
, users will consistently receive less than intended.
Manual Review
In case of deposit flow also check subtract the user shares from totalShare
.
Likelihood: None/Very Low, when the keeper call cancelFlow after an order execution Impact: High, Inflation/deflation of total shares, and too many fees refunded.
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.