Understanding Reentrancy Attacks in Smart Contracts
📖 Scenario: You are learning about smart contracts on the Ethereum blockchain. One common security problem is the reentrancy attack, where a malicious contract repeatedly calls back into a vulnerable contract to drain funds.In this project, you will create a simple vulnerable contract, then add a fix to prevent reentrancy attacks.
🎯 Goal: Build a smart contract that holds Ether and allows withdrawals. First, create a vulnerable version that can be attacked by reentrancy. Then, add a guard to prevent the attack.
📋 What You'll Learn
Create a contract with a mapping to track user balances
Write a withdraw function that sends Ether to the user
Add a boolean lock variable to prevent reentrancy
Use the lock variable to guard the withdraw function
Print events to show when withdrawals happen
💡 Why This Matters
🌍 Real World
Smart contracts on blockchains hold real money. Preventing reentrancy attacks protects users' funds from being stolen.
💼 Career
Blockchain developers must understand and fix reentrancy vulnerabilities to build secure decentralized applications.
Progress0 / 4 steps