DeFiFoundry
50,000 USDC
View results
Submission Details
Severity: high
Invalid

Incorrect Share Calculation in `PerpetualVault._mint`

Summary

The _mint function in the PerpetualVault contract incorrectly calculates the initial shares for the first deposit, leading to inflated share values. This results in incorrect accounting, allowing the first depositor to withdraw significantly more funds than deposited when subsequent deposits occur.

Vulnerability Details

When minting shares for the first deposit, the initial shares are calculated as depositInfo[depositId].amount * 1e8. This arbitrary multiplication by 1e8 inflates the share values significantly. As a result, the first depositor receives a disproportionately large number of shares compared to the actual value of their deposit. Subsequent deposits are calculated proportionally, but the initial inflated shares cause an imbalance in the share distribution.

Root Cause:
The initial share calculation in the _mint function uses an arbitrary multiplier (1e8), leading to inflated share values for the first depositor.

Proof of Concept:

  1. Initial Share Calculation:

    if (totalShares == 0) {
    _shares = depositInfo[depositId].amount * 1e8;
    }
  2. Example Scenario:

    • First Deposit:

      • User A deposits 1,000 tokens.

      • Shares minted: 1,000 * 1e8 = 100,000,000,000 shares.

    • Second Deposit:

      • User B deposits 1,000 tokens.

      • Total amount before deposit: 1,000 tokens.

      • Shares minted: 1,000 * 100,000,000,000 / 1,000 = 100,000,000,000 shares.

    • Withdrawal:

      • User A and User B both have 100,000,000,000 shares.

      • User A can withdraw 50% of the vault's assets, even though they only deposited 1,000 tokens.

      • This results in User A withdrawing more than their fair share, causing losses for User B.

Impact

Severe inflation of shares causes incorrect asset distribution, enabling the first depositor to withdraw significantly more funds than they deposited. This results in potential theft of funds from later depositors, undermining the fairness and integrity of the vault.

Tools Used

manual

Recommendations

Updates

Lead Judging Commences

n0kto Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!