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.
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:
Initial Share Calculation:
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.
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.
manual
consider using dead share technique if the goal is to prevent first deposit inflation attack. see reference and other technique:
https://mixbytes.io/blog/overview-of-the-inflation-attack
https://blog.openzeppelin.com/a-novel-defense-against-erc4626-inflation-attacks
or Consider removing the 1e8
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.