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!: Update to acvm 0.11.0 #1322

Merged
merged 12 commits into from May 12, 2023
23 changes: 12 additions & 11 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
Expand Up @@ -24,7 +24,7 @@ edition = "2021"
rust-version = "1.66"

[workspace.dependencies]
acvm = "0.10.3"
acvm = "0.11.0"
arena = { path = "crates/arena" }
fm = { path = "crates/fm" }
iter-extended = { path = "crates/iter-extended" }
Expand Down
10 changes: 4 additions & 6 deletions crates/nargo/src/ops/codegen_verifier.rs
@@ -1,10 +1,8 @@
use acvm::SmartContract;

use crate::NargoError;

pub fn codegen_verifier(
backend: &impl SmartContract,
pub fn codegen_verifier<B: SmartContract>(
backend: &B,
verification_key: &[u8],
) -> Result<String, NargoError> {
Ok(backend.eth_contract_from_vk(verification_key))
) -> Result<String, B::Error> {
backend.eth_contract_from_vk(verification_key)
}
35 changes: 16 additions & 19 deletions crates/nargo/src/ops/preprocess.rs
@@ -1,26 +1,23 @@
use acvm::ProofSystemCompiler;
use iter_extended::vecmap;
use iter_extended::try_vecmap;
use noirc_driver::{CompiledContract, CompiledProgram};

use crate::{
artifacts::{
contract::{PreprocessedContract, PreprocessedContractFunction},
program::PreprocessedProgram,
},
NargoError,
use crate::artifacts::{
contract::{PreprocessedContract, PreprocessedContractFunction},
program::PreprocessedProgram,
};

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

pub fn preprocess_program(
backend: &impl ProofSystemCompiler,
pub fn preprocess_program<B: ProofSystemCompiler>(
backend: &B,
compiled_program: CompiledProgram,
) -> Result<PreprocessedProgram, NargoError> {
) -> Result<PreprocessedProgram, B::Error> {
// TODO: currently `compiled_program`'s bytecode is already optimized for the backend.
// In future we'll need to apply those optimizations here.
let optimized_bytecode = compiled_program.circuit;
let (proving_key, verification_key) = backend.preprocess(&optimized_bytecode);
let (proving_key, verification_key) = backend.preprocess(&optimized_bytecode)?;

Ok(PreprocessedProgram {
backend: String::from(BACKEND_IDENTIFIER),
Expand All @@ -31,26 +28,26 @@ pub fn preprocess_program(
})
}

pub fn preprocess_contract(
backend: &impl ProofSystemCompiler,
pub fn preprocess_contract<B: ProofSystemCompiler>(
backend: &B,
compiled_contract: CompiledContract,
) -> Result<PreprocessedContract, NargoError> {
let preprocessed_contract_functions = vecmap(compiled_contract.functions, |func| {
) -> Result<PreprocessedContract, B::Error> {
let preprocessed_contract_functions = try_vecmap(compiled_contract.functions, |func| {
// TODO: currently `func`'s bytecode is already optimized for the backend.
// In future we'll need to apply those optimizations here.
let optimized_bytecode = func.bytecode;
let (proving_key, verification_key) = backend.preprocess(&optimized_bytecode);
let (proving_key, verification_key) = backend.preprocess(&optimized_bytecode)?;

PreprocessedContractFunction {
Ok(PreprocessedContractFunction {
name: func.name,
function_type: func.function_type,
abi: func.abi,

bytecode: optimized_bytecode,
proving_key,
verification_key,
}
});
})
})?;

Ok(PreprocessedContract {
name: compiled_contract.name,
Expand Down
12 changes: 4 additions & 8 deletions crates/nargo/src/ops/prove.rs
Expand Up @@ -2,15 +2,11 @@ use acvm::acir::circuit::Circuit;
use acvm::ProofSystemCompiler;
use noirc_abi::WitnessMap;

use crate::NargoError;

pub fn prove_execution(
backend: &impl ProofSystemCompiler,
pub fn prove_execution<B: ProofSystemCompiler>(
backend: &B,
circuit: &Circuit,
solved_witness: WitnessMap,
proving_key: &[u8],
) -> Result<Vec<u8>, NargoError> {
let proof = backend.prove_with_pk(circuit, solved_witness, proving_key);

Ok(proof)
) -> Result<Vec<u8>, B::Error> {
backend.prove_with_pk(circuit, solved_witness, proving_key)
}
12 changes: 4 additions & 8 deletions crates/nargo/src/ops/verify.rs
Expand Up @@ -2,16 +2,12 @@ use acvm::acir::circuit::Circuit;
use acvm::ProofSystemCompiler;
use noirc_abi::WitnessMap;

use crate::NargoError;

pub fn verify_proof(
backend: &impl ProofSystemCompiler,
pub fn verify_proof<B: ProofSystemCompiler>(
backend: &B,
circuit: &Circuit,
proof: &[u8],
public_inputs: WitnessMap,
verification_key: &[u8],
) -> Result<bool, NargoError> {
let valid_proof = backend.verify_with_vk(proof, public_inputs, circuit, verification_key);

Ok(valid_proof)
) -> Result<bool, B::Error> {
backend.verify_with_vk(proof, public_inputs, circuit, verification_key)
}
2 changes: 1 addition & 1 deletion crates/nargo_cli/Cargo.toml
Expand Up @@ -37,7 +37,7 @@ termcolor = "1.1.2"
color-eyre = "0.6.2"

# Backends
acvm-backend-barretenberg = { git = "https://github.com/noir-lang/aztec_backend", rev = "677f10e07011849f8aa0d75fe80390bb3081b1e5", default-features = false }
acvm-backend-barretenberg = { git = "https://github.com/noir-lang/aztec_backend", rev = "a26215db10e9e2d382078cc045c32467ca1cb278", default-features = false }

[dev-dependencies]
tempdir = "0.3.7"
Expand Down
27 changes: 18 additions & 9 deletions crates/nargo_cli/src/cli/check_cmd.rs
@@ -1,5 +1,5 @@
use crate::{errors::CliError, resolver::Resolver};
use acvm::ProofSystemCompiler;
use acvm::Backend;
use clap::Args;
use iter_extended::btree_map;
use noirc_abi::{AbiParameter, AbiType, MAIN_RETURN_NAME};
Expand All @@ -17,15 +17,21 @@ pub(crate) struct CheckCommand {
compile_options: CompileOptions,
}

pub(crate) fn run(args: CheckCommand, config: NargoConfig) -> Result<(), CliError> {
check_from_path(config.program_dir, &args.compile_options)?;
pub(crate) fn run<B: Backend>(
backend: &B,
args: CheckCommand,
config: NargoConfig,
) -> Result<(), CliError<B>> {
check_from_path(backend, config.program_dir, &args.compile_options)?;
println!("Constraint system successfully built!");
Ok(())
}

fn check_from_path<P: AsRef<Path>>(p: P, compile_options: &CompileOptions) -> Result<(), CliError> {
let backend = crate::backends::ConcreteBackend::default();

fn check_from_path<B: Backend, P: AsRef<Path>>(
backend: &B,
p: P,
compile_options: &CompileOptions,
) -> Result<(), CliError<B>> {
let mut driver = Resolver::resolve_root_manifest(p.as_ref(), backend.np_language())?;

driver.check_crate(compile_options).map_err(|_| CliError::CompilationError)?;
Expand Down Expand Up @@ -148,12 +154,13 @@ d2 = ["", "", ""]
let pass_dir =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("{TEST_DATA_DIR}/pass"));

let backend = crate::backends::ConcreteBackend::default();
let config = CompileOptions::default();
let paths = std::fs::read_dir(pass_dir).unwrap();
for path in paths.flatten() {
let path = path.path();
assert!(
super::check_from_path(path.clone(), &config).is_ok(),
super::check_from_path(&backend, path.clone(), &config).is_ok(),
"path: {}",
path.display()
);
Expand All @@ -166,12 +173,13 @@ d2 = ["", "", ""]
let fail_dir =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("{TEST_DATA_DIR}/fail"));

let backend = crate::backends::ConcreteBackend::default();
let config = CompileOptions::default();
let paths = std::fs::read_dir(fail_dir).unwrap();
for path in paths.flatten() {
let path = path.path();
assert!(
super::check_from_path(path.clone(), &config).is_err(),
super::check_from_path(&backend, path.clone(), &config).is_err(),
"path: {}",
path.display()
);
Expand All @@ -183,13 +191,14 @@ d2 = ["", "", ""]
let pass_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join(format!("{TEST_DATA_DIR}/pass_dev_mode"));

let backend = crate::backends::ConcreteBackend::default();
let config = CompileOptions { allow_warnings: true, ..Default::default() };

let paths = std::fs::read_dir(pass_dir).unwrap();
for path in paths.flatten() {
let path = path.path();
assert!(
super::check_from_path(path.clone(), &config).is_ok(),
super::check_from_path(&backend, path.clone(), &config).is_ok(),
"path: {}",
path.display()
);
Expand Down
17 changes: 11 additions & 6 deletions crates/nargo_cli/src/cli/codegen_verifier_cmd.rs
Expand Up @@ -4,6 +4,7 @@ use crate::{
cli::compile_cmd::compile_circuit, constants::CONTRACT_DIR, constants::TARGET_DIR,
errors::CliError,
};
use acvm::Backend;
use clap::Args;
use nargo::ops::{codegen_verifier, preprocess_program};
use noirc_driver::CompileOptions;
Expand All @@ -18,9 +19,11 @@ pub(crate) struct CodegenVerifierCommand {
compile_options: CompileOptions,
}

pub(crate) fn run(args: CodegenVerifierCommand, config: NargoConfig) -> Result<(), CliError> {
let backend = crate::backends::ConcreteBackend::default();

pub(crate) fn run<B: Backend>(
backend: &B,
args: CodegenVerifierCommand,
config: NargoConfig,
) -> Result<(), CliError<B>> {
// TODO(#1201): Should this be a utility function?
let circuit_build_path = args
.circuit_name
Expand All @@ -30,12 +33,14 @@ pub(crate) fn run(args: CodegenVerifierCommand, config: NargoConfig) -> Result<(
Some(circuit_build_path) => read_program_from_file(circuit_build_path)?,
None => {
let compiled_program =
compile_circuit(&backend, config.program_dir.as_ref(), &args.compile_options)?;
preprocess_program(&backend, compiled_program)?
compile_circuit(backend, config.program_dir.as_ref(), &args.compile_options)?;
preprocess_program(backend, compiled_program)
.map_err(CliError::ProofSystemCompilerError)?
}
};

let smart_contract_string = codegen_verifier(&backend, &preprocessed_program.verification_key)?;
let smart_contract_string = codegen_verifier(backend, &preprocessed_program.verification_key)
.map_err(CliError::SmartContractError)?;

let contract_dir = config.program_dir.join(CONTRACT_DIR);
create_named_dir(&contract_dir, "contract");
Expand Down