Skip to content

Commit b8379fa

Browse files
committed
CTF initial code
0 parents  commit b8379fa

File tree

220 files changed

+30810
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+30810
-0
lines changed

.github/workflows/lint.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
ci:
13+
runs-on: ${{ matrix.os }}
14+
15+
strategy:
16+
matrix:
17+
os: [ubuntu-latest]
18+
node: [lts/*]
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@master
23+
24+
- name: Setup node env
25+
uses: actions/setup-node@v3
26+
with:
27+
node-version: ${{ matrix.node }}
28+
cache: yarn
29+
30+
- name: Install dependencies
31+
run: yarn install --immutable
32+
33+
- name: Run hardhat node, deploy contracts (& generate contracts typescript output)
34+
run: yarn chain & yarn deploy
35+
36+
- name: Run hardhat lint
37+
run: yarn hardhat:lint --max-warnings=0
38+
39+
- name: Run nextjs lint
40+
run: yarn next:lint --max-warnings=0
41+
42+
- name: Check typings on nextjs
43+
run: yarn next:check-types

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# dependencies
2+
node_modules
3+
4+
# yarn
5+
.yarn/*
6+
!.yarn/patches
7+
!.yarn/plugins
8+
!.yarn/releases
9+
!.yarn/sdks
10+
!.yarn/versions
11+
12+
# eslint
13+
.eslintcache
14+
15+
# misc
16+
.DS_Store
17+
18+
# IDE
19+
.vscode
20+
.idea
21+
22+
# cli
23+
dist

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
yarn lint-staged --verbose

.lintstagedrc.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const path = require("path");
2+
3+
const buildNextEslintCommand = (filenames) =>
4+
`yarn next:lint --fix --file ${filenames
5+
.map((f) => path.relative(path.join("packages", "nextjs"), f))
6+
.join(" --file ")}`;
7+
8+
const checkTypesNextCommand = () => "yarn next:check-types";
9+
10+
const buildHardhatEslintCommand = (filenames) =>
11+
`yarn hardhat:lint-staged --fix ${filenames
12+
.map((f) => path.relative(path.join("packages", "hardhat"), f))
13+
.join(" ")}`;
14+
15+
module.exports = {
16+
"packages/nextjs/**/*.{ts,tsx}": [
17+
buildNextEslintCommand,
18+
checkTypesNextCommand,
19+
],
20+
"packages/hardhat/**/*.{ts,tsx}": [buildHardhatEslintCommand],
21+
};

.yarn/plugins/@yarnpkg/plugin-typescript.cjs

Lines changed: 9 additions & 0 deletions
Large diffs are not rendered by default.

.yarn/releases/yarn-3.2.3.cjs

Lines changed: 783 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
enableColors: true
2+
3+
nmHoistingLimits: workspaces
4+
5+
nodeLinker: node-modules
6+
7+
plugins:
8+
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
9+
spec: "@yarnpkg/plugin-typescript"
10+
11+
yarnPath: .yarn/releases/yarn-3.2.3.cjs

CONTRIBUTING.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Welcome to Scaffold-ETH 2 Contributing Guide
2+
3+
Thank you for investing your time in contributing to Scaffold-ETH 2!
4+
5+
This guide aims to provide an overview of the contribution workflow to help us make the contribution process effective for everyone involved.
6+
7+
## About the Project
8+
9+
Scaffold-ETH 2 is a minimal and forkable repo providing builders with a starter kit to build decentralized applications on Ethereum.
10+
11+
Read the [README](README.md) to get an overview of the project.
12+
13+
### Vision
14+
15+
The goal of Scaffold-ETH 2 is to provide the primary building blocks for a decentralized application.
16+
17+
The repo can be forked to include integrations and more features, but we want to keep the master branch simple and minimal.
18+
19+
### Project Status
20+
21+
The project is under active development.
22+
23+
You can view the open Issues, follow the development process and contribute to the project.
24+
25+
## Getting started
26+
27+
You can contribute to this repo in many ways:
28+
29+
- Solve open issues
30+
- Report bugs or feature requests
31+
- Improve the documentation
32+
33+
Contributions are made via Issues and Pull Requests (PRs). A few general guidelines for contributions:
34+
35+
- Search for existing Issues and PRs before creating your own.
36+
- Contributions should only fix/add the functionality in the issue OR address style issues, not both.
37+
- If you're running into an error, please give context. Explain what you're trying to do and how to reproduce the error.
38+
- Please use the same formatting in the code repository. You can configure your IDE to do it by using the prettier / linting config files included in each package.
39+
- If applicable, please edit the README.md file to reflect the changes.
40+
41+
### Issues
42+
43+
Issues should be used to report problems, request a new feature, or discuss potential changes before a PR is created.
44+
45+
#### Solve an issue
46+
47+
Scan through our [existing issues](https://github.com/scaffold-eth/scaffold-eth-2/issues) to find one that interests you.
48+
49+
If a contributor is working on the issue, they will be assigned to the individual. If you find an issue to work on, you are welcome to assign it to yourself and open a PR with a fix for it.
50+
51+
#### Create a new issue
52+
53+
If a related issue doesn't exist, you can open a new issue.
54+
55+
Some tips to follow when you are creating an issue:
56+
57+
- Provide as much context as possible. Over-communicate to give the most details to the reader.
58+
- Include the steps to reproduce the issue or the reason for adding the feature.
59+
- Screenshots, videos etc., are highly appreciated.
60+
61+
### Pull Requests
62+
63+
#### Pull Request Process
64+
65+
We follow the ["fork-and-pull" Git workflow](https://github.com/susam/gitpr)
66+
67+
1. Fork the repo
68+
2. Clone the project
69+
3. Create a new branch with a descriptive name
70+
4. Commit your changes to the new branch
71+
5. Push changes to your fork
72+
6. Open a PR in our repository and tag one of the maintainers to review your PR
73+
74+
Here are some tips for a high-quality pull request:
75+
76+
- Create a title for the PR that accurately defines the work done.
77+
- Structure the description neatly to make it easy to consume by the readers. For example, you can include bullet points and screenshots instead of having one large paragraph.
78+
- Add the link to the issue if applicable.
79+
- Have a good commit message that summarises the work done.
80+
81+
Once you submit your PR:
82+
83+
- We may ask questions, request additional information or ask for changes to be made before a PR can be merged. Please note that these are to make the PR clear for everyone involved and aims to create a frictionless interaction process.
84+
- As you update your PR and apply changes, mark each conversation resolved.
85+
86+
Once the PR is approved, we'll "squash-and-merge" to keep the git commit history clean.

LICENCE

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

README.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
![BuidlGuidl CTF](./packages/nextjs/public/readme-image.jpg?raw=true)
2+
3+
**Welcome to the BuidlGuidl CTF**
4+
5+
⚡️ Live at https://ctf.buidlguidl.com
6+
7+
If you have your own stack already, go straight the CTF site and start playing.
8+
9+
We have created a stack which contains all the tools that you need to play the CTF. Keep reading to learn how to set it up.
10+
11+
## Setting up the environment
12+
13+
### Requirements
14+
15+
You'll need to have the following tools installed in your machine:
16+
17+
- [Node (>= v18.18)](https://nodejs.org/en/download/)
18+
- Yarn ([v1](https://classic.yarnpkg.com/en/docs/install/) or [v2+](https://yarnpkg.com/getting-started/install))
19+
- [Git](https://git-scm.com/downloads)
20+
21+
### Setting up your local testing environment
22+
23+
First install the Scaffold-ETH 2 CTF extension with create-eth:
24+
25+
```bash
26+
npx create-eth@latest -e ctf-extension
27+
```
28+
29+
This will set up a new folder with all the tools you need to play the CTF.
30+
31+
Go into the folder and run the following commands in separate terminals:
32+
33+
1. Run a local blockchain:
34+
35+
```
36+
yarn chain
37+
```
38+
39+
2. Deploy the challenges contracts locally:
40+
41+
```
42+
yarn deploy
43+
```
44+
45+
> Note: This command will update the `deployedContracts.ts` file (in the `scripts` and `nextjs` packages), which contains the deployed contracts addresses and ABIs.
46+
47+
3. Start Ponder (event indexer):
48+
49+
```
50+
yarn ponder:dev
51+
```
52+
53+
> Note: This just runs the ponder indexer locally, which is used to keep track of all the events happening in the blockchain.
54+
55+
4. Start the frontend (NextJS app):
56+
57+
```
58+
yarn start
59+
```
60+
61+
Now your app on `http://localhost:3000` is running entirely locally. You can break things without any consequences :)
62+
63+
## Repo structure / Key files
64+
65+
This is a [yarn](https://yarnpkg.com/features/workspaces) monorepo with different packages:
66+
67+
```
68+
ctf/
69+
└── packages/
70+
├── hardhat/
71+
├── nextjs/
72+
├── scripts/
73+
└── ponder/
74+
```
75+
76+
### hardhat
77+
78+
Comes preconfigured with [hardhat](https://hardhat.org/) and contains the smart contracts and deployment scripts for the CTF challenges.
79+
80+
It uses hardhat-deploy to deploy the contracts.
81+
82+
#### Key files in hardhat
83+
84+
- `contracts/`: The source directory where all your smart contracts should be. It already contains all the challenge contracts and the NFT Flag minter contract.
85+
- `deploy/`: This directory contains all your deployments scripts. When you run `yarn deploy` all the scripts present in this directory will be executed in numbered order.
86+
87+
<details>
88+
<summary>Example (How to deploy a contract)</summary>
89+
90+
1. Create the smart contract:
91+
92+
- Add your new contract file (e.g., `Challenge2Solution.sol`) in the `packages/hardhat/contracts/` directory.
93+
94+
2. Create a deployment script:
95+
96+
- Add a new file (or use the already created `02_deploy_challenge_2_solution.ts` file as a starting point) in the `deploy/` directory.
97+
- Write your deployment script as needed (you can use `00_deploy_your_contract.ts` to guide you)
98+
99+
3. Deploy your contract locally:
100+
101+
- Run `yarn deploy --tags solution2` to deploy your solution contract locally. The `tags` make sure that your are only deploying the solution contract and not all the other challenges (that were deployed with `yarn deploy` or `yarn deploy --tags CTF`).
102+
103+
4. When tested and ready, deploy your contract to Optimism (ask us for some funds if you need!):
104+
- > Note: You need a private key to deploy the contracts. You can generate one with `yarn generate` or add your own private key in the `.env` files in `/packages/hardhat` and `packages/scripts` folders.
105+
- Run `yarn deploy --tags solution2 --network optimism` to deploy your solution contract to Optimism.
106+
107+
For more details on deployment, including configuring deployer accounts or the network you want to deploy to, see the [Scaffold-ETH 2 deployment docs](https://docs.scaffoldeth.io/deploying/deploy-smart-contracts).
108+
109+
</details>
110+
111+
### NextJS
112+
113+
This is the frontend of the game. Main pages:
114+
115+
- _"Profile"_ shows the team profile and the flags they have minted.
116+
- _"Challenges"_ shows the Challenges descriptions, Goals and Hints.
117+
- _"Leaderboard"_ shows the current top teams in the game.
118+
- _"Debug Contracts"_ lists all the deployed contracts and allows you to interact with them.
119+
120+
Key folders and files:
121+
122+
- `app/`: Contains the Next.js pages and components (uses [app router](https://nextjs.org/docs/app)).
123+
- `contracts/`: Contains deployed contracts ABIs and addresses.
124+
- `package.json`: Dependencies and scripts for the Next.js app.
125+
- `scaffold.config.ts`: Configuration file, you can check the different settings in our [docs](https://docs.scaffoldeth.io/deploying/deploy-nextjs-app#scaffold-app-configuration)
126+
127+
### scripts
128+
129+
Contains scripts to interact with the deployed contracts. This package comes pre-installed with [viem](https://viem.sh/)
130+
which helps you interface with the Blockchain using Typescript scripts.
131+
132+
#### Key files and directories:
133+
134+
- `src/`: Contains the script files.
135+
- `example.ts`: A basic example script demonstrating how to interact with contracts.
136+
- `contracts/`: Contains deployed contracts ABIs and addresses. (generated by `yarn deploy`)
137+
138+
To run scripts, navigate to the scripts package and run the script using `yarn tsx`:
139+
140+
```shell
141+
cd packages/scripts
142+
yarn tsx src/example.ts
143+
```
144+
145+
- You can generate a PK for the deployer account with `yarn generate` or fill the `.env` file with your own PK to run the transactions.
146+
- Check the `TARGET_CHAIN` variable in the example script to see how to deploy to the live network. (default is localhost)
147+
148+
### Ponder
149+
150+
No need to take a look here, since it's not part of the game. Just the indexer we use to keep track of all the contract events happening.

0 commit comments

Comments
 (0)