CBCP Smart Contracts and dApps 3 — Questions and Answers
Question 1: Which consensus-related attack involves a miner reordering transactions in a block to profit from price movements in a DeFi protocol?
- Sybil attack
- Eclipse attack
- Maximal Extractable Value (MEV) (Correct answer)
- 51% attack
Correct answer: Maximal Extractable Value (MEV)
MEV refers to the profit miners or validators can extract by including, excluding, or reordering transactions within the blocks they produce.
Question 2: What does the term 'gas limit' represent in an Ethereum transaction?
- The maximum Ether value that can be transferred
- The maximum amount of computational work the sender is willing to pay for (Correct answer)
- The block's throughput capacity in transactions per second
- The minimum fee required by miners
Correct answer: The maximum amount of computational work the sender is willing to pay for
Gas limit is the maximum units of gas a sender authorizes for a transaction; if execution requires more gas, it reverts but the gas is still consumed.
Question 3: Which Solidity function visibility modifier makes a function accessible only within the contract that defines it and not by derived contracts?
- public
- external
- internal
- private (Correct answer)
Correct answer: private
Private functions are only accessible within the contract they are defined in, unlike internal functions which are also accessible in derived (child) contracts.
Question 4: What is the main advantage of using the ERC-1155 multi-token standard over separate ERC-20 and ERC-721 contracts?
- It supports Proof of Work mining only
- It allows a single contract to manage multiple fungible and non-fungible token types, reducing deployment costs (Correct answer)
- It automatically burns tokens after transfer
- It enables tokens to earn staking rewards natively
Correct answer: It allows a single contract to manage multiple fungible and non-fungible token types, reducing deployment costs
ERC-1155 lets a single contract manage any combination of fungible and non-fungible tokens, enabling batch transfers and significantly lower gas costs.
Question 5: In the context of DApps, what is the purpose of the Web3.js or Ethers.js library?
- To compile Solidity source code into EVM bytecode
- To provide a JavaScript interface for interacting with Ethereum nodes and smart contracts (Correct answer)
- To run a local Ethereum node in the browser
- To generate cryptographic key pairs for wallets
Correct answer: To provide a JavaScript interface for interacting with Ethereum nodes and smart contracts
Web3.js and Ethers.js are JavaScript libraries that enable frontend DApp code to communicate with Ethereum nodes via JSON-RPC, call contract functions, and listen for events.
Question 6: What is 'flash loan' in DeFi smart contracts?
- A long-term undercollateralized loan issued by a DAO
- An uncollateralized loan that must be borrowed and repaid within a single transaction (Correct answer)
- A loan where repayment is enforced by a hardware security module
- A micro-loan protocol that uses off-chain credit scores
Correct answer: An uncollateralized loan that must be borrowed and repaid within a single transaction
Flash loans are atomic, uncollateralized loans where borrowing and repayment occur in one transaction; if repayment fails, the entire transaction reverts.
Question 7: Which tool is most commonly used to test and deploy Ethereum smart contracts in a local development environment?
- MetaMask
- Hardhat or Truffle (Correct answer)
- Infura
- Etherscan
Correct answer: Hardhat or Truffle
Hardhat and Truffle provide local Ethereum node emulation, automated testing frameworks, and deployment scripts for smart contract development.
Which consensus-related attack involves a miner reordering transactions in a block to profit from price movements in a DeFi protocol?