Submitted by cmichel, also found by 0x0x0x, gzeon, Ruhum, gpersoon, hack3r-0m, and pauliax
The Streaming contract allows the deposit and reward tokens to be the same token.
The reward and deposit balances are also correctly tracked independently in depositTokenAmount and rewardTokenAmount.
However, when recovering tokens this leads to issues as the token is recovered twice, once for deposits and another time for rewards:
Given recoverTokens == depositToken, Stream creator calls recoverTokens(token = depositToken, creator).
Example:
Creator receives 1500 - 1000 = 500 excess deposit and 1000 - 500 = 500 excess reward.
When using the same deposit and reward token, the stream creator can steal tokens from the users who will be unable to withdraw their profit or claim their rewards.
One needs to be careful with using .balanceOf in this special case as it includes both deposit and reward balances.
Add a special case for recoverTokens when token == depositToken == rewardToken and then the excess should be ERC20(token).balanceOf(address(this)) - (depositTokenAmount - redeemedDepositTokens) - (rewardTokenAmount + rewardTokenFeeAmount);
brockelmore (Streaming Protocol) confirmed
