Ethereum Developer Ethereum Virtual Machine (EVM) and Gas Optimization 2 — Questions and Answers
Question 1: What is 'gas' in the context of the Ethereum network?
- The cryptocurrency used to reward validators
- A unit measuring the computational work required to execute operations (Correct answer)
- The total amount of Ether held in a contract
- The number of pending transactions in the mempool
Correct answer: A unit measuring the computational work required to execute operations
Gas is a unit that measures the computational effort required to execute specific operations, preventing infinite loops and metering resource usage.
Question 2: What is the approximate gas cost of writing to a new (zero-to-nonzero) storage slot using SSTORE?
- 200 gas
- 2,100 gas
- 20,000 gas (Correct answer)
- 200,000 gas
Correct answer: 20,000 gas
Writing to a new storage slot (cold zero-to-nonzero SSTORE) costs approximately 20,000 gas, making persistent storage the most expensive EVM resource.
Question 3: After EIP-1559, what happens to the base fee portion of a transaction fee?
- It is paid to validators as a block reward
- It is burned and permanently removed from circulation (Correct answer)
- It is sent to the Ethereum Foundation treasury
- It is redistributed proportionally to all stakers
Correct answer: It is burned and permanently removed from circulation
EIP-1559 introduced a base fee that is burned with every transaction, creating a deflationary pressure on ETH supply.
Question 4: In Ethereum's EIP-1559 fee model, what is the 'priority fee' (tip)?
- A mandatory fee for smart contract deployment
- An optional fee paid directly to validators to incentivize faster inclusion (Correct answer)
- A fee charged when a transaction reverts
- A fee paid to the network for state storage
Correct answer: An optional fee paid directly to validators to incentivize faster inclusion
The priority fee (maxPriorityFeePerGas) is an optional tip paid directly to the block proposer to incentivize including a transaction in the current block.
Question 5: What triggers a gas refund in Ethereum smart contracts?
- When a transaction completes without errors
- When a storage slot is cleared by writing zero to a non-zero value (Correct answer)
- When a function is declared as 'pure'
- When a contract calls another contract successfully
Correct answer: When a storage slot is cleared by writing zero to a non-zero value
Clearing a storage slot (writing zero to a previously non-zero slot) provides a partial gas refund, incentivizing state cleanup and reducing blockchain bloat.
Question 6: What happens when a transaction runs 'out of gas' in Ethereum?
- The transaction is retried automatically with more gas
- All state changes revert and the consumed gas is not refunded (Correct answer)
- The transaction is queued until gas prices drop
- Only the failed opcode is skipped and execution continues
Correct answer: All state changes revert and the consumed gas is not refunded
When gas is exhausted, the EVM reverts all state changes from that transaction, but the gas already consumed is kept by the validator as compensation.
Question 7: How much gas does a standard ETH transfer (no data, no contract) cost?
- 5,000 gas
- 21,000 gas (Correct answer)
- 50,000 gas
- 100,000 gas
Correct answer: 21,000 gas
A standard ETH transfer costs exactly 21,000 gas, which is the fixed base transaction cost on Ethereum for a simple value transfer.
What is 'gas' in the context of the Ethereum network?