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

feat: update to ACVM 0.5.0 #902

Merged
merged 4 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
307 changes: 236 additions & 71 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ edition = "2021"
rust-version = "1.66"

[workspace.dependencies]
acvm = "0.4.1"
acvm = "0.5.0"
arena = { path = "crates/arena" }
fm = { path = "crates/fm" }
iter-extended = { path = "crates/iter-extended" }
Expand Down
4 changes: 2 additions & 2 deletions crates/nargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ termcolor = "1.1.2"
tempdir = "0.3.7"

# Backends
aztec_backend = { optional = true, package = "barretenberg_static_lib", git = "https://github.com/noir-lang/aztec_backend", rev = "cff757dca7971161e4bd25e7a744d910c37c22be" }
aztec_wasm_backend = { optional = true, package = "barretenberg_wasm", git = "https://github.com/noir-lang/aztec_backend", rev = "cff757dca7971161e4bd25e7a744d910c37c22be" }
aztec_backend = { optional = true, package = "barretenberg_static_lib", git = "https://github.com/noir-lang/aztec_backend", rev = "74b4d8d8b118e4477880c04149e5e9d93d388384" }
aztec_wasm_backend = { optional = true, package = "barretenberg_wasm", git = "https://github.com/noir-lang/aztec_backend", rev = "74b4d8d8b118e4477880c04149e5e9d93d388384" }
marlin_arkworks_backend = { optional = true, git = "https://github.com/noir-lang/marlin_arkworks_backend", rev = "144378edad821bfaa52bf2cacca8ecc87514a4fc" }
color-eyre = "0.6.2"

Expand Down
4 changes: 2 additions & 2 deletions crates/nargo/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn compile_and_preprocess_circuit<P: AsRef<Path>>(
let compiled_program = compile_circuit(program_dir, false, allow_warnings)?;
let circuit_path = save_acir_to_dir(&compiled_program.circuit, circuit_name, &circuit_dir);

preprocess_with_path(circuit_name, circuit_dir, compiled_program.circuit)?;
preprocess_with_path(circuit_name, circuit_dir, &compiled_program.circuit)?;

Ok(circuit_path)
}
Expand All @@ -65,7 +65,7 @@ pub fn compile_circuit<P: AsRef<Path>>(
fn preprocess_with_path<P: AsRef<Path>>(
key_name: &str,
preprocess_dir: P,
circuit: Circuit,
circuit: &Circuit,
) -> Result<(PathBuf, PathBuf), CliError> {
let backend = crate::backends::ConcreteBackend;

Expand Down
1 change: 1 addition & 0 deletions crates/nargo/src/cli/contract_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(crate) fn run(args: ContractCommand, config: NargoConfig) -> Result<(), CliE
let compiled_program = compile_circuit(config.program_dir.clone(), false, args.allow_warnings)?;

let backend = crate::backends::ConcreteBackend;
#[allow(deprecated)]
let smart_contract_string = backend.eth_contract_from_cs(compiled_program.circuit);

let mut contract_dir = config.program_dir;
Expand Down
2 changes: 1 addition & 1 deletion crates/nargo/src/cli/gates_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn count_gates_with_path<P: AsRef<Path>>(
num_opcodes
);

let exact_circuit_size = backend.get_exact_circuit_size(compiled_program.circuit);
let exact_circuit_size = backend.get_exact_circuit_size(&compiled_program.circuit);
println!("Backend circuit size: {exact_circuit_size}");

Ok(())
Expand Down
9 changes: 4 additions & 5 deletions crates/nargo/src/cli/prove_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn prove_with_path<P: AsRef<Path>>(
}
None => {
let backend = crate::backends::ConcreteBackend;
backend.preprocess(compiled_program.circuit.clone())
backend.preprocess(&compiled_program.circuit)
}
};

Expand All @@ -108,17 +108,16 @@ pub fn prove_with_path<P: AsRef<Path>>(
)?;

let backend = crate::backends::ConcreteBackend;
let proof =
backend.prove_with_pk(compiled_program.circuit.clone(), solved_witness, proving_key);
let proof = backend.prove_with_pk(&compiled_program.circuit, solved_witness, &proving_key);

if check_proof {
let no_proof_name = "".into();
verify_proof(
compiled_program,
&compiled_program,
public_inputs,
return_value,
&proof,
verification_key,
&verification_key,
no_proof_name,
)?;
}
Expand Down
24 changes: 9 additions & 15 deletions crates/nargo/src/cli/verify_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
constants::{PROOFS_DIR, PROOF_EXT, TARGET_DIR, VERIFIER_INPUT_FILE},
errors::CliError,
};
use acvm::{FieldElement, ProofSystemCompiler};
use acvm::ProofSystemCompiler;
use clap::Args;
use noirc_abi::input_parser::{Format, InputValue};
use noirc_driver::CompiledProgram;
Expand Down Expand Up @@ -54,7 +54,7 @@ fn verify_with_path<P: AsRef<Path>>(
}
None => {
let backend = crate::backends::ConcreteBackend;
backend.preprocess(compiled_program.circuit.clone())
backend.preprocess(&compiled_program.circuit)
}
};

Expand All @@ -64,35 +64,29 @@ fn verify_with_path<P: AsRef<Path>>(
read_inputs_from_file(program_dir, VERIFIER_INPUT_FILE, Format::Toml, &public_abi)?;

verify_proof(
compiled_program,
&compiled_program,
public_inputs_map,
return_value,
&load_hex_data(&proof_path)?,
verification_key,
&verification_key,
proof_path,
)
}

pub(crate) fn verify_proof(
compiled_program: CompiledProgram,
compiled_program: &CompiledProgram,
public_inputs_map: InputMap,
return_value: Option<InputValue>,
proof: &[u8],
verification_key: Vec<u8>,
verification_key: &[u8],
proof_name: PathBuf,
) -> Result<(), CliError> {
let public_abi = compiled_program.abi.public_abi();
let public_abi = compiled_program.abi.clone().public_abi();
let public_inputs = public_abi.encode(&public_inputs_map, return_value)?;

let public_inputs_vec: Vec<FieldElement> = public_inputs.values().copied().collect();

let backend = crate::backends::ConcreteBackend;
let valid_proof = backend.verify_with_vk(
proof,
public_inputs_vec,
compiled_program.circuit,
verification_key,
);
let valid_proof =
backend.verify_with_vk(proof, public_inputs, &compiled_program.circuit, verification_key);

if valid_proof {
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_evaluator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod ssa;
use acvm::{
acir::circuit::{opcodes::Opcode as AcirOpcode, Circuit, PublicInputs},
acir::native_types::{Expression, Witness},
compiler::fallback::IsBlackBoxSupported,
compiler::transformers::IsBlackBoxSupported,
Language,
};
use errors::{RuntimeError, RuntimeErrorKind};
Expand Down
1 change: 1 addition & 0 deletions crates/noirc_evaluator/src/ssa/acir_gen/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ pub(crate) fn to_radix_base(
a: lhs.clone(),
b: result.clone(),
radix,
is_little_endian: true,
}));

evaluator.opcodes.push(AcirOpcode::Arithmetic(subtract(lhs, FieldElement::one(), &bytes)));
Expand Down
6 changes: 6 additions & 0 deletions crates/noirc_evaluator/src/ssa/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ impl Opcode {
BlackBoxFunc::AES => {
todo!("ICE: AES is unimplemented")
}
BlackBoxFunc::Keccak256 => {
todo!("ICE: Keccak256 is unimplemented")
}
BlackBoxFunc::RANGE | BlackBoxFunc::AND | BlackBoxFunc::XOR => {
unimplemented!("ICE: these opcodes do not have Noir builtin functions")
}
Expand All @@ -86,6 +89,9 @@ impl Opcode {
Opcode::LowLevel(op) => {
match op {
BlackBoxFunc::AES => todo!("ICE: AES is unimplemented"),
BlackBoxFunc::Keccak256 => {
todo!("ICE: Keccak256 is unimplemented")
}
BlackBoxFunc::SHA256 | BlackBoxFunc::Blake2s => (32, ObjectType::Unsigned(8)),
BlackBoxFunc::HashToField128Security => (1, ObjectType::NativeField),
// See issue #775 on changing this to return a boolean
Expand Down
2 changes: 2 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// In code
//
"aeiou",
"arraysort",
"arithmetization",
"arity",
"barretenberg",
Expand All @@ -22,6 +23,7 @@
"injective",
"interner",
"intrinsics",
"keccak",
"krate",
"lvalue",
"merkle",
Expand Down