Skip to content

Commit

Permalink
Merge #692 #743
Browse files Browse the repository at this point in the history
692: [CLI] Changes compiler error message for console.assert r=collinc97 a=damirka

Closes #580

- changes error message for console.assert inside main()
- small rewrite of setup command
- adds some auto-formatting 

## Motivation

Current error message causes confusion. 

## Test Plan

Does not require additional testing.

743: Bump self_update from 0.25.0 to 0.26.0 r=collinc97 a=dependabot-preview[bot]

Bumps [self_update](https://github.com/jaemk/self_update) from 0.25.0 to 0.26.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/jaemk/self_update/blob/master/CHANGELOG.md">self_update's changelog</a>.</em></p>
<blockquote>
<h2>[0.26.0]</h2>
<h3>Added</h3>
<h3>Changed</h3>
<ul>
<li>Clean up dangling temporary directories on Windows.</li>
</ul>
<h3>Removed</h3>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li>See full diff in <a href="https://github.com/jaemk/self_update/commits">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://api.dependabot.com/badges/compatibility_score?dependency-name=self_update&package-manager=cargo&previous-version=0.25.0&new-version=0.26.0)](https://dependabot.com/compatibility-score/?dependency-name=self_update&package-manager=cargo&previous-version=0.25.0&new-version=0.26.0)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language
- `@dependabot badge me` will comment on this PR with code to add a "Dependabot enabled" badge to your readme

Additionally, you can set the following in your Dependabot [dashboard](https://app.dependabot.com):
- Update frequency (including time of day and day of week)
- Pull request limits (per update run and/or open at any time)
- Out-of-range updates (receive only lockfile updates, if desired)
- Security updates (receive only security updates, if desired)



</details>

Co-authored-by: damirka <damirka.ru@gmail.com>
Co-authored-by: collin <collin.chin@berkeley.edu>
Co-authored-by: Collin Chin <collin.chin@berkeley.edu>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
  • Loading branch information
4 people committed Mar 9, 2021
3 parents c243491 + a18b757 + 2ffdd83 commit 976356e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 76 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/errors/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
131 changes: 60 additions & 71 deletions leo/commands/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<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))
// 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::<Bls12_377, Compiler<Fr, _>, Vec<Fr>>::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::<Bls12_377>::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::<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))
}
}

0 comments on commit 976356e

Please sign in to comment.