Recall & Review
beginner
What is a reentrancy attack in blockchain smart contracts?
A reentrancy attack happens when a smart contract calls another contract that calls back into the original contract before the first call finishes, allowing repeated withdrawals or actions that can drain funds or cause unexpected behavior.
Click to reveal answer
beginner
Why are reentrancy attacks dangerous?
They let attackers repeatedly withdraw funds or manipulate contract state before the contract updates its balance or state, leading to loss of money or corrupted data.Click to reveal answer
intermediate
What is the common pattern to prevent reentrancy attacks?
Use the 'checks-effects-interactions' pattern: first check conditions, then update state, and only after that interact with other contracts or send funds.
Click to reveal answer
intermediate
How does the 'ReentrancyGuard' contract help prevent attacks?
It uses a lock mechanism to prevent a contract function from being called again before the first call finishes, blocking reentrant calls.
Click to reveal answer
advanced
Give a simple example of a vulnerable Solidity function to reentrancy.
A function that sends Ether to a user before updating their balance, like: <pre>function withdraw(uint amount) public { require(balances[msg.sender] >= amount); (bool success, ) = msg.sender.call{value: amount}(""); require(success); balances[msg.sender] -= amount; }</pre> This allows reentrancy because balance is updated after sending Ether.Click to reveal answer
What is the main cause of a reentrancy attack?
✗ Incorrect
Reentrancy attacks happen when a contract calls another contract before updating its own state, allowing the called contract to call back and exploit the original contract.
Which pattern helps prevent reentrancy attacks?
✗ Incorrect
The Checks-Effects-Interactions pattern ensures state changes happen before external calls, preventing reentrancy.
What does the ReentrancyGuard contract do?
✗ Incorrect
ReentrancyGuard uses a lock to prevent a function from being reentered before the first call finishes.
In Solidity, what is a risky way to send Ether that can cause reentrancy?
✗ Incorrect
Using call.value() (or call with value) before updating state allows the called contract to reenter and exploit the contract.
Which of these is NOT a way to prevent reentrancy?
✗ Incorrect
Allowing multiple reentrant calls is exactly what causes reentrancy attacks, so it is not a prevention method.
Explain what a reentrancy attack is and why it can cause loss of funds in smart contracts.
Think about a contract calling another contract that calls back before state updates.
You got /3 concepts.
Describe the 'checks-effects-interactions' pattern and how it helps prevent reentrancy attacks.
Focus on the order of operations in a function.
You got /4 concepts.