Cryptocurrency Smart Contracts and dApps 2 — Questions and Answers
Question 1: What is a 'reentrancy attack' in the context of smart contracts?
- A bug where a contract calls itself recursively to drain funds before state updates (Correct answer)
- An attack where an outsider rewrites contract bytecode on-chain
- A method to replay old transactions on a new network
- A technique to front-run pending transactions in the mempool
Correct answer: A bug where a contract calls itself recursively to drain funds before state updates
In a reentrancy attack, a malicious contract repeatedly calls back into the vulnerable contract before its balance is updated, draining its ETH — famously exploited in The DAO hack.
Question 2: Which Ethereum Improvement Proposal (EIP) introduced the standard interface for fungible tokens?
- EIP-721
- EIP-1155
- EIP-20 (Correct answer)
- EIP-4337
Correct answer: EIP-20
EIP-20 (also called ERC-20) defines the standard interface for fungible tokens on Ethereum, enabling interoperability across wallets and exchanges.
Question 3: What does 'gas limit' represent in an Ethereum transaction?
- The maximum amount of ETH willing to pay per unit of gas
- The maximum units of computational work the sender allows the transaction to consume (Correct answer)
- The total ETH balance needed to deploy a contract
- The block-level cap on all fees collected by validators
Correct answer: The maximum units of computational work the sender allows the transaction to consume
The gas limit caps how many computational steps a transaction may execute; if execution exceeds this limit, the transaction reverts but the gas spent is still consumed.
Question 4: In Solidity, what does the 'view' function modifier indicate?
- The function can receive ETH
- The function modifies state variables
- The function reads state but does not modify it (Correct answer)
- The function can only be called by the contract owner
Correct answer: The function reads state but does not modify it
'view' functions promise not to alter blockchain state, so they can be called off-chain for free without submitting a transaction.
Question 5: What is the primary purpose of an oracle in a smart contract ecosystem?
- To compile Solidity code into EVM bytecode
- To supply real-world external data to on-chain contracts that cannot access it natively (Correct answer)
- To validate block headers for light clients
- To relay Layer 2 transactions back to Layer 1
Correct answer: To supply real-world external data to on-chain contracts that cannot access it natively
Blockchains are deterministic and isolated, so oracles act as trusted data feeds that bring off-chain information (prices, weather, sports scores) onto the chain.
Question 6: Which smart contract upgrade pattern keeps the contract logic separate from its storage?
- Factory pattern
- Proxy pattern (Correct answer)
- Singleton pattern
- Registry pattern
Correct answer: Proxy pattern
The proxy pattern routes calls through an immutable proxy contract to a replaceable logic contract, allowing upgrades without migrating user balances or addresses.
Question 7: What does 'ABI' stand for in the context of smart contracts?
- Automated Block Index
- Application Binary Interface (Correct answer)
- Asset-Backed Instrument
- Audited Bytecode Instance
Correct answer: Application Binary Interface
The ABI (Application Binary Interface) defines how to encode function calls and decode return values when interacting with a compiled smart contract.
What is a 'reentrancy attack' in the context of smart contracts?