CBCP Smart Contracts and dApps 4 — Questions and Answers
Question 1: What is the 'ABI' (Application Binary Interface) in the context of Ethereum smart contracts?
- A cryptographic hash of the contract bytecode
- A JSON description of a contract's functions and events used to encode/decode interactions (Correct answer)
- The bytecode representation stored on the blockchain
- A digital signature proving contract ownership
Correct answer: A JSON description of a contract's functions and events used to encode/decode interactions
The ABI is a JSON specification that defines how to encode function calls and decode return values when interacting with a deployed smart contract.
Question 2: In Solidity, what is the difference between 'storage' and 'memory' variable locations?
- Storage is temporary and cheaper; memory is permanent and expensive
- Storage is permanent and persists on-chain; memory is temporary and exists only during execution (Correct answer)
- Storage holds only primitive types; memory holds complex structs
- Storage is encrypted; memory is plaintext
Correct answer: Storage is permanent and persists on-chain; memory is temporary and exists only during execution
Storage variables are written to the blockchain and persist between transactions, while memory variables are temporary and discarded after function execution ends.
Question 3: What distinguishes a 'pure' function from a 'view' function in Solidity?
- Pure functions can modify state; view functions cannot
- Pure functions neither read nor modify state; view functions can read but not modify state (Correct answer)
- Pure functions are payable; view functions are not
- Pure functions require on-chain verification; view functions do not
Correct answer: Pure functions neither read nor modify state; view functions can read but not modify state
A pure function promises to neither read nor write contract state, while a view function may read state but not modify it.
Question 4: Which attack vector exploits a smart contract that uses block.timestamp for randomness or time-sensitive logic?
- Timestamp manipulation by miners within a small window (Correct answer)
- Hash collision attacks on the timestamp value
- Network eclipse causing timestamp desynchronization
- Front-running the block inclusion order
Correct answer: Timestamp manipulation by miners within a small window
Miners can adjust block.timestamp by a few seconds, making it an unreliable source of randomness or precise time measurement in smart contracts.
Question 5: What is 'tokenomics' in the context of DApp design?
- The cryptographic algorithm used to secure token transfers
- The economic model governing a token's supply, distribution, incentives, and utility within an ecosystem (Correct answer)
- The process of converting ERC-20 tokens to ERC-721 tokens
- A tax applied to token transactions on decentralized exchanges
Correct answer: The economic model governing a token's supply, distribution, incentives, and utility within an ecosystem
Tokenomics describes the economic design of a token system including total supply, emission schedule, staking rewards, and incentive structures that drive participant behavior.
Question 6: In a decentralized exchange (DEX) using an Automated Market Maker (AMM), what determines the token swap price?
- An order book matching buyers and sellers
- A mathematical formula based on the ratio of token reserves in a liquidity pool (Correct answer)
- A price feed from a centralized oracle provider
- A governance vote held every 24 hours
Correct answer: A mathematical formula based on the ratio of token reserves in a liquidity pool
AMMs like Uniswap use the constant product formula (x * y = k) where the price is determined by the current ratio of two token reserves in the pool.
Question 7: What is 'impermanent loss' in DeFi liquidity provision?
- Funds permanently lost when a smart contract is hacked
- The temporary reduction in value a liquidity provider experiences compared to simply holding tokens when prices diverge (Correct answer)
- The gas fees paid when depositing tokens into a liquidity pool
- Interest lost when withdrawing funds before a lockup period ends
Correct answer: The temporary reduction in value a liquidity provider experiences compared to simply holding tokens when prices diverge
Impermanent loss occurs when the price ratio of tokens in a liquidity pool changes after deposit, making the LP's position less valuable than just holding the tokens outright.
What is the 'ABI' (Application Binary Interface) in the context of Ethereum smart contracts?