From 6448dac047467412407ea5bb89b9832b5736c158 Mon Sep 17 00:00:00 2001 From: damirka Date: Wed, 24 Feb 2021 19:17:44 +0300 Subject: [PATCH 1/5] Fixes #580 - changes error message for console.assert inside main() - small rewrite of setup command - adds some autoformatting --- compiler/src/errors/console.rs | 5 +- leo/commands/setup.rs | 141 ++++++++++++++++----------------- 2 files changed, 72 insertions(+), 74 deletions(-) diff --git a/compiler/src/errors/console.rs b/compiler/src/errors/console.rs index c68a0035dd..7e7064d8de 100644 --- a/compiler/src/errors/console.rs +++ b/compiler/src/errors/console.rs @@ -50,8 +50,9 @@ impl ConsoleError { } pub fn assertion_depends_on_input(span: Span) -> Self { - let message = - "console.assert() failed to evaluate. This error is caused by empty input file values".to_string(); + let message = "console.assert() does not produce constraints and cannot use inputs. \ + Assertions should only be used in @test functions" + .to_string(); Self::new_from_span(message, span) } diff --git a/leo/commands/setup.rs b/leo/commands/setup.rs index fafb8467a7..17a2811fea 100644 --- a/leo/commands/setup.rs +++ b/leo/commands/setup.rs @@ -17,10 +17,7 @@ use super::build::Build; use crate::{commands::Command, context::Context}; use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType}; -use leo_package::{ - outputs::{ProvingKeyFile, VerificationKeyFile}, - source::{MAIN_FILENAME, SOURCE_DIRECTORY_NAME}, -}; +use leo_package::outputs::{ProvingKeyFile, VerificationKeyFile}; use anyhow::{anyhow, Result}; use rand::thread_rng; @@ -64,75 +61,75 @@ impl Command for Setup { let path = ctx.dir()?; let package_name = ctx.manifest()?.get_package_name(); - match input { - Some((program, checksum_differs)) => { - // Check if a proving key and verification key already exists - let keys_exist = ProvingKeyFile::new(&package_name).exists_at(&path) - && VerificationKeyFile::new(&package_name).exists_at(&path); - - // If keys do not exist or the checksum differs, run the program setup - // If keys do not exist or the checksum differs, run the program setup - let (proving_key, prepared_verifying_key) = if !keys_exist || checksum_differs { - tracing::info!("Starting..."); - - // Run the program setup operation - let rng = &mut thread_rng(); - let (proving_key, prepared_verifying_key) = - Groth16::, Vec>::setup(&program, rng)?; - - // TODO (howardwu): Convert parameters to a 'proving key' struct for serialization. - // Write the proving key file to the output directory - let proving_key_file = ProvingKeyFile::new(&package_name); - tracing::info!("Saving proving key ({:?})", proving_key_file.full_path(&path)); - let mut proving_key_bytes = vec![]; - proving_key.write(&mut proving_key_bytes)?; - let _ = proving_key_file.write_to(&path, &proving_key_bytes)?; - tracing::info!("Complete"); - - // Write the verification key file to the output directory - let verification_key_file = VerificationKeyFile::new(&package_name); - tracing::info!("Saving verification key ({:?})", verification_key_file.full_path(&path)); - let mut verification_key = vec![]; - proving_key.vk.write(&mut verification_key)?; - let _ = verification_key_file.write_to(&path, &verification_key)?; - tracing::info!("Complete"); - - (proving_key, prepared_verifying_key) - } else { - tracing::info!("Detected saved setup"); - - // Read the proving key file from the output directory - tracing::info!("Loading proving key..."); - - if self.skip_key_check { - tracing::info!("Skipping curve check"); - } - let proving_key_bytes = ProvingKeyFile::new(&package_name).read_from(&path)?; - let proving_key = - Parameters::::read(proving_key_bytes.as_slice(), !self.skip_key_check)?; - tracing::info!("Complete"); - - // Read the verification key file from the output directory - tracing::info!("Loading verification key..."); - let verifying_key_bytes = VerificationKeyFile::new(&package_name).read_from(&path)?; - let verifying_key = VerifyingKey::::read(verifying_key_bytes.as_slice())?; - - // Derive the prepared verifying key file from the verifying key - let prepared_verifying_key = PreparedVerifyingKey::::from(verifying_key); - tracing::info!("Complete"); - - (proving_key, prepared_verifying_key) - }; - - Ok((program, proving_key, prepared_verifying_key)) - } - None => { - let mut main_file_path = path; - main_file_path.push(SOURCE_DIRECTORY_NAME); - main_file_path.push(MAIN_FILENAME); + if input.is_none() { + return Err(anyhow!("Unable to build, check that main file exists")); + } - Err(anyhow!("Unable to build, check that main file exists")) + let (program, checksum_differs) = input.unwrap(); + + // Check if a proving key and verification key already exists + let keys_exist = ProvingKeyFile::new(&package_name).exists_at(&path) + && VerificationKeyFile::new(&package_name).exists_at(&path); + + // If keys do not exist or the checksum differs, run the program setup + // If keys do not exist or the checksum differs, run the program setup + let (proving_key, prepared_verifying_key) = if !keys_exist || checksum_differs { + tracing::info!("Starting..."); + + // Run the program setup operation + let (proving_key, prepared_verifying_key) = { + let rng = &mut thread_rng(); + let setup_res = Groth16::, Vec>::setup(&program, rng); + match setup_res { + Ok((proving_key, prepared_verifying_key)) => (proving_key, prepared_verifying_key), + // for some reason, using `anyhow!("{}", err)` here causes stack overflow - FIXME + Err(_err) => return Err(anyhow!("{}", "Unable to setup, see command output for more details")), + } + }; + + // TODO (howardwu): Convert parameters to a 'proving key' struct for serialization. + // Write the proving key file to the output directory + let proving_key_file = ProvingKeyFile::new(&package_name); + tracing::info!("Saving proving key ({:?})", proving_key_file.full_path(&path)); + let mut proving_key_bytes = vec![]; + proving_key.write(&mut proving_key_bytes)?; + let _ = proving_key_file.write_to(&path, &proving_key_bytes)?; + tracing::info!("Complete"); + + // Write the verification key file to the output directory + let verification_key_file = VerificationKeyFile::new(&package_name); + tracing::info!("Saving verification key ({:?})", verification_key_file.full_path(&path)); + let mut verification_key = vec![]; + proving_key.vk.write(&mut verification_key)?; + let _ = verification_key_file.write_to(&path, &verification_key)?; + tracing::info!("Complete"); + + (proving_key, prepared_verifying_key) + } else { + tracing::info!("Detected saved setup"); + + // Read the proving key file from the output directory + tracing::info!("Loading proving key..."); + + if self.skip_key_check { + tracing::info!("Skipping curve check"); } - } + let proving_key_bytes = ProvingKeyFile::new(&package_name).read_from(&path)?; + let proving_key = Parameters::::read(proving_key_bytes.as_slice(), !self.skip_key_check)?; + tracing::info!("Complete"); + + // Read the verification key file from the output directory + tracing::info!("Loading verification key..."); + let verifying_key_bytes = VerificationKeyFile::new(&package_name).read_from(&path)?; + let verifying_key = VerifyingKey::::read(verifying_key_bytes.as_slice())?; + + // Derive the prepared verifying key file from the verifying key + let prepared_verifying_key = PreparedVerifyingKey::::from(verifying_key); + tracing::info!("Complete"); + + (proving_key, prepared_verifying_key) + }; + + Ok((program, proving_key, prepared_verifying_key)) } } From 2ffdd839afbab4f6c349800ae555b88f8ad041a3 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 8 Mar 2021 11:00:36 +0000 Subject: [PATCH 2/5] Bump self_update from 0.25.0 to 0.26.0 Bumps [self_update](https://github.com/jaemk/self_update) from 0.25.0 to 0.26.0. - [Release notes](https://github.com/jaemk/self_update/releases) - [Changelog](https://github.com/jaemk/self_update/blob/master/CHANGELOG.md) - [Commits](https://github.com/jaemk/self_update/commits) Signed-off-by: dependabot-preview[bot] --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 881ab30a24..eb05f174c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2312,9 +2312,9 @@ dependencies = [ [[package]] name = "self_update" -version = "0.25.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5abe13436707b8fd0044592de0b8d9565ab700fbb06611d6e4d89384687da195" +checksum = "9031099ba3962ce8faaff991066bcbe6ec1f7ccb0be12a4b56733028ae090054" dependencies = [ "hyper", "indicatif", diff --git a/Cargo.toml b/Cargo.toml index 6628e10f2f..8dddb64f54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -128,7 +128,7 @@ version = "0.11.1" features = [ "blocking", "json", "multipart" ] [dependencies.self_update] -version = "0.25.0" +version = "0.26.0" features = [ "archive-zip" ] [dependencies.serde] From 96eea741ee1e5d82a8b2c468a4c4e68e72ed9e76 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 8 Mar 2021 11:01:03 +0000 Subject: [PATCH 3/5] Bump indexmap from 1.6.1 to 1.6.2 Bumps [indexmap](https://github.com/bluss/indexmap) from 1.6.1 to 1.6.2. - [Release notes](https://github.com/bluss/indexmap/releases) - [Commits](https://github.com/bluss/indexmap/compare/1.6.1...1.6.2) Signed-off-by: dependabot-preview[bot] --- Cargo.lock | 4 ++-- ast/Cargo.toml | 2 +- compiler/Cargo.toml | 2 +- imports/Cargo.toml | 2 +- state/Cargo.toml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 881ab30a24..7917e0c180 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1051,9 +1051,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.1" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg", "hashbrown", diff --git a/ast/Cargo.toml b/ast/Cargo.toml index 75a84f0111..07ac9c6f6f 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -35,7 +35,7 @@ path = "../input" version = "1.2.3" [dependencies.indexmap] -version = "1.6.1" +version = "1.6.2" features = [ "serde-1" ] [dependencies.pest] diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index 9f44f8b213..e9679a1c08 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -79,7 +79,7 @@ version = "1.3" version = "0.4.2" [dependencies.indexmap] -version = "1.6.1" +version = "1.6.2" features = [ "serde-1" ] [dependencies.pest] diff --git a/imports/Cargo.toml b/imports/Cargo.toml index f7a53f98fc..59b4129c2d 100644 --- a/imports/Cargo.toml +++ b/imports/Cargo.toml @@ -30,7 +30,7 @@ path = "../asg" version = "1.2.3" [dependencies.indexmap] -version = "1.6.1" +version = "1.6.2" features = [ "serde-1" ] [dependencies.thiserror] diff --git a/state/Cargo.toml b/state/Cargo.toml index 72b7c71b02..63f590435c 100644 --- a/state/Cargo.toml +++ b/state/Cargo.toml @@ -41,7 +41,7 @@ default-features = false version = "0.2.0" [dependencies.indexmap] -version = "1.6.1" +version = "1.6.2" features = [ "serde-1" ] [dependencies.rand] From 12c8c6b3da4d137922bf9a540397fae1ac5aa223 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 8 Mar 2021 23:39:40 +0000 Subject: [PATCH 4/5] Bump serde from 1.0.123 to 1.0.124 Bumps [serde](https://github.com/serde-rs/serde) from 1.0.123 to 1.0.124. - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](https://github.com/serde-rs/serde/compare/v1.0.123...v1.0.124) Signed-off-by: dependabot-preview[bot] --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ffcc86a70f..e7215b85a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2360,9 +2360,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.123" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" +checksum = "bd761ff957cb2a45fbb9ab3da6512de9de55872866160b23c25f1a841e99d29f" dependencies = [ "serde_derive", ] @@ -2379,9 +2379,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.123" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" +checksum = "1800f7693e94e186f5e25a28291ae1570da908aff7d97a095dec1e56ff99069b" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", From 64cc9fa9c95c571cf1a640520fae6c7ecf38250f Mon Sep 17 00:00:00 2001 From: collin Date: Mon, 8 Mar 2021 16:18:24 -0800 Subject: [PATCH 5/5] remove unsafe unwrap --- leo/commands/setup.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/leo/commands/setup.rs b/leo/commands/setup.rs index 6f3c82a9a7..8d2c052b38 100644 --- a/leo/commands/setup.rs +++ b/leo/commands/setup.rs @@ -55,12 +55,9 @@ impl Command for Setup { let path = context.dir()?; let package_name = context.manifest()?.get_package_name(); - // If Build failed - exit. - if input.is_none() { - return Err(anyhow!("Unable to build, check that main file exists")); - } + // Check if leo build failed + let (program, checksum_differs) = input.ok_or(anyhow!("Unable to build, check that main file exists"))?; - let (program, checksum_differs) = input.unwrap(); // Check if a proving key and verification key already exists let keys_exist = ProvingKeyFile::new(&package_name).exists_at(&path) && VerificationKeyFile::new(&package_name).exists_at(&path);