The SablierFlow contract contains a potential division-by-zero vulnerability in the _calculateDepletionTime function. This vulnerability could lead to a panic error when the ratePerSecond variable is zero, causing the contract to revert unexpectedly.
The issue is in the following function, which calculates the depletion time based on the contract's solvency rate :
https://github.com/Cyfrin/2024-10-sablier/blob/8a2eac7a916080f2022527408b004578b21c51d0/src/SablierFlow.sol#L93
If ratePerSecond
is zero, dividing solvencyAmount
by ratePerSecond
results in a division-by-zero panic. This leads to an immediate halt in the execution of the function and reverts the transaction, causing instability for any users or external contracts relying on this function.
Add the following test to tests folder :
The division-by-zero occurs when ratePerSecond
is equal to zero, which can happen under certain configurations or states of the contract. This error has been reproduced in a unit test (testDivisionByZero
) that intentionally sets ratePerSecond
to zero.
This vulnerability has a medium impact as it could lead to:
Unexpected Reverts: The division-by-zero panic causes the transaction to revert. This affects the contract's usability and can disrupt functionality for users and dependent contracts.
Potential Denial of Service: If ratePerSecond
can be manipulated externally, this could be exploited to cause repeated reverts, creating a denial of service.
1- Foundry for setting up and running the unit test.
2- Manual Code Review to locate the vulnerable line of code.
1- Fallback Logic: If ratePerSecond being zero is an expected but rare case, implement fallback logic to handle this scenario safely.
2-Check for Zero: Before performing division, add a check to ensure ratePerSecond
is non-zero:
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.