Open code423n4 opened 2 years ago
WatchPug
For the arithmetic operations that will never over/underflow, using the unchecked directive (Solidity v0.8 has default overflow/underflow checks) can save some gas from the unnecessary internal over/underflow checks.
For example:
https://github.com/pooltogether/v4-periphery/blob/0e94c54774a6fce29daf9cb23353208f80de63eb/contracts/TwabRewards.sol#L153-L153
uint256 _amount = _numberOfEpochs * _promotion.tokensPerEpoch;
_numberOfEpochs is uint8 _promotion.tokensPerEpoch is uint216
_numberOfEpochs
_promotion.tokensPerEpoch
_numberOfEpochs * _promotion.tokensPerEpoch will never overflow.
_numberOfEpochs * _promotion.tokensPerEpoch
Handle
WatchPug
Vulnerability details
For the arithmetic operations that will never over/underflow, using the unchecked directive (Solidity v0.8 has default overflow/underflow checks) can save some gas from the unnecessary internal over/underflow checks.
For example:
https://github.com/pooltogether/v4-periphery/blob/0e94c54774a6fce29daf9cb23353208f80de63eb/contracts/TwabRewards.sol#L153-L153
_numberOfEpochs
is uint8_promotion.tokensPerEpoch
is uint216_numberOfEpochs * _promotion.tokensPerEpoch
will never overflow.