mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-24 07:48:04 +03:00
Fixes #580
- changes error message for console.assert inside main() - small rewrite of setup command - adds some autoformatting
This commit is contained in:
parent
6fb1e713ed
commit
6448dac047
@ -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)
|
||||
}
|
||||
|
@ -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::<Bls12_377, Compiler<Fr, _>, Vec<Fr>>::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::<Bls12_377>::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::<Bls12_377>::read(verifying_key_bytes.as_slice())?;
|
||||
|
||||
// Derive the prepared verifying key file from the verifying key
|
||||
let prepared_verifying_key = PreparedVerifyingKey::<Bls12_377>::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);
|
||||
|
||||
Err(anyhow!("Unable to build, check that main file exists"))
|
||||
}
|
||||
if input.is_none() {
|
||||
return 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::<Bls12_377, Compiler<Fr, _>, Vec<Fr>>::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::<Bls12_377>::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::<Bls12_377>::read(verifying_key_bytes.as_slice())?;
|
||||
|
||||
// Derive the prepared verifying key file from the verifying key
|
||||
let prepared_verifying_key = PreparedVerifyingKey::<Bls12_377>::from(verifying_key);
|
||||
tracing::info!("Complete");
|
||||
|
||||
(proving_key, prepared_verifying_key)
|
||||
};
|
||||
|
||||
Ok((program, proving_key, prepared_verifying_key))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user