The function distributeDebtToVaults in Market.sol has a potential division-by-zero vulnerability due to an insufficient check on totalVaultSharesX18. The function includes a check to prevent distribution when there is zero delegated credit, but it does not revalidate this condition before division occurs. This could lead to contract failure, incorrect debt distribution, or panic state misclassification under certain market conditions.
This check only validates the value at the beginning of the function.
If totalVaultSharesX18 becomes zero after this check (due to changes in state variables or external calls), any subsequent division operation involving totalVaultSharesX18 may cause a division-by-zero error.
This could result in unexpected contract behavior, including:
Reverts halting contract execution.
Incorrect debt distribution.
If exploited or encountered, this could completely break debt distribution logic, potentially leading to incorrect credit allocations or contract failures.
The impact depends on whether totalVaultSharesX18 is modified dynamically before division, which varies based on contract interactions.
Manual Code Review
Add an additional check right before any division to ensure totalVaultSharesX18 has not changed
Instead of performing a direct division, ensure totalVaultSharesX18 is non-zero before performing calculations:
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.