CBCP Smart Contracts and dApps Questions and Answers — Questions and Answers
Question 1: A smart contract for a decentralized insurance dApp needs to automatically process a claim based on the real-world occurrence of a hurricane. Since the blockchain cannot directly access external weather data, what component is essential for the smart contract to receive this information securely and reliably?
- A state channel to communicate with weather APIs directly.
- A decentralized oracle network to fetch and verify external data. (Correct answer)
- An inter-blockchain communication protocol to query a weather-focused sidechain.
- A hard-fork of the main blockchain to include a weather data feed.
Correct answer: A decentralized oracle network to fetch and verify external data.
Blockchains are deterministic, isolated systems and cannot natively access off-chain data. A decentralized oracle network serves as a secure bridge, retrieving external data (like weather reports), verifying its accuracy through consensus, and delivering it to the smart contract to trigger its execution.
Question 2: A developer deploys a complex dApp to the Ethereum network. Users report that their transactions are failing or taking a very long time to confirm during periods of high network activity. The developer advises users to increase the 'gas price' in their wallet settings. What is the primary function of 'gas' in this context?
- It is a unit used to measure the dApp's on-chain storage requirements.
- It is a fixed fee paid to the dApp developers for using their service.
- It is a mechanism for funding the Ethereum Foundation's research and development.
- It is a unit measuring the computational effort required for a transaction, which validators are compensated for. (Correct answer)
Correct answer: It is a unit measuring the computational effort required for a transaction, which validators are compensated for.
Gas is the unit used to measure the amount of computational work required to execute transactions or smart contract functions on the Ethereum network. Users pay a fee (gas fee), calculated by multiplying the gas used by the gas price, to compensate validators for the computational resources they expend to process and secure the transaction.
Question 3: A development team is building a decentralized social media platform. They want to ensure the user interface is fast and responsive, similar to a traditional web app, while the core logic for content ownership and user interactions is handled by smart contracts. Which of the following BEST describes a typical architectural stack for such a dApp?
- The entire application, including the frontend UI and all data, is stored and executed directly on the blockchain.
- A traditional frontend (HTML/CSS/JS) interacts with smart contracts for backend logic, and may use decentralized storage (like IPFS) for media files. (Correct answer)
- The application logic is run on a centralized server which then batches transactions and submits them to the blockchain.
- Smart contracts are used to query a centralized database where all user data and application logic is stored.
Correct answer: A traditional frontend (HTML/CSS/JS) interacts with smart contracts for backend logic, and may use decentralized storage (like IPFS) for media files.
A standard dApp architecture involves a separation of concerns. The frontend (user interface) is typically built with standard web technologies (HTML, CSS, JavaScript) for a good user experience. This frontend then communicates with the backend, which consists of smart contracts deployed on a blockchain. For large files like images or videos, decentralized storage solutions like IPFS are often used instead of storing them directly on the blockchain due to cost and performance constraints.
Question 4: A DeFi protocol's smart contract contains a function that sends funds to an external address. An attacker discovers that they can repeatedly call this function from their own malicious contract before the original function completes its state update, allowing them to withdraw more funds than they are entitled to. This vulnerability is known as a:
- Integer Overflow Attack
- Reentrancy Attack (Correct answer)
- Timestamp Dependence Vulnerability
- Front-Running Attack
Correct answer: Reentrancy Attack
A reentrancy attack occurs when an external call from a vulnerable contract allows the called contract to call back into the original contract before its state is updated. This can lead to the logic being executed multiple times, often to drain funds, as famously happened in the 2016 DAO hack.
Question 5: Due to the immutable nature of blockchains, fixing a bug in a deployed smart contract is a significant challenge. Which design pattern allows developers to update the application logic of a dApp without requiring users to migrate their data to a new contract address?
- The Singleton Pattern
- The Factory Pattern
- The Proxy Pattern (Correct answer)
- The Observer Pattern
Correct answer: The Proxy Pattern
The Proxy Pattern is a common method for enabling smart contract upgrades. It involves separating the contract's state and logic. Users interact with a proxy contract that holds the state (data), which then delegates calls to a separate logic contract. To upgrade, a new logic contract is deployed, and the proxy contract is simply updated to point to the new logic contract's address, preserving the original state and contract address for users.
Question 6: Which of the following describes a Decentralized Autonomous Organization (DAO)?
- A corporation that uses blockchain to track its physical assets and supply chain.
- A government agency that uses smart contracts to automate regulatory compliance.
- A software company that develops dApps for a variety of blockchain platforms.
- An internet-native organization where rules are encoded as smart contracts and operational decisions are made by its members, typically through voting with governance tokens. (Correct answer)
Correct answer: An internet-native organization where rules are encoded as smart contracts and operational decisions are made by its members, typically through voting with governance tokens.
A Decentralized Autonomous Organization (DAO) is an entity with no central leadership. It is collectively owned and managed by its members. Its rules are encoded in smart contracts on a blockchain, and decisions are made through proposals and voting by members, who typically hold governance tokens that represent voting power.
A smart contract for a decentralized insurance dApp needs to automatically process a claim based on the real-world occurrence of a hurricane.
Since the blockchain cannot directly access external weather data, what component is essential for the smart contract to receive this information securely and reliably?