This repository contains my personal solutions and exploit scripts for the Ethernaut CTF challenges, built using the Foundry development framework.
Note: Code comments are in English, while detailed analysis notes in
notes/are in Chinese.说明: 代码注释为英文,
notes/目录下的详细分析笔记为中文。
The project is organized by challenge levels. Each level typically consists of the original contract, an attack contract, a deployment script, and a markdown note.
.
├── src
│ └── <LevelName>
│ └── Attack<LevelName>.sol # Attack logic / Smart Contract
│ └── <LevelName>.sol # Original level contract
├── script
│ └── <LevelName>
│ └── DeployAttack<LevelName>.s.sol # Foundry Script for deployment
├── notes
│ └── <LevelName>.md # Analysis & Walkthrough (Chinese)
├── .env # Environment variables
└── foundry.toml # Foundry configuration
Ensure you have Foundry installed. If not, run:
curl -L https://foundry.paradigm.xyz | bash
foundryupCreate a .env file in the root directory to store your private key and RPC URL.
This project uses specific versions of OpenZeppelin for some levels (e.g., Re-entrancy uses Solidity 0.6). Install them using:
forge install openzeppelin/openzeppelin-contracts@v3.4.2 --no-commitImportant: Do not commit your .env file to version control.
Content format for .env (Plain Text):
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_API_KEY
PRIVATE_KEY=0xYourPrivateKeyHere...
Load the environment variables:
source .envReplace the path with the specific level you want to solve. Below is an example for the King level.
Option A: Simulation (Dry Run) Run the script locally to check if the logic works.
forge script script/King/DeployAcctackKing.s.sol --rpc-url $SEPOLIA_RPC_URL -vvvvOption B: Broadcast (On-chain) Execute the script on the Sepolia testnet.
forge script script/King/DeployAcctackKing.s.sol --rpc-url $SEPOLIA_RPC_URL --broadcast| ID | Level Name | Key Concepts | Solution Script | Analysis Note |
|---|---|---|---|---|
| 09 | King | Denial of Service (DoS) / Push vs Pull | Script | Note |
| 10 | Re-entrancy | Re-entrancy Attack | Script | Note |
| ... | ... | ... | ... | ... |