DEV Community

hamzairshad02
hamzairshad02

Posted on

Ethernaut Level 2 Walkthrough - Fal1out

This level reminds me of that Todd Howard game which 4th installment was heavily criticized and memed out because of the errors present in the game. This level indicates the very same scenario.

The very first hint to solve this level is given right at the title of the level name.

Image description

You notice that underline on the L1? That is our way out to solve this level.

Let’s start by understanding our contract first by understanding each function present in there.

  • Fal1out(): This function is commented as the constructor of the contract which indicates the one calling out this function is the owner of this contract. Usually when a contract’s constructor is called the one deploying the contract is the owner if it is not changed by some other condition or method.
  • allocate(): This function allocates the amount to the allocator.
  • sendAllocation(): This function requires you to have allocations more than zero in order to send them.
  • collectAllocations(): This function collects all the allocations and is locked by the ‘onlyOwner’ modifier which requires you to be the owner of the contract to utilize this function.
  • allocatorBalance(): This function simply returns the allocations by an allocator.

Now we see that we need to take ownership of this contract and unlock the ‘collectAllocations()’ method to collect all the allocations and finish the level.

Now look at the very first function of this contract which is commented as the ‘constructor’ and look at the contract’s name. Notice how both the constructor and contract name is different? This is the conflict that we need to take advantage of. As our very first hint at the title also highlights the spelling mistake between ‘Fallout’ and ‘Fal1out’ so this implies that there is no constructor declared for the contract.

Now when we deploy the contract by clicking ‘Get new instance’ button we can see that there is actually no owner declared for the contract by the following commands.

Image description

This is due to the typo in the constructor which implies that it is never called and hence the contract is deployed without an owner.

So in order to simply become the owner we have to call the ‘Fal1out’ function and unlock the ‘collectAllocations()’ method to collect all the allocations.

This can be done by the following command and can be verified.

Image description

As you can see we called the ‘Fal1out()’ function and became the owner of the contract all we have to do is finally call the ‘collectAllocations()’ function to finish the level.

Image description

Now simply click on ‘Submit Instance’ button and get done with the level.

Top comments (0)