Blockchain Technology Smart Contract Fundamentals 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 that replays signed transactions on a different blockchain
- A vulnerability caused by integer overflow in Solidity arithmetic
- An exploit that forges validator signatures to steal ETH
Correct answer: A bug where a contract calls itself recursively to drain funds before state updates
A reentrancy attack occurs when a malicious contract repeatedly calls back into the victim before the victim updates its balance, allowing repeated withdrawals.
Question 2: Which Solidity keyword prevents a function from modifying contract state?
- payable
- pure
- view (Correct answer)
- internal
Correct answer: view
'view' functions can read state but cannot modify it, while 'pure' functions cannot read or modify state at all.
Question 3: What does the ERC-20 standard primarily define?
- Rules for non-fungible tokens on Ethereum
- A common interface for fungible tokens on Ethereum (Correct answer)
- The Ethereum consensus mechanism specification
- A standard for cross-chain atomic swaps
Correct answer: A common interface for fungible tokens on Ethereum
ERC-20 defines a standard interface (functions like transfer, approve, allowance) for fungible tokens so wallets and exchanges can interact with any compliant token uniformly.
Question 4: In Ethereum's ABI (Application Binary Interface), what is its primary purpose?
- To encrypt transaction data before broadcasting
- To define how to encode and decode function calls and return values (Correct answer)
- To compress bytecode for cheaper deployment
- To authenticate contract deployers via digital signatures
Correct answer: To define how to encode and decode function calls and return values
The ABI specifies the encoding scheme for calling contract functions and interpreting their return data so external applications can interact correctly.
Question 5: What is the purpose of the 'fallback' function in a Solidity smart contract?
- It runs automatically when a contract is deployed
- It is called when no other function matches the incoming call data (Correct answer)
- It handles failed external calls and reverts them
- It upgrades a contract to a new implementation address
Correct answer: It is called when no other function matches the incoming call data
The fallback function executes when a call arrives that doesn't match any function selector, or when ETH is sent without call data and no receive() exists.
Question 6: Which of the following best describes 'gas limit' in an Ethereum transaction?
- The maximum ETH price the sender will pay per unit of computation
- The maximum amount of computational work the sender authorizes for the transaction (Correct answer)
- The total ETH fee already deducted from the sender's wallet
- The block-level cap set by miners on total fees collected
Correct answer: The maximum amount of computational work the sender authorizes for the transaction
The gas limit is the maximum number of gas units the sender is willing to consume; unused gas is refunded, but the transaction fails if it exceeds the limit.
Question 7: What does the Solidity 'require' statement do when its condition evaluates to false?
- It silently skips the rest of the function
- It reverts the transaction and refunds remaining gas (Correct answer)
- It emits an error event and continues execution
- It selfdestruct the contract to prevent further damage
Correct answer: It reverts the transaction and refunds remaining gas
'require' reverts all state changes and returns remaining gas to the caller when the condition fails, making it ideal for input validation.
What is a 'reentrancy attack' in the context of smart contracts?