According to the Solidity docs, "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." Each operation involving a uint8
costs an extra 22-28 gas (depending on whether the other operand is also a variable of type uint8
) as compared to ones involving uint256
, due to the compiler having to clear the higher bits of the memory word before operating on the uint8
, as well as the associated stack operations of doing so.
There are 2 instances of this issue.
File Link | Instance Count | Instance Links |
---|---|---|
ISwapRouter.sol | 2 | 8,13 |
44 gas
baudit: a custom static code analysis tool; manual review
Use uint256
/int256
for integers, then downcast (using OpenZeppelin's SafeCast) where needed.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.