Understand Solidity storage layout, ABI and gas

8 steps · about 3 h · Intermediate

  1. Solidity value and reference types (reference, Solidity Documentation, 30 min)

    Review exact bit widths, fixed vs dynamic types and data location rules before tracing how values map onto EVM words.

  2. Layout of state variables in storage (doc, Solidity Documentation, 25 min)

    Learn 32-byte slot packing, struct alignment, inheritance order and how mappings and dynamic arrays hash their slot locations.

  3. Layout in memory (doc, Solidity Documentation, 15 min)

    Contrast transient 32-byte-aligned memory allocation and the free memory pointer with persistent storage slots.

  4. Layout in calldata (doc, Solidity Documentation, 15 min)

    See why read-only calldata avoids memory copies and how dynamic offsets are structured in incoming transactions.

  5. Contract ABI specification (reference, Solidity Documentation, 30 min)

    Master 4-byte function selectors, head/tail dynamic encoding, event topic hashing and packed encoding.

  6. Cleaning up variables (doc, Solidity Documentation, 15 min)

    Understand when the compiler inserts bit-masking instructions for types smaller than 256 bits and why that affects gas.

  7. The Solidity optimizer (doc, Solidity Documentation, 25 min)

    Learn what the opcode and Yul optimizers rewrite, how optimizer runs trade deployment size against call gas, and what stays unchanged.

  8. Yul intermediate representation (doc, Solidity Documentation, 25 min)

    Connect high-level Solidity storage and calldata rules to the typed assembly blocks used when auditing or tuning hot paths.