Blockchain Security Training Smart Contract Exploit Analysis 2 — Questions and Answers
Question 1: In a reentrancy attack, what must the vulnerable contract do BEFORE updating its internal state?
- Make an external call that transfers value (Correct answer)
- Emit an event
- Increment a nonce
- Pause the contract
Correct answer: Make an external call that transfers value
Reentrancy occurs when an external call is made before state changes, letting the callee re-enter and exploit stale state.
Question 2: Which coding pattern most directly prevents reentrancy attacks?
- Checks-Effects-Interactions (Correct answer)
- Lazy initialization
- Proxy delegation
- Factory pattern
Correct answer: Checks-Effects-Interactions
Checks-Effects-Interactions updates state before external calls, removing the reentrancy window.
Question 3: The 2016 DAO hack on Ethereum primarily exploited which vulnerability class?
- Reentrancy (Correct answer)
- Integer overflow
- Front-running
- Access control misconfiguration
Correct answer: Reentrancy
The DAO's split function made an external call before zeroing the balance, allowing recursive withdrawals.
Question 4: A read-only reentrancy attack abuses what specifically?
- A view function returning inconsistent state mid-execution (Correct answer)
- An overflowing loop counter
- A missing return value check
- An unbounded gas refund
Correct answer: A view function returning inconsistent state mid-execution
Read-only reentrancy exploits view functions that report stale or inconsistent values while a callback is in progress.
Question 5: Which mechanism does OpenZeppelin's ReentrancyGuard use to block reentry?
- A status flag locked during execution (nonReentrant modifier) (Correct answer)
- A gas stipend cap
- A timelock on every call
- A signature nonce per transaction
Correct answer: A status flag locked during execution (nonReentrant modifier)
ReentrancyGuard sets a lock variable that reverts any nested call into a guarded function.
Question 6: Cross-function reentrancy is dangerous because the attacker re-enters through:
- A different function sharing the same state variables (Correct answer)
- The constructor
- A pure helper function
- The fallback of an unrelated contract
Correct answer: A different function sharing the same state variables
Cross-function reentrancy re-enters a separate function that reads or writes the same unupdated state.
Question 7: Why does using `transfer()` (2300 gas) no longer reliably prevent reentrancy?
- Gas costs can change via hard forks, breaking the fixed stipend assumption (Correct answer)
- It now forwards all gas by default
- It silently swallows reverts
- It bypasses the receive function
Correct answer: Gas costs can change via hard forks, breaking the fixed stipend assumption
EIP-driven gas repricing (e.g., EIP-1884) can make the 2300 stipend insufficient or its protection assumption unreliable, so guards are preferred.
In a reentrancy attack, what must the vulnerable contract do BEFORE updating its internal state?