Chapter 34: Quiz

Blockchain Fundamentals for Prediction Markets

Test your understanding of blockchain concepts, Ethereum, smart contracts, and their application to prediction markets.


Question 1

What is the primary data structure that links blocks in a blockchain?

A) A doubly-linked list using memory pointers B) A hash chain where each block contains the cryptographic hash of the previous block C) A relational database with foreign key constraints D) A binary search tree indexed by block number

Answer: B

Explanation: Each block header contains the hash of the previous block, creating a cryptographic chain. If any historical block is modified, its hash changes, which invalidates the reference in the next block, cascading through all subsequent blocks. This is fundamentally different from pointer-based linked lists because the link is cryptographic and tamper-evident.


Question 2

Why is censorship resistance particularly valuable for prediction markets?

A) It reduces the cost of running the platform B) It makes markets faster C) It prevents governments and intermediaries from shutting down markets or restricting participation D) It eliminates the need for oracles

Answer: C

Explanation: Historical precedent shows that centralized prediction markets (like Intrade) can be shut down by regulators. Blockchain-based prediction markets, deployed as smart contracts across thousands of nodes, cannot be easily taken offline by any single entity. While front-end interfaces can be targeted, the underlying market contracts remain operational.


Question 3

In Ethereum's Proof of Stake consensus mechanism, what happens to a validator who acts maliciously?

A) Their mining equipment is confiscated B) They receive a warning from the Ethereum Foundation C) Their staked ETH is partially or fully destroyed (slashed) D) They are banned from the network permanently

Answer: C

Explanation: Slashing is the penalty mechanism in PoS. Validators who violate protocol rules (e.g., signing conflicting blocks) have a portion of their staked ETH destroyed. This economic penalty aligns validator incentives with honest behavior, as malicious actions result in direct financial loss.


Question 4

What is the difference between an Externally Owned Account (EOA) and a Contract Account on Ethereum?

A) EOAs can hold ETH but contract accounts cannot B) EOAs are controlled by private keys and can initiate transactions; contract accounts are controlled by code and can only execute in response to transactions C) Contract accounts have higher gas limits than EOAs D) There is no practical difference; the terms are interchangeable

Answer: B

Explanation: EOAs are controlled by private keys held by users. They can initiate transactions by signing them. Contract accounts have associated bytecode and storage; they execute their code when triggered by a transaction from an EOA or a call from another contract. Contract accounts cannot initiate transactions on their own.


Question 5

If a transaction on Ethereum runs out of gas during execution, what happens?

A) The transaction is automatically retried with more gas B) The transaction is rolled back (state changes reverted) but the gas consumed is still paid C) The transaction partially executes up to the gas limit D) The gas is refunded and the transaction is removed from the mempool

Answer: B

Explanation: When a transaction exceeds its gas limit, the EVM reverts all state changes made during execution. However, the sender still pays for the gas consumed up to the point of failure. This design prevents denial-of-service attacks where users submit computationally expensive transactions without paying.


Question 6

What is the purpose of the ABI (Application Binary Interface) in Ethereum?

A) It compiles Solidity code into bytecode B) It defines how to encode function calls and decode return values when interacting with a smart contract C) It manages private keys for wallet applications D) It determines the gas cost of each EVM opcode

Answer: B

Explanation: The ABI is a JSON specification that describes a contract's functions, their parameters, return types, and events. When calling a contract function, the function name and parameters must be ABI-encoded into the transaction's data field. The ABI enables tools like web3.py to construct these encoded calls and decode the results.


Question 7

In the EIP-1559 fee model, what happens to the base fee portion of the transaction fee?

A) It goes to the block validator as a reward B) It is burned (destroyed), permanently removing ETH from circulation C) It is deposited into a protocol treasury D) It is redistributed to all ETH holders

Answer: B

Explanation: Under EIP-1559, the base fee is algorithmically determined by network congestion and is burned upon transaction inclusion. Only the priority fee (tip) goes to the validator. This burning mechanism creates a deflationary pressure on ETH supply when network usage is high.


Question 8

A prediction market trade on Ethereum L1 costs 200,000 gas. With a base fee of 30 gwei, a priority fee of 2 gwei, and ETH priced at $3,500, what is the approximate transaction cost in USD?

A) $0.70 B) $7.00 C) $22.40 D) $224.00

Answer: C

Explanation: Transaction cost = gas_used * (base_fee + priority_fee) * ETH_price = 200,000 * (30 + 2) * 10^-9 * 3,500 = 200,000 * 32 * 10^-9 * 3,500 = 0.0064 * 3,500 = $22.40. This illustrates why Layer 2 solutions are essential for economically viable prediction market trading.


Question 9

What does the approve function in the ERC-20 standard do?

A) Transfers tokens directly from one address to another B) Authorizes a specified address (typically a smart contract) to spend up to a certain amount of tokens on the caller's behalf C) Creates new tokens and assigns them to an address D) Burns tokens permanently from the caller's balance

Answer: B

Explanation: The approve/transferFrom pattern is fundamental to DeFi interactions. When interacting with a prediction market contract, a user first calls approve on the collateral token (e.g., USDC) to authorize the market contract to spend their tokens. Then the market contract calls transferFrom to pull the collateral when the user places a bet.


Question 10

In the context of prediction market tokens, what does the "split" operation do?

A) Divides one token into two tokens with half the value each B) Converts one unit of collateral into one YES token and one NO token for a binary market C) Splits a market into two separate sub-markets D) Separates the token's metadata from its value

Answer: B

Explanation: In a binary prediction market, the split operation converts collateral (e.g., 1 USDC) into a complete set of outcome tokens (1 YES + 1 NO). The merge operation is the reverse: combining 1 YES + 1 NO back into 1 unit of collateral. This mechanism ensures that YES price + NO price approximates 1 (the collateral unit), maintaining the prediction market invariant.


Question 11

Which Layer 2 solution does Polymarket primarily use?

A) Arbitrum One B) Optimism C) Polygon PoS D) zkSync Era

Answer: C

Explanation: Polymarket operates on the Polygon PoS sidechain, which offers very low transaction fees (fractions of a cent), fast block times (~2 seconds), and sufficient security for typical prediction market sizes. This makes small bets economically viable, unlike Ethereum L1 where gas costs could exceed the bet amount.


Question 12

What is the key difference between an Optimistic Rollup and a ZK-Rollup?

A) Optimistic Rollups are faster; ZK-Rollups are slower B) Optimistic Rollups assume transactions are valid and allow challenges; ZK-Rollups generate cryptographic proofs of validity C) ZK-Rollups are centralized; Optimistic Rollups are decentralized D) They are the same technology with different names

Answer: B

Explanation: Optimistic Rollups process transactions off-chain and assume they are valid. There is a challenge period (typically 7 days) during which anyone can submit a fraud proof to dispute an invalid transaction. ZK-Rollups generate zero-knowledge validity proofs for each batch, which are verified on L1. ZK-Rollups provide faster finality (no challenge period) but are more computationally expensive to produce proofs.


Question 13

How is an Ethereum address derived from a private key?

A) The private key is directly used as the address B) The address is the SHA-256 hash of the private key C) The public key is derived from the private key via elliptic curve multiplication, then the address is the last 20 bytes of the Keccak-256 hash of the public key D) The address is randomly generated and linked to the private key in a database

Answer: C

Explanation: The derivation chain is: private key (256-bit random integer) -> public key (via elliptic curve point multiplication on secp256k1) -> address (last 20 bytes of Keccak-256 hash of the public key). This is a one-way process: you cannot derive the private key from the address or public key.


Question 14

What is a reentrancy attack in smart contracts?

A) A user entering the same market twice B) An attacker contract calling back into the vulnerable contract during execution, before the first call completes, potentially draining funds C) A validator including the same transaction in multiple blocks D) A denial-of-service attack that prevents contract execution

Answer: B

Explanation: Reentrancy occurs when a contract makes an external call to an attacker's contract, and the attacker's contract calls back into the original contract before the first execution completes. If the original contract has not updated its state (e.g., zeroing a balance) before the external call, the attacker can repeatedly withdraw funds. The Checks-Effects-Interactions pattern prevents this by updating state before making external calls.


Question 15

In web3.py, what is a "provider"?

A) A Python package that provides smart contract templates B) A service or connection that gives web3.py access to an Ethereum node's API C) A wallet that provides signing capabilities D) A testing framework for smart contracts

Answer: B

Explanation: A provider is the connection layer between web3.py and the blockchain. It communicates with an Ethereum node (either local or remote) via HTTP, WebSocket, or IPC protocols. Services like Infura and Alchemy run Ethereum nodes and expose their APIs for developers to connect through providers.


Question 16

What is the purpose of the gas limit in an Ethereum transaction?

A) To set the minimum gas price the sender is willing to pay B) To cap the maximum amount of computational work the transaction can perform, protecting the sender from unexpectedly expensive execution C) To limit the number of transactions a block can contain D) To restrict how much ETH can be transferred

Answer: B

Explanation: The gas limit is set by the transaction sender and represents the maximum gas the transaction is allowed to consume. If execution requires more gas, it reverts. This protects senders from unexpectedly expensive operations (e.g., a function that turns out to iterate over a large dataset). The sender pays for gas actually consumed, up to the gas limit.


Question 17

Why are events (logs) important for prediction market applications?

A) They are the only way to read contract state B) They provide a cheaper, indexed way to track on-chain activity (trades, market creation, settlement) that off-chain applications can efficiently query C) They are required for transactions to be valid D) They prevent front-running attacks

Answer: B

Explanation: Events are emitted during transaction execution and stored in transaction receipts, not in contract storage. They are significantly cheaper to emit than storage writes and are automatically indexed by block number and topic, making them efficient to query. Prediction market applications use events to track trades, monitor market activity, and build historical datasets.


Question 18

What does the nonce field in an Ethereum transaction represent, and why is it important?

A) A random number used for proof-of-work mining B) The number of transactions previously sent from the sender's account; it ensures transactions are processed in order and prevents replay attacks C) A cryptographic salt for the transaction hash D) The number of blocks since the last transaction from this account

Answer: B

Explanation: The nonce is a sequential counter that starts at 0 for each account. Each new transaction must use the next nonce value. This serves two purposes: (1) it ensures transactions from the same sender are processed in order, and (2) it prevents replay attacks where a valid signed transaction could be broadcast multiple times.


Question 19

What is MEV (Miner/Maximal Extractable Value) and how does it affect prediction market traders?

A) The mining reward for producing blocks B) The maximum amount of ETH a validator can stake C) The profit a block producer can extract by reordering, inserting, or censoring transactions; it can lead to front-running and sandwich attacks on market trades D) The fee paid to oracle providers

Answer: C

Explanation: MEV refers to the profit that block producers (validators) can extract by manipulating transaction ordering within a block. For prediction market traders, this manifests as front-running (a bot sees your trade in the mempool and trades ahead of you) and sandwich attacks (a bot buys before your trade and sells after, profiting from the price impact you create). This is a significant concern for on-chain trading.


Question 20

When connecting to Polygon from Python using web3.py, what is the primary difference from connecting to Ethereum mainnet?

A) You need a different version of web3.py B) You use a different RPC endpoint URL; the web3.py API remains the same C) Polygon requires a special authentication token not needed for Ethereum D) You cannot use web3.py with Polygon; a different library is required

Answer: B

Explanation: Connecting to any Ethereum-compatible chain (Polygon, Arbitrum, Optimism, Base) uses the same web3.py library and API. The only difference is the RPC endpoint URL passed to the provider. The chain ID will differ (137 for Polygon vs. 1 for Ethereum mainnet), but all contract interaction patterns are identical.


Question 21

What is the ERC-1155 token standard, and why is it relevant to prediction markets?

A) A standard for non-fungible tokens only B) A multi-token standard that can represent both fungible and non-fungible tokens in a single contract, enabling efficient management of multiple outcome tokens C) A standard for decentralized exchanges D) A governance token standard

Answer: B

Explanation: ERC-1155 allows a single contract to manage multiple token types, each identified by a token ID. This is ideal for prediction markets where a single market may have multiple outcomes, each represented by a different token ID within the same contract. Polymarket's Conditional Token Framework uses ERC-1155, where different token IDs represent different outcome positions across many markets.


Question 22

What is the Checks-Effects-Interactions pattern in smart contract development?

A) A testing methodology for smart contracts B) A security pattern where functions first validate inputs (checks), then update state (effects), and finally interact with external contracts (interactions), preventing reentrancy C) A deployment process for smart contracts D) A gas optimization technique

Answer: B

Explanation: The Checks-Effects-Interactions pattern is the primary defense against reentrancy attacks. By updating all internal state (effects) before making any external calls (interactions), the contract ensures that even if the external call triggers a callback, the state is already updated and the attacker cannot exploit stale state. Checks (input validation with require statements) come first to fail early and save gas.


Question 23

How does The Graph help developers working with blockchain prediction market data?

A) It provides a graphical interface for trading B) It indexes blockchain event data and exposes it through GraphQL APIs, enabling efficient queries over historical on-chain data without scanning blocks manually C) It generates visual charts of market prices D) It manages graph databases for smart contracts

Answer: B

Explanation: Querying historical blockchain data by scanning blocks is slow and resource-intensive. The Graph indexes event data from smart contracts into "subgraphs" that can be queried via GraphQL. For prediction markets, this means you can efficiently query historical trades, market states, and user activity without iterating through millions of blocks. Many DeFi and prediction market protocols maintain their own subgraphs.


Question 24

What is the significance of Ethereum's transition from Proof of Work to Proof of Stake ("The Merge")?

A) It doubled Ethereum's transaction throughput B) It reduced energy consumption by approximately 99.95%, changed the security model from computational power to economic stake, and improved finality guarantees C) It eliminated all gas fees D) It made Ethereum incompatible with ERC-20 tokens

Answer: B

Explanation: The Merge (September 2022) transitioned Ethereum from PoW to PoS. This dramatically reduced energy consumption, changed the security assumption from "no entity controls >50% of hash power" to "no entity controls >33% of staked ETH," and introduced epoch-based finality (~12.8 minutes) instead of purely probabilistic finality. Transaction throughput and gas fees were not directly affected by the Merge; those are addressed by Layer 2 solutions.


Question 25

A prediction market protocol stores market data on-chain. Which of the following design choices would MOST reduce gas costs for users?

A) Storing all market metadata (description, resolution source, tags) as on-chain string variables B) Storing only essential data (outcome token IDs, collateral address, resolution state) on-chain and keeping metadata off-chain (e.g., IPFS) with an on-chain hash reference C) Using larger integer types (uint256) for all numeric values to avoid overflow D) Emitting events for every state change instead of updating storage variables

Answer: B

Explanation: On-chain storage is the most expensive operation on Ethereum (20,000 gas for a new storage slot, 5,000 for updates). Storing lengthy strings (market descriptions, tags) on-chain is extremely costly. The optimal approach is to store only the minimum data needed for contract logic on-chain and keep metadata off-chain (IPFS, centralized storage) with an on-chain content hash for verification. Option D is a partial measure, but events alone cannot replace storage for data the contract needs to reference during execution.