Level 1 - Fallback ⏺
Last updated
Last updated
Look carefully at the contract's code below.
You will beat this level if
you claim ownership of the contract
you reduce its balance to 0
Things that might help:
How to send ether when interacting with an ABI
How to send ether outside of the ABI
Converting to and from wei/ether units (see help()
command)
Fallback methods
The exploit in this contract is in the receive()
function as it changes the owner to any msg.sender
provided that the msg.sender
has previously been added to the contributions
mapping.
Start by contributing to the contract as this is needed to pass the require
check in the receive()
function. The contribution must be less than 0.001 ETH
to pass the require
on the contribute()
function (line 23
).
Become the owner by sending an amount of ETH directly to the contract which will get picked up by the receive()
function (line 38
).
Now you are the owner, withdraw all the funds.
Submit instance... 🥳
You know the basics of how ether goes in and out of contracts, including the usage of the fallback method.
You've also learned about OpenZeppelin's Ownable contract, and how it can be used to restrict the usage of some methods to a privileged address.
Move on to the next level when you're ready!
This exploit shows how logic in the receive()
function should be carefully reviewed as even though it can't be easily called through a standard contract function call, it's still possible to call it.
The logic doesn't make much sense as I don't see what was trying to be achieved. Maybe to have a "secret" way to change the owner?