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

## [G-23] Structs can be packed into fewer storage slots by editing time variables

Summary

[G-23] Structs can be packed into fewer storage slots by editing time variables

The following structures could be optimized moving the position of certain values in order to save a lot slots:

Enums are represented by integers; the possibility listed first by 0, the next by 1, and so forth.
An enum type just acts like uintN, where N is the smallest legal value large enough to accomodate all the possibilities.

Refference: https://ethdebug.github.io/solidity-data-representation

https://docs.soliditylang.org/en/v0.8.17/internals/layout_in_storage.html#storage-inplace-encoding

file: /src/interfaces/ISwapRouter.sol
5 struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
15 }

https://github.com/Cyfrin/2023-07-beedle/blob/main/src/interfaces/ISwapRouter.sol#L5-L15

Recommended Code

/// @audit the uint24 fee variabel is cut and past on the bottom.
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
+ + uint24 fee;
uint160 sqrtPriceLimitX96;

Support

FAQs

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