Blockchain Technology Smart Contract Fundamentals 4 — Questions and Answers
Question 1: What is 'delegatecall' in Solidity, and why is it risky?
- A call that transfers ETH to another contract using the caller's gas allowance
- A low-level call that executes another contract's code in the calling contract's storage context (Correct answer)
- A restricted function call only available to the contract owner
- A batched call that groups multiple transactions into one for efficiency
Correct answer: A low-level call that executes another contract's code in the calling contract's storage context
delegatecall runs the target's code but reads and writes the caller's storage slots, so a malicious or buggy implementation can corrupt or drain the proxy's state.
Question 2: In DeFi, what is a 'flash loan' and what makes it unique compared to traditional loans?
- A loan with a fixed 0% APR offered by central banks to DeFi protocols
- An uncollateralized loan that must be borrowed and repaid within a single transaction (Correct answer)
- A loan secured by NFTs that settles in under one minute on-chain
- A micro-loan capped at $1,000 disbursed instantly via Layer 2
Correct answer: An uncollateralized loan that must be borrowed and repaid within a single transaction
Flash loans are uncollateralized because the smart contract enforces that the borrowed funds plus fee must be returned before the transaction finalizes, reverting everything if not.
Question 3: What does ERC-721 define, and how does it differ from ERC-20?
- ERC-721 defines governance voting tokens; ERC-20 defines stablecoins only
- ERC-721 defines non-fungible tokens where each token has a unique ID; ERC-20 defines fungible tokens (Correct answer)
- ERC-721 defines Layer 2 bridging; ERC-20 defines Layer 1 token wrapping
- ERC-721 defines multi-token batches; ERC-20 defines single-token standards
Correct answer: ERC-721 defines non-fungible tokens where each token has a unique ID; ERC-20 defines fungible tokens
ERC-721 tokens are non-fungible — each has a unique tokenId and is not interchangeable — whereas ERC-20 tokens are identical and interchangeable units.
Question 4: What is 'front-running' in the context of smart contracts and blockchain?
- Deploying a contract before a competitor's identical contract to claim priority
- Inserting a transaction ahead of a pending one after observing it in the mempool to profit (Correct answer)
- Forking a blockchain to roll back an unfavorable transaction result
- Submitting the same transaction twice to guarantee at least one confirmation
Correct answer: Inserting a transaction ahead of a pending one after observing it in the mempool to profit
Front-runners monitor the mempool, then pay a higher gas price to have their transaction mined first, exploiting information about a pending trade.
Question 5: What is the purpose of the 'selfdestruct' opcode in Solidity?
- It pauses a contract temporarily until an owner re-enables it
- It permanently removes a contract's code and storage, sending its ETH balance to a specified address (Correct answer)
- It resets all state variables to their default values without deleting the contract
- It burns the contract's ETH balance to reduce circulating supply
Correct answer: It permanently removes a contract's code and storage, sending its ETH balance to a specified address
selfdestruct deletes contract bytecode and storage from the Ethereum state and forcibly sends any remaining ETH to the target address, even if that address has no payable function.
Question 6: Which smart contract pattern separates data storage from business logic to enable upgrades?
- Factory pattern
- Eternal storage pattern (Correct answer)
- Singleton pattern
- Observer pattern
Correct answer: Eternal storage pattern
The eternal storage pattern stores all state in a generic key-value contract separate from the logic contract, so logic can be replaced without losing data.
Question 7: What is 'gas optimization' and why is it important for smart contract developers?
- Reducing network latency so transactions confirm faster on Ethereum
- Writing code that minimizes EVM computational steps to lower transaction costs (Correct answer)
- Compressing contract bytecode to reduce the deployment file size on disk
- Batching validator rewards to reduce the number of payout transactions
Correct answer: Writing code that minimizes EVM computational steps to lower transaction costs
Every EVM opcode costs gas; optimizing code reduces costs for users and can make a contract economically viable where a naive implementation would be prohibitively expensive.
What is 'delegatecall' in Solidity, and why is it risky?