Merge pull request #589 from AleoHQ/add-check-setup

[CLI] Adds --skip-key-check option to setup, run and prove commands
This commit is contained in:
Howard Wu 2021-02-03 11:31:35 -08:00 committed by GitHub
commit bdae2425a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 19 deletions

47
.github/workflows/leo-setup.yml vendored Normal file
View File

@ -0,0 +1,47 @@
name: leo-setup
on:
pull_request:
push:
branches:
- master
paths-ignore:
- 'docs/**'
- 'documentation/**'
env:
RUST_BACKTRACE: 1
jobs:
add:
name: Add Package ('leo add')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: rustfmt
- name: Install Leo
uses: actions-rs/cargo@v1
env:
CARGO_NET_GIT_FETCH_WITH_CLI: true
with:
command: install
args: --path .
- name: 'leo setup for examples'
env:
USER: ${{ secrets.ALEO_PM_USERNAME }}
PASS: ${{ secrets.ALEO_PM_PASSWORD }}
run: |
cd examples/pedersen-hash
leo setup
leo setup
leo setup --skip-key-check
leo clean

View File

@ -29,24 +29,24 @@ use std::{convert::TryFrom, env::current_dir, time::Instant};
pub struct ProveCommand; pub struct ProveCommand;
impl CLI for ProveCommand { impl CLI for ProveCommand {
type Options = (); type Options = bool;
type Output = (Proof<Bls12_377>, PreparedVerifyingKey<Bls12_377>); type Output = (Proof<Bls12_377>, PreparedVerifyingKey<Bls12_377>);
const ABOUT: AboutType = "Run the program and produce a proof"; const ABOUT: AboutType = "Run the program and produce a proof";
const ARGUMENTS: &'static [ArgumentType] = &[]; const ARGUMENTS: &'static [ArgumentType] = &[];
const FLAGS: &'static [FlagType] = &[]; const FLAGS: &'static [FlagType] = &[("--skip-key-check")];
const NAME: NameType = "prove"; const NAME: NameType = "prove";
const OPTIONS: &'static [OptionType] = &[]; const OPTIONS: &'static [OptionType] = &[];
const SUBCOMMANDS: &'static [SubCommandType] = &[]; const SUBCOMMANDS: &'static [SubCommandType] = &[];
#[cfg_attr(tarpaulin, skip)] #[cfg_attr(tarpaulin, skip)]
fn parse(_arguments: &ArgMatches) -> Result<Self::Options, CLIError> { fn parse(arguments: &ArgMatches) -> Result<Self::Options, CLIError> {
Ok(()) Ok(!arguments.is_present("skip-key-check"))
} }
#[cfg_attr(tarpaulin, skip)] #[cfg_attr(tarpaulin, skip)]
fn output(options: Self::Options) -> Result<Self::Output, CLIError> { fn output(do_setup_check: Self::Options) -> Result<Self::Output, CLIError> {
let (program, parameters, prepared_verifying_key) = SetupCommand::output(options)?; let (program, parameters, prepared_verifying_key) = SetupCommand::output(do_setup_check)?;
// Begin "Proving" context for console logging // Begin "Proving" context for console logging
let span = tracing::span!(tracing::Level::INFO, "Proving"); let span = tracing::span!(tracing::Level::INFO, "Proving");

View File

@ -28,24 +28,24 @@ use std::time::Instant;
pub struct RunCommand; pub struct RunCommand;
impl CLI for RunCommand { impl CLI for RunCommand {
type Options = (); type Options = bool;
type Output = (); type Output = ();
const ABOUT: AboutType = "Run a program with input variables"; const ABOUT: AboutType = "Run a program with input variables";
const ARGUMENTS: &'static [ArgumentType] = &[]; const ARGUMENTS: &'static [ArgumentType] = &[];
const FLAGS: &'static [FlagType] = &[]; const FLAGS: &'static [FlagType] = &[("--skip-key-check")];
const NAME: NameType = "run"; const NAME: NameType = "run";
const OPTIONS: &'static [OptionType] = &[]; const OPTIONS: &'static [OptionType] = &[];
const SUBCOMMANDS: &'static [SubCommandType] = &[]; const SUBCOMMANDS: &'static [SubCommandType] = &[];
#[cfg_attr(tarpaulin, skip)] #[cfg_attr(tarpaulin, skip)]
fn parse(_arguments: &ArgMatches) -> Result<Self::Options, CLIError> { fn parse(arguments: &ArgMatches) -> Result<Self::Options, CLIError> {
Ok(()) Ok(!arguments.is_present("skip-key-check"))
} }
#[cfg_attr(tarpaulin, skip)] #[cfg_attr(tarpaulin, skip)]
fn output(options: Self::Options) -> Result<(), CLIError> { fn output(do_setup_check: Self::Options) -> Result<(), CLIError> {
let (proof, prepared_verifying_key) = ProveCommand::output(options)?; let (proof, prepared_verifying_key) = ProveCommand::output(do_setup_check)?;
// Begin "Verifying" context for console logging // Begin "Verifying" context for console logging
let span = tracing::span!(tracing::Level::INFO, "Verifying"); let span = tracing::span!(tracing::Level::INFO, "Verifying");

View File

@ -39,7 +39,7 @@ use std::{convert::TryFrom, env::current_dir, time::Instant};
pub struct SetupCommand; pub struct SetupCommand;
impl CLI for SetupCommand { impl CLI for SetupCommand {
type Options = (); type Options = bool;
type Output = ( type Output = (
Compiler<Fr, EdwardsGroupType>, Compiler<Fr, EdwardsGroupType>,
Parameters<Bls12_377>, Parameters<Bls12_377>,
@ -48,23 +48,23 @@ impl CLI for SetupCommand {
const ABOUT: AboutType = "Run a program setup"; const ABOUT: AboutType = "Run a program setup";
const ARGUMENTS: &'static [ArgumentType] = &[]; const ARGUMENTS: &'static [ArgumentType] = &[];
const FLAGS: &'static [FlagType] = &[]; const FLAGS: &'static [FlagType] = &[("--skip-key-check")];
const NAME: NameType = "setup"; const NAME: NameType = "setup";
const OPTIONS: &'static [OptionType] = &[]; const OPTIONS: &'static [OptionType] = &[];
const SUBCOMMANDS: &'static [SubCommandType] = &[]; const SUBCOMMANDS: &'static [SubCommandType] = &[];
#[cfg_attr(tarpaulin, skip)] #[cfg_attr(tarpaulin, skip)]
fn parse(_arguments: &ArgMatches) -> Result<Self::Options, CLIError> { fn parse(arguments: &ArgMatches) -> Result<Self::Options, CLIError> {
Ok(()) Ok(!arguments.is_present("skip-key-check"))
} }
#[cfg_attr(tarpaulin, skip)] #[cfg_attr(tarpaulin, skip)]
fn output(options: Self::Options) -> Result<Self::Output, CLIError> { fn output(do_check: Self::Options) -> Result<Self::Output, CLIError> {
// Get the package name // Get the package name
let path = current_dir()?; let path = current_dir()?;
let package_name = Manifest::try_from(path.as_path())?.get_package_name(); let package_name = Manifest::try_from(path.as_path())?.get_package_name();
match BuildCommand::output(options)? { match BuildCommand::output(())? {
Some((program, checksum_differs)) => { Some((program, checksum_differs)) => {
// Begin "Setup" context for console logging // Begin "Setup" context for console logging
let span = tracing::span!(tracing::Level::INFO, "Setup"); let span = tracing::span!(tracing::Level::INFO, "Setup");
@ -116,8 +116,11 @@ impl CLI for SetupCommand {
// Read the proving key file from the output directory // Read the proving key file from the output directory
tracing::info!("Loading proving key..."); tracing::info!("Loading proving key...");
if !do_check {
tracing::info!("Skipping curve check");
}
let proving_key_bytes = ProvingKeyFile::new(&package_name).read_from(&path)?; let proving_key_bytes = ProvingKeyFile::new(&package_name).read_from(&path)?;
let proving_key = Parameters::<Bls12_377>::read(proving_key_bytes.as_slice(), true)?; let proving_key = Parameters::<Bls12_377>::read(proving_key_bytes.as_slice(), do_check)?;
tracing::info!("Complete"); tracing::info!("Complete");
// Read the verification key file from the output directory // Read the verification key file from the output directory