Sablier

Sablier
DeFiFoundry
53,440 USDC
View results
Submission Details
Severity: medium
Invalid

`SablierV2LockupDynamic::_calculateStreamedAmountForMultipleSegments` does not take into account payments that are due now

Summary

The _calculateStreamedAmountForMultipleSegments in SablierV2LockupDynamic.sol will not take into account a user's segment amount if block.timestamp equals currentSegmentTimestamp

Vulnerability Details

The function _calculateStreamedAmountForMultipleSegments calculates the current user's amount that he has and can withdraw. The problem is that the while loop will skip 1 of the payments if the currentSegmentTimestamp equals blockTimestamp

This is how the while loop inside the function looks like:

while (currentSegmentTimestamp < blockTimestamp) {
previousSegmentAmounts += segments[index].amount;
index += 1;
currentSegmentTimestamp = segments[index].timestamp;
}

It loops until the currentSegmentTimestamp is less than blockTimestamp which means that if they are equal it will exit out. This is a problem because the payment that is due now is not taken into account and if a user tries to withdraw now and his last payment is due now it will be skipped and the user will have to reinvoke the function again or will think that he has to wait more until his payment comes

Impact

This leads to a user not being able to receive his full amount in some cases when currentSegmentTimestamp equals blockTimestamp. If a user has a payment and it unlocks now, he should have access to it.

Tools Used

Manual review

Recommendations

Change the while loop to include the payments that are due now

- while (currentSegmentTimestamp < blockTimestamp) {
+ while (currentSegmentTimestamp <= blockTimestamp) {
previousSegmentAmounts += segments[index].amount;
index += 1;
currentSegmentTimestamp = segments[index].timestamp;
}
Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.