diff --git a/Cargo.lock b/Cargo.lock index 6c152769ac..1eaf8481b4 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", @@ -2309,9 +2309,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", @@ -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", diff --git a/Cargo.toml b/Cargo.toml index 4436163eab..9efc7f6ecf 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] diff --git a/ast/Cargo.toml b/ast/Cargo.toml index c98dd62d73..3ec4548606 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -22,7 +22,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 3f65f95a8e..663f987286 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/compiler/src/errors/console.rs b/compiler/src/errors/console.rs index b6862c12a8..58391c57fe 100644 --- a/compiler/src/errors/console.rs +++ b/compiler/src/errors/console.rs @@ -57,8 +57,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/imports/Cargo.toml b/imports/Cargo.toml index c7e143d0a1..8ab4665f8a 100644 --- a/imports/Cargo.toml +++ b/imports/Cargo.toml @@ -30,7 +30,7 @@ path = "../parser" version = "1.2.3" [dependencies.indexmap] -version = "1.6.1" +version = "1.6.2" features = [ "serde-1" ] [dependencies.thiserror] diff --git a/leo/commands/setup.rs b/leo/commands/setup.rs index 5f76d88dd0..085d0069bc 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; @@ -60,74 +57,66 @@ impl Command for Setup { let path = context.dir()?; let package_name = context.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 - 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)) + // Check if leo build failed + let (program, checksum_differs) = input.ok_or(anyhow!("Unable to build, check that main file exists"))?; + + // 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 + 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) + .map_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"); } - None => { - let mut main_file_path = path; - main_file_path.push(SOURCE_DIRECTORY_NAME); - main_file_path.push(MAIN_FILENAME); + 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"); - Err(anyhow!("Unable to build, check that main file exists")) - } - } + // 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)) } } 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]