From f681ab01967ef8e58584a0e3ef2ed0abe9b3c484 Mon Sep 17 00:00:00 2001 From: six <51x@keemail.me> Date: Sat, 29 Oct 2022 13:59:00 +0200 Subject: [PATCH] Making challenges public --- Prequalification_Challenges/ink/README.md | 16 +++ .../kusamaverse/README.md | 10 ++ Prequalification_Challenges/rust/Cargo.toml | 14 +++ Prequalification_Challenges/rust/Makefile | 26 +++++ Prequalification_Challenges/rust/README.md | 13 +++ Prequalification_Challenges/rust/output.txt | 3 + Prequalification_Challenges/rust/src/main.rs | 102 ++++++++++++++++++ Prequalification_Challenges/wss/README.md | 9 ++ README.md | 73 ++++++++++--- 9 files changed, 251 insertions(+), 15 deletions(-) create mode 100644 Prequalification_Challenges/ink/README.md create mode 100644 Prequalification_Challenges/kusamaverse/README.md create mode 100644 Prequalification_Challenges/rust/Cargo.toml create mode 100644 Prequalification_Challenges/rust/Makefile create mode 100644 Prequalification_Challenges/rust/README.md create mode 100644 Prequalification_Challenges/rust/output.txt create mode 100644 Prequalification_Challenges/rust/src/main.rs create mode 100644 Prequalification_Challenges/wss/README.md diff --git a/Prequalification_Challenges/ink/README.md b/Prequalification_Challenges/ink/README.md new file mode 100644 index 0000000..961b26d --- /dev/null +++ b/Prequalification_Challenges/ink/README.md @@ -0,0 +1,16 @@ +## search&ink! challenge + +This challenge has four requirements to pass: + +1. Map the services behind 45.77.137.182 and a way to connect (Alice helps!) +2. Find the flag on-chain! Format as in other challenges PMC{...} +3. Deploy the flipper ink! smart contract from your player DOT address (the one you use in the prequalifer registration form) +4. Automate the coin clip funcion call and share the code through the registration form + +This challenge requires you to have a basic understanding of Substrate and ink! smart contracts. + +Please make sure to upload your solution through the form when you submit it - a text file is enough with a short explanation. + +_Keccak256: 0x82703a464305aad655e2eb617f31e6e57b7e959bf8528f1d3b5968cc02ed60ac_ + +_Challenge author: six_ diff --git a/Prequalification_Challenges/kusamaverse/README.md b/Prequalification_Challenges/kusamaverse/README.md new file mode 100644 index 0000000..1508401 --- /dev/null +++ b/Prequalification_Challenges/kusamaverse/README.md @@ -0,0 +1,10 @@ +## Kusamaverse challenge + +This is a very simple challenge. Just find the Polkadot Ambassador space in the Kusamaverse and you will know what to do from there. +[Kusamaverse Link](kusama.momentum.xyz/) + +Please make sure to upload your code you used to solve it through the form when you submit the prequalification. + +_Keccak256: 0x896c90f019d0aaa7977ce81c7d7299b1b43d302295f2d567509ab7e3060a797f_ + +_Challenge author: six_ diff --git a/Prequalification_Challenges/rust/Cargo.toml b/Prequalification_Challenges/rust/Cargo.toml new file mode 100644 index 0000000..7e8338e --- /dev/null +++ b/Prequalification_Challenges/rust/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "pmc" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +base64 = "0.13.0" +rand = "0.8" +num-bigint = { version = "0.4", features = ["rand"] } +byte_string = "1.0.0" +num = "0.4.0" +num-primes = "0.3.0" diff --git a/Prequalification_Challenges/rust/Makefile b/Prequalification_Challenges/rust/Makefile new file mode 100644 index 0000000..bdc2be7 --- /dev/null +++ b/Prequalification_Challenges/rust/Makefile @@ -0,0 +1,26 @@ +prog :=pmc + +debug ?= + +$(info debug is $(debug)) + +ifdef debug + release := + target :=debug + extension :=debug +else + release :=--release + target :=release + extension := +endif + +build: + cargo build $(release) + #strip -s ./target/release/$(prog) + #strip --strip-unneeded -R .note -R .comment -R .gnu.version -R .note.ABI-tag ./target/release/$(prog) + cp ./src/flag.txt ./target/release/ + cp ./src/p.txt ./target/release/ + cp ./src/q.txt ./target/release/ + +help: + @echo "usage: make $(prog) [debug=1]" diff --git a/Prequalification_Challenges/rust/README.md b/Prequalification_Challenges/rust/README.md new file mode 100644 index 0000000..2669ad5 --- /dev/null +++ b/Prequalification_Challenges/rust/README.md @@ -0,0 +1,13 @@ +## Cryptography challenge (Rust) + +You are given the output of one cryptography system and the code that generates the output, the problem is we do not have access to the 3 files the code uses! + +The first one is the flag.txt and the others are two files that have random prime numbers P and Q! + +Can you help us decrypting the output and get the flag? + +This challenge requires you to have cryptography and coding skills. Any language is accepted to get the solution. + +_Keccak256: 0x42ce6fca873fe4dc4ce4d9accdb53e02fdb497ffa6b30f421cea36c81d8ea289_ + +_Challenge author: Rooney and Factoreal_ diff --git a/Prequalification_Challenges/rust/output.txt b/Prequalification_Challenges/rust/output.txt new file mode 100644 index 0000000..034a398 --- /dev/null +++ b/Prequalification_Challenges/rust/output.txt @@ -0,0 +1,3 @@ +n = 149611115935957861847433086030752568567261984621907082786040721407247152663716327519502231379009349403555478392331033952810164148573046688871056752042985601125672198741962270290757469688983708043363147130089304518146209920862956021757294842740478378766019286017585191433945507772906003202456007271670509560001 +c1 = 11740426501805700850493692315559578006370589284427206683940757663851146928230684257857117868496707849557168733347824952878380002709870656084949136086910227474133572170435190357845596727976524907841665784086757438386127200855803916010658428188870224409869769764930590879768926281176340935298646735957803036584600929550783080264478281164795674968941326608349176841871873099501077633763111936830560662765218747733834005879942262007725665002064520328109065794417151034621508526996605515243332144564900123239641752620534071998915306976614235709910119552618406674682923068789777245990088973508240448060554699343918041672 +c2 = 143776697087614888263290942500784196016072840323599778499088161935967819360208875932978673848883138508459204320371154339262196712020509264705583964011692527986711085787805336007197757175874259405887701369759903484733471121241423255620536627876637530300427365389368282535238625160577144155748657877913834928967 diff --git a/Prequalification_Challenges/rust/src/main.rs b/Prequalification_Challenges/rust/src/main.rs new file mode 100644 index 0000000..0e8a6c1 --- /dev/null +++ b/Prequalification_Challenges/rust/src/main.rs @@ -0,0 +1,102 @@ +use std::fs; +extern crate num_bigint; +extern crate rand; +extern crate byte_string; +extern crate num_primes; +use num_bigint::{BigInt}; +//use num_primes::Generator; + +extern crate num; +use num::Integer; +use num::One; +use num::Zero; +use std::convert::TryInto; + +fn pow(n: BigInt, exp: BigInt) -> BigInt { + n.pow(exp.try_into().expect("exponent too large for pow()")) +} + +fn modinv(n: &BigInt, p: &BigInt) -> BigInt { + if p.is_one() { return BigInt::one() } + + let (mut a, mut m, mut x, mut inv) = (n.clone(), p.clone(), BigInt::zero(), BigInt::one()); + + while a > BigInt::one() { + let (div, rem) = a.div_rem(&m); + inv -= div * &x; + a = rem; + std::mem::swap(&mut a, &mut m); + std::mem::swap(&mut x, &mut inv); + } + + if inv < BigInt::zero() { inv += p } + + inv +} +fn lcm(first: BigInt, second: BigInt) -> BigInt { + &first * &second / gcd(first, second) +} + +fn gcd(first: BigInt, second: BigInt) -> BigInt { + let mut max = first; + let mut min = second; + if min > max { + let val = max; + max = min; + min = val; + } + + loop { + let res = &max % &min; + if res == BigInt::parse_bytes(b"0", 2).unwrap(){ + return min; + } + + max = min; + min = res; + } +} + +fn main() -> std::io::Result<()>{ + let contents = fs::read_to_string("./flag.txt") + .expect("We lost the flag!"); + let contents = contents.to_string(); + let contents = contents.trim().to_string(); + let mut binary_flag = "".to_string(); + for character in contents.clone().bytes() { + binary_flag += &format!("{0:08b}", character); + } + let flag_int = BigInt::parse_bytes(binary_flag.as_bytes(), 2).unwrap(); + // let p: BigInt = rng.sample(RandomBits::new(512)); + // let q: BigInt = rng.sample(RandomBits::new(512)); + let p_ = fs::read_to_string("./p.txt") + .expect("We lost the p number! You can create p.txt with a large prime P"); + let p_ = p_.to_string(); + let p_ = p_.trim().to_string(); + let p = BigInt::parse_bytes(p_.as_bytes(), 10).unwrap(); + + let q_ = fs::read_to_string("./q.txt") + .expect("We lost the q number! You can create q.txt with a large prime Q"); + let q_ = q_.to_string(); + let q_ = q_.trim().to_string(); + let q = BigInt::parse_bytes(q_.as_bytes(), 10).unwrap(); + + let n: BigInt = &p * &q; + println!("n = {}", &n); + let one: BigInt = BigInt::parse_bytes(b"1", 2).unwrap(); + let one_: BigInt = BigInt::parse_bytes(b"1", 2).unwrap(); + + let e: BigInt = BigInt::parse_bytes(b"65537", 10).unwrap(); + let phi = lcm(&p - &one, &q - &one); + let d: BigInt = modinv(&e, &phi); + let n_1: BigInt = &n + one; + let eight: BigInt = BigInt::parse_bytes(b"1000", 2).unwrap(); + let pow_n_2: BigInt = &n * &n; + let d_8: BigInt = &d /&eight; + let c1: BigInt = n_1.modpow(&d_8, &pow_n_2); + let c2: BigInt = flag_int.modpow(&e, &n); + println!("c1 = {}", &c1); + println!("c2 = {}", &c2); + + Ok(()) +} diff --git a/Prequalification_Challenges/wss/README.md b/Prequalification_Challenges/wss/README.md new file mode 100644 index 0000000..7338a4e --- /dev/null +++ b/Prequalification_Challenges/wss/README.md @@ -0,0 +1,9 @@ +## Fibonacci WSS challenge + +Connect to the WSS service and solve the challenge presented: 45.77.137.182:3333 + +This challenge requires you to have basic problem solving and coding skills. Any language is accepted for get the solution. Please make sure to upload your solution through the form when you submit it. + +_Keccak256: 0x2f2d4bb11521956c486925241ffcca0cbf7b79bbd9be8eafaeb4fab95713b12d_ + +_Challenge author: Natoshi Sakamoto_ diff --git a/README.md b/README.md index e3e6ad9..4b8a108 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,74 @@ # Polkadot Metaverse Championship - Challenges -Details are coming this week. +## How to qualify and get a pass to the physical event? -## Prequalification requirements (rust and js code to be added soon) +Solve at least three challenges from the four provided in this repository and submit them in the form linked below. -1. Polkadot address -2. Accessing PMC Metaverse -3. Fix borken code (rust or javascript) -4. Execute the fixed code and extract the flag -5. Submit the flag to the PMC registration form -6. Join the event physically! +You can find all the four prequalification challenges in the "Prequalification_Challenges" folder. If you played Capture The Flag /CTF/ games before, this process is very similar to you already. + +The flag format: __PMC{This_Could_be_a_Flag.!}__ + +What you are looking for in each challenge is to generate the data between PMC{......}. + +After you solve at least three challenges, you can submit the form and request your invitation: +__[Prequalify me!](https://www.cognitoforms.com/UnconditionalPeace/PolkadotMetaverseChampionshipPrequalification)__ + +## How to verify a flag? + +You can verify your flag is correct without submitting the form. Install keccak256 with cargo and compare your findings. Example command: + +``` +echo 'PMC{This_Could_be_a_Flag.!}'|keccak256 +``` + +The output of the example command should be: 0x6104a5489b671452684fee77579df24e6f2441d1f8a832c7366cf2cfc5194935 + +The flags have the following keccak256 values: + +``` +kusamaverse - 0x896c90f019d0aaa7977ce81c7d7299b1b43d302295f2d567509ab7e3060a797f +ink - 0x82703a464305aad655e2eb617f31e6e57b7e959bf8528f1d3b5968cc02ed60ac +wss - 0x2f2d4bb11521956c486925241ffcca0cbf7b79bbd9be8eafaeb4fab95713b12d +rust - 0x42ce6fca873fe4dc4ce4d9accdb53e02fdb497ffa6b30f421cea36c81d8ea289 +python - 0xf00b792cd63a035c76abe2fca4afe8d8b7eb8527b9b547b672545c71ee4ca77f + +``` + +## Prequalification challenges + +__WSS challenge__: you need to play with a websocket connection and get the flag from the service. + +__Rust challenge:__ you need to work with cryptography and math. The correct math will return you the flag. + +__ink! challenge__: you need to get the flag from an already running Substrate node. + +__Kusamaverse challenge__: find the flag in Kusamaverse - this one is very easy, but important for the main event. + +We also have an __optional 3D design challenge__ for the Hall of Fame, near the four listed above. If you submit it using the form, we'll add the design to the Hall of Fame, where all the successfully prequalified players get listed. + +## Support and feedback for the prequalification + +We don't help with the solution. If something is unclear or you need help or think you found a bug, we are always open to hear from you. +You can contact us anytime though our email address contact@metaversechampionship.gg or you can also find six through Matrix (:hexff@matrix.org). ## Challenges for the main event +The details of these challenges will be shared on 2022 December 6th 10:00 CET. The teams will need to solve at least one from each track. You can already prepare libraries and some code befor the hackathon, but the final ideation and project needs to come out during the main event. + ### Track 1 - Collaboration + Challenge 1 - by Momentum -Challenge 2 - by Unit Network +Challenge 2 - Creator to be disclosed. + +### Track 2 - Privacy and Security -### Track 2 - Security and Privacy Challenge 1 - by CCTF -Challenge 2 - To be disclosed. + +Challenge 2 - Creator to be disclosed. ### Track 3 - GameFi and NFT -Challenge 1 - RMRK -Challenge 2 - KILT Protocol +Challenge 1 - by RMRK -### Bonus challenges -To be disclosed. +Challenge 2 - Creator to be disclosed.