← All Ethereum Developer Flashcard Decks

Ethereum Virtual Machine (EVM) and Gas Optimization Flashcards

7 cards from real Ethereum Developer practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 7 Ethereum Virtual Machine (EVM) and Gas Optimization flashcards as text
  1. Which Solidity technique saves gas by fitting multiple small variables into a single 32-byte storage slot?

    Answer: Struct packing

    Struct packing arranges variables so multiple small types (e.g., two uint128s) share one 32-byte slot, reducing the number of costly SSTORE and SLOAD operations.

  2. Why is reading function parameters from calldata cheaper than from memory in Solidity?

    Answer: Calldata is read-only and avoids the gas cost of copying data into memory

    Calldata is immutable transaction input that can be read directly without allocating or copying into memory, saving the gas cost of mstore and mload operations.

  3. Why can using `uint8` for local variables cost MORE gas than `uint256` in Solidity?

    Answer: The EVM's 256-bit word size requires extra masking operations when using smaller types

    Since the EVM natively operates on 256-bit words, using uint8 in local variables forces the compiler to add bit-masking operations, adding gas overhead.

  4. When are `view` functions completely free (zero gas cost) in Ethereum?

    Answer: When called externally off-chain via eth_call (not as part of a transaction)

    View functions cost zero gas when called off-chain via eth_call because they don't modify state and no transaction is broadcast to the network.

  5. Which gas optimization pattern moves expensive computation off-chain and uses on-chain verification only?

    Answer: Merkle proofs and cryptographic verification

    Merkle proofs allow a contract to verify membership in a large dataset with O(log n) on-chain hashing instead of storing and iterating the full dataset.

  6. How does using Solidity `library` contracts reduce deployment gas costs?

    Answer: Library code is deployed once and reused via delegatecall, shrinking the calling contract's bytecode

    External library functions are deployed once on-chain; contracts that use them reference the single deployment via DELEGATECALL, reducing each contract's bytecode size and deployment cost.

  7. Why are Solidity events more gas-efficient than contract storage for recording historical data?

    Answer: Events are stored in cheaper transaction logs (~8 gas/byte) rather than costly contract storage (~20,000 gas per slot)

    Emitting an event stores data in transaction logs at roughly 375 gas per topic and 8 gas per byte of data, far cheaper than the 20,000 gas cost of a new SSTORE.