mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 05:45:30 +03:00
Adds verification key output support
This commit is contained in:
parent
f86c9d8076
commit
853faf54f6
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -397,6 +397,7 @@ dependencies = [
|
||||
"snarkos-errors",
|
||||
"snarkos-gadgets",
|
||||
"snarkos-models",
|
||||
"snarkos-utilities",
|
||||
"structopt",
|
||||
"toml",
|
||||
]
|
||||
|
@ -23,6 +23,7 @@ snarkos-curves = { path = "../snarkOS/curves", version = "0.8.0" }
|
||||
snarkos-errors = { path = "../snarkOS/errors", version = "0.8.0" }
|
||||
snarkos-gadgets = { path = "../snarkOS/gadgets", version = "0.8.0" }
|
||||
snarkos-models = { path = "../snarkOS/models", version = "0.8.0" }
|
||||
snarkos-utilities = { path = "../snarkOS/utilities", version = "0.8.0" }
|
||||
|
||||
clap = { version = "2.33.0" }
|
||||
colored = { version = "1.9" }
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{cli::*, cli_types::*};
|
||||
use crate::commands::BuildCommand;
|
||||
use crate::errors::CLIError;
|
||||
use crate::files::ProvingKeyFile;
|
||||
use crate::files::{ProvingKeyFile, VerificationKeyFile};
|
||||
use crate::manifest::Manifest;
|
||||
use leo_compiler::compiler::Compiler;
|
||||
|
||||
@ -9,6 +9,7 @@ use snarkos_algorithms::snark::{
|
||||
generate_random_parameters, prepare_verifying_key, Parameters, PreparedVerifyingKey,
|
||||
};
|
||||
use snarkos_curves::bls12_377::{Bls12_377, Fr};
|
||||
use snarkos_utilities::bytes::ToBytes;
|
||||
|
||||
use clap::ArgMatches;
|
||||
use rand::thread_rng;
|
||||
@ -61,6 +62,11 @@ impl CLI for SetupCommand {
|
||||
parameters.write(&mut proving_key);
|
||||
ProvingKeyFile::new(&package_name).write_to(&path, &proving_key)?;
|
||||
|
||||
// Write the proving key file to the inputs directory
|
||||
let mut verification_key = vec![];
|
||||
prepared_verifying_key.write(&mut verification_key);
|
||||
VerificationKeyFile::new(&package_name).write_to(&path, &verification_key)?;
|
||||
|
||||
Ok((program, parameters, prepared_verifying_key))
|
||||
}
|
||||
}
|
||||
|
@ -26,11 +26,17 @@ pub enum CLIError {
|
||||
#[fail(display = "{}", _0)]
|
||||
OutputsDirectoryError(OutputsDirectoryError),
|
||||
|
||||
#[fail(display = "{}", _0)]
|
||||
ProvingKeyFileError(ProvingKeyFileError),
|
||||
|
||||
#[fail(display = "{}", _0)]
|
||||
RunError(RunError),
|
||||
|
||||
#[fail(display = "{}", _0)]
|
||||
SourceDirectoryError(SourceDirectoryError),
|
||||
|
||||
#[fail(display = "{}", _0)]
|
||||
VerificationKeyFileError(VerificationKeyFileError),
|
||||
}
|
||||
|
||||
impl From<BuildError> for CLIError {
|
||||
@ -75,6 +81,12 @@ impl From<OutputsDirectoryError> for CLIError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ProvingKeyFileError> for CLIError {
|
||||
fn from(error: ProvingKeyFileError) -> Self {
|
||||
CLIError::ProvingKeyFileError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RunError> for CLIError {
|
||||
fn from(error: RunError) -> Self {
|
||||
CLIError::RunError(error)
|
||||
@ -87,6 +99,12 @@ impl From<SourceDirectoryError> for CLIError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<VerificationKeyFileError> for CLIError {
|
||||
fn from(error: VerificationKeyFileError) -> Self {
|
||||
CLIError::VerificationKeyFileError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::error::Error> for CLIError {
|
||||
fn from(error: serde_json::error::Error) -> Self {
|
||||
CLIError::Crate("serde_json", format!("{}", error))
|
||||
|
@ -3,3 +3,6 @@ pub use self::main::*;
|
||||
|
||||
pub mod proving_key;
|
||||
pub use self::proving_key::*;
|
||||
|
||||
pub mod verification_key;
|
||||
pub use self::verification_key::*;
|
||||
|
19
leo/errors/files/verification_key.rs
Normal file
19
leo/errors/files/verification_key.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug, Fail)]
|
||||
pub enum VerificationKeyFileError {
|
||||
#[fail(display = "{}: {}", _0, _1)]
|
||||
Crate(&'static str, String),
|
||||
|
||||
#[fail(display = "creating: {}", _0)]
|
||||
Creating(io::Error),
|
||||
|
||||
#[fail(display = "writing: {}", _0)]
|
||||
Writing(io::Error),
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for VerificationKeyFileError {
|
||||
fn from(error: std::io::Error) -> Self {
|
||||
VerificationKeyFileError::Crate("std::io", format!("{}", error))
|
||||
}
|
||||
}
|
@ -3,3 +3,6 @@ pub use self::main::*;
|
||||
|
||||
pub mod proving_key;
|
||||
pub use self::proving_key::*;
|
||||
|
||||
pub mod verification_key;
|
||||
pub use self::verification_key::*;
|
||||
|
@ -1,14 +1,14 @@
|
||||
//! The `main.leo` file.
|
||||
|
||||
use crate::directories::inputs::INPUTS_DIRECTORY_NAME;
|
||||
use crate::errors::MainFileError;
|
||||
use crate::errors::ProvingKeyFileError;
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub static PROVING_FILE_EXTENSION: &str = ".leo.pk";
|
||||
pub static PROVING_KEY_FILE_EXTENSION: &str = ".leo.pk";
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ProvingKeyFile {
|
||||
@ -28,18 +28,18 @@ impl ProvingKeyFile {
|
||||
if !path.ends_with(INPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
path.push(PathBuf::from(format!("{}{}", self.package_name, PROVING_FILE_EXTENSION)));
|
||||
path.push(PathBuf::from(format!("{}{}", self.package_name, PROVING_KEY_FILE_EXTENSION)));
|
||||
}
|
||||
path.exists()
|
||||
}
|
||||
|
||||
pub fn write_to(self, path: &PathBuf, proving_key: &[u8]) -> Result<(), MainFileError> {
|
||||
pub fn write_to(self, path: &PathBuf, proving_key: &[u8]) -> Result<(), ProvingKeyFileError> {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
if !path.ends_with(INPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
path.push(PathBuf::from(format!("{}{}", self.package_name, PROVING_FILE_EXTENSION)));
|
||||
path.push(PathBuf::from(format!("{}{}", self.package_name, PROVING_KEY_FILE_EXTENSION)));
|
||||
}
|
||||
|
||||
let mut file = File::create(&path)?;
|
||||
|
52
leo/files/verification_key.rs
Normal file
52
leo/files/verification_key.rs
Normal file
@ -0,0 +1,52 @@
|
||||
//! The `main.leo` file.
|
||||
|
||||
use crate::directories::inputs::INPUTS_DIRECTORY_NAME;
|
||||
use crate::errors::VerificationKeyFileError;
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub static VERIFICATION_KEY_FILE_EXTENSION: &str = ".leo.vk";
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct VerificationKeyFile {
|
||||
pub package_name: String,
|
||||
}
|
||||
|
||||
impl VerificationKeyFile {
|
||||
pub fn new(package_name: &str) -> Self {
|
||||
Self {
|
||||
package_name: package_name.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn exists_at(self, path: &PathBuf) -> bool {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
if !path.ends_with(INPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
path.push(PathBuf::from(format!("{}{}", self.package_name, VERIFICATION_KEY_FILE_EXTENSION)));
|
||||
}
|
||||
path.exists()
|
||||
}
|
||||
|
||||
pub fn write_to(self, path: &PathBuf, verification_key: &[u8]) -> Result<(), VerificationKeyFileError> {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
if !path.ends_with(INPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
path.push(PathBuf::from(format!("{}{}", self.package_name, VERIFICATION_KEY_FILE_EXTENSION)));
|
||||
}
|
||||
|
||||
let mut file = File::create(&path)?;
|
||||
file.write_all(verification_key)?;
|
||||
|
||||
log::info!("Verification key stored in {:?}", path);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user