Introduction
- In this lesson, you'll dive into the solution of the Reentrancy Fundamentals: Attack Lab.
Prerequisites
Code Solution
Tip
- To maximize viewing space, click the icon within the bottom left corner
- Green highlights: Correspond to additions.
- Red highlights: Correspond to removals.
Explanation
Tip:
This section can relate the solution's code to the Process Diagram. Use the Process Diagram (and the Process Diagram's Explanation section) to understand the solution.
Challenge: Attacker.sol should be able to steal all ETH from Vulnerable.sol
- Marker
1
: Corresponds to the Process Diagram's Seeding Phase -1
- Marker
2
: Corresponds to the Process Diagram's Transfer Phase -3a
. This initiates the first cycle of the Attack Loop. - Marker
4
: Initiates all subsequent cycles of the Process Diagram's 'attack loop'. This process continues until allETH
has been transferred to theAttacker
Contract.- To help visualize this process, review the Event Trace section.Tip
- Marker
1
: Deposits_ATTACK_AMOUNT
(i.e., 1ETH
) into the Attacker's account withinVulnerable
Contract. This will ensure that Marker5
will not be evaluated. - Marker
3
: Will ensure theVulnerable
Contract only sends availableETH
. IfVulnerable
Contract tries to sendETH
that it doesn't have, Marker6
will cause a revert operation.
Event Trace
Tip:
Use the event trace (below) to understand the solution's execution flow
Reflection
- Does the event trace correspond to your understanding of Reentrancy?Self Quiz
Next Steps
- In the Reentrancy Fundamentals: Defend Theory, you'll learn design patterns that can help mitigate Reentrancy attacks
Disclosures
Warning: