code-423n4 / 2021-12-pooltogether-findings

0 stars 0 forks source link

`_nextPromotionId/_latestPromotionId` calculation can be done more efficiently #133

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

0x0x0x

Vulnerability details

https://github.com/pooltogether/v4-periphery/blob/b520faea26bcf60371012f6cb246aa149abd3c7d/contracts/TwabRewards.sol#L98-L99

Here promotion id calculations are done as follows:

uint256 _nextPromotionId = _latestPromotionId + 1;
_latestPromotionId = _nextPromotionId;

This calculation can be done much more efficiently as follows:

uint256 _nextPromotionId = ++_latestPromotionId;

Incrementing is cheaper than applying + 1 and this way less loads are required.

PierrickGT commented 2 years ago

It may be more gas efficient but it is also less legible, so for this reason, we won't implement this change.

dmvt commented 2 years ago

This is a gas optimization, not a non-critical.