Lack of sanity check for `stoptime`
The stream creation function did not check that the stop time is after the current time, so a user could create a stream that has already ended. Such a stream cannot be cancelled, and the user wastes gas compared to a simple token transfer.
rvierdiiev Follow with pashov, jonatascm and 5 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-11-nounsdao-judging/issues/66
Found by
rvierdiiev, pashov, jonatascm, WATCHPUG, chainNue, csanuragjain, hansfriese, ctf_sec
Summary
We believe when the stoptime is before the current time, then it might be wrong.
Vulnerability Detail
Creating a stream with a stopTime earlier than the current time is the equivalent of making a simple ERC20 transfer, except that a stream will be much more expensive in terms of gas cost.
Therefore, we believe there is no such use case and the system should include a sanity check to ensure stoptime > block.timestamp.
Impact
If the user calls createAndFundStream() with a wrong/unintended stoptime that is earlier than the current time, the stream will not be able to be canceled.
Code Snippet
https://github.com/sherlock-audit/2022-11-nounsdao/blob/main/src/StreamFactory.sol#L184-L213
Tool used
Manual Review
Recommendation
function createStream(
address payer,
address recipient,
uint256 tokenAmount,
address tokenAddress,
uint256 startTime,
uint256 stopTime,
uint8 nonce
) public returns (address stream) {
// These input checks are here rather than in Stream because these parameters are written
// using clone-with-immutable-args, meaning they are already set when Stream is created and can't be
// verified there. The main benefit of this approach is significant gas savings.
if (payer == address(0)) revert PayerIsAddressZero();
if (recipient == address(0)) revert RecipientIsAddressZero();
if (tokenAmount == 0) revert TokenAmountIsZero();
if (stopTime <= startTime) revert DurationMustBePositive();
if (tokenAmount < stopTime - startTime) revert TokenAmountLessThanDuration();
+ if (stopTime <= block.timestamp) revert StopTimeLessThanCurrentTime();
stream = streamImplementation.cloneDeterministic(
encodeData(payer, recipient, tokenAmount, tokenAddress, startTime, stopTime),
salt(
msg.sender, payer, recipient, tokenAmount, tokenAddress, startTime, stopTime, nonce
)
);
IStream(stream).initialize();
emit StreamCreated(
msg.sender, payer, recipient, tokenAmount, tokenAddress, startTime, stopTime, stream
);
}
Discussion
eladmallel
Fix PR: https://github.com/nounsDAO/streamer/pull/8
jack-the-pug
Fix confirmed!
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the `createStream` function lacked a check that `stopTime` is greater than the current block timestamp.
Impact
A stream created with a past stop time cannot be cancelled, and the user pays unnecessary gas.
What the attacker needed
User calls createAndFundStream(); stopTime earlier than current time
The fix
The issue was fixed by adding a check that reverts if `stopTime` is less than or equal to the current block timestamp.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A stream is a way to send tokens gradually over time. The code allowed someone to set the end time in the past, which makes the stream useless and impossible to cancel. This wastes gas and locks funds in a broken stream.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.