Level 11 - Elevator ⏺⏺
Last updated
Last updated
This elevator won't let you reach the top of your building. Right?
Things that might help:
Sometimes solidity is not good at keeping promises.
This Elevator
expects to be used from a Building
.
top
must first return false
when called, then true
the next time. The interface for Building
is set to msg.sender
.
Create a contract that exploits this by implementing a function isLastFloor
that sets top
to true
.
Submit instance... 🥳
You can use the view
function modifier on an interface in order to prevent state modifications. The pure
modifier also prevents functions from modifying the state. Make sure you read Solidity's documentation and learn its caveats.
An alternative way to solve this level is to build a view function which returns different results depends on input data but don't modify state, e.g. gasleft()
.
The function isLastFloor
is called twice, with the returned value changing for the same input as the state is changed.
If the isLastFloor
had been restricted to view, then this attack wouldn't be possible (unless it was calling a library, which doesn't have runtime checks to make sure it doesn't modify the state when it says it's view)