CBSA Smart Contracts & Decentralized Applications 2 — Questions and Answers
Question 1: Which Solidity visibility modifier makes a function callable only from within the contract itself and not from derived contracts?
- internal
- private (Correct answer)
- external
- public
Correct answer: private
The `private` modifier restricts function access to the defining contract only, excluding derived contracts.
Question 2: In Ethereum smart contracts, what is a 'reentrancy attack'?
- An attacker replaying a signed transaction multiple times
- An external contract recursively calling back into the victim contract before state updates complete (Correct answer)
- Manipulating the contract's constructor during deployment
- Overflowing an integer variable to redirect funds
Correct answer: An external contract recursively calling back into the victim contract before state updates complete
Reentrancy attacks occur when a malicious contract calls back into the victim before its state (like balance) is updated, draining funds.
Question 3: What does the ERC-721 standard define?
- A fungible token interface for DeFi protocols
- A standard for non-fungible tokens (NFTs) on Ethereum (Correct answer)
- A wrapped ether standard for Layer 2 bridges
- A multi-token standard supporting both fungible and non-fungible tokens
Correct answer: A standard for non-fungible tokens (NFTs) on Ethereum
ERC-721 defines the standard interface for non-fungible tokens, where each token has a unique identifier.
Question 4: Which design pattern separates a smart contract's logic from its data storage to enable upgradability?
- Factory pattern
- Oracle pattern
- Proxy pattern (Correct answer)
- Multisig pattern
Correct answer: Proxy pattern
The proxy pattern delegates calls to a logic contract while keeping state in the proxy, allowing the logic to be replaced without changing the storage address.
Question 5: What is the purpose of the `require` statement in a Solidity smart contract?
- To import external libraries at compile time
- To validate conditions and revert the transaction if the condition is false (Correct answer)
- To define immutable state variables
- To emit events for off-chain listeners
Correct answer: To validate conditions and revert the transaction if the condition is false
`require` validates inputs or conditions and reverts the transaction with an optional error message if the condition fails.
Question 6: In the context of dApps, what role does IPFS primarily serve?
- Executing smart contract logic off-chain
- Providing decentralized storage for large files and front-end assets (Correct answer)
- Generating cryptographic keys for wallet addresses
- Routing transactions between Layer 1 and Layer 2 networks
Correct answer: Providing decentralized storage for large files and front-end assets
IPFS (InterPlanetary File System) provides content-addressed, decentralized storage commonly used for dApp front-ends and NFT metadata.
Question 7: What is 'gas stipend' in the context of Ethereum smart contract calls?
- A fee discount given to frequent contract deployers
- The fixed amount of gas forwarded when a contract sends Ether using `transfer` or `send` (Correct answer)
- The maximum gas an EOA can spend per block
- A gas refund issued when storage slots are cleared
Correct answer: The fixed amount of gas forwarded when a contract sends Ether using `transfer` or `send`
Solidity's `transfer` and `send` forward only 2,300 gas, preventing reentrancy but limiting what the recipient contract can do.
Which Solidity visibility modifier makes a function callable only from within the contract itself and not from derived contracts?