Process
Storage Analysis
Last updated:
October 14, 2021

This security review step focuses on analyzing contract storage use as it pertains to inheritance patterns and efficiency.

Identify top-level contracts

Use a Visual Inspection Tool to generate an inheritance diagram and identify which contracts should be reviewed for use of storage.

Generate the storage layout for top-level contracts

Use a Visual Inspection Tool to generate a C3 linearization of the inherited storage layout. In simpler terms this means the final sequence of variables in storage. For example, if contract A inherits from contract B, any storage variables will automatically be concatenated with contract variables from A in the final layout.

Ensure each variable is necessary and efficiently chosen

Since storage updates are expensive, it's important that storage is used where it is necessary for the execution of the contract.

Where storage is needed, is it write-once? If so, it may be possible to use code storage through CREATE3. See the sstore2 library (https://github.com/0xsequence/sstore2) for a practical implementation.

Ensure storage is packed correctly

Solidity packs storage slots into 256-bit chunks (words). When variables taking up less than 256-bits are used (e.g., uint64), their ordering in the final storage layout can affect the final storage consumption of the contract.

See the Uniswap V3 core pool contract as a great example of variable packing.

See Also: