This template is based on Zellic's example-ctf-challenge, which was updated by minaminao, and further enhanced to streamline the process of developing challenges using this template.
$ forge init --template bshyuunn/foundry-ctf-template my-solidity-challenge
$ cd my-solidity-challenge
$ make all
$ nc localhost 31337
1 - launch new instance
2 - kill instance
3 - get flag (if isSolved() is true)
action?
First, place your custom challenge files in the src/
directory. The Setup.col
file is essential, and you also need to implement the isSolved
function to check if the challenge has been solved. Other environment setup tasks should be handled in the constructor.
Additionally, you can write a script to solve the challenge in the script/
directory, and you can add test code for your challenge in the test/
directory.
Next, to configure the environment for your challenge, modify the docker-compose.yml
file. Change simple-challenge:
to the name of your challenge and adjust other values in the file to fit your challenge's environment.
services:
simple-challenge:
build: ./build
ports:
- "31337:31337"
- "8545:8545"
restart: unless-stopped
environment:
- FLAG=CTF{FLAG}
- PORT=31337
- HTTP_PORT=8545
- PUBLIC_IP=localhost
- SHARED_SECRET=47066539167276956766098200939677720952863069100758808950316570929135279551683
- SETUP_CONTRACT_VALUE=0
- USER_VALUE=10000000000000
- EVM_VERSION=cancun # `cancun`, `shanghai`, `paris`, `london`, etc...
-
FLAG
The secret value participants need to find. -
PORT
The port for service communication (default:31337
).
If changed, also updatedocker-compose.yml
underports: - "31337:31337"
. -
HTTP_PORT
The port for RPC communication with the Ethereum node (default:8545
).
If changed, also updatedocker-compose.yml
underports: - "8545:8545"
. -
PUBLIC_IP
The public IP for hosting the service (set tolocalhost
for local development). -
SHARED_SECRET
An authentication value used when creating a blockchain network internally. (this value should be set randomly) -
SETUP_CONTRACT_VALUE
The value sent to the Setup Contract (default:0
). -
USER_VALUE
The initial balance value for the CTF player. -
EVM_VERSION
The Ethereum version to use (cancun
,shanghai
,paris
, etc.).
Additionally, when changing the EVM_VERSION
, make sure to properly set the desired version in the foundry.toml
file as well:
[profile.default]
evm_version = "cancun" # Set to your desired version, such as `cancun`, `shanghai`, `paris`, `london`, etc.