Improper handling of decimals can lead to the minting of false shares, negatively impacting the protocol.
The PerpetualVault::_mint function is used in various operations such as deposit, afterOrderExecution, and runSwap to calculate the number of shares received based on the given amount. However, an issue arises when totalAmountBefore == 0, as the value is then set to 1.
When totalAmountBefore = 0 due to various conditions, it is automatically updated to 1. However, this does not account for decimals properly, leading to incorrect _shares calculations, especially with high decimal values from amount * totalShares. Ideally, totalAmountBefore should be used to reduce the decimals generated from amount * totalShares.
This scenario enables malicious actors to inflate their shares, effectively taking funds from others by increasing their own share allocation.
It also creates an imbalance in share distribution, which can negatively impact the overall protocol.
Manual Review
Change totalAmountBefore = 1 to totalAmountBefore = 1e(decimals)
No proof when this can happen: Most of the time totalAmountBefore equals 0 (balance minus amount sent), it means totalShares equals 0. If it could happen with very specific conditions, report with that tag didn't add the needed details to be validated.
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.