CBCP Smart Contracts and dApps 5 — Questions and Answers
Question 1: What is the purpose of the 'require' statement in Solidity?
- To import external libraries at compile time
- To validate conditions and revert the transaction with a message if the condition is false (Correct answer)
- To declare a variable that cannot be changed after deployment
- To emit an event on the blockchain
Correct answer: To validate conditions and revert the transaction with a message if the condition is false
The require statement checks a condition at runtime; if it fails, it reverts the transaction and optionally provides an error message, refunding remaining gas.
Question 2: Which design pattern is used in DApps to separate concerns by having a frontend interact with multiple specialized smart contracts rather than one monolithic contract?
- Monolith pattern
- Diamond (EIP-2535) or modular contract pattern (Correct answer)
- Singleton pattern
- Factory pattern only
Correct answer: Diamond (EIP-2535) or modular contract pattern
Modular contract patterns like the Diamond standard (EIP-2535) split logic into facets or separate contracts, improving maintainability and enabling upgrades without size limits.
Question 3: What is 'slippage' in the context of decentralized exchange transactions?
- A smart contract bug that allows unauthorized token minting
- The difference between the expected token price at order submission and the actual execution price (Correct answer)
- A fee charged by validators for priority transaction inclusion
- The delay between signing a transaction and its on-chain confirmation
Correct answer: The difference between the expected token price at order submission and the actual execution price
Slippage occurs because AMM prices shift continuously; a large trade or high volatility can cause the execution price to differ significantly from the quoted price.
Question 4: In a DAO (Decentralized Autonomous Organization), what mechanism is most commonly used to prevent token holders from voting with borrowed tokens?
- Delegated proof of stake consensus
- Snapshot-based voting where token balances are recorded at a specific block before the proposal (Correct answer)
- Multi-signature wallet approval for each vote
- Zero-knowledge proofs verifying token ownership
Correct answer: Snapshot-based voting where token balances are recorded at a specific block before the proposal
Snapshot voting records token balances at a specific block height before a proposal is created, preventing vote manipulation through flash loans or late token acquisition.
Question 5: What is the EVM (Ethereum Virtual Machine) stack-based architecture's maximum stack depth?
- 256 elements
- 512 elements
- 1024 elements (Correct answer)
- 2048 elements
Correct answer: 1024 elements
The EVM has a maximum stack depth of 1024 items; exceeding this limit causes a stack overflow and reverts the transaction.
Question 6: What problem does the 'commit-reveal' scheme solve in smart contract-based applications?
- It reduces gas costs by batching state changes
- It prevents front-running by hiding a user's intent until after the commitment phase (Correct answer)
- It enables cross-chain communication without a bridge
- It compresses calldata to reduce transaction size
Correct answer: It prevents front-running by hiding a user's intent until after the commitment phase
In a commit-reveal scheme, users first submit a hash of their action (commit), then later reveal the actual action, preventing others from copying or front-running the intent.
Question 7: Which Ethereum Improvement Proposal introduced the concept of 'meta-transactions' to allow users to interact with DApps without holding ETH for gas?
- EIP-1559
- EIP-2612 and EIP-712 (gasless transactions via relayers)
- EIP-4337 (Account Abstraction) (Correct answer)
- EIP-1820
Correct answer: EIP-4337 (Account Abstraction)
EIP-4337 (Account Abstraction) enables smart contract wallets and paymasters so users can pay gas in tokens or have a relayer sponsor fees, eliminating the need to hold ETH.
What is the purpose of the 'require' statement in Solidity?