Coder Social home page Coder Social logo

ctf-cyfrin's Introduction

CTF

A minimal repo to help create capture the flag (CTF) challenges.

Getting Started

Requirements

  • Git
    • You'll know you've done it right if you can run git --version
  • Foundry / Foundryup
    • This will install forge, cast, and anvil
    • You can test you've installed them right by running forge --version and get an output like: forge 0.2.0 (f016135 2022-07-04T00:15:02.930499Z)
    • To get the latest of each, just run foundryup

Quickstart

  1. Install the package into your project.
forge install cyfrin/ctf --no-commit
  1. Create a registration CTF contract

This will be the NFT contract, and the place you'll add challenge contracts to.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {CTFRegistry} from "lib/ctf/src/protocol/CTFRegistry.sol";

contract SimpleCTFRegistry is CTFRegistry {
    constructor() CTFRegistry("Our CTF", "CTF") {}
}
  1. Create a challenge contract

You'll need to add the following functions:

  • solveChallenge() - This is the optional function that will be called when a user solves the challenge. The more important part, is that you need something to call _updateAndRewardSolver() which will update the user's NFT with the challenge they solved.
  • attribute() - This is the attribute that will be shown on the NFT.
  • description() - This is the description that will be shown on the NFT.
  • specialImage() - This is the image that will be shown on the NFT. There is a base NFT that will be used if this is left blank.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {Challenge} from "lib/ctf/src/protocol/Challenge.sol";

contract SimpleCTFChallenge is Challenge {
    string constant BLANK_TWITTER_HANDLE = "";

    constructor(address registry) Challenge(registry) {}

    function solveChallenge() external {
        _updateAndRewardSolver(BLANK_TWITTER_HANDLE);
    }

    function attribute() external pure override returns (string memory) {
        return "Getting learned!";
    }

    function description() external pure override returns (string memory) {
        return "This is a simple CTF challenge.";
    }

    function specialImage() external pure returns (string memory) {
        return BLANK_TWITTER_HANDLE;
    }
}
  1. Deploy, and add the contract to the registry
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import {Script} from "forge-std/Script.sol";
import {SimpleCTFChallenge} from "../test/mocks/SimpleCTFChallenge.sol";
import {SimpleCTFRegistry} from "../test/mocks/SimpleCTFRegistry.sol";

contract MockDeploy is Script {
    function run() external {
        SimpleCTFRegistry registry = new SimpleCTFRegistry();
        SimpleCTFChallenge challenge = new SimpleCTFChallenge(address(registry));
        registry.addChallenge(address(challenge));
    }
}

ctf-cyfrin's People

Contributors

patrickalphac avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.