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

0 stars 0 forks source link

Less than 256 uints are not efficient #49

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

pauliax

Vulnerability details

Impact

Lower than uint256 size storage instance variables are actually less gas efficient. E.g. using uint8 does not give any efficiency, actually, it is the opposite as EVM operates on default of 256-bit values so uint8 is more expensive in this case as it needs a conversion. It only gives improvements in cases where you can pack variables together, e.g. structs. For example, I think there is no reason to store nextDrawId (contract DrawBeacon) in uint32 or withdrawAccumulator (contract Reserve) in uint224. Same with loops, e.g. here uint8 does not give any efficiency: for (uint8 i = 0; i <= maxWinningTierIndex; i++) {

aodhgan commented 3 years ago

We prefer to use the smallest/most suitable type for the purpose, to ease readability of the code.

GalloDaSballo commented 3 years ago

The sponsor acknowledges, and I agree that there's no harm in using lower than 256 uints