The PerpetualVault.sol contract calculates user withdrawal amounts based on their share of the total collateral in the vault. This design allows the withdrawal amount of a user to be reduced if the total collateral decreases due to losses incurred by other users, even if the user has personally made a profit. This creates a dependency where a user's profits and losses are influenced by the performance of others, contradicting the protocol's goal of providing a simplified and independent leveraged trading experience.
In the PerpetualVault.sol contract, the amount of collateral tokens a user receives upon withdrawal is calculated based on their share of the total collateral in the vault. This calculation is done in the _handleReturn function as follows:
This design means that even if a user has personally made a profit, their withdrawal amount can be reduced if the total collateral in the vault has decreased due to losses incurred by other users. This creates a dependency where the profits and losses of one user are influenced by the performance of others.
Direct Financial Loss: Users who have personally made a profit may receive less collateral than they deposited if other users incur losses.
Reduced Trust: This dependency undermines user trust in the protocol, as users cannot independently benefit from their own successful trades.
Protocol Misalignment: This design contradicts the protocol's goal of simplifying leveraged trading for individual users, as it introduces collective risk that users cannot control.
This vulnerability contradicts the protocol's goal of providing a simplified and independent leveraged trading experience for users. Specifically:
What does the system do?
Simplifies the process of leveraged trading for users who may not want to actively manage their positions.
Provides a way for users to participate in leveraged trading with reduced active management.
The current implementation introduces a collective risk model, where users' profits and losses are interdependent, which is not aligned with the goal of simplifying independent leveraged trading.
Manual Code Review
Foundry (for testing and validation)
Below is a Foundry test case demonstrating how a user's withdrawal amount can be reduced due to losses incurred by other users:
Isolate User Collateral: Implement a mechanism where each user's collateral is managed separately. This ensures that a user's profits and losses are independent of other users' performance.
Introduce an Insurance Fund: Create an insurance fund to cover losses, ensuring that profitable users are not penalized for the losses of others.
Revise Profit/Loss Calculation: Modify the withdrawal logic to calculate profits and losses based on individual user performance rather than the collective performance of all users.
By addressing this vulnerability, the protocol can better align with its goal of simplifying leveraged trading for individual users while maintaining fairness and trust.
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.