It seems that specifying something less than uint256
counterintuitively increases gas costs (or at best makes them equal to uint256 with optimization).
And since the minimum write to storage is 32 bytes (256 bits), it doesn't seem like specifying uint8
would necessarily save you gas either.
In what cases could one use uint<256
to save on gas?
One possible example: in a struct, if you group/list 8 uint32
variables together, would writing to those 256 bits (which presumably are stored consecutively in one word) be the same storage / gas cost as a single uint256
in the struct?