Since _averageBalance is always bigger than _averageTotalSupplies[0]. We can implement the, if statement earlier. This will ensure to output 0 earlier. Furthermore, _averageBalance is in stack and this check costs less gas. Therefore, the code can be implemented as follows:
Handle
0x0x0x
Vulnerability details
https://github.com/pooltogether/v4-periphery/blob/b520faea26bcf60371012f6cb246aa149abd3c7d/contracts/TwabRewards.sol#L302-L321 is as follows:
Since
_averageBalance
is always bigger than_averageTotalSupplies[0]
. We can implement the, if statement earlier. This will ensure to output 0 earlier. Furthermore,_averageBalance
is in stack and this check costs less gas. Therefore, the code can be implemented as follows: