Welcome to the BuidlGuidl CTF Devconnect Argentina
⚡️ Live at https://ctf-argentina.buidlguidl.com
If you have your own stack already, go straight to the CTF site and start playing.
We have created this stack, which contains all the tools you need to play the CTF.
Once you have solved a challenge locally, you can deploy your solution to Optimism, and then interact with the live contracts from the frontend by switching the network to Optimism. If you are using a script, make sure you are pointing it to the Optimism RPC.
Live challenges addresses and ABIs are already stored in your
externalContracts.tsfile.
Keep reading to learn how to set everything up.
You'll need to have the following tools installed in your machine:
- Node (>= v20.18.3)
- Yarn (v1 or v2+)
- Git
- Foundryup (if foundry is selected)
Note for Windows users. Foundryup is not currently supported by Powershell or Cmd, and has issues with Git Bash. You will need to use WSL as your terminal.
First, install the Scaffold-ETH 2 CTF extension with create-eth:
npx create-eth@latest -e buidlguidl/ctf-argentinaThis will create a new folder with all the tools you need to play the CTF locally. Afterward, you’ll be able to deploy the solutions to Optimism and capture the flags in the live game.
Go into the folder and run the following commands in separate terminals:
- Run a local blockchain:
yarn chain
- Deploy the challenges contracts locally:
hardhat
yarn deploy
foundry
yarn deploy --file DeployChallenges.s.sol && yarn deploy --file DeployChallenge12.s.sol
Note: This command will update the
deployedContracts.tsfile (in thescriptsandnextjspackages), which contains the deployed contracts addresses and ABIs.
- Start the frontend (NextJS app):
yarn start
Now your app on http://localhost:3000 is running entirely locally. You can break things without any consequences :)
This is a yarn monorepo with different packages:
ctf/
└── packages/
├── {solidity-framework}/
├── nextjs/
└── scripts/
Comes preconfigured with hardhat and contains the smart contracts and deployment scripts for the CTF challenges.
It uses hardhat-deploy to deploy the contracts.
contracts/: The source directory where all your smart contracts should be. It already contains all the challenge contracts and the NFT Flag minter contract.deploy/: This directory contains all your deployments scripts. When you runyarn deployall the scripts present in this directory will be executed in numbered order.
Example (How to deploy a contract)
-
Create the smart contract:
- Add your new contract file (e.g.,
Challenge2Solution.sol) in thepackages/hardhat/contracts/directory.
- Add your new contract file (e.g.,
-
Create a deployment script:
- Add a new file (or use the already created
02_deploy_challenge_2_solution.tsfile as a starting point) in thedeploy/directory. - Write your deployment script as needed (you can use
00_deploy_your_contract.tsto guide you)
- Add a new file (or use the already created
-
Deploy your contract locally:
- Run
yarn deploy --tags solution2to deploy your solution contract locally. Thetagsmake sure that your are only deploying the solution contract and not all the other challenges (that were deployed withyarn deployoryarn deploy --tags CTF).
- Run
-
When tested and ready, deploy your contract to Optimism (ask us for some funds if you need!):
-
Note: You need a private key to deploy the contracts. You can generate one with
yarn generateor add your own private key in the.envfiles in/packages/hardhatandpackages/scriptsfolders. - Run
yarn deploy --tags solution2 --network optimismto deploy your solution contract to Optimism.
-
For more details on deployment, including configuring deployer accounts or the network you want to deploy to, see the Scaffold-ETH 2 deployment docs.
Comes preconfigured with Foundry development environment and contains the smart contracts and deployment scripts for the CTF challenges.
contracts/: The source directory where all your smart contracts should be. It already contains all the challenge contracts and the NFT Flag minter contract.script/: This directory contains all your deployments scripts. When you runyarn deployit defaults toDeploy.s.sol, but you can also deploy any other script from this directory (e.g.,yarn deploy --file DeploySolution2.s.sol).
Example (How to deploy your solution contracts)
-
Create the smart contract:
- Add your new contract file (e.g.,
Challenge2Solution.sol) in thepackages/foundry/contracts/directory.
- Add your new contract file (e.g.,
-
Create a deployment script:
- Add a new file (or use the already created
DeploySolution2.s.solfile as a starting point) in thescript/directory. - Write your deployment script as needed (you can use
DeployChallenges.s.solto guide you)
- Add a new file (or use the already created
-
Deploy your contract locally:
- Run
yarn deploy --file DeploySolution2.s.solto deploy your solution contract locally.yarn deployby default runsDeploy.s.solwhich is useful when deploying multiple solutions at once. Use the--fileflag when you want to deploy a specific solution
- Run
-
When tested and ready, deploy your contract to Optimism (ask us for some funds if you need!):
-
Note: You need a foundry keystore account to deploy. Either:
- Generate with random private key: Run
yarn generateand updateETH_KEYSTORE_ACCOUNT=scaffold-eth-custominpackages/foundry/.env. - Create one with existing private key: Run
yarn account:import, enter your private key, and updateETH_KEYSTORE_ACCOUNT=scaffold-eth-custominpackages/foundry/.env.
- Generate with random private key: Run
-
TIP: You can check configured account balance with
yarn account. -
Run
yarn deploy --file DeploySolution2.s.sol --network optimismto deploy your solution contract to Optimism.
For more details on deployment, including configuring deployer accounts or the network you want to deploy to, see the Scaffold-ETH 2 foundry deployment.
-
This is the frontend to track your local progress in the CTF game and the UI to interact with the deployed contracts. Main pages:
- "Homepage" shows your progress, with the flags you have minted and the pending flags.
- "Debug Contracts" lists all the deployed contracts and allows you to interact with them.
Key folders and files:
app/: Contains the Next.js pages and components (uses app router).contracts/: Contains deployed contracts ABIs and addresses.package.json: Dependencies and scripts for the Next.js app.scaffold.config.ts: Configuration file (you can switch between local and Optimism networks by changingtargetNetwork). For extra info check our docs.
Contains scripts to interact with the deployed contracts. This package comes pre-installed with viem which helps you interface with the Blockchain using Typescript scripts.
src/: Contains the script files.example.ts: A basic example script demonstrating how to interact with contracts.
contracts/: Contains deployed contracts ABIs and addresses. (generated byyarn deploy)
To run the script in the local chain (test account PK with loaded funds):
cd packages/scripts
yarn tsx src/example.tsTo run the script with your own PK (generated via yarn generate or yarn account:import):
cd packages/scripts
yarn tsx-with-pk src/example.ts- Check the
TARGET_CHAINvariable in the example script to see how to deploy to the live network. (default is localhost)