In the core/src/libraries/Helpers.sol file, within the calculateSegmentTimestamps function, if the user inputs a segments length of 0, the function will revert due to an overflow.
In the calculateSegmentTimestamps function, if the user inputs a segments length of 0, there will create a variable namedsegmentsWithTimestamps whose length is 0, and the segmentsWithTimestamps[0] will revert due to an overflow.
https://github.com/Cyfrin/2024-05-Sablier/blob/43d7e752a68bba2a1d73d3d6466c3059079ed0c6/v2-core/src/libraries/Helpers.sol#L16C4-L36C16
The same scenario in the checkCreateLockupDynamic function, but checkCreateLockupDynamic function validates the length of the variable segments.
Taking the creation of a LockupDynamic stream as an example, in the SablierV2LockupDynamic.sol file, the user creates a stream through the createWithDurations function. The createWithDurations function first calls the calculateSegmentTimestamps function, followed by the _create function. The initially called calculateSegmentTimestamps function does not check the length of segments, while the subsequently called _create function (through the checkCreateLockupDynamic function) does check the length of segments. This results in a delayed validation of the user's input for the segments length.
When create the lockupDynamic stream, The function call procedure looks like this:
When calling the calculateSegmentTimestamps function, there is no check for segments.length within this function. If the user inputs a segments length of 0, the function will revert due to an overflow.
The _create function calls the checkCreateLockupDynamic function, which checks the user's input for segments.length.
A similar problem occurs with `Helps.sol:calculateTrancheTimestamps中
This could save a lot of gas if the revert condition is met earlier.
Manual Review
in v2-core/src/libraries/Helpers.sol:calculateSegmentTimestamps, add the check for segments.length.
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.