This repository demonstrates the Reentrancy attack on a smart contracts and presents solutions to mitigate it.
A reentrancy attack occurs when a malicious contract calls a function in a vulnerable contract, and then recursively calls back into the vulnerable contract before the first function call finishes. This can lead to unexpected behavior and potentially the draining of funds from the vulnerable contract.
- Attacker.sol
This contract is used to perform the reentrancy attack on the bank contract(s). - Bank - Vulnerable.sol
This bank contract is vulnerable to reentrancy attacks. - Bank - Logical Solution.sol
This bank contract uses a logical solution to prevent reentrancy attacks by updating the balance before sending funds. - Bank - Reentrancy Guard Solution.sol
This bank contract uses OpenZeppelin's ReentrancyGuard to prevent reentrancy attacks.
- Clone the repository.
- Open Remix IDE.
- Upload the smart contract files to Remix IDE.
- Deploy the bank contracts and the attacker contract as needed and observe the outputs in the Remix IDE console.
Reentrancy Attack | Smart Contract Security Tutorial Part 2
Note: The code linked to the video may have had issues, which have been addressed and fixed here.