Skip to content

FallbackDev/ethernaut-foundry-solutions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ethernaut Solutions with Foundry 🇨🇳

Foundry License Status

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/ 目录下的详细分析笔记为中文。

Repository Structure

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

How to Run

1. Prerequisites

Ensure you have Foundry installed. If not, run:

curl -L https://foundry.paradigm.xyz | bash
foundryup

Create a .env file in the root directory to store your private key and RPC URL.

2. Install Dependencies

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-commit

3. Setup Environment

Important: 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 .env

4. Run Exploit

Replace 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 -vvvv

Option B: Broadcast (On-chain) Execute the script on the Sepolia testnet.

forge script script/King/DeployAcctackKing.s.sol --rpc-url $SEPOLIA_RPC_URL --broadcast

Progress

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
... ... ... ... ...

Disclaimer

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published