What are the most impactful gas optimizations you reach for in a Solidity contract, and how do you decide they're actually worth it?

technical-conceptual · Senior level · software-engineering, blockchain-web3

What the interviewer is really asking

Assesses whether the candidate knows where EVM gas actually goes (storage dominates) and optimizes from measurement rather than folklore, with awareness of warm/cold access and calldata vs memory.

What to say

What to avoid

Example answers

Strong: I start from the fact that storage is the expensive resource, so I pack related small fields into one slot, cache a storage value in a local before looping over it, and skip writes that don't change the value. I lean on warm/cold access knowledge from EIP-2929 and use calldata for external array args to avoid the memory copy. Then I prove it with Foundry gas snapshots before and after, and I'll skip a packing trick if it hurts readability for a tiny saving, because audit time costs more than the gas.

Weak: I'd make all the variables uint256 since that's the EVM word size, wrap arithmetic in unchecked, and use shorter variable names. Those are the standard gas tricks so the contract ends up cheaper.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.