After learning the basics of Solidity assembly in Part 1: Playing with Yul let’s now dive deeper! 💪
We’re going to solve the Ethernaut challenges, written by Openzeppelin, entirely in assembly. We’ll use some more advanced assembly and also learn about Ethereum security exploits. On top of that we’ll use Foundry, built by Paradigm, to run our scripts, tests, and deploy to Goerli testnet.
Hopefully you’ll learn a lot going through this article!
The idea is that you should try the challenges yourself, one by one, and after each challenge go checkout my repo to understand the Yul version. You’ll see that throughout the challenges, the same assembly techniques are used over and over so it might be a bit boring after a while.
This article is not meant to be read alone. I just wrote here some explanations of the code for some difficult parts. So your first step should be to go to my Ethernaut-yul repo
I will not give detailed explanations on how to solve each challenge. Most challenges are pretty basic, and you’ll find a lot of explanations if you search online. This tutorial is mostly focused on Assembly.
evm.codes is a great website if you don’t understand what some opcodes do.
Just like with Part 1, if you have any questions, or issues understanding what I wrote, or if you just wanna chat → message me on Twitter 0xteddav
This repo is a mix of Foundry and Hardhat, so it can also be a good boilerplate for your future projects (you’re welcome 😁).
Install Foundry: https://github.com/foundry-rs/foundry/#installation
Then run yarn to install the dependencies in package.json
And copy .env.tmpl to .env and enter the correct values for your private key and the RPC you’re going to use.
Each level is solved by a forge script. You’ll find all scripts in script/foundry.
You’ll find a template in Level.s.sol that you can copy/paste. You’ll just need to:
If you’re running the levels locally, you have to run anvil (or hardhat node) as fork of Goerli