{"id":13718706,"url":"https://github.com/starknet-edu/starknet-cc-ctf-challenges","last_synced_at":"2025-05-07T10:33:45.268Z","repository":{"id":95149571,"uuid":"538055810","full_name":"starknet-edu/starknet-cc-ctf-challenges","owner":"starknet-edu","description":null,"archived":false,"fork":false,"pushed_at":"2022-11-20T10:07:49.000Z","size":38175,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-08-04T01:11:28.361Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Cairo","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/starknet-edu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-09-18T09:11:23.000Z","updated_at":"2024-04-10T01:55:13.000Z","dependencies_parsed_at":"2023-03-05T20:30:19.193Z","dependency_job_id":null,"html_url":"https://github.com/starknet-edu/starknet-cc-ctf-challenges","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starknet-edu%2Fstarknet-cc-ctf-challenges","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starknet-edu%2Fstarknet-cc-ctf-challenges/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starknet-edu%2Fstarknet-cc-ctf-challenges/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starknet-edu%2Fstarknet-cc-ctf-challenges/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/starknet-edu","download_url":"https://codeload.github.com/starknet-edu/starknet-cc-ctf-challenges/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224592161,"owners_count":17337047,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T01:00:36.282Z","updated_at":"2024-11-14T08:30:45.057Z","avatar_url":"https://github.com/starknet-edu.png","language":"Cairo","funding_links":[],"categories":["CTFs and Wargames"],"sub_categories":["CTFs"],"readme":"# StarkNet-CC CTF 2022 Challenges\r\n\r\nThe repository hosts challenges given at the StarkNet-CC CTF, held on Nov 1st 2022 in Lisbon.\r\nThe infra is based on the [Paradigm CTF](\"https://github.com/paradigmxyz/paradigm-ctf-2022\") infrastructure.\r\nEach challenge is a separate directory containing the following\r\n\r\n- Contracts in Cairo\r\n- Deployment script using [starknet.py](\"https://github.com/software-mansion/starknet.py\")\r\n\r\n## Versions\r\n\r\nThe challenges are targeting the following versions:\r\n\r\n```\r\ncairo-lang==0.10.0\r\nstarknet-devnet==0.3.3\r\nstarknet-py==0.5.2a0\r\n```\r\n\r\n## Installing\r\n\r\n### Prerequisites\r\n\r\n- Docker\r\n- Python 3\r\n\r\n### Configuration\r\n\r\nYou'll need to set the following environment variables:\r\n\r\n- `PYTHONPATH` to point to mpwn\r\n- You can source the existing `envs.sh` file: `source envs.sh`\r\n\r\nIt's recommended that you run everything from a `venv`:\r\n\r\n```bash\r\npython3 -m venv venv\r\n. ./venv/bin/activate\r\n```\r\n\r\nInstall the requirements in the requirements file if you are running the first time.\r\nRequirements match those in the development environment\r\n\r\n```bash\r\npip install -r requirements.txt\r\n```\r\n\r\nYou'll also need to install the following:\r\n\r\n- `pip install pyyaml ecdsa pysha3 web3`\r\n\r\n## Usage\r\n\r\n### Build everything\r\n\r\n```bash\r\n./local-build.sh\r\n```\r\n\r\n### Run a challenge\r\n\r\nRunning a challenge will open a port which users will `nc` to.\r\nChallenge name is the same as its directory.\r\n\r\n```\r\n./local-run.sh solve-me 31337 5050\r\n```\r\n\r\nOn another terminal:\r\n\r\n```\r\nnc localhost 31337\r\n```\r\n\r\nWhen prompted for the ticket, use any value\r\n\r\n```\r\n$ nc localhost 31337\r\n1 - launch new instance\r\n2 - kill instance\r\n3 - get flag\r\naction? 1\r\nticket please: ticket\r\n\r\nyour private blockchain has been deployed\r\nit will automatically terminate in 30 minutes\r\nhere's some useful information\r\n```\r\n\r\n### Running the autosolver\r\n\r\nAll challenges come with a solution in the private directory (avoid if you do not want spoilers). To run the solution, start the challenge as explained above. _DO NOT_ run `nc`.\r\nComment out all but the challenge you want to solve in the `solve.sh` file.\r\n\r\nRun:\r\n\r\n```bash\r\n./solve.sh\r\n```\r\n\r\n## Create new Challenge\r\n\r\nTo create a new challenge, please create a new PR, following a similar structure to the existing examples.\r\nThe new directory should contain:\r\n\r\n- A `public` dir (this will be made public to the contesters)\r\n- A `private` dir (this will remain private for testing and internal use)\r\n- A `info.yaml` file, with the authors name, and a short description of the challenge\r\n\r\n### The public dir\r\n\r\nThe public dir should have the following structure:\r\n\r\n- `./public/contracts`\r\n- `./public/deploy`\r\n\r\nThe contracts dir should have all the contract needed to setup the sandbox environment on the deployed devnet.\r\nThe deploy dir should have a file called `chal.py`, in charge of setting up the contracts and checking results\r\n\r\nThe public dir should also have the `Dockerfile` that will later be used during the event, and for local testing.\r\n\r\n#### The structure of chal.py\r\n\r\n- The script should have a `deploy` function which deploys the contracts, and gives some information on the deployment process\r\n- The script should have a `check` function running the final check on the state, to make sure the challenges was solved correctly\r\n\r\n### The private dir\r\n\r\nThe private dir should have a solution to the challenge, that we can easily run and test that all challenges are working well. The solution file should be called `solve.py`\r\n\r\n## Checking challenge packaging with docker\r\n\r\nThe best way to make sure the challenge and the solution works is to build a local docker image, and to test it with the existing infra. Here are the instructions on how to do this:\r\n\r\n1. Copy the same structure of the example challenges: `public`, `private`, `chal.py`, `Dockerfile`, etc. The infra expects the filenames in this format. The names `chal.py`, `solve.py` should be kept and only their content should be updated.\r\n2. Update `Dockerfile` with the current contract names and the order in which they should be compiled (see examples)\r\n3. Update the `chal.py` script for the correct contract names in your `public/contracts`\r\n4. Update the `solve.py` to call and execute the correct sequence of calls. No need to setup new accounts etc.\r\n\r\nNext are instructions to create a local image and test it\r\n\r\n1. Inside the `public` directory of the challenge, which contains the file `Dockerfile`, run a docker build command:\r\n\r\n```\r\ndocker build -t  \u003cCHALLENGE_NAME\u003e .\r\n```\r\n\r\n2. Update the `local-build.sh` file with the name of the challenge dir. (add it to the list of existing challenges)\r\n\r\n3. Run the challenge with `./local-run.sh \u003cCHALLENGE_NAME\u003e 31337 5050`\r\n\r\n4. Update the `solver.sh` file to include the challenge name, and comment out all other challenges\r\n\r\n5. Run the solver file `./solver.sh`\r\n\r\nThe result of the run should be the template flag name\r\n\r\n**NOTICE** first, check you can create a new instance by running the server with the \u003cCHALLENGE*NAME\u003e try to `nc` to it as described. To test the `solve.py` script, run the sever again \\_without* running `nc`. Only run `solve.py` with on \u003cCHALLENGE_NAME\u003e uncommented.\r\n\r\n## Running solutions manually\r\n\r\nThe dir `./manual-solutions` has the example for the solution as it should be written by the contesters.\r\nYou can write and run a similar solution as well.\r\n\r\n1. Run the `run.sh` script as before\r\n2. `nc` to the port and select create new instance (as before)\r\n3. Update the `node_url`, `private_key`, `contract`, `player_address` variables after running `nc` and creating a new instance\r\n4. Write the solution to the challenge\r\n5. Run the script bring the state to the desired conditions\r\n6. Run `nc` again and ask for the flag\r\n\r\n### Questions\r\n\r\n- Following the structure of the examples should solve most of the issues.\r\n\r\n- For any question, please feel free to open an issue on this repo\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarknet-edu%2Fstarknet-cc-ctf-challenges","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstarknet-edu%2Fstarknet-cc-ctf-challenges","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarknet-edu%2Fstarknet-cc-ctf-challenges/lists"}