Division before multiplication result in loss of token reward if the reward update time elapse is small
Division before multiplication result in loss of token reward\\nWhen calcuting the reward, we are calling\\n```\\n function currentRewardsPerToken() public view returns (uint256) {\\n        // Rewards do not accrue if the total balance is zero\\n        if (totalBalance == 0) return rewardsPerTokenStored;\\n\\n        // @audit\\n        // loss of precision\\n        // The number of rewards to apply is based on the reward rate and the amount of time that has passed since the last reward update\\n        uint256 rewardsToApply = ((block.timestamp - lastRewardUpdate) * rewardRate) /\\n            REWARD_PERIOD;\\n\\n        // The rewards per token is the current rewards per token plus the rewards to apply divided by the total staked balance\\n        return rewardsPerTokenStored + (rewardsToApply * 10 ** stakedTokenDecimals) / totalBalance;\\n    }\\n```\\n\\nthe precision loss can be high because the accumulated reward depends on the time elapse:\\n(block.timestamp - lastRewardUpdate)\\nand the REWARD_PERIOD is hardcoded to one days:\\n```\\n    /// @notice Amount of time (in seconds) that the reward rate is distributed over\\n    uint48 public constant REWARD_PERIOD = uint48(1 days);\\n```\\n\\nif the time elapse is short and the currentRewardsPerToken is updated frequently, the precision loss can be heavy and even rounded to zero\\nthe lower the token precision, the heavier the precision loss\\nSome tokens have low decimals (e.g. USDC has 6). Even more extreme, some tokens like Gemini USD only have 2 decimals.\\nconsider as extreme case, if the reward token is Gemini USD, the reward rate is set to 1000 * 10 = 10 ** 4 = 10000\\nif the update reward keep getting called within 8 seconds\\n8 * 10000 / 86400 is already rounded down to zero and no reward is accuring for user
Avoid division before multiplcation and only perform division at last
Division before multiplication result in loss of token reward if the reward update time elapse is small
```\\n function currentRewardsPerToken() public view returns (uint256) {\\n        // Rewards do not accrue if the total balance is zero\\n        if (totalBalance == 0) return rewardsPerTokenStored;\\n\\n        // @audit\\n        // loss of precision\\n        // The number of rewards to apply is based on the reward rate and the amount of time that has passed since the last reward update\\n        uint256 rewardsToApply = ((block.timestamp - lastRewardUpdate) * rewardRate) /\\n            REWARD_PERIOD;\\n\\n        // The rewards per token is the current rewards per token plus the rewards to apply divided by the total staked balance\\n        return rewardsPerTokenStored + (rewardsToApply * 10 ** stakedTokenDecimals) / totalBalance;\\n    }\\n```\\n