The _mint
function contains a division by zero vulnerability that can result in unfair share distributions.
_mint
function
The function calculates _shares
using the following logic:
The problem occurs when totalAmountBefore == 0
, where it is forcefully set to 1
. This prevents a division-by-zero error but leads to incorrect share calculations.
Unfair Share Distribution: The use of totalAmountBefore = 1
can cause inflated or incorrect share allocation, leading to some depositors getting an unfair advantage.
Potential Exploitation: A user could deposit when totalAmountBefore == 0
to receive disproportionate shares, diluting existing holders.
Incorrect Accounting: The contract's share issuance mechanism becomes unreliable, possibly affecting future operations.
Manual code review
Static analysis
Instead of setting totalAmountBefore = 1
, implement a proper fix:
Ensure Proper Initialization
Validate totalAmountBefore
before performing the division.
Check if totalAmountBefore == 0
and handle it gracefully instead of assigning 1
.
Revert Instead of Hardcoding a Value
This prevents transactions from proceeding under invalid conditions.
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.