diff --git a/phase2/Cargo.toml b/phase2/Cargo.toml index a3c740a..3776e8e 100644 --- a/phase2/Cargo.toml +++ b/phase2/Cargo.toml @@ -24,7 +24,7 @@ num-traits = "0.2.8" itertools = "0.9.0" hex = "0.4.0" cfg-if = "0.1.10" -reqwest = { version = "0.10", features = ["blocking"] } +reqwest = { version = "0.10", features = ["blocking", "json"] } bellman_ce = { path = "../bellman", default-features = false } # active features depend on build type # needed for native only but don't break wasm if present diff --git a/phase2/src/bin/curl.rs b/phase2/src/bin/tornado.rs similarity index 68% rename from phase2/src/bin/curl.rs rename to phase2/src/bin/tornado.rs index 6b615f1..b8caa5b 100644 --- a/phase2/src/bin/curl.rs +++ b/phase2/src/bin/tornado.rs @@ -6,6 +6,7 @@ extern crate itertools; extern crate blake2; extern crate rand; extern crate byteorder; +extern crate serde_json; use std::io::Read; use std::io::Write; @@ -15,13 +16,22 @@ use itertools::Itertools; use blake2::Digest; use reqwest::blocking::multipart; use std::time::Duration; +use serde_json::{Map, Value}; fn main() { - let disallow_points_at_infinity = false; - let entropy = "qweqwe"; + //let url = "https://ceremony.tornado.cash"; + let url = "http://localhost:3000/api"; + println!("Welcome to Tornado Cash Trusted Setup ceremony"); + + // Ask the user to provide some information for additional entropy + let mut entropy = String::new(); + println!("Type some random text and press [ENTER] to provide additional entropy..."); + std::io::stdin() + .read_line(&mut entropy) + .expect("expected to read some random text from the user"); println!("Downloading challenge..."); - let mut resp = reqwest::blocking::get("https://trustedaf.poma.in/challenge").unwrap(); + let mut resp = reqwest::blocking::get(&*format!("{}/challenge", url)).unwrap(); if !resp.status().is_success() { println!("Cannot download challenge"); std::process::exit(1); @@ -61,20 +71,21 @@ fn main() { ChaChaRng::from_seed(&seed) }; + let disallow_points_at_infinity = false; let mut params = MPCParameters::read(&*challenge, disallow_points_at_infinity, true).expect("unable to read params"); - println!("Contributing..."); + println!("Generating contribution..."); let hash = params.contribute(&mut rng); println!("Contribution hash: 0x{:02x}", hash.iter().format("")); - println!("Sending parameters"); + println!("Uploading response"); let mut response: Vec = vec![]; params.write(&mut response).expect("failed to write updated parameters"); File::create("response").unwrap().write_all(&*response).unwrap(); let part = multipart::Part::bytes(response).file_name("response").mime_str("application/octet-stream").unwrap(); let client = reqwest::blocking::Client::new(); - let resp = client.post("https://trustedaf.poma.in/response") + let resp = client.post(&*format!("{}/response", url)) .multipart(multipart::Form::new().part("response", part)) .timeout(Duration::from_secs(300)) .send() @@ -85,5 +96,9 @@ fn main() { std::process::exit(1); } - println!("Done"); + let resp_json: Map = resp.json().unwrap(); + + println!("Your contribution is successfully uploaded! Your contribution index: {}", resp_json["contributionIndex"]); + println!("If you want to provide additional information to your contribution (your name etc.)"); + println!("Please visit the page: {}/authorize-contribution?token={}", url, resp_json["token"].as_str().unwrap()); }