Solidity Solidity Advanced Patterns and Architecture 2 — Questions and Answers
Question 1: What is the Commit-Reveal scheme used for in Solidity?
- Hiding user inputs until all participants commit, then revealing to prevent front-running (Correct answer)
- Encrypting contract state so only the owner can read it
- Committing to an upgrade before executing it
- Compressing large arrays into a hash for cheaper storage
Correct answer: Hiding user inputs until all participants commit, then revealing to prevent front-running
In commit-reveal, users first submit a hash of their choice (commit), then reveal the plaintext after all commits are collected, preventing front-runners from copying the winning move.
Question 2: What is a 'Multisig wallet' and why is it used for managing smart contract ownership?
- A contract requiring M-of-N key signatures to execute transactions, distributing trust and preventing single-point-of-failure (Correct answer)
- A wallet that batches multiple transactions into one for gas savings
- A contract that automatically splits ETH among multiple owners
- A wallet that requires a time lock before any transaction executes
Correct answer: A contract requiring M-of-N key signatures to execute transactions, distributing trust and preventing single-point-of-failure
A multisig requires multiple authorized signers to approve each transaction, ensuring no single compromised key can unilaterally control protocol funds or upgrades.
Question 3: What does the `TimelockController` in OpenZeppelin provide for contract governance?
- A mandatory delay between proposing and executing privileged operations, giving users time to exit if they disagree (Correct answer)
- Automatic rate limiting of token transfers
- Scheduled gas price adjustments
- A time-based access control replacing Ownable
Correct answer: A mandatory delay between proposing and executing privileged operations, giving users time to exit if they disagree
TimelockController enforces a waiting period (e.g., 48 hours) between queuing and executing admin operations, allowing users to review and react before changes take effect.
Question 4: What is the purpose of EIP-712 typed structured data signing in Solidity?
- It enables users to sign structured off-chain messages that can be verified on-chain, with human-readable type information (Correct answer)
- It compresses calldata for cheaper ERC-20 transfers
- It defines a standard for contract metadata storage
- It replaces ECDSA with a cheaper signature scheme
Correct answer: It enables users to sign structured off-chain messages that can be verified on-chain, with human-readable type information
EIP-712 provides a standard way to hash and sign structured data off-chain, enabling meta-transactions and gasless approvals where wallets show readable type information to users.
Question 5: What is a 'meta-transaction' in Solidity and how does it work?
- A transaction where a relayer pays gas on behalf of a user, with the user signing an EIP-712 message instead (Correct answer)
- A transaction that wraps multiple calls into one using Multicall
- A transaction that executes only if a prior transaction succeeded
- A transaction submitted to multiple chains simultaneously
Correct answer: A transaction where a relayer pays gas on behalf of a user, with the user signing an EIP-712 message instead
In meta-transactions, the user signs a message off-chain; a relayer submits it on-chain and pays gas, enabling gasless UX while the contract verifies the user's signature.
Question 6: What is the Multicall pattern in Solidity and what benefit does it provide?
- It bundles multiple function calls into a single transaction, reducing gas overhead and enabling atomic batch operations (Correct answer)
- It calls the same function on multiple contracts simultaneously
- It parallelizes EVM execution across multiple threads
- It allows calling functions on other chains in one transaction
Correct answer: It bundles multiple function calls into a single transaction, reducing gas overhead and enabling atomic batch operations
Multicall aggregates several contract calls into one transaction, saving the 21,000 gas base cost per transaction and ensuring all operations succeed or fail atomically.
What is the Commit-Reveal scheme used for in Solidity?