A replication of DAO Hack vulnerability
This code is integrated using Remix Ethereum IDE. To run this project, open Remix IDE in your web browser and create files to run the code.
The infamous DAO hack was happened in 2016, a year after the launch of Ethereum. This hack was a result of reentrancy attack. splitDAO
was the function prone to this attack.
This hack resulted in famous hard fork which led to Ethereum and Ethereum Classic. In this repo, I'll highlight the discrepancy and it's solution using the pattern of CHECK-EFFECT-INTERACTION.
- Load the GitHub repo
- Compile & Deploy FundRaiser
- Compile & Deploy Attacker, with FundRaiser address as parameter
- Set Value to 10000 and call
deposit
on Fundraiser. This will deposit money on YOUR balance - Call getTotalFunds on Fundraiser. Should show 10000.
- Set Value to 400 and call
depositFunds
on Attacker. This will deposit money on the ATTACKER's balance - Call getTotalFunds on Fundraiser. Should show 10400.
- Call getFunds on Attacker. Should show 0. The attacker has 0 funds currently.
- Call withdrawFunds on Attacker. This is the attack.
- Call getFunds on Attacker. Should show 1600 -- 4x what the Attacker deposited!
- Delete both deployed contracts. Re-deploy both, but this time, build & deploy the UpdatedFundRaiser
- Add funds to both, and try to drain via attack. The attack should fail.
Use this repo for the purpose of study.