πŸ” Master Solidity: Must-Know Interview Questions for Ethereum Developers πŸ› οΈ (Theory Only)

Magda JankowskaMagda Jankowska
10 min read

As blockchain technology evolves, the demand for skilled Ethereum developers, particularly those proficient in Solidity, continues to rise. Whether you’re a developer preparing for an interview or a recruiter evaluating candidates, having a comprehensive list of questions is key. This article compiles over 200 carefully curated interview questions, each of which can be answered in three sentences or less. These questions are grouped into categories, making it easier to assess specific areas of knowledge.

🧩 Basic Solidity Questions

What is Solidity?
πŸ“ Solidity is a high-level programming language designed for writing smart contracts on the Ethereum blockchain.

How does Ethereum differ from Bitcoin?
⚑ Ethereum is a platform for decentralized applications with its own cryptocurrency, Ether, while Bitcoin is primarily a digital currency with a limited scripting language.

What is a smart contract?
πŸ”— A smart contract is a self-executing contract with the terms of the agreement directly written into code.

What are the main data types in Solidity?
πŸ—ƒοΈ Solidity supports several data types, including uint, int, bool, address, bytes, and string.

How do you declare a variable in Solidity?
✍️ Variables in Solidity are declared with a data type, followed by a variable name, e.g., uint myVariable.

What is the difference between public and private visibility in Solidity?
πŸ”’ public functions and variables can be accessed externally, while private ones can only be accessed within the contract that defines them.

What is an address in Solidity?
🏠 An address in Solidity is a 20-byte value that represents the location of an account or contract on the Ethereum network.

Explain the use of the msg.sender keyword.
πŸ“¬ msg.sender refers to the address of the account that called the contract's function.

What is the fallback function in Solidity?
πŸšͺ The fallback function is a special function that gets executed when a contract is called, but no other function matches the given function signature.

How does Ethereum handle gas fees?
β›½ Gas fees in Ethereum are the costs required to perform transactions or execute contracts, measured in β€œgas” units and paid in Ether.

πŸ”’ What is the difference between private, internal, public, and external functions?

  • Private functions are accessible only within the contract, internal functions are accessible within the contract and derived contracts, public functions are accessible from anywhere, and external functions are accessible only from outside the contract.

πŸ“ Approximately, how large can a smart contract be?

  • A smart contract can be up to 24KB in size.

πŸ”„ What is the difference between create and create2?

  • create generates a contract at an address based on the sender and nonce, while create2 allows specifying the contract address deterministically using a salt.

πŸ”’ What is access control and why is it important?

  • Access control restricts who can execute certain functions, protecting contracts from unauthorized use and potential vulnerabilities.

βž• What major change with arithmetic happened with Solidity 0.8.0?

  • Solidity 0.8.0 introduced automatic overflow and underflow checks, reverting transactions on arithmetic errors.

πŸ”§ What special CALL is required for proxies to work?

  • The delegatecall function is used for proxies, allowing a contract to execute code from another contract in the context of the caller.

πŸ’Έ Prior to EIP-1559, how do you calculate the dollar cost of an Ethereum transaction?

  • The cost is calculated as Gas Price Γ— Gas Used Γ— ETH Price.

🎲 What are the challenges of creating a random number on the blockchain?

  • Blockchain data is deterministic and public, making it difficult to generate truly random numbers without potential manipulation.

πŸ’Έ What is the difference between transfer and transferFrom in ERC20?

  • transfer sends tokens from the caller's account, while transferFrom allows transferring tokens on behalf of another address after approval.

πŸ”‘ What hash function does Ethereum primarily use?

  • Ethereum primarily uses the Keccak-256 hash function.

πŸ’° How much is 1 gwei of Ether?

  • 1 gwei equals 0.000000001 Ether.

πŸ’° How much is 1 wei of Ether?

  • 1 wei equals 0.000000000000000001 Ether.

πŸ” What is the difference between tx.origin and msg.sender?

  • tx.origin returns the address of the original sender of the transaction, while msg.sender returns the address of the immediate caller.

βš™οΈ Intermediate Solidity Questions

What is the purpose of the require function in Solidity?
βœ… The require function checks for a condition and reverts the transaction if the condition is not met.

Explain the mapping data type in Solidity.
πŸ”‘ mapping is a key-value store where keys are hashed and mapped to corresponding values, similar to a hash table.

What are events in Solidity?
πŸ“’ Events in Solidity allow contracts to log information that can be accessed by external applications, particularly useful for asynchronous communication.

What is the selfdestruct function?
πŸ’£ selfdestruct removes a contract from the blockchain and sends all its remaining Ether to a specified address.

What is the difference between memory and storage in Solidity?
πŸ—‚οΈ memory is temporary and used for variables within function execution, while storage is permanent and used for state variables.

What is inheritance in Solidity?
🧬 Inheritance in Solidity allows a contract to inherit properties and functions from another contract, promoting code reuse.

Explain the concept of a modifier in Solidity.
πŸŽ›οΈ A modifier is a function that is used to alter the behavior of other functions, typically for access control or input validation.

What are libraries in Solidity?
πŸ“š Libraries are reusable pieces of code that can be called from within contracts but do not have a state or persistent storage.

What is the delegatecall function?
🎭 delegatecall allows a contract to execute code from another contract in the context of the caller contract, preserving the original caller's state.

What is the purpose of the constructor in Solidity?
🚧 The constructor is a special function that is executed only once when a contract is deployed, used for initial setup.

βš™οΈ How do you write a gas-efficient for loop in Solidity?

  • Use fixed-size loops or batch processing with optimized state changes to minimize gas usage and avoid dynamic resizing.

πŸ” What is the difference between abi.encode and abi.encodePacked?

  • abi.encode provides a tightly packed ABI-encoded output, while abi.encodePacked produces a more compact but less collision-resistant encoding.

πŸ”’ uint8, uint32, uint64, uint128, uint256 are all valid uint sizes. Are there others?

  • No, uint8, uint32, uint64, uint128, and uint256 are the only valid sizes; other sizes are not supported.

⚠️ Under what circumstances could abi.encodePacked create a vulnerability?

  • abi.encodePacked can cause collisions if used improperly, leading to vulnerabilities where different inputs produce the same output.

πŸ“– What is the difference between a cold read and a warm read?

  • A cold read accesses data from storage directly, which is more expensive, while a warm read uses cached data from memory, which is cheaper.

β›½ What is the effect on gas of making a function payable?

  • Making a function payable allows it to receive Ether and may increase gas usage due to the additional checks and storage operations.

πŸ” What is a signature replay attack?

  • A signature replay attack involves reusing a signed transaction or message on a different network or contract to perform unauthorized actions.

πŸ› οΈ What is gas griefing?

  • Gas griefing is an attack where a malicious actor sends transactions with high gas fees to prevent other transactions from being processed or to exploit gas limits.

πŸ’Έ Describe the three types of storage gas costs.

  • SSTORE: Changing storage costs more than reading.

  • SLOAD: Reading storage is relatively cheaper.

  • Storage refund: Partial refund is given for clearing storage.

⚠️ What danger do ERC777 tokens pose?

  • ERC777 tokens can pose risks such as accidental token transfers to unintended contracts due to their hooks and complex features.

🏷️ How does safeMint differ from mint in the OpenZeppelin ERC721 implementation?

  • safeMint ensures the recipient is capable of receiving ERC721 tokens, while mint does not include this check.

πŸ₯ͺ What is a sandwich attack?

  • A sandwich attack involves placing transactions around a target transaction to manipulate its outcome and profit from price changes.

πŸ”— How large a uint can be packed with an address in one slot?

  • A uint up to uint64 can be packed with an address in one slot.

πŸ” What is ERC165 used for?

  • ERC165 is used for contract introspection, allowing contracts to query if another contract implements a particular interface.

πŸ’Έ What does ERC721A do to reduce mint costs? What is the tradeoff?

  • ERC721A batches multiple token mints into a single transaction to reduce gas costs, but it sacrifices some flexibility and adds complexity.

⏱️ What is TWAP?

  • Time-Weighted Average Price (TWAP) is a method of averaging prices over time to smooth out volatility and provide a stable price reference.

πŸ’³ What is a fee-on-transfer token?

  • A fee-on-transfer token deducts a fee from each transfer, which is either burned or redistributed.

πŸ“‰ How does Compound Finance calculate utilization?

  • Utilization is calculated as the ratio of borrowed assets to the total supply of assets in a lending pool.

πŸ›‘οΈ Advanced Solidity Questions

How does Solidity handle overflows in arithmetic operations?
πŸ”’ Before Solidity 0.8.0, overflows were unchecked by default, but after 0.8.0, Solidity throws an error on overflow/underflow.

What is a reentrancy attack?
πŸ›‘οΈ A reentrancy attack occurs when a function makes an external call to another contract, allowing the caller to call back into the original function before the first execution is complete, potentially leading to unexpected behavior.

⚠️ What is an ERC20 approval frontrunning attack?

  • It’s an attack where a malicious actor observes an approval transaction and submits a transaction to spend the approved tokens before the legitimate transaction executes.

πŸ” What opcode accomplishes address(this).balance?

  • The opcode BALANCE is used to retrieve the balance of an address, including address(this).balance.

πŸ”Ž What is an anonymous Solidity event?

  • An anonymous event is one without a name, allowing it to be used for debugging or internal tracking without polluting the event logs.

πŸ“œ Under what circumstances can a function receive a mapping as an argument?

  • Functions cannot directly receive mappings as arguments, but mappings can be used internally within functions.

πŸ”„ What is an inflation attack in ERC4626?

  • An inflation attack involves manipulating the vault’s protocol to issue excess tokens, diluting the value of existing tokens.

πŸ”’ How many arguments can a Solidity function have?

  • Solidity functions can have up to 1024 arguments.

πŸ—ƒοΈ How many storage slots does uint64[] x = [1,2,3,4,5] use? Does it differ from memory?

  • In storage, uint64[] uses one slot for the array length and additional slots for each element, depending on the array size. In memory, the array is contiguous and does not occupy distinct slots, but it is still subject to size limitations.

πŸ”„ What is the difference between an optimistic rollup and a zk-rollup?

  • Optimistic rollups assume transactions are valid and only challenge incorrect ones, while zk-rollups use zero-knowledge proofs to verify transactions off-chain and ensure correctness.

πŸ—‚οΈ How does EIP1967 pick the storage slots, how many are there, and what do they represent?

  • EIP1967 uses predefined storage slots for the implementation address, admin address, and beacon, with three slots: 0x360894a13ba1a3210667c828492db98e0e7b7e7d, 0x1, and 0x2.

🌐 Under what circumstances would a smart contract that works on Ethereum not work on Polygon or Optimism? (Assume no dependencies on external contracts)

  • Differences in network parameters, gas costs, and execution environments could cause compatibility issues between Ethereum and Layer 2 solutions like Polygon or Optimism.

βš–οΈ Why is strict inequality comparisons more gas efficient than ≀ or β‰₯? What extra opcode(s) are added?

  • Strict inequality comparisons (e.g., >, <) are more gas efficient because they do not require additional branching or conditional opcodes that are needed for ≀ or β‰₯.

πŸ› οΈ If a proxy calls an implementation, and the implementation self-destructs in the function that gets called, what happens?

  • If the implementation self-destructs, the proxy will fail to execute further functions from the destroyed implementation, leading to potential reverts or errors.

πŸ”Š How does Uniswap V3 determine the boundaries of liquidity intervals?

  • Uniswap V3 uses fixed ranges within a price curve, allowing liquidity providers to concentrate their liquidity within specified price ranges for greater efficiency.

πŸ“‰ What is the risk-free rate?

  • The risk-free rate is the theoretical return on an investment with zero risk, often used as a benchmark for comparing investment returns.

πŸ“š What is the difference between bytes and bytes1[] in memory?

  • bytes is a dynamically-sized byte array, while bytes1[] is a fixed-size array of single-byte elements; bytes can grow or shrink, while bytes1[] has a fixed size.

πŸ‘₯ If a user calls a proxy that makes a delegatecall to A, and A makes a regular call to B, from A's perspective, who is msg.sender? From B's perspective, who is msg.sender? From the proxy's perspective, who is msg.sender?

  • From A’s perspective, msg.sender is the proxy contract. From B's perspective, msg.sender is still the proxy contract. From the proxy's perspective, msg.sender is the user who initiated the transaction.

πŸ”’ Why do a significant number of contract bytecodes begin with 6080604052? What does that bytecode sequence do?

  • This bytecode sequence is a common initialization pattern for Ethereum contracts, setting up the runtime environment and ensuring proper contract setup.

These questions serve as a valuable resource for both interview preparation and candidate evaluation, ensuring that essential aspects of Solidity and Ethereum development are thoroughly covered. Happy coding and good luck with your interviews!

0
Subscribe to my newsletter

Read articles from Magda Jankowska directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Magda Jankowska
Magda Jankowska

Security Researcher for Web3 and Dark Web Bug hunter Ethical Hacker