Ethereum Developer Interview Questions
By: Adel Rustum
Tags: Blockchain, Interview, Solidity, Ethereum

A job interview is not only a test that filters out under-qualified candidates; it’s also a great opportunity for the candidates themselves to assess how good the development team of the future employer is!

If your interviewer is asking primitive, lame, or wrong questions (yes they can ask you something that totally doesn’t make sense); then it’s a red flag, and maybe you should reconsider joining this company, if they’re asking you well formulated challenging questions, and they’re not giving up on you when you don’t know the answer, but instead give you small hints that eventually lead up to the correct answer; then you’re looking at a professional lead developer that knows how to mentor and guide their team-mates while still challenging them.

I decided to compile a small list of questions that in my opinion would make a good start for an Ethereum Developer interview (they’re not necessarily about Solidity and definitely do not cover all topics); I broke it into 3 levels: Easy, medium, and hard, and I also added a small coding task (i.e. you can talk the talk, but can you walk the walk?).

Btw we all look at things differently, so some of you might want to re-categorize the questions, re-phrase them (or the answers) in a different way…Again it’s just a template, so feel free to improvise with it and use those questions as segways to other questions that you come up with!

Have a go at the questions before you look at the answers (which are at the bottom).

Questions

Level: Easy

What differentiates a common transaction from a contract deployment transaction? What web3 function helps you convert between different Ether denominations (and what’s the smallest one)? What action(s) do you need to do to be able to send Ether from your account? What’s the difference between Bitcoin and Ethereum when it comes to finding out the account balance? What’s the most commonly used Ethereum development framework? What features does it have? What extra properties/functions does the “address” type have? What happens when a transaction runs out of gas? What is a fallback function? How do you make a contract reject Ether payments? How many values can you return from a function? Which types can be assigned “memory” or “storage” locations?

Level: Medium

What Geth startup option allows client applications to interact remotely with Solidity contracts? What parts of it can make this interaction secure? What are hash functions? Can you mention 2 of their properties? How are they used in Ethereum? What are Merkle tries? How can they be used? How many are there in a block? What do you need to start your own Ethereum network? How do you insure that 2 nodes are on the same network? What transaction parameter protects Ethereum from denial of service attacks? What goes inside a genesis block? What transaction attributes/values let you know that it hasn’t’ been mined yet? What costs more gas to save in storage, uint8 or uint256, and why? What’s better to use for a short text? Bytes32 or string, and why? Mention some of the functions that a contract should have to be an ERC-20 token contract.

Level: Hard

What is GHOST protocol? What benefits did it give to Ethereum? How does fast block generation affect the network security? How is the new contract address calculated? And why is the deployed contract code shorter than the compiled code? In which circumstances would you use the new CREATE2 opcode to deploy a contract? If your contract is inheriting from 2 contracts that have the same function; which contract wins (i.e. when you call that function by name; from which parent contract will it be called)? If you want to use delegateCall to call an interface function; how do you calculate the function signature? Why should tx.origin be avoided? When to mark a function as “external”? What benefits would that give you if you called it from inside a contract? Can you cite one common application of this concept? Which struct consumes more space, and why?

9. How can you send Ether to a contract that doesn’t accept Ether (i.e. there is no fallback function or the fallback function always reverts)?

10. How is extcodesize used, and why it should be avoided?

Answers

Level: Easy

1. What differentiates a common transaction from a contract deployment transaction?

The “to” field is missing and the “data” one is present.

2. What web3 function helps you convert between different Ether denominations (and what’s the smallest one)?

web3.fromWei and web3.toWei. Wei is the smallest denomination.

3. What action(s) do you need to do to be able to send Ether from your account?

Unlock your private key or account.

4. What’s the difference between Bitcoin and Ethereum when it comes to finding out the account balance?

Bitcoin scans your unspent transaction outputs (UTXO) to find out your balance; while Ethereum stores your account balance in the latest state.

5. What’s the most commonly used Ethereum development framework? What features does it have?

Truffle; it makes it easier to compile, deploy, build, test, and run console commands.

6. What extra properties/functions does the “address” type have?

If it’s marked as “payable”; .balance, .transfer, .send.

7. What happens when a transaction runs out of gas?

All state changes are reverted and the miner gets the gas consumed up to the point where the gas ran out.

8. What is a fallback function? How do you make a contract reject Ether payments?

A fallback function is called when you call a function that doesn’t exist or you send Ether. You can make a contract reject Ether by omitting the fallback function (depending on the compiler version), not mark it with “payable”, or make it always revert.

9. How many values can you return from a function?

14 values max (that’s a function of the stack depth).

10. Which types can be assigned “memory” or “storage” locations?

Only reference types (i.e. structs and arrays).

Level: Medium

1. What Geth startup option allows client applications to interact remotely with Solidity contracts? What parts of it can make this interaction secure?

Start Geth with “--rpc” and specify which api’s can be called (-- rpcapi “eth, net, web3”).

2. What are hash functions? Can you mention 2 of their properties? How are they used in Ethereum?

Hash functions are mathematical algorithms that map arbitrary size input data to fixed size output bit string; they are deterministic (the same input always gives the same output), have an avalanche effect (small change in input; causes a big change in output). It’s used to link blocks to each other (among many other things).

3. What are Merkle tries? How can they be used? How many are there in a block?

Merkle tries are a data structure that stores data in the leaves and the hashes in the nodes, each node is the hash of the hash of the 2 nodes below it. They can be used to compare large and complex data structures just by comparing the roots. Blocks have 3 Merkle trees: Transactions, receipts, and state.

4. What do you need to start your own Ethereum network? How do you insure that 2 nodes are on the same network?

You need a network id and a genesis block. To insure that 2 nodes are on the same network; get the latest block hash from the first node; go to the second node and get the same block number then compare the hashes.

5. What transaction parameter protects Ethereum from denial of service attacks?

The “gas” parameter; execution stops and changes are reverted when the transaction runs out of gas.

6. What goes inside a genesis block?

Chain ID, difficulty, coinbase, preallocated Ether to some accounts, a nonce.

7. What transaction attributes/values let you know that it hasn’t’ been mined yet?

Its blockHash, blockNumber, and transactionIndex are all zeros.

8. What costs more gas to save in storage, uint8 or uint256, and why?

Uint8 costs more because the EVM works with 32 bytes stack elements and 32 bytes storage slots so when you have uint8 (1 byte) then further operations are required to downscale and optimize storage.

9. What’s better to use for a short text? Bytes32 or string, and why?

Bytes32 because it fits in a single word in the EVM, while string is a dynamic array which consumes more gas for initial storage allocation and further expansions.

10. Mention some of the functions that a contract should have to be an ERC-20 token contract.

BalanceOf, approve, transferFrom.

Level: Hard

1. What is GHOST protocol? What benefits did it give to Ethereum? How does fast block generation affects the network security?

Greedy Heaviest Observed Subtree protocol takes in consideration the weights of the sub-trees at the current block (as opposed to just one block) when deciding which branch to consider as the “longest” (and most secure). The benefits were that uncle blocks are no longer discarded and the hash rate that was consumed while mining them is part of the calculation to choose the longest (heaviest) branch, consequently miners are rewarded for uncle blocks; so slower miners (for various reasons) are not sidelined which makes mining more decentralized. If block generation is too fast; network latency will cause block propagation uneven and slower nodes will always be too late and mine on blocks that are already discarded or deeper in the past than the most current block, so they will always lose the mining race and never get rewarded leading to mining centralization and concentration of wealth in the fastest nodes.

2. How is the new contract address calculated? And why is the deployed contract code shorter than the compiled code?

It’s calculated from a hash of the sender’s address and the transaction nonce.

The deployed code is shorter because the constructor is only run on deployment and we don’t need to store it; plus there is the piece of code that unpacks and directs the EVM to the final bytecode.

3. In which circumstances would you use the new CREATE2 opcode to deploy a contract?

When you need to know the address that the future contract with a certain bytecode will use before actually deploying it.

4. If your contract is inheriting from 2 contracts that have the same function; which contract wins (i.e. when you call that function by name; from which parent contract will it be called)?

The right most contract in the mentioned inheritance list (e.g. contract child is parent1, parent2; parent2 wins).

5. If you want to use delegateCall to call an interface function; how do you calculate the function signature?

It’s the first 4 bytes of the keccak256 hash of its canonical signature, or theInstance.theFunction.selector.

6. Why should tx.origin be avoided?

An attacking contract can trick the victim contract to send it some Ether, then inside its fallback function they can call the victim’s function that uses tx.origin as a check; and it will pass that check because in this case the tx.origin is the victim contract that sent the Ether in the first place which in turn called that function!

7. When to mark a function as “external”? What benefits would that give you if you called it from inside a contract? Can you cite one common application of this concept.

For external calls the compiler doesn’t expect internal calls so it doesn’t copy arguments to memory; instead it allows to read them directly from calldata which is cheaper. Calling external functions internally creates an internal transaction which allows the calling contract to pass transaction parameters such as “value” and “gas”. It is for instance used in MultiSig contracts when changing the list of owners.

8. Which struct consumes more space, and why?

MyStructB consumes more space because structs are packed tightly meaning their attributes are packed into 32 byte words in sequence so in MyStructA param1 + param2 fit into one word (i.e. 32 bytes) so the entire struct (param1+param2+param3) fits into 2 words, while in MyStructB param1+param2 takes 2 words so the total (param1+param2+param3) takes 3 words.

9. How can you send Ether to a contract that doesn’t accept Ether (i.e. there is no fallback function or the fallback function always reverts)?

Use selfdestruct, because it doesn’t execute the fallback function.

10. How is extcodesize used, and why it should be avoided?

If your function relies on calling extcodesize; you can have another contract call this function from their constructor. When the attacking contract is being deployed and the constructor is called; the address of the contract at that stage still doesn’t have any bytecode attached to it so extcodesize will return 0.

Coding Test

This test should be conducted in a live session (e.g. Google Hangouts).

Let’s keep it simple here; we are not trying to code CryptoKitties! We just want to see if the person being interviewed can code, and what’s their coding style.

Write a contract (or contracts) that allow you to store your name as a state variable for a fee; only the owner can store it without a fee.

Sample Solution

Again we all have different coding styles; this is my version that shows inheritance, modifiers, events, adding comments to make the code more clear, etc…

I hope you find this article useful whether you’re an interviewer or someone being interviewed…good luck in that case!