The enrootDeposits function in the EnrootFacet contract has a potential divide by zero issue when calculating depositBdv within the loop that iterates over stems. This issue arises when enrootData.totalAmountRemoved becomes zero, which can occur if no deposits are removed during the execution of the function.
The enrootDeposits function is responsible for updating the BDV (Bean Denominated Value) of multiple unripe deposits (stems) for a given token. It iterates over each deposit, calculates depositBdv based on the proportion of newTotalBdv to totalAmountRemoved, and then adds the deposit back with the new BDV. Below is the critical section of the function:
The potential divide by zero issue occurs in the calculation of depositBdv:
If enrootData.totalAmountRemoved is zero, the division operation enrootData.newTotalBdv.div(enrootData.totalAmountRemoved) will cause a runtime exception due to division by zero. This can happen if no deposits (amounts) are removed during the execution of enrootDeposits.
Division by zero will cause the transaction to revert, leading to potential loss of gas and user inconvenience. The contract might fail to update the BDV and stalk calculations correctly, leading to inconsistencies in the token deposit system.
Manual Review
To mitigate the divide by zero issue, ensure that enrootData.totalAmountRemoved is checked before performing the division operation. If totalAmountRemoved is zero, handle this edge case appropriately, such as by skipping the division or setting depositBdv to a default value.
Invalid as per docs https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity
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.