aavegotchi / aavegotchi-realm-diamond

23 stars 9 forks source link

Smaller uint used in local variables #9

Closed mudgen closed 2 years ago

mudgen commented 2 years ago

It is unnecessary and costs more gas to use smaller sized uints for local variables. The reason is because EVMs native uint size is uint256.

It is done in some places in the InstallationFacet:

https://github.com/aavegotchi/aavegotchi-realm-diamond/blob/dev/contracts/InstallationDiamond/facets/InstallationFacet.sol#L196

However it could be done to limit the number of iterations of a loop to 256, but I would prefer using an explicit check for this. For example before the loop starts: require(_installationTypes.length < 257, "Two many installations");

Note: Using smaller uints is a gas optimization when packing structs that are stored in contract storage.

mudgen commented 2 years ago

Nice