Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: Remove keys from preprocessed artifacts #2283

Merged
merged 6 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion crates/nargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ iter-extended.workspace = true
serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true
noirc_errors.workspace = true
base64.workspace = true
regex = "1.9.1"
3 changes: 0 additions & 3 deletions crates/nargo/src/artifacts/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,4 @@ pub struct PreprocessedContractFunction {
deserialize_with = "super::deserialize_circuit"
)]
pub bytecode: Circuit,

pub proving_key: Option<Vec<u8>>,
pub verification_key: Option<Vec<u8>>,
}
3 changes: 0 additions & 3 deletions crates/nargo/src/artifacts/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,4 @@ pub struct PreprocessedProgram {
deserialize_with = "super::deserialize_circuit"
)]
pub bytecode: Circuit,

pub proving_key: Option<Vec<u8>>,
pub verification_key: Option<Vec<u8>>,
}
2 changes: 0 additions & 2 deletions crates/nargo/src/ops/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
pub use self::codegen_verifier::codegen_verifier;
pub use self::execute::execute_circuit;
pub use self::preprocess::{preprocess_contract_function, preprocess_program};
pub use self::prove::prove_execution;
pub use self::verify::verify_proof;

mod codegen_verifier;
mod execute;
mod foreign_calls;
mod preprocess;
mod prove;
mod verify;
67 changes: 0 additions & 67 deletions crates/nargo/src/ops/preprocess.rs

This file was deleted.

45 changes: 25 additions & 20 deletions crates/nargo_cli/src/cli/codegen_verifier_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ use super::{
use crate::errors::CliError;
use acvm::Backend;
use clap::Args;
use nargo::{
ops::{codegen_verifier, preprocess_program},
package::Package,
};
use nargo::artifacts::program::PreprocessedProgram;
use nargo::{ops::codegen_verifier, package::Package};
use nargo_toml::{find_package_manifest, resolve_workspace_from_toml};
use noirc_driver::CompileOptions;
use noirc_frontend::graph::CrateName;

// TODO(#1388): pull this from backend.
const BACKEND_IDENTIFIER: &str = "acvm-backend-barretenberg";

/// Generates a Solidity verifier smart contract for the program
#[derive(Debug, Clone, Args)]
pub(crate) struct CodegenVerifierCommand {
Expand Down Expand Up @@ -70,26 +71,30 @@ fn smart_contract_for_package<B: Backend>(
circuit_build_path: PathBuf,
compile_options: &CompileOptions,
) -> Result<String, CliError<B>> {
let common_reference_string = read_cached_common_reference_string();
let (common_reference_string, preprocessed_program) = if circuit_build_path.exists() {
let program = read_program_from_file(circuit_build_path)?;
let common_reference_string =
update_common_reference_string(backend, &common_reference_string, &program.bytecode)
.map_err(CliError::CommonReferenceStringError)?;
(common_reference_string, program)
let preprocessed_program = if circuit_build_path.exists() {
read_program_from_file(circuit_build_path)?
} else {
let (_, program) = compile_package(backend, package, compile_options)?;
let common_reference_string =
update_common_reference_string(backend, &common_reference_string, &program.circuit)
.map_err(CliError::CommonReferenceStringError)?;
let (program, _) = preprocess_program(backend, true, &common_reference_string, program)
.map_err(CliError::ProofSystemCompilerError)?;
(common_reference_string, program)

PreprocessedProgram {
backend: String::from(BACKEND_IDENTIFIER),
abi: program.abi,
bytecode: program.circuit,
}
};

let verification_key = preprocessed_program
.verification_key
.expect("Verification key should exist as `true` is passed to `preprocess_program`");
let common_reference_string = read_cached_common_reference_string();
let common_reference_string = update_common_reference_string(
backend,
&common_reference_string,
&preprocessed_program.bytecode,
)
.map_err(CliError::CommonReferenceStringError)?;

let (_, verification_key) = backend
.preprocess(&common_reference_string, &preprocessed_program.bytecode)
.map_err(CliError::ProofSystemCompilerError)?;

let smart_contract_string = codegen_verifier(
backend,
&common_reference_string,
Expand Down
28 changes: 16 additions & 12 deletions crates/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use acvm::acir::circuit::OpcodeLabel;
use acvm::{acir::circuit::Circuit, Backend};
use iter_extended::try_vecmap;
use iter_extended::vecmap;
use nargo::artifacts::contract::PreprocessedContractFunction;
use nargo::artifacts::program::PreprocessedProgram;
use nargo::package::Package;
use nargo::prepare_package;
use nargo::{artifacts::contract::PreprocessedContract, NargoError};
Expand All @@ -15,8 +17,6 @@ use noirc_frontend::hir::Context;

use clap::Args;

use nargo::ops::{preprocess_contract_function, preprocess_program};

use crate::errors::{CliError, CompileError};

use super::fs::{
Expand Down Expand Up @@ -80,13 +80,14 @@ pub(crate) fn run<B: Backend>(
)
.map_err(CliError::CommonReferenceStringError)?;

preprocess_contract_function(
backend,
args.include_keys,
&common_reference_string,
func,
)
.map_err(CliError::ProofSystemCompilerError)
Ok::<_, CliError<B>>(PreprocessedContractFunction {
name: func.name,
function_type: func.function_type,
is_internal: func.is_internal,
abi: func.abi,

bytecode: func.bytecode,
})
})?;

Ok(PreprocessedContract {
Expand All @@ -109,9 +110,12 @@ pub(crate) fn run<B: Backend>(
update_common_reference_string(backend, &common_reference_string, &program.circuit)
.map_err(CliError::CommonReferenceStringError)?;

let (preprocessed_program, _) =
preprocess_program(backend, args.include_keys, &common_reference_string, program)
.map_err(CliError::ProofSystemCompilerError)?;
let preprocessed_program = PreprocessedProgram {
backend: String::from(BACKEND_IDENTIFIER),
abi: program.abi,
bytecode: program.circuit,
};

save_program_to_file(&preprocessed_program, &package.name, &circuit_dir);
}
}
Expand Down
54 changes: 27 additions & 27 deletions crates/nargo_cli/src/cli/prove_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@ use acvm::Backend;
use clap::Args;
use nargo::artifacts::program::PreprocessedProgram;
use nargo::constants::{PROVER_INPUT_FILE, VERIFIER_INPUT_FILE};
use nargo::ops::{preprocess_program, prove_execution, verify_proof};
use nargo::ops::{prove_execution, verify_proof};
use nargo::package::Package;
use nargo_toml::{find_package_manifest, resolve_workspace_from_toml};
use noirc_abi::input_parser::Format;
use noirc_driver::CompileOptions;
use noirc_frontend::graph::CrateName;

use super::compile_cmd::compile_package;
use super::fs::common_reference_string::update_common_reference_string;
use super::fs::{
common_reference_string::{
read_cached_common_reference_string, update_common_reference_string,
write_cached_common_reference_string,
},
common_reference_string::read_cached_common_reference_string,
inputs::{read_inputs_from_file, write_inputs_to_file},
program::read_program_from_file,
proof::save_proof_to_dir,
};
use super::NargoConfig;
use crate::{cli::execute_cmd::execute_program, errors::CliError};

// TODO(#1388): pull this from backend.
const BACKEND_IDENTIFIER: &str = "acvm-backend-barretenberg";

/// Create proof for this program. The proof is returned as a hex encoded string.
#[derive(Debug, Clone, Args)]
pub(crate) struct ProveCommand {
Expand Down Expand Up @@ -85,29 +86,33 @@ pub(crate) fn prove_package<B: Backend>(
check_proof: bool,
compile_options: &CompileOptions,
) -> Result<(), CliError<B>> {
let common_reference_string = read_cached_common_reference_string();

let (common_reference_string, preprocessed_program, debug_data) = if circuit_build_path.exists()
{
let (preprocessed_program, debug_data) = if circuit_build_path.exists() {
let program = read_program_from_file(circuit_build_path)?;
let common_reference_string =
update_common_reference_string(backend, &common_reference_string, &program.bytecode)
.map_err(CliError::CommonReferenceStringError)?;
(common_reference_string, program, None)

(program, None)
} else {
let (context, program) = compile_package(backend, package, compile_options)?;
let common_reference_string =
update_common_reference_string(backend, &common_reference_string, &program.circuit)
.map_err(CliError::CommonReferenceStringError)?;
let (program, debug) = preprocess_program(backend, true, &common_reference_string, program)
.map_err(CliError::ProofSystemCompilerError)?;
(common_reference_string, program, Some((debug, context)))
let preprocessed_program = PreprocessedProgram {
backend: String::from(BACKEND_IDENTIFIER),
abi: program.abi,
bytecode: program.circuit,
};
(preprocessed_program, Some((program.debug, context)))
};

write_cached_common_reference_string(&common_reference_string);
let common_reference_string = read_cached_common_reference_string();
let common_reference_string = update_common_reference_string(
backend,
&common_reference_string,
&preprocessed_program.bytecode,
)
.map_err(CliError::CommonReferenceStringError)?;

let (proving_key, verification_key) = backend
.preprocess(&common_reference_string, &preprocessed_program.bytecode)
.map_err(CliError::ProofSystemCompilerError)?;

let PreprocessedProgram { abi, bytecode, proving_key, verification_key, .. } =
preprocessed_program;
let PreprocessedProgram { abi, bytecode, .. } = preprocessed_program;

// Parse the initial witness values from Prover.toml
let (inputs_map, _) =
Expand All @@ -128,17 +133,12 @@ pub(crate) fn prove_package<B: Backend>(
Format::Toml,
)?;

let proving_key =
proving_key.expect("Proving key should exist as `true` is passed to `preprocess_program`");

let proof =
prove_execution(backend, &common_reference_string, &bytecode, solved_witness, &proving_key)
.map_err(CliError::ProofSystemCompilerError)?;

if check_proof {
let public_inputs = public_abi.encode(&public_inputs, return_value)?;
let verification_key = verification_key
.expect("Verification key should exist as `true` is passed to `preprocess_program`");
let valid_proof = verify_proof(
backend,
&common_reference_string,
Expand Down
Loading