Blockchain Smart Contract Fundamentals Questions and Answers — Questions and Answers
Question 1: A developer deploys a smart contract to the Ethereum mainnet. After deployment, they discover a logical bug in one of the functions. What is the primary consequence of blockchain's immutability in this scenario?
- The contract can be paused by any user to prevent further use.
- The developer can directly edit the contract's code on the blockchain to patch the bug.
- The contract's code is permanently unchangeable, and the bug cannot be directly fixed in the deployed version. (Correct answer)
- The Ethereum network will automatically roll back the transaction that deployed the buggy contract.
Correct answer: The contract's code is permanently unchangeable, and the bug cannot be directly fixed in the deployed version.
Immutability is a core feature of blockchains, meaning that once data (like a smart contract) is written, it cannot be altered or deleted. This ensures security and trust but also means that any bugs in a deployed contract are permanent in that specific instance. Mitigation requires deploying a new, corrected contract and migrating state, or having implemented an upgradeability pattern (like a proxy) beforehand.
Question 2: What is the primary function of the Ethereum Virtual Machine (EVM)?
- To design the user interface for decentralized applications (dApps).
- To provide a sandboxed, deterministic execution environment for smart contracts. (Correct answer)
- To encrypt transaction data before it is added to a block.
- To facilitate cross-chain communication between Ethereum and other blockchains.
Correct answer: To provide a sandboxed, deterministic execution environment for smart contracts.
The EVM is the computation engine of the Ethereum network. It acts as a decentralized, sandboxed virtual machine that executes smart contract bytecode. This isolated environment ensures that smart contracts run exactly as written on all nodes in the network without interfering with the host system, which is essential for maintaining consensus.
Question 3: A smart contract is designed to trigger an insurance payout for a flight delay. To function correctly, it needs to know the official landing time of a specific flight. How does a smart contract on a deterministic blockchain typically obtain this type of real-world information?
- By directly querying a public flight tracking API from within the contract code.
- By allowing users to vote on the landing time after the fact.
- Through a trusted external data feed service known as a blockchain oracle. (Correct answer)
- By using a built-in time function within the EVM to access real-world clocks.
Correct answer: Through a trusted external data feed service known as a blockchain oracle.
Blockchains and smart contracts cannot directly access off-chain data because it would break the deterministic nature required for consensus. A blockchain oracle is a necessary third-party service that acts as a bridge, fetching and verifying real-world data (like flight times or asset prices) and relaying it to the smart contract in a secure and reliable way.
Question 4: A smart contract has a `withdraw` function where the code first sends Ether to the user's address and then updates the user's balance in the contract's storage. Which classic smart contract vulnerability does this specific order of operations create?
- Integer Overflow
- Timestamp Dependence
- Denial of Service (DoS)
- Reentrancy Attack (Correct answer)
Correct answer: Reentrancy Attack
This sequence creates a reentrancy vulnerability. A malicious contract can exploit this by implementing a fallback function that recursively calls the `withdraw` function *after* receiving the Ether but *before* the original call updates the balance. This allows the attacker to drain the contract's funds. The secure pattern is Checks-Effects-Interactions: update the balance first, then send the Ether.
Question 5: Which of the following best describes the role of "gas" in the context of the Ethereum blockchain?
- A cryptographic token used exclusively for staking in Proof of Stake consensus.
- A fixed-fee paid to the developers of a smart contract upon deployment.
- A unit of measurement for the computational effort required to execute operations. (Correct answer)
- The physical hardware required to run an Ethereum node.
Correct answer: A unit of measurement for the computational effort required to execute operations.
Gas is the unit that measures the amount of computational work required to perform operations, such as transactions or smart contract executions, on the Ethereum network. Each operation has a fixed gas cost. The total transaction fee (paid in ETH) is the amount of gas used multiplied by the gas price (in Gwei), which prevents network spam and compensates validators for their computational resources.
Question 6: A developer is creating a decentralized autonomous organization (DAO) where token holders can vote on proposals. The smart contract automatically tallies votes and executes the winning proposal if a quorum is met. What fundamental property of smart contracts ensures this process will execute exactly as programmed without manual intervention?
- Self-Execution (Correct answer)
- Anonymity
- Scalability
- Interoperability
Correct answer: Self-Execution
Self-execution is the core principle that smart contracts are programs that automatically run when predetermined conditions are met. The terms of the agreement (the DAO's voting rules) are written directly into code, and the contract will enforce those rules (tallying votes, executing proposals) without the need for a traditional intermediary.
A developer deploys a smart contract to the Ethereum mainnet.
After deployment, they discover a logical bug in one of the functions.
What is the primary consequence of blockchain's immutability in this scenario?