Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The TempleGoldStaking.sol contract is a fork of the Synthetix rewards distribution contract, with slight modifications. The code special-cases the scenario where there are no users, by not updating the cumulative rate when the _totalSupply is zero, but it does not include such a condition for the tracking of the timestamp from L476.
Because of this, even when there are no users staking, the accounting logic still thinks funds were being dispersed during that timeframe (because the starting timestamp is updated),
As a result, if the distributeRewards() function is called prior to there being any users staking, the funds that should have gone to the first stakers will instead accrue to nobody, and be locked in the contract forever.
Example Scenario
Alice is distributionStarter and Bob is a person who wants to stake Temple.
Alice calls the distributeRewards() function to mint TGLD for this contract.
Let's suppose the minted TGLD is 786400 ether to calculate simply. Then rewardRate becomes 1 ether.
After 24 hours, Bob stakes 10000 TGLD into the contract.
After 6 days, Bob withdraw all staked TGLD and claim rewards. Then he gets 686400 ether.
As a result, 86400 ether is locked in the contract.
Recommendation
In the function distributeRewards(), check if there are enough reward tokens already in the contract.
Checklist