diff --git a/Cargo.lock b/Cargo.lock index 4bc43819..4457c4fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -211,7 +211,7 @@ dependencies = [ "serde-xml-rs", "serde_derive", "serde_json", - "url 2.2.0", + "url 2.2.2", "uuid", ] @@ -262,7 +262,7 @@ dependencies = [ "serde_json", "smallvec", "time 0.2.23", - "url 2.2.0", + "url 2.2.2", "uuid", ] @@ -1673,19 +1673,6 @@ dependencies = [ "webpki", ] -[[package]] -name = "hyper-tls" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed" -dependencies = [ - "bytes 0.5.6", - "hyper 0.13.10", - "native-tls", - "tokio 0.2.24", - "tokio-tls", -] - [[package]] name = "hyper-tls" version = "0.5.0" @@ -2094,16 +2081,6 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" -[[package]] -name = "mime_guess" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" -dependencies = [ - "mime", - "unicase", -] - [[package]] name = "mince" version = "0.1.0" @@ -2155,29 +2132,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "mio-named-pipes" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" -dependencies = [ - "log", - "mio 0.6.23", - "miow 0.3.6", - "winapi 0.3.9", -] - -[[package]] -name = "mio-uds" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" -dependencies = [ - "iovec", - "libc", - "mio 0.6.23", -] - [[package]] name = "miow" version = "0.2.2" @@ -2986,42 +2940,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "reqwest" -version = "0.10.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0718f81a8e14c4dbb3b34cf23dc6aaf9ab8a0dfec160c534b3dbca1aaa21f47c" -dependencies = [ - "base64 0.13.0", - "bytes 0.5.6", - "encoding_rs", - "futures-core", - "futures-util", - "http", - "http-body 0.3.1", - "hyper 0.13.10", - "hyper-tls 0.4.3", - "ipnet", - "js-sys", - "lazy_static", - "log", - "mime", - "mime_guess", - "native-tls", - "percent-encoding 2.1.0", - "pin-project-lite 0.2.6", - "serde", - "serde_json", - "serde_urlencoded", - "tokio 0.2.24", - "tokio-tls", - "url 2.2.0", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] - [[package]] name = "reqwest" version = "0.11.3" @@ -3036,7 +2954,7 @@ dependencies = [ "http", "http-body 0.4.2", "hyper 0.14.7", - "hyper-tls 0.5.0", + "hyper-tls", "ipnet", "js-sys", "lazy_static", @@ -3050,7 +2968,7 @@ dependencies = [ "serde_urlencoded", "tokio 1.6.0", "tokio-native-tls", - "url 2.2.0", + "url 2.2.2", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", @@ -3562,7 +3480,7 @@ dependencies = [ [[package]] name = "setup1-contributor" -version = "0.3.0" +version = "0.4.0" dependencies = [ "age", "algebra", @@ -3583,7 +3501,7 @@ dependencies = [ "phase1-cli", "phase1-coordinator", "rand 0.7.3", - "reqwest 0.11.3", + "reqwest", "secrecy", "serde", "serde_derive", @@ -3598,7 +3516,7 @@ dependencies = [ "tracing", "tracing-appender", "tracing-subscriber", - "url 2.2.0", + "url 2.2.2", ] [[package]] @@ -3611,7 +3529,7 @@ dependencies = [ [[package]] name = "setup1-verifier" -version = "0.3.0" +version = "0.4.0" dependencies = [ "algebra", "anyhow", @@ -3625,17 +3543,20 @@ dependencies = [ "phase1-coordinator", "rand 0.7.3", "rand_xorshift", - "reqwest 0.10.10", + "reqwest", "serde", "serde_derive", "serde_json", "serial_test", "setup-utils", + "setup1-shared", "snarkos-toolkit", + "structopt", "thiserror", - "tokio 0.2.24", + "tokio 1.6.0", "tracing", "tracing-subscriber", + "url 2.2.2", ] [[package]] @@ -4460,17 +4381,10 @@ dependencies = [ "futures-core", "iovec", "lazy_static", - "libc", "memchr", "mio 0.6.23", - "mio-named-pipes", - "mio-uds", - "num_cpus", "pin-project-lite 0.1.12", - "signal-hook-registry", "slab", - "tokio-macros 0.2.6", - "winapi 0.3.9", ] [[package]] @@ -4507,19 +4421,11 @@ dependencies = [ "memchr", "mio 0.7.7", "num_cpus", + "once_cell", "pin-project-lite 0.2.6", + "signal-hook-registry", "tokio-macros 1.2.0", -] - -[[package]] -name = "tokio-macros" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a" -dependencies = [ - "proc-macro2 1.0.24", - "quote 1.0.7", - "syn 1.0.60", + "winapi 0.3.9", ] [[package]] @@ -4566,16 +4472,6 @@ dependencies = [ "webpki", ] -[[package]] -name = "tokio-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" -dependencies = [ - "native-tls", - "tokio 0.2.24", -] - [[package]] name = "tokio-util" version = "0.3.1" @@ -4621,13 +4517,13 @@ checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" [[package]] name = "tracing" -version = "0.1.21" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0987850db3733619253fe60e17cb59b82d37c7e6c0236bb81e4d6b87c879f27" +checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "log", - "pin-project-lite 0.1.12", + "pin-project-lite 0.2.6", "tracing-attributes", "tracing-core", ] @@ -4645,9 +4541,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.11" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80e0ccfc3378da0cce270c946b676a376943f5cd16aeba64568e7939806f4ada" +checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", @@ -4656,9 +4552,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" +checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052" dependencies = [ "lazy_static", ] @@ -4762,15 +4658,6 @@ dependencies = [ "tinystr", ] -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check", -] - [[package]] name = "unicode-bidi" version = "0.3.4" @@ -4852,9 +4739,9 @@ dependencies = [ [[package]] name = "url" -version = "2.2.0" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5909f2b0817350449ed73e8bcd81c8c3c8d9a7a5d8acba4b27db277f1868976e" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" dependencies = [ "form_urlencoded", "idna 0.2.0", diff --git a/setup1-cli-tools/README.md b/setup1-cli-tools/README.md index 14c81054..042bc2eb 100644 --- a/setup1-cli-tools/README.md +++ b/setup1-cli-tools/README.md @@ -5,20 +5,28 @@ Some handy utilities for testing purposes ## Build Guide ```bash -# Requires specific nightly to work -rustup default nightly-2020-08-15 -# After choosing the nightly you can build with: +# Requires specific rustc version +rustup default 1.48 +# After setting the toolchain, you can build with: cargo build --release ``` ~~Works on stable and nightly! (tested on 1.50 stable and 1.52 nightly)~~ +Alternatively, to add the binaries to the PATH run: + +```bash +cargo install --path . +``` + +This will add the `public-key-extractor` and `view-key` binaries to `.cargo/bin` folder + ## Usage ```bash # To generate a view key: -./view_key +view-key > view_key.txt # To produce a public key out of a private key: -./public_key_extractor --path keys.json +public-key-extractor --path keys.json ``` diff --git a/setup1-cli-tools/keys.json b/setup1-cli-tools/keys.json new file mode 100644 index 00000000..2788efe2 --- /dev/null +++ b/setup1-cli-tools/keys.json @@ -0,0 +1 @@ +{"encryptedSeed":"6167652d656e6372797074696f6e2e6f72672f76310a2d3e20736372797074205433706877594d4e76784b71436d412b4143726d4d412031380a6455565770614952767a3755316f386f777437526b642b453033556f4d304272704c3735424d63585a48450a2d2d2d20464e7a624663423452643467666b316f364c62725330702f7774344e565644356e3166764444675a7277340ab8ae2b2a5245a066ed34c546d97826f01ce13225886bbb87e4075f39fd7f8735ba6c99f51c51225f041be140ea888c3f8c3a090fd4c083727786c043103acf01b1357ce5c68c701c882e30d40dd55269d0cf85c02a08209a567d1e991d9d0114","encryptedPrivateKey":"6167652d656e6372797074696f6e2e6f72672f76310a2d3e20736372797074206557303278375676345a5870486762493073745a77512031380a47585a4d303132316f4f33423668665841676c7878712f795a30614c766d4c36464b69636e6278327774450a2d2d2d2042324d682f472b394c694b5668656e4a4a6b374f654e2f6b2f426b64362f33477566344939333661342b450af9cba882dd40a72d30859f0119f2d14ba22d2f3046c68d6143078ab2e71b76558213aa49b3ddf3b704992d3d78a210ba28fbe85407fbff2f334036aad8f085d51f1ca50ad5d85cd3361b0880ea39c3ea4aab3a87e5f8589c4e47e8","address":"aleo1703jy63jyhxrhyyfd2pwmn5q8puzp8ta4fsxdjvdyx5wmfwpmy9svxq3a9"} \ No newline at end of file diff --git a/setup1-cli-tools/src/view_key.rs b/setup1-cli-tools/src/view_key.rs index 12e2b60f..0da86d7e 100644 --- a/setup1-cli-tools/src/view_key.rs +++ b/setup1-cli-tools/src/view_key.rs @@ -4,5 +4,5 @@ fn main() { let mut rng = rand::thread_rng(); let private_key = PrivateKey::new(&mut rng).expect("Should generate a random PrivateKey struct"); let view_key = ViewKey::from(&private_key).expect("Should create a ViewKey from a PrivateKey"); - println!("{}", view_key); + print!("{}", view_key); } diff --git a/setup1-contributor/Cargo.toml b/setup1-contributor/Cargo.toml index 03111d0e..2ec7e34c 100644 --- a/setup1-contributor/Cargo.toml +++ b/setup1-contributor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "setup1-contributor" -version = "0.3.0" +version = "0.4.0" authors = ["The Aleo Team "] description = "Aleo Setup Contributor" homepage = "https://github.com/AleoHQ/aleo-setup" diff --git a/setup1-contributor/README.md b/setup1-contributor/README.md index 852d200c..a84adda9 100644 --- a/setup1-contributor/README.md +++ b/setup1-contributor/README.md @@ -1 +1,35 @@ # setup1-contributor + +## Build Guide + +To build the contributor run: + +```bash +# Requires specific rustc version +rustup default 1.48 + +# Build the binary +cargo build --release +``` + +To add the binary to the PATH run: T + +```bash +cargo install --path . +``` + +This will add the `aleo-setup-contributor` binary to `.cargo/bin` folder + +## Usage + +Generate a seed and a private key: + +```bash +aleo-setup-contributor generate --keys-path keys.json +``` + +Run the contributor: +```bash +aleo-setup-contributor --api-url https://... --keys-path keys.json +``` +where `--api-url` is a coordinator api address diff --git a/setup1-contributor/src/cli/commands/contribute.rs b/setup1-contributor/src/cli/commands/contribute.rs index 7bd34a0a..084338ec 100644 --- a/setup1-contributor/src/cli/commands/contribute.rs +++ b/setup1-contributor/src/cli/commands/contribute.rs @@ -11,9 +11,7 @@ use std::path::PathBuf; #[structopt( name = "Contribute", about = "Contribute to Aleo Setup I", - rename_all = "snake-case", setting(AppSettings::ColoredHelp), - setting(AppSettings::DisableHelpSubcommand), setting(AppSettings::DisableVersion) )] pub struct ContributeOptions { @@ -32,10 +30,10 @@ pub struct ContributeOptions { pub passphrase: Option, /// Specify the URL of the ceremony coordinator. - #[structopt(rename_all = "screaming-snake-case")] - pub coordinator_api_url: Url, + #[structopt(long, help = "Coordinator api url")] + pub api_url: Url, /// Read seed and private key at the given path. - #[structopt(rename_all = "screaming-snake-case", parse(from_os_str))] + #[structopt(long, help = "Path to a file containing seed and private key")] pub keys_path: PathBuf, } diff --git a/setup1-contributor/src/cli/commands/generate.rs b/setup1-contributor/src/cli/commands/generate.rs index 646bdf38..eea5b70e 100644 --- a/setup1-contributor/src/cli/commands/generate.rs +++ b/setup1-contributor/src/cli/commands/generate.rs @@ -8,9 +8,7 @@ use std::path::PathBuf; #[structopt( name = "Generate", about = "Generate a seed and an Aleo private key for contribution", - rename_all = "snake-case", setting(AppSettings::ColoredHelp), - setting(AppSettings::DisableHelpSubcommand), setting(AppSettings::DisableVersion) )] pub struct GenerateOptions { @@ -20,6 +18,6 @@ pub struct GenerateOptions { #[structopt(long)] pub passphrase: Option, /// Store the seed and private key at the given path. - #[structopt(rename_all = "screaming-snake-case", parse(from_os_str))] + #[structopt(long, help = "Store the seed and private key at the given path")] pub keys_path: PathBuf, } diff --git a/setup1-contributor/src/commands/contribute.rs b/setup1-contributor/src/commands/contribute.rs index e44c88c8..92c1d2b2 100644 --- a/setup1-contributor/src/commands/contribute.rs +++ b/setup1-contributor/src/commands/contribute.rs @@ -114,7 +114,7 @@ impl Contribute { // TODO (raychu86): Pass in pipelining options from the CLI. let contribute = Self { - server_url: opts.coordinator_api_url.clone(), + server_url: opts.api_url.clone(), participant_id: Address::from(&private_key)?.to_string(), private_key: private_key.to_string(), upload_mode: opts.upload_mode.clone(), @@ -886,12 +886,10 @@ async fn request_coordinator_public_settings(coordinator_url: &Url) -> anyhow::R } pub async fn contribute_subcommand(opts: &ContributeOptions) -> anyhow::Result<()> { - let public_settings = request_coordinator_public_settings(&opts.coordinator_api_url) - .await - .map_err(|e| { - tracing::error!("Can't get the coordinator public settings, got error: {}", e); - e - })?; + let public_settings = request_coordinator_public_settings(&opts.api_url).await.map_err(|e| { + tracing::error!("Can't get the coordinator public settings, got error: {}", e); + e + })?; let environment = crate::utils::environment_by_setup_kind(&public_settings.setup); diff --git a/setup1-verifier/Cargo.toml b/setup1-verifier/Cargo.toml index a969e122..35cf797b 100644 --- a/setup1-verifier/Cargo.toml +++ b/setup1-verifier/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "setup1-verifier" -version = "0.3.0" +version = "0.4.0" authors = ["The Aleo Team "] description = "Verifier implementation of Phase 1" homepage = "https://github.com/AleoHQ/aleo-setup" @@ -16,6 +16,7 @@ path = "src/main.rs" phase1 = { path = "../phase1" } phase1-cli = { path = "../phase1-cli" } phase1-coordinator = { path = "../phase1-coordinator", features= ["operator"] } +setup1-shared = { version = "0.1", path = "../setup1-shared" } setup-utils = { path = "../setup-utils", default-features = false } snarkos-toolkit = { git = "https://github.com/AleoHQ/snarkOS", rev = "6357695", package = "snarkos-toolkit", default-features = false } @@ -27,14 +28,16 @@ ctrlc = { version = "3.1.7" } futures-util = { version = "0.3.5" } hex = { version = "0.4.2" } rand = { version = "0.7.3" } -reqwest = { version = "0.10", features = ["json"] } +reqwest = { version = "0.11", features = ["json"] } serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0" } serde_derive = { version = "1.0" } +structopt = "0.3.21" thiserror = { version = "1.0" } -tokio = { version = "0.2.22", features = ["full"] } -tracing = { version = "0.1.19" } +tokio = { version = "1.6", features = ["macros", "rt-multi-thread", "signal"] } +tracing = { version = "0.1.26" } tracing-subscriber = { version = "0.2" } +url = "2.2.2" [dev-dependencies] lazy_static = { version = "1.4.0" } diff --git a/setup1-verifier/README.md b/setup1-verifier/README.md index 7e66ecf0..651551c4 100644 --- a/setup1-verifier/README.md +++ b/setup1-verifier/README.md @@ -2,39 +2,37 @@ ## Build Guide -To build the verifier and its accompanying binaries, run: +To build the verifier run: + ```bash +# Requires specific rustc version +rustup default 1.48 + +# Build the binary cargo build --release ``` -## Usage +To add the binary to the PATH run: -To run the verifier, start by copying the binaries to your working directory: ```bash -cp ../target/release/setup1-verifier ../target/release/view-key /path/to/working/directory +cargo install --path . ``` -Next, generate and print out a view key: -```bash -# To print the view key to stdout -./view-key +This will add the `setup1-verifier` binary to `.cargo/bin` folder -# Or to write it to a file -./view-key > view_key.txt -``` +## Usage + +Generate a view key using [cli tools](../setup1-cli-tools) -Lastly, run the verifier: ```bash -./setup1-verifier MODE COORDINATOR_API_URL VIEW_KEY +view-key > view_key.txt ``` -where `MODE` is one of `development | inner | outer | universal`, -`COORDINATOR_API_URL` is an address of a coordinator, for example `http://localhost:9000`, -and `VIEW_KEY` is the string generated by the `view-key` binary. -Alternatively, you may use `xargs` to read view key from the file: +Run the verifier: ```bash -cat view_key.txt | xargs ./setup1-verifier MODE COORDINATOR_API_URL +setup1-verifier --api-url http://localhost:9000 --view-key view_key.txt ``` +where `--api-url` is a coordinator api address ## Log levels @@ -42,10 +40,10 @@ The `setup1-verifier` binary is set up to read the `RUST_LOG` environment variable to control the logs. Here are some examples: ```bash # INFO, WARN and ERROR messages will be logged -RUST_LOG=info ./setup1-verifier MODE COORDINATOR_API_URL VIEW_KEY +RUST_LOG=info setup1-verifier ... # We can also control logs in the dependencies. The following command # will log TRACE, DEBUG, INFO, WARN and ERROR from all the sources # but only WARN and ERROR from the hyper dependency -RUST_LOG="trace,hyper=warn" ./setup1-verifier MODE COORDINATOR_API_URL VIEW_KEY +RUST_LOG="trace,hyper=warn" setup1-verifier ... ``` diff --git a/setup1-verifier/src/coordinator_requests.rs b/setup1-verifier/src/coordinator_requests.rs index c0c25b79..47b0507e 100644 --- a/setup1-verifier/src/coordinator_requests.rs +++ b/setup1-verifier/src/coordinator_requests.rs @@ -1,8 +1,7 @@ use crate::{errors::VerifierError, objects::LockResponse, utils::AleoAuthentication, verifier::Verifier}; -use snarkos_toolkit::account::{Address, ViewKey}; +use snarkos_toolkit::account::Address; use reqwest::Client; -use std::str::FromStr; use tracing::{debug, error, info}; impl Verifier { @@ -16,18 +15,17 @@ impl Verifier { pub(crate) async fn join_queue(&self) -> Result { let coordinator_api_url = &self.coordinator_api_url; - let view_key = ViewKey::from_str(&self.view_key)?; - let aleo_address = Address::from_view_key(&view_key)?.to_string(); + let aleo_address = Address::from_view_key(&self.view_key)?.to_string(); let method = "post"; let path = "/v1/queue/verifier/join"; - let authentication = AleoAuthentication::authenticate(&view_key, &method, &path)?; + let authentication = AleoAuthentication::authenticate(&self.view_key, &method, &path)?; info!("Attempting to join as verifier join the queue as {}", aleo_address); match Client::new() - .post(&format!("{}{}", &coordinator_api_url, &path)) + .post(coordinator_api_url.join(path).expect("Should create a path")) .header("Authorization", authentication.to_string()) .send() .await @@ -65,13 +63,12 @@ impl Verifier { let method = "post"; let path = "/v1/verifier/try_lock"; - let view_key = ViewKey::from_str(&self.view_key)?; - let authentication = AleoAuthentication::authenticate(&view_key, &method, &path)?; + let authentication = AleoAuthentication::authenticate(&self.view_key, &method, &path)?; info!("Verifier attempting to lock a chunk"); match Client::new() - .post(&format!("{}{}", &coordinator_api_url, &path)) + .post(coordinator_api_url.join(path).expect("Should create a path")) .header("Authorization", authentication.to_string()) .send() .await @@ -115,14 +112,12 @@ impl Verifier { let method = "post"; let path = format!("/v1/verifier/try_verify/{}", chunk_id); - let view_key = ViewKey::from_str(&self.view_key)?; - info!("Verifier running verification of a contribution at chunk {}", chunk_id); let signature_path = format!("{}", path.replace("./", "")); - let authentication = AleoAuthentication::authenticate(&view_key, &method, &signature_path)?; + let authentication = AleoAuthentication::authenticate(&self.view_key, &method, &signature_path)?; match Client::new() - .post(&format!("{}{}", &coordinator_api_url, &path)) + .post(coordinator_api_url.join(&path).expect("Should create a path")) .header("Authorization", authentication.to_string()) .send() .await @@ -160,14 +155,12 @@ impl Verifier { let method = "get"; let path = format!("/v1/download/response/{}", response_locator); - let view_key = ViewKey::from_str(&self.view_key)?; - info!("Verifier downloading a response file at {} ", response_locator); let signature_path = format!("{}", path.replace("./", "")); - let authentication = AleoAuthentication::authenticate(&view_key, &method, &signature_path)?; + let authentication = AleoAuthentication::authenticate(&self.view_key, &method, &signature_path)?; match Client::new() - .get(&format!("{}{}", &coordinator_api_url, &path)) + .get(coordinator_api_url.join(&path).expect("Should create a path")) .header("Authorization", authentication.to_string()) .send() .await @@ -205,14 +198,12 @@ impl Verifier { let method = "get"; let path = format!("/v1/download/challenge/{}", challenge_locator); - let view_key = ViewKey::from_str(&self.view_key)?; - info!("Verifier downloading a challenge file at {} ", challenge_locator); let signature_path = format!("{}", path.replace("./", "")); - let authentication = AleoAuthentication::authenticate(&view_key, &method, &signature_path)?; + let authentication = AleoAuthentication::authenticate(&self.view_key, &method, &signature_path)?; match Client::new() - .get(&format!("{}{}", &coordinator_api_url, &path)) + .get(coordinator_api_url.join(&path).expect("Should create a path")) .header("Authorization", authentication.to_string()) .send() .await @@ -254,10 +245,8 @@ impl Verifier { let method = "post"; let path = format!("/v1/upload/challenge/{}", next_challenge_locator); - let view_key = ViewKey::from_str(&self.view_key)?; - let signature_path = format!("{}", path.replace("./", "")); - let authentication = AleoAuthentication::authenticate(&view_key, &method, &signature_path)?; + let authentication = AleoAuthentication::authenticate(&self.view_key, &method, &signature_path)?; info!( "Verifier uploading a response with size {} to {} ", @@ -266,7 +255,7 @@ impl Verifier { ); match Client::new() - .post(&format!("{}{}", &coordinator_api_url, &path)) + .post(coordinator_api_url.join(&path).expect("Should create a path")) .header("Authorization", authentication.to_string()) .header("Content-Type", "application/octet-stream") .body(signature_and_next_challenge_file_bytes) diff --git a/setup1-verifier/src/main.rs b/setup1-verifier/src/main.rs index 25267dd0..25858f52 100644 --- a/setup1-verifier/src/main.rs +++ b/setup1-verifier/src/main.rs @@ -1,12 +1,14 @@ use setup1_verifier::{utils::init_logger, verifier::Verifier}; use phase1_coordinator::environment::{Development, Environment, Parameters, Production}; +use setup1_shared::structures::{PublicSettings, SetupKind}; use snarkos_toolkit::account::{Address, ViewKey}; +use structopt::StructOpt; +use url::Url; -use std::{env, str::FromStr}; +use std::{path::PathBuf, str::FromStr}; use tracing::info; -#[inline] fn development() -> Environment { Development::from(Parameters::TestCustom { number_of_chunks: 64, @@ -16,57 +18,69 @@ fn development() -> Environment { .into() } -#[inline] fn inner() -> Environment { Production::from(Parameters::AleoInner).into() } -#[inline] fn outer() -> Environment { Production::from(Parameters::AleoOuter).into() } -#[inline] fn universal() -> Environment { Production::from(Parameters::AleoUniversal).into() } +#[derive(Debug, StructOpt)] +#[structopt(name = "Aleo setup verifier")] +struct Options { + #[structopt(long, help = "Path to a file containing verifier view key")] + view_key: PathBuf, + #[structopt(long, help = "Coordinator api url, for example http://localhost:9000")] + api_url: Url, +} + +async fn request_coordinator_public_settings(coordinator_url: &Url) -> anyhow::Result { + let settings_endpoint_url = coordinator_url.join("/v1/contributor/settings")?; + let client = reqwest::Client::new(); + let bytes = client.post(settings_endpoint_url).send().await?.bytes().await?; + PublicSettings::decode(&bytes.to_vec()) + .map_err(|e| anyhow::anyhow!("Error decoding coordinator PublicSettings: {}", e)) +} + #[tokio::main] async fn main() { - let args: Vec = env::args().collect(); - if args.len() < 4 || args.len() > 5 { - println!( - "aleo-setup-verifier {{ 'development', 'inner', 'outer', 'universal' }} {{ COORDINATOR_API_URL }} {{ VERIFIER_VIEW_KEY }} {{ (optional) TRACE }}" - ); - return; - } - - let environment = match args[1].as_str() { - "development" => development(), - "inner" => inner(), - "outer" => outer(), - "universal" => universal(), - _ => panic!("Invalid environment"), - }; + let options = Options::from_args(); - let tasks_storage_path = format!("{}_verifier.tasks", args[1].as_str()); + init_logger(); + + let public_settings = request_coordinator_public_settings(&options.api_url) + .await + .expect("Can't get the coordinator public settings"); - let coordinator_api_url = args[2].clone(); + let environment = match public_settings.setup { + SetupKind::Development => development(), + SetupKind::Inner => inner(), + SetupKind::Outer => outer(), + SetupKind::Universal => universal(), + }; - let view_key = ViewKey::from_str(&args[3]).expect("invalid view key"); - let _address = Address::from_view_key(&view_key).expect("address not derived correctly"); + let storage_prefix = format!("{:?}", public_settings.setup).to_lowercase(); + let tasks_storage_path = format!("{}_verifier.tasks", storage_prefix); - init_logger(); + let raw_view_key = std::fs::read_to_string(options.view_key).expect("View key not found"); + let view_key = ViewKey::from_str(&raw_view_key).expect("Invalid view key"); + let address = Address::from_view_key(&view_key).expect("Address not derived correctly"); // Initialize the verifier info!("Initializing verifier..."); let verifier = Verifier::new( - coordinator_api_url.to_string(), - view_key.to_string(), - environment.into(), + options.api_url.clone(), + view_key, + address, + environment, tasks_storage_path, ) - .expect("failed to initialize verifier"); + .expect("Failed to initialize verifier"); verifier.start_verifier().await; } diff --git a/setup1-verifier/src/verifier.rs b/setup1-verifier/src/verifier.rs index cdf3ced5..751ed44e 100644 --- a/setup1-verifier/src/verifier.rs +++ b/setup1-verifier/src/verifier.rs @@ -21,6 +21,7 @@ use chrono::Utc; use std::{fs, str::FromStr, sync::Arc, thread::sleep, time::Duration}; use tokio::{signal, sync::Mutex}; use tracing::{debug, error, info, trace, warn}; +use url::Url; /// Returns a pretty print of the given hash bytes for logging. macro_rules! pretty_hash { @@ -44,13 +45,13 @@ macro_rules! pretty_hash { /// The verifier used to manage and dispatch/execute verifier operations /// to the remote coordinator. /// -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct Verifier { /// The url of the coordinator that will be - pub(crate) coordinator_api_url: String, + pub(crate) coordinator_api_url: Url, /// The view key that will be used for server authentication - pub(crate) view_key: String, + pub(crate) view_key: ViewKey, /// The identity of the verifier pub(crate) verifier: Participant, @@ -65,17 +66,33 @@ pub struct Verifier { pub(crate) tasks_storage_path: String, } +// Manual implementation, since ViewKey doesn't implement Clone +impl Clone for Verifier { + fn clone(&self) -> Self { + let view_key = ViewKey::from_str(&self.view_key.to_string()).expect("Error cloning the verifier ViewKey"); + Self { + coordinator_api_url: self.coordinator_api_url.clone(), + view_key, + verifier: self.verifier.clone(), + environment: self.environment.clone(), + tasks: self.tasks.clone(), + tasks_storage_path: self.tasks_storage_path.clone(), + } + } +} + impl Verifier { /// /// Initialize a new verifier. /// pub fn new( - coordinator_api_url: String, - view_key: String, + coordinator_api_url: Url, + view_key: ViewKey, + address: Address, environment: Environment, tasks_storage_path: String, ) -> Result { - let verifier_id = Address::from_view_key(&ViewKey::from_str(&view_key)?)?.to_string(); + let verifier_id = address.to_string(); Ok(Self { coordinator_api_url, @@ -329,8 +346,7 @@ impl Verifier { )?; let message = contribution_state.signature_message()?; - let view_key = ViewKey::from_str(&self.view_key)?; - let signature = AleoAuthentication::sign(&view_key, message)?; + let signature = AleoAuthentication::sign(&self.view_key, message)?; let contribution_file_signature = ContributionFileSignature::new(signature, contribution_state)?; @@ -494,9 +510,13 @@ mod tests { batch_size: 512, }); + let view_key = ViewKey::from_str(TEST_VIEW_KEY).expect("Invalid view key"); + let address = Address::from_view_key(&view_key).expect("Address not derived correctly"); + Verifier::new( - "test_coordinator_url".to_string(), - TEST_VIEW_KEY.to_string(), + Url::from_str("http://test_coordinator_url").unwrap(), + view_key, + address, environment.into(), "TEST_VERIFIER.tasks".to_string(), ) @@ -560,8 +580,7 @@ mod tests { let message = contribution_state.signature_message().unwrap(); // Derive the verifier address - let view_key = ViewKey::from_str(&verifier.view_key).unwrap(); - let address = Address::from_view_key(&view_key).unwrap(); + let address = Address::from_view_key(&verifier.view_key).unwrap(); // Check that the signature verifies assert!(AleoAuthentication::verify(&address.to_string(), signature, message).unwrap())