Ethernaut Level1 — Fallback

Tellico Lungrevink
1 min readJul 8, 2022

The Ethernaut is a Web3/Solidity based wargame inspired on overthewire.org. Here’s the solution to the Level 1 — Fallback.

The challenge informs me that:

Look carefully at the contract's code below.You will beat this level if
1. you claim ownership of the contract
2. you reduce its balance to 0

Below, I get a full code of the Contract. There are two interesting functions. The main one seems to be the contribute function:

The function allows to take over the account, but only if the sender’s contributions exceed current owner’s contributions. That wouldn’t be easy, since the amount of owner’s contribution are set to 1k Ether on construction:

Fortunately, there’s also a fallback receive function (which will be called upon sending ether to the contract without calling any methods). This one gives the ownership to the sender in case they have contributed anything at all in the past. So no need to beat the 1k Ether owner contribution:

https://gist.github.com/tellico-lungrevink/2fd14b075f222366a563227ae9f8ef64

So it turns out, that I need to only contribute the smallest possible amount, and the the fallback receive function will set me as an owner. Then I’ll be able to clear the Smart Contrat’s balance with the withdraw function:

await contract.contribute({value:1});
await contract.send(1);
await contract.withdraw();

After submitting those three function, all I need is wait a moment (that’s three separate block needed). After all three transaction complete, I can submit the solution and go the next level.

--

--