sablier-labs / v2-core

⏳ Core smart contracts of the Sablier V2 token distribution protocol
https://sablier.com
Other
288 stars 38 forks source link

Check if the start time is in the future in linear contract #938

Closed andreivladbrg closed 3 weeks ago

andreivladbrg commented 3 weeks ago

Now, since cliff time can be zero, this check is not enough in SablierV2LockupLinear._calculateStreamedAmount:

https://github.com/sablier-labs/v2-core/blob/cf246ef5199289539426ee19476f3ef9ebf0556d/src/SablierV2LockupLinear.sol#L191-L195

Test to run

It will revert with a PRB Math error since we use `unchecked`: https://app.warp.dev/block/OBorEzMLUvWOk9R8CmXlky ```solidity function test_Cancel_Pending_Linear() public { vm.warp({ newTimestamp: defaults.START_TIME() - 100 }); LockupLinear.Timestamps memory timestamps = defaults.lockupLinearTimestamps(); timestamps.cliff = 0; uint256 streamId = createDefaultStreamWithTimestamps(timestamps); console2.log("Stream ID: %d status is %d", streamId, uint8(lockup.statusOf(streamId))); lockup.cancel(streamId); } ```

Thus, we should also check if the start time is in the future.

Also, ref of the issue here.

PaulRBerg commented 3 weeks ago

It is worth noting that this bug does not affect any Sablier contract running in production, since we haven't deployed V2.2 yet.