Blockchain 101 Certification Blockchain 101 Certification Smart Contracts & DApps 2 — Questions and Answers
Question 1: What is a 'reentrancy attack' in smart contract security?
- Calling a function twice in the same transaction to double fees
- An external contract recursively calling back into the vulnerable contract before the first execution completes (Correct answer)
- A replay attack on signed transactions
- A bug that prevents contract deployment
Correct answer: An external contract recursively calling back into the vulnerable contract before the first execution completes
A reentrancy attack exploits a contract that sends Ether before updating its state, allowing the recipient contract to re-enter and drain funds.
Question 2: What is the purpose of the 'require' statement in Solidity?
- To import external libraries
- To validate conditions and revert the transaction if the condition is false (Correct answer)
- To declare state variables
- To emit events
Correct answer: To validate conditions and revert the transaction if the condition is false
The `require` statement checks a condition and if it fails, reverts all state changes and optionally returns an error message.
Question 3: What is a token standard ERC-20 used for on Ethereum?
- Non-fungible collectibles
- Fungible tokens with a standard interface for transfers and approvals (Correct answer)
- Decentralized identity credentials
- Layer 2 payment channels
Correct answer: Fungible tokens with a standard interface for transfers and approvals
ERC-20 defines a common interface for fungible tokens, enabling interoperability between wallets, exchanges, and DApps.
Question 4: How does ERC-721 differ from ERC-20?
- ERC-721 tokens are fungible; ERC-20 tokens are not
- ERC-721 tokens are non-fungible, each with a unique ID; ERC-20 tokens are interchangeable (Correct answer)
- ERC-721 is for governance; ERC-20 is for payments
- ERC-721 uses Proof of Work; ERC-20 uses Proof of Stake
Correct answer: ERC-721 tokens are non-fungible, each with a unique ID; ERC-20 tokens are interchangeable
ERC-721 tokens each have a unique token ID making them non-fungible, unlike ERC-20 where each unit is identical and interchangeable.
Question 5: What is an oracle in the context of smart contracts?
- A blockchain audit tool
- A service that provides real-world external data to smart contracts (Correct answer)
- A consensus algorithm validator
- A smart contract testing framework
Correct answer: A service that provides real-world external data to smart contracts
Oracles bridge the on-chain and off-chain worlds by feeding external data (prices, weather, events) into smart contracts that cannot access the internet directly.
Question 6: What does it mean for a smart contract to be 'immutable'?
- It cannot process more than one transaction
- Its deployed code cannot be changed after deployment (Correct answer)
- It does not store state variables
- It only runs on private blockchains
Correct answer: Its deployed code cannot be changed after deployment
Once deployed on-chain, smart contract code is permanently stored and cannot be altered, requiring proxy patterns or new deployments for upgrades.
What is a 'reentrancy attack' in smart contract security?