20,000 USDC
View results
Submission Details
Severity: gas
Valid

Usage of `uint` and `int` smaller than 32 bytes (256 bits) incurs overhead

Summary

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.

Vulnerability Details

There are 2 instances of this issue.

File: src/interfaces/ISwapRouter.sol
/// @audit uint24
8: uint24 fee;
/// @audit uint160
13: uint160 sqrtPriceLimitX96;
File Link Instance Count Instance Links
ISwapRouter.sol 2 8,13

Impact

44 gas

Tools Used

baudit: a custom static code analysis tool; manual review

Recommendations

Use uint256/int256 for integers, then downcast (using OpenZeppelin's SafeCast) where needed.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.