From 6448dac047467412407ea5bb89b9832b5736c158 Mon Sep 17 00:00:00 2001 From: damirka Date: Wed, 24 Feb 2021 19:17:44 +0300 Subject: [PATCH 1/3] 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/3] 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 64cc9fa9c95c571cf1a640520fae6c7ecf38250f Mon Sep 17 00:00:00 2001 From: collin Date: Mon, 8 Mar 2021 16:18:24 -0800 Subject: [PATCH 3/3] 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);