useage of uint / int smaller than 32 bytes incurs overhead
When using elements that are smaller than 32 bytes, your contract’s gas usage may be higher. This is because the EVM operates on 32 bytes at a time. Therefore, if the element is smaller than that, the EVM must use more operations in order to reduce the size of the element from 32 bytes to the desired size.
When using elements that are smaller than 32 bytes, your contract’s gas usage may be higher. This is because the EVM operates on 32 bytes at a time. Therefore, if the element is smaller than that, the EVM must use more operations in order to reduce the size of the element from 32 bytes to the desired size.
resource : https://docs.soliditylang.org/en/v0.8.11/internals/layout_in_storage.html
Use a larger size then downcast where needed
POC : https://github.com/code-423n4/2022-07-swivel/blob/main/Swivel/Swivel.sol#L15 https://github.com/code-423n4/2022-07-swivel/blob/main/Swivel/Swivel.sol#L578 https://github.com/code-423n4/2022-07-swivel/blob/main/Swivel/Swivel.sol#L600 https://github.com/code-423n4/2022-07-swivel/blob/main/Swivel/Swivel.sol#L620 https://github.com/code-423n4/2022-07-swivel/blob/main/Swivel/Swivel.sol#L634