CCE Smart Contracts and Ethereum 4 — Questions and Answers
Question 1: What is the purpose of the 'fallback' function in a Solidity smart contract?
- To initialize state variables at deployment
- To execute when no other function matches the call or when Ether is sent without data (Correct answer)
- To destroy the contract and return funds
- To emit events for off-chain listeners
Correct answer: To execute when no other function matches the call or when Ether is sent without data
The fallback function executes when a call to the contract doesn't match any function signature or when plain Ether is sent without accompanying call data.
Question 2: Which Ethereum Improvement Proposal introduced the ERC-20 token standard?
- EIP-55
- EIP-721
- EIP-20 (Correct answer)
- EIP-1559
Correct answer: EIP-20
EIP-20 formally codified the ERC-20 fungible token standard, defining the interface functions like transfer, approve, and allowance.
Question 3: What does 'reentrancy' mean in the context of smart contract vulnerabilities?
- A contract calling itself recursively during deployment
- An external contract calling back into the vulnerable contract before its first execution completes (Correct answer)
- Replaying an old transaction on a new network
- Executing a contract function twice with the same nonce
Correct answer: An external contract calling back into the vulnerable contract before its first execution completes
Reentrancy occurs when an external malicious contract calls back into the victim contract before its state is updated, enabling repeated fund withdrawals.
Question 4: What is the role of an 'oracle' in Ethereum smart contracts?
- A validator node that finalizes blocks
- A bridge that supplies real-world off-chain data to on-chain contracts (Correct answer)
- A compiler that translates Solidity to EVM bytecode
- A mechanism for upgrading contract logic without redeployment
Correct answer: A bridge that supplies real-world off-chain data to on-chain contracts
Oracles act as trusted data feeds that bring external information (prices, weather, sports results) onto the blockchain where smart contracts can consume it.
Question 5: In Solidity, what is the difference between 'memory' and 'storage' data locations?
- Memory is persistent across transactions; storage is temporary
- Storage persists on the blockchain permanently; memory exists only during a function call (Correct answer)
- Memory stores contract bytecode; storage stores event logs
- Storage is cheaper in gas; memory is more expensive
Correct answer: Storage persists on the blockchain permanently; memory exists only during a function call
Storage variables are written to the blockchain and persist between transactions, while memory variables are temporary and cleared after each function execution.
Question 6: What is an Ethereum 'event' used for in smart contracts?
- Triggering automatic contract execution at a scheduled time
- Logging data to the blockchain that off-chain applications can listen to (Correct answer)
- Sending Ether to another address without a function call
- Pausing contract execution until a condition is met
Correct answer: Logging data to the blockchain that off-chain applications can listen to
Events emit indexed logs stored in transaction receipts that DApps and external services can efficiently subscribe to and filter.
Question 7: Which design pattern is commonly used to make Ethereum smart contracts upgradeable?
- Factory pattern
- Proxy pattern (Correct answer)
- Singleton pattern
- Observer pattern
Correct answer: Proxy pattern
The proxy pattern separates storage from logic; the proxy contract holds state and delegates calls to an implementation contract that can be swapped out.
What is the purpose of the 'fallback' function in a Solidity smart contract?