From 746cf0f05057a22e74a0da43603cb3e2dce6fe2d Mon Sep 17 00:00:00 2001 From: vezenovm Date: Mon, 6 May 2024 22:35:19 +0000 Subject: [PATCH 01/15] update bb gateCount command to take in a program in a single request --- barretenberg/cpp/src/barretenberg/bb/main.cpp | 14 ++++++++------ .../tooling/backend_interface/src/cli/gates.rs | 18 +++++++++--------- .../tooling/backend_interface/src/lib.rs | 1 + .../backend_interface/src/proof_system.rs | 2 +- .../tooling/nargo_cli/src/cli/info_cmd.rs | 15 ++++++++------- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index 9db639ea0a5..2d4af7dc6c8 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -302,13 +302,15 @@ void prove(const std::string& bytecodePath, const std::string& witnessPath, cons */ void gateCount(const std::string& bytecodePath) { - auto constraint_system = get_constraint_system(bytecodePath); - acir_proofs::AcirComposer acir_composer(0, verbose); - acir_composer.create_circuit(constraint_system); - auto gate_count = acir_composer.get_total_circuit_size(); + auto constraint_systems = get_constraint_systems(bytecodePath); + for (auto constraint_system : constraint_systems) { + acir_proofs::AcirComposer acir_composer(0, verbose); + acir_composer.create_circuit(constraint_system); + auto gate_count = acir_composer.get_total_circuit_size(); - writeUint64AsRawBytesToStdout(static_cast(gate_count)); - vinfo("gate count: ", gate_count); + writeUint64AsRawBytesToStdout(static_cast(gate_count)); + vinfo("gate count: ", gate_count); + } } /** diff --git a/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs b/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs index aca05f0232a..75d11a640e0 100644 --- a/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs +++ b/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs @@ -13,7 +13,7 @@ pub(crate) struct GatesCommand { } impl GatesCommand { - pub(crate) fn run(self, binary_path: &Path) -> Result { + pub(crate) fn run(self, binary_path: &Path) -> Result, BackendError> { let output = std::process::Command::new(binary_path) .arg("gates") .arg("-c") @@ -27,17 +27,17 @@ impl GatesCommand { } // Note: barretenberg includes the newline, so that subsequent prints to stdout // are not on the same line as the gates output. - const EXPECTED_BYTES: usize = 8; - let gates_bytes: [u8; EXPECTED_BYTES] = - output.stdout.as_slice().try_into().map_err(|_| { + let mut values = Vec::new(); + for value_bytes in output.stdout.chunks(8) { + // Convert bytes to u64 in little-endian format + let value = u64::from_le_bytes(value_bytes.try_into().map_err(|_| { BackendError::UnexpectedNumberOfBytes(EXPECTED_BYTES, output.stdout.clone()) - })?; - - // Convert bytes to u64 in little-endian format - let value = u64::from_le_bytes(gates_bytes); + })?); + values.push(value as u32) + } - Ok(value as u32) + Ok(values) } } diff --git a/noir/noir-repo/tooling/backend_interface/src/lib.rs b/noir/noir-repo/tooling/backend_interface/src/lib.rs index eab98852555..19ad28fa793 100644 --- a/noir/noir-repo/tooling/backend_interface/src/lib.rs +++ b/noir/noir-repo/tooling/backend_interface/src/lib.rs @@ -69,6 +69,7 @@ impl Backend { backends_directory().join(&name).join(BINARY_NAME) }; + Backend { name, binary_path } } diff --git a/noir/noir-repo/tooling/backend_interface/src/proof_system.rs b/noir/noir-repo/tooling/backend_interface/src/proof_system.rs index fa1f82a5722..43fd7cbd1ec 100644 --- a/noir/noir-repo/tooling/backend_interface/src/proof_system.rs +++ b/noir/noir-repo/tooling/backend_interface/src/proof_system.rs @@ -17,7 +17,7 @@ use crate::cli::{ use crate::{Backend, BackendError}; impl Backend { - pub fn get_exact_circuit_size(&self, program: &Program) -> Result { + pub fn get_exact_circuit_size(&self, program: &Program) -> Result, BackendError> { let binary_path = self.assert_binary_exists()?; self.assert_correct_version()?; diff --git a/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs b/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs index 3695fb57d31..9fb120ff416 100644 --- a/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs +++ b/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs @@ -280,10 +280,15 @@ impl From for Vec { fn count_opcodes_and_gates_in_program( backend: &Backend, - compiled_program: CompiledProgram, + mut compiled_program: CompiledProgram, package: &Package, expression_width: ExpressionWidth, ) -> Result { + // Unconstrained functions do not matter to a backend circuit count so we clear them + // before sending a serialized program to the backend + compiled_program.program.unconstrained_functions.clear(); + + let program_circuit_sizes = backend.get_exact_circuit_size(&compiled_program.program)?; let functions = compiled_program .program .functions @@ -293,11 +298,7 @@ fn count_opcodes_and_gates_in_program( Ok(FunctionInfo { name: compiled_program.names[i].clone(), acir_opcodes: function.opcodes.len(), - // Unconstrained functions do not matter to a backend circuit count so we pass nothing here - circuit_size: backend.get_exact_circuit_size(&Program { - functions: vec![function], - unconstrained_functions: Vec::new(), - })?, + circuit_size: program_circuit_sizes[i], }) }) .collect::>()?; @@ -318,7 +319,7 @@ fn count_opcodes_and_gates_in_contract( name: function.name, // TODO(https://github.com/noir-lang/noir/issues/4720) acir_opcodes: function.bytecode.functions[0].opcodes.len(), - circuit_size: backend.get_exact_circuit_size(&function.bytecode)?, + circuit_size: backend.get_exact_circuit_size(&function.bytecode)?[0], }) }) .collect::>()?; From 48ac058e07081fea56a24193eb7d6f8e8ccf25a5 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Mon, 6 May 2024 22:53:30 +0000 Subject: [PATCH 02/15] rename and diff cleanup --- noir/noir-repo/tooling/backend_interface/src/cli/gates.rs | 1 + noir/noir-repo/tooling/backend_interface/src/lib.rs | 1 - noir/noir-repo/tooling/backend_interface/src/proof_system.rs | 2 +- noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs | 4 ++-- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs b/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs index 75d11a640e0..79acec59417 100644 --- a/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs +++ b/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs @@ -27,6 +27,7 @@ impl GatesCommand { } // Note: barretenberg includes the newline, so that subsequent prints to stdout // are not on the same line as the gates output. + const EXPECTED_BYTES: usize = 8; let mut values = Vec::new(); for value_bytes in output.stdout.chunks(8) { diff --git a/noir/noir-repo/tooling/backend_interface/src/lib.rs b/noir/noir-repo/tooling/backend_interface/src/lib.rs index 19ad28fa793..eab98852555 100644 --- a/noir/noir-repo/tooling/backend_interface/src/lib.rs +++ b/noir/noir-repo/tooling/backend_interface/src/lib.rs @@ -69,7 +69,6 @@ impl Backend { backends_directory().join(&name).join(BINARY_NAME) }; - Backend { name, binary_path } } diff --git a/noir/noir-repo/tooling/backend_interface/src/proof_system.rs b/noir/noir-repo/tooling/backend_interface/src/proof_system.rs index 43fd7cbd1ec..f9a4b9c33e6 100644 --- a/noir/noir-repo/tooling/backend_interface/src/proof_system.rs +++ b/noir/noir-repo/tooling/backend_interface/src/proof_system.rs @@ -17,7 +17,7 @@ use crate::cli::{ use crate::{Backend, BackendError}; impl Backend { - pub fn get_exact_circuit_size(&self, program: &Program) -> Result, BackendError> { + pub fn get_exact_circuit_sizes(&self, program: &Program) -> Result, BackendError> { let binary_path = self.assert_binary_exists()?; self.assert_correct_version()?; diff --git a/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs b/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs index 9fb120ff416..2f2d71daef0 100644 --- a/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs +++ b/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs @@ -288,7 +288,7 @@ fn count_opcodes_and_gates_in_program( // before sending a serialized program to the backend compiled_program.program.unconstrained_functions.clear(); - let program_circuit_sizes = backend.get_exact_circuit_size(&compiled_program.program)?; + let program_circuit_sizes = backend.get_exact_circuit_sizes(&compiled_program.program)?; let functions = compiled_program .program .functions @@ -319,7 +319,7 @@ fn count_opcodes_and_gates_in_contract( name: function.name, // TODO(https://github.com/noir-lang/noir/issues/4720) acir_opcodes: function.bytecode.functions[0].opcodes.len(), - circuit_size: backend.get_exact_circuit_size(&function.bytecode)?[0], + circuit_size: backend.get_exact_circuit_sizes(&function.bytecode)?[0], }) }) .collect::>()?; From 54bc28f45e4101cd31a1662840d75429efabb9f2 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Tue, 7 May 2024 01:14:48 +0000 Subject: [PATCH 03/15] cargo clippy --- noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs b/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs index 2f2d71daef0..2446cd63ca8 100644 --- a/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs +++ b/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use acvm::acir::circuit::{ExpressionWidth, Program}; +use acvm::acir::circuit::ExpressionWidth; use backend_interface::BackendError; use clap::Args; use iter_extended::vecmap; From 989f41af2ed5ba844a07d8d7c92493238d71e9f9 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Tue, 7 May 2024 01:55:55 +0000 Subject: [PATCH 04/15] update gate command test --- .../acvm-repo/acvm_js/src/execute.rs | 31 +++++++++++++++++++ .../backend_interface/src/cli/gates.rs | 3 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/noir/noir-repo/acvm-repo/acvm_js/src/execute.rs b/noir/noir-repo/acvm-repo/acvm_js/src/execute.rs index 338511874c9..63dd568abc4 100644 --- a/noir/noir-repo/acvm-repo/acvm_js/src/execute.rs +++ b/noir/noir-repo/acvm-repo/acvm_js/src/execute.rs @@ -141,6 +141,37 @@ pub async fn execute_program( .await } +#[wasm_bindgen(js_name = executeProgramWithReturnWitness, skip_jsdoc)] +pub async fn execute_program_with_return_witness( + solver: &WasmBlackBoxFunctionSolver, + program: Vec, + initial_witness: JsWitnessMap, + foreign_call_executor: &ForeignCallHandler, +) -> Result { + console_error_panic_hook::set_once(); + + let program: Program = Program::deserialize_program(&program) + .map_err(|_| JsExecutionError::new("Failed to deserialize circuit. This is likely due to differing serialization formats between ACVM_JS and your compiler".to_string(), None, None))?; + + let mut witness_stack = execute_program_with_native_program_and_return( + solver, + &program, + initial_witness, + &foreign_call_handler, + ) + .await?; + let solved_witness = + witness_stack.pop().expect("Should have at least one witness on the stack").witness; + + let main_circuit = &program.functions[0]; + let return_witness = + extract_indices(&solved_witness, main_circuit.return_values.0.iter().copied().collect()) + .map_err(|err| JsExecutionError::new(err, None, None))?; + + Ok((solved_witness, return_witness).into()) +} + + #[wasm_bindgen(js_name = executeProgramWithBlackBoxSolver, skip_jsdoc)] pub async fn execute_program_with_black_box_solver( solver: &WasmBlackBoxFunctionSolver, diff --git a/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs b/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs index 79acec59417..d8f42b26e6e 100644 --- a/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs +++ b/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs @@ -59,7 +59,8 @@ fn gate_command() -> Result<(), BackendError> { let output = gate_command.run(backend.binary_path())?; // Mock backend always returns zero gates. - assert_eq!(output, 0); + assert_eq!(output.len(), 1); + assert_eq!(output[0], 0); Ok(()) } From eb57f08385f78a3df1e710fcdac734cdd066747d Mon Sep 17 00:00:00 2001 From: vezenovm Date: Tue, 7 May 2024 01:56:41 +0000 Subject: [PATCH 05/15] remove accidentally committed method --- .../acvm-repo/acvm_js/src/execute.rs | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/noir/noir-repo/acvm-repo/acvm_js/src/execute.rs b/noir/noir-repo/acvm-repo/acvm_js/src/execute.rs index 63dd568abc4..338511874c9 100644 --- a/noir/noir-repo/acvm-repo/acvm_js/src/execute.rs +++ b/noir/noir-repo/acvm-repo/acvm_js/src/execute.rs @@ -141,37 +141,6 @@ pub async fn execute_program( .await } -#[wasm_bindgen(js_name = executeProgramWithReturnWitness, skip_jsdoc)] -pub async fn execute_program_with_return_witness( - solver: &WasmBlackBoxFunctionSolver, - program: Vec, - initial_witness: JsWitnessMap, - foreign_call_executor: &ForeignCallHandler, -) -> Result { - console_error_panic_hook::set_once(); - - let program: Program = Program::deserialize_program(&program) - .map_err(|_| JsExecutionError::new("Failed to deserialize circuit. This is likely due to differing serialization formats between ACVM_JS and your compiler".to_string(), None, None))?; - - let mut witness_stack = execute_program_with_native_program_and_return( - solver, - &program, - initial_witness, - &foreign_call_handler, - ) - .await?; - let solved_witness = - witness_stack.pop().expect("Should have at least one witness on the stack").witness; - - let main_circuit = &program.functions[0]; - let return_witness = - extract_indices(&solved_witness, main_circuit.return_values.0.iter().copied().collect()) - .map_err(|err| JsExecutionError::new(err, None, None))?; - - Ok((solved_witness, return_witness).into()) -} - - #[wasm_bindgen(js_name = executeProgramWithBlackBoxSolver, skip_jsdoc)] pub async fn execute_program_with_black_box_solver( solver: &WasmBlackBoxFunctionSolver, From ce96f48711bbac2c557ee4315fb19cf9bcc18b6f Mon Sep 17 00:00:00 2001 From: vezenovm Date: Wed, 8 May 2024 18:51:08 +0000 Subject: [PATCH 06/15] return json from gateCount and adapt nargo info to use it, also initial workspace shell script to start removing nargo info --- barretenberg/cpp/src/barretenberg/bb/main.cpp | 42 +++++++++++++++++-- .../dsl/acir_format/acir_format.hpp | 2 + .../acir_format/acir_to_constraint_buf.hpp | 1 + noir-projects/Earthfile | 4 +- noir-projects/gates_report.sh | 35 ++++++++++++++++ .../backend_interface/src/cli/gates.rs | 31 +++++++------- .../tooling/backend_interface/src/cli/mod.rs | 2 + .../backend_interface/src/proof_system.rs | 7 +++- .../tooling/nargo_cli/src/cli/compile_cmd.rs | 2 +- .../tooling/nargo_cli/src/cli/fs/program.rs | 9 +++- .../tooling/nargo_cli/src/cli/info_cmd.rs | 8 ++-- 11 files changed, 115 insertions(+), 28 deletions(-) create mode 100755 noir-projects/gates_report.sh diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index 2d4af7dc6c8..1d972ad8748 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -17,9 +17,12 @@ #include #include #include +#include #include +#include #include #include +// #include #include #include @@ -296,21 +299,52 @@ void prove(const std::string& bytecodePath, const std::string& witnessPath, cons * @brief Computes the number of Barretenberg specific gates needed to create a proof for the specific ACIR circuit * * Communication: - * - stdout: The number of gates is written to stdout + * - stdout: A JSON string of the number of ACIR opcodes and final backend circuit size * * @param bytecodePath Path to the file containing the serialized circuit */ void gateCount(const std::string& bytecodePath) { + // All circuit reports will be built into the string below + std::string functions_string = "{\"functions\": [\n "; auto constraint_systems = get_constraint_systems(bytecodePath); + size_t i = 0; for (auto constraint_system : constraint_systems) { acir_proofs::AcirComposer acir_composer(0, verbose); acir_composer.create_circuit(constraint_system); - auto gate_count = acir_composer.get_total_circuit_size(); + auto circuit_size = acir_composer.get_total_circuit_size(); + + // Build individual circuit report + auto result_string = format("{\n \"acir_opcodes\": ", + constraint_system.num_acir_opcodes, + ",\n \"circuit_size\": ", + circuit_size, + "\n }"); + + // Attach a comma if we still circuit reports to generate + if (i != (constraint_systems.size() - 1)) { + result_string = format(result_string, ","); + } + + functions_string = format(functions_string, result_string); - writeUint64AsRawBytesToStdout(static_cast(gate_count)); - vinfo("gate count: ", gate_count); + i++; } + functions_string = format(functions_string, "\n]}"); + + const char* jsonData = functions_string.c_str(); + size_t length = strlen(jsonData); + std::vector data(jsonData, jsonData + length); + writeRawBytesToStdout(data); + + // TODO(maxim): allow writing to the output path + // if (output_path == "-") { + // writeRawBytesToStdout(data); + // vinfo("info written to stdout"); + // } else { + // write_file(output_path, data); + // vinfo("info written to: ", output_path); + // } } /** diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp index 8b7823260d0..9add17a1451 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp @@ -32,6 +32,8 @@ struct AcirFormat { // to be able to verify SNARKs on Ethereum. bool recursive; + uint32_t num_acir_opcodes; + std::vector public_inputs; std::vector logic_constraints; diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 110087d40af..3e77b60d689 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -477,6 +477,7 @@ AcirFormat circuit_serde_to_acir_format(Program::Circuit const& circuit) // `varnum` is the true number of variables, thus we add one to the index which starts at zero af.varnum = circuit.current_witness_index + 1; af.recursive = circuit.recursive; + af.num_acir_opcodes = static_cast(circuit.opcodes.size()); af.public_inputs = join({ map(circuit.public_parameters.value, [](auto e) { return e.value; }), map(circuit.return_values.value, [](auto e) { return e.value; }) }); std::map block_id_to_block_constraint; diff --git a/noir-projects/Earthfile b/noir-projects/Earthfile index 645eddc4973..2baf9e78007 100644 --- a/noir-projects/Earthfile +++ b/noir-projects/Earthfile @@ -32,10 +32,12 @@ test: gates-report: FROM +build + WORKDIR /usr/src/noir-projects/ + WORKDIR /usr/src/noir-projects/noir-protocol-circuits COPY ../barretenberg/cpp/+preset-clang-assert/bin/bb /usr/src/barretenberg/cpp/build/bin/bb RUN NARGO_BACKEND_PATH=/usr/src/barretenberg/cpp/build/bin/bb nargo info --json > gates_report.json - + SAVE ARTIFACT gates_report.json gates_report.json \ No newline at end of file diff --git a/noir-projects/gates_report.sh b/noir-projects/gates_report.sh new file mode 100755 index 00000000000..0d767242814 --- /dev/null +++ b/noir-projects/gates_report.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -eu + +echo "Compile noir-protocol-circuits for gates report..." +cd noir-protocol-circuits +PROTOCOL_CIRCUITS_DIR=$PWD + +# Compile programs into artifacts that the backend expects +NARGO=${NARGO:-../../noir/noir-repo/target/release/nargo} +$NARGO compile --only-acir + +BB_BIN=${BB_BIN:-../../barretenberg/cpp/build/bin/bb} + +echo "{\"programs\": [" > gates_report.json + +# Bound for checking where to place last parentheses +NUM_ARTIFACTS=$(ls -1q "$PROTOCOL_CIRCUITS_DIR/target"/*.gz | wc -l) + +ITER="1" +for pathname in "$PROTOCOL_CIRCUITS_DIR/target"/*.gz; do + ARTIFACT_NAME=$(basename -s .gz "$pathname") + + echo "{\"package_name\": \"$ARTIFACT_NAME\"," >> gates_report.json + $BB_BIN gates -b "./target/$ARTIFACT_NAME.gz" >> gates_report.json + + if (($ITER == $NUM_ARTIFACTS)); then + echo "}" >> gates_report.json + else + echo "}, " >> gates_report.json + fi + + ITER=$(( $ITER + 1 )) +done + +echo "]}" >> gates_report.json \ No newline at end of file diff --git a/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs b/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs index d8f42b26e6e..9d3d4dc0f39 100644 --- a/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs +++ b/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs @@ -1,3 +1,4 @@ +use serde::Deserialize; use std::path::{Path, PathBuf}; use crate::BackendError; @@ -12,8 +13,19 @@ pub(crate) struct GatesCommand { pub(crate) bytecode_path: PathBuf, } +#[derive(Deserialize, Clone, Debug)] +struct GatesResponse { + functions: Vec, +} + +#[derive(Deserialize, Clone, Debug)] +pub struct CircuitReport { + pub acir_opcodes: u32, + pub circuit_size: u32, +} + impl GatesCommand { - pub(crate) fn run(self, binary_path: &Path) -> Result, BackendError> { + pub(crate) fn run(self, binary_path: &Path) -> Result, BackendError> { let output = std::process::Command::new(binary_path) .arg("gates") .arg("-c") @@ -25,20 +37,11 @@ impl GatesCommand { if !output.status.success() { return Err(BackendError::CommandFailed(string_from_stderr(&output.stderr))); } - // Note: barretenberg includes the newline, so that subsequent prints to stdout - // are not on the same line as the gates output. - - const EXPECTED_BYTES: usize = 8; - let mut values = Vec::new(); - for value_bytes in output.stdout.chunks(8) { - // Convert bytes to u64 in little-endian format - let value = u64::from_le_bytes(value_bytes.try_into().map_err(|_| { - BackendError::UnexpectedNumberOfBytes(EXPECTED_BYTES, output.stdout.clone()) - })?); - values.push(value as u32) - } - Ok(values) + let gates_info: GatesResponse = + serde_json::from_slice(&output.stdout).expect("Backend should return valid json"); + + Ok(gates_info.functions) } } diff --git a/noir/noir-repo/tooling/backend_interface/src/cli/mod.rs b/noir/noir-repo/tooling/backend_interface/src/cli/mod.rs index b4dec859839..e6d42a54cb9 100644 --- a/noir/noir-repo/tooling/backend_interface/src/cli/mod.rs +++ b/noir/noir-repo/tooling/backend_interface/src/cli/mod.rs @@ -20,6 +20,8 @@ pub(crate) use version::VersionCommand; pub(crate) use vk_as_fields::VkAsFieldsCommand; pub(crate) use write_vk::WriteVkCommand; +pub use gates::CircuitReport; + #[test] fn no_command_provided_works() -> Result<(), crate::BackendError> { // This is a simple test to check that the binaries work diff --git a/noir/noir-repo/tooling/backend_interface/src/proof_system.rs b/noir/noir-repo/tooling/backend_interface/src/proof_system.rs index f9a4b9c33e6..303f1c023c9 100644 --- a/noir/noir-repo/tooling/backend_interface/src/proof_system.rs +++ b/noir/noir-repo/tooling/backend_interface/src/proof_system.rs @@ -11,13 +11,16 @@ use tempfile::tempdir; use tracing::warn; use crate::cli::{ - GatesCommand, InfoCommand, ProofAsFieldsCommand, ProveCommand, VerifyCommand, + CircuitReport, GatesCommand, InfoCommand, ProofAsFieldsCommand, ProveCommand, VerifyCommand, VkAsFieldsCommand, WriteVkCommand, }; use crate::{Backend, BackendError}; impl Backend { - pub fn get_exact_circuit_sizes(&self, program: &Program) -> Result, BackendError> { + pub fn get_exact_circuit_sizes( + &self, + program: &Program, + ) -> Result, BackendError> { let binary_path = self.assert_binary_exists()?; self.assert_correct_version()?; diff --git a/noir/noir-repo/tooling/nargo_cli/src/cli/compile_cmd.rs b/noir/noir-repo/tooling/nargo_cli/src/cli/compile_cmd.rs index 54e8535f094..85417bb3138 100644 --- a/noir/noir-repo/tooling/nargo_cli/src/cli/compile_cmd.rs +++ b/noir/noir-repo/tooling/nargo_cli/src/cli/compile_cmd.rs @@ -215,7 +215,7 @@ pub(super) fn save_program( only_acir_opt: bool, ) { if only_acir_opt { - only_acir(program.program, circuit_dir); + only_acir(program.program, &package.name, circuit_dir); } else { let program_artifact = ProgramArtifact::from(program.clone()); save_program_to_file(&program_artifact, &package.name, circuit_dir); diff --git a/noir/noir-repo/tooling/nargo_cli/src/cli/fs/program.rs b/noir/noir-repo/tooling/nargo_cli/src/cli/fs/program.rs index 77005e8d5af..fd3d94918cc 100644 --- a/noir/noir-repo/tooling/nargo_cli/src/cli/fs/program.rs +++ b/noir/noir-repo/tooling/nargo_cli/src/cli/fs/program.rs @@ -18,9 +18,14 @@ pub(crate) fn save_program_to_file>( } /// Writes the bytecode as acir.gz -pub(crate) fn only_acir>(program: Program, circuit_dir: P) -> PathBuf { +pub(crate) fn only_acir>( + program: Program, + crate_name: &CrateName, + circuit_dir: P, +) -> PathBuf { create_named_dir(circuit_dir.as_ref(), "target"); - let circuit_path = circuit_dir.as_ref().join("acir").with_extension("gz"); + let name: String = crate_name.into(); + let circuit_path = circuit_dir.as_ref().join(&name).with_extension("gz"); let bytes = Program::serialize_program(&program); write_to_file(&bytes, &circuit_path); diff --git a/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs b/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs index 2446cd63ca8..48e3fb78678 100644 --- a/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs +++ b/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs @@ -294,11 +294,11 @@ fn count_opcodes_and_gates_in_program( .functions .into_par_iter() .enumerate() - .map(|(i, function)| -> Result<_, BackendError> { + .map(|(i, _)| -> Result<_, BackendError> { Ok(FunctionInfo { name: compiled_program.names[i].clone(), - acir_opcodes: function.opcodes.len(), - circuit_size: program_circuit_sizes[i], + acir_opcodes: program_circuit_sizes[i].acir_opcodes as usize, + circuit_size: program_circuit_sizes[i].circuit_size, }) }) .collect::>()?; @@ -319,7 +319,7 @@ fn count_opcodes_and_gates_in_contract( name: function.name, // TODO(https://github.com/noir-lang/noir/issues/4720) acir_opcodes: function.bytecode.functions[0].opcodes.len(), - circuit_size: backend.get_exact_circuit_sizes(&function.bytecode)?[0], + circuit_size: backend.get_exact_circuit_sizes(&function.bytecode)?[0].circuit_size, }) }) .collect::>()?; From 1b2c761c609445b75b2df096c8d9841f955b9b72 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Wed, 8 May 2024 18:53:07 +0000 Subject: [PATCH 07/15] remove earthfile changes and unnecessary imports --- barretenberg/cpp/src/barretenberg/bb/main.cpp | 2 -- noir-projects/Earthfile | 3 --- 2 files changed, 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index 1d972ad8748..83ba1496987 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -17,12 +17,10 @@ #include #include #include -#include #include #include #include #include -// #include #include #include diff --git a/noir-projects/Earthfile b/noir-projects/Earthfile index 2baf9e78007..71e13896267 100644 --- a/noir-projects/Earthfile +++ b/noir-projects/Earthfile @@ -32,12 +32,9 @@ test: gates-report: FROM +build - WORKDIR /usr/src/noir-projects/ - WORKDIR /usr/src/noir-projects/noir-protocol-circuits COPY ../barretenberg/cpp/+preset-clang-assert/bin/bb /usr/src/barretenberg/cpp/build/bin/bb RUN NARGO_BACKEND_PATH=/usr/src/barretenberg/cpp/build/bin/bb nargo info --json > gates_report.json - SAVE ARTIFACT gates_report.json gates_report.json \ No newline at end of file From 77e65ce54fe9881bd0414481722a31cfe99ff14d Mon Sep 17 00:00:00 2001 From: vezenovm Date: Wed, 8 May 2024 19:00:29 +0000 Subject: [PATCH 08/15] update issue on gates report script --- noir-projects/gates_report.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/noir-projects/gates_report.sh b/noir-projects/gates_report.sh index 0d767242814..daba486cba0 100755 --- a/noir-projects/gates_report.sh +++ b/noir-projects/gates_report.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash set -eu +# TODO(https://github.com/noir-lang/noir/issues/4962): This script is still yet to be integrated with noir-lang/noir-gates-diff +# The script needs some slight updating as `nargo info` expects a complete JSON object, while this script expects a single object field +# representing a list of circuit reports for a program. echo "Compile noir-protocol-circuits for gates report..." cd noir-protocol-circuits PROTOCOL_CIRCUITS_DIR=$PWD From 20661684409d6171e8e5525acf6fd8fac6977264 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Wed, 8 May 2024 19:07:03 +0000 Subject: [PATCH 09/15] revert only acir naming changes --- noir-projects/gates_report.sh | 1 + noir/noir-repo/tooling/nargo_cli/src/cli/compile_cmd.rs | 2 +- noir/noir-repo/tooling/nargo_cli/src/cli/fs/program.rs | 9 ++------- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/noir-projects/gates_report.sh b/noir-projects/gates_report.sh index daba486cba0..affbf07d1f4 100755 --- a/noir-projects/gates_report.sh +++ b/noir-projects/gates_report.sh @@ -4,6 +4,7 @@ set -eu # TODO(https://github.com/noir-lang/noir/issues/4962): This script is still yet to be integrated with noir-lang/noir-gates-diff # The script needs some slight updating as `nargo info` expects a complete JSON object, while this script expects a single object field # representing a list of circuit reports for a program. +# The ACIR tests in barretenberg also expect every target bytecode to have the name `acir.gz` while this script expects the same name of the package echo "Compile noir-protocol-circuits for gates report..." cd noir-protocol-circuits PROTOCOL_CIRCUITS_DIR=$PWD diff --git a/noir/noir-repo/tooling/nargo_cli/src/cli/compile_cmd.rs b/noir/noir-repo/tooling/nargo_cli/src/cli/compile_cmd.rs index 85417bb3138..54e8535f094 100644 --- a/noir/noir-repo/tooling/nargo_cli/src/cli/compile_cmd.rs +++ b/noir/noir-repo/tooling/nargo_cli/src/cli/compile_cmd.rs @@ -215,7 +215,7 @@ pub(super) fn save_program( only_acir_opt: bool, ) { if only_acir_opt { - only_acir(program.program, &package.name, circuit_dir); + only_acir(program.program, circuit_dir); } else { let program_artifact = ProgramArtifact::from(program.clone()); save_program_to_file(&program_artifact, &package.name, circuit_dir); diff --git a/noir/noir-repo/tooling/nargo_cli/src/cli/fs/program.rs b/noir/noir-repo/tooling/nargo_cli/src/cli/fs/program.rs index fd3d94918cc..77005e8d5af 100644 --- a/noir/noir-repo/tooling/nargo_cli/src/cli/fs/program.rs +++ b/noir/noir-repo/tooling/nargo_cli/src/cli/fs/program.rs @@ -18,14 +18,9 @@ pub(crate) fn save_program_to_file>( } /// Writes the bytecode as acir.gz -pub(crate) fn only_acir>( - program: Program, - crate_name: &CrateName, - circuit_dir: P, -) -> PathBuf { +pub(crate) fn only_acir>(program: Program, circuit_dir: P) -> PathBuf { create_named_dir(circuit_dir.as_ref(), "target"); - let name: String = crate_name.into(); - let circuit_path = circuit_dir.as_ref().join(&name).with_extension("gz"); + let circuit_path = circuit_dir.as_ref().join("acir").with_extension("gz"); let bytes = Program::serialize_program(&program); write_to_file(&bytes, &circuit_path); From 51391633538c00f87f694583d2ad77208d43c7c4 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Wed, 8 May 2024 19:12:37 +0000 Subject: [PATCH 10/15] cleanup bb main and fix noir backend_interface gates test --- barretenberg/cpp/src/barretenberg/bb/main.cpp | 10 ---------- .../tooling/backend_interface/src/cli/gates.rs | 3 ++- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index 83ba1496987..820cc522ad7 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -334,15 +333,6 @@ void gateCount(const std::string& bytecodePath) size_t length = strlen(jsonData); std::vector data(jsonData, jsonData + length); writeRawBytesToStdout(data); - - // TODO(maxim): allow writing to the output path - // if (output_path == "-") { - // writeRawBytesToStdout(data); - // vinfo("info written to stdout"); - // } else { - // write_file(output_path, data); - // vinfo("info written to: ", output_path); - // } } /** diff --git a/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs b/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs index 9d3d4dc0f39..d30c5454650 100644 --- a/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs +++ b/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs @@ -63,7 +63,8 @@ fn gate_command() -> Result<(), BackendError> { let output = gate_command.run(backend.binary_path())?; // Mock backend always returns zero gates. assert_eq!(output.len(), 1); - assert_eq!(output[0], 0); + assert_eq!(output[0].acir_opcodes, 0); + assert_eq!(output[0].circuit_size, 0); Ok(()) } From 3bb1ae73bceb8db69cdf11984c5d5ffcf19d0411 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Wed, 8 May 2024 19:14:59 +0000 Subject: [PATCH 11/15] clippy --- noir/noir-repo/tooling/backend_interface/src/cli/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noir/noir-repo/tooling/backend_interface/src/cli/mod.rs b/noir/noir-repo/tooling/backend_interface/src/cli/mod.rs index e6d42a54cb9..1da21e1724a 100644 --- a/noir/noir-repo/tooling/backend_interface/src/cli/mod.rs +++ b/noir/noir-repo/tooling/backend_interface/src/cli/mod.rs @@ -20,7 +20,7 @@ pub(crate) use version::VersionCommand; pub(crate) use vk_as_fields::VkAsFieldsCommand; pub(crate) use write_vk::WriteVkCommand; -pub use gates::CircuitReport; +pub(crate) use gates::CircuitReport; #[test] fn no_command_provided_works() -> Result<(), crate::BackendError> { From ec4d2537a4730086d7b3a7d26d707ff825e24e00 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Wed, 8 May 2024 19:54:28 +0000 Subject: [PATCH 12/15] bring back serde to backend_interface --- noir/noir-repo/Cargo.lock | 1 + noir/noir-repo/tooling/backend_interface/Cargo.toml | 1 + noir/noir-repo/tooling/backend_interface/src/cli/gates.rs | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/noir/noir-repo/Cargo.lock b/noir/noir-repo/Cargo.lock index a8c63c032aa..859579c077f 100644 --- a/noir/noir-repo/Cargo.lock +++ b/noir/noir-repo/Cargo.lock @@ -462,6 +462,7 @@ dependencies = [ "dirs", "flate2", "reqwest", + "serde", "serde_json", "tar", "tempfile", diff --git a/noir/noir-repo/tooling/backend_interface/Cargo.toml b/noir/noir-repo/tooling/backend_interface/Cargo.toml index f6b5d5d0132..b731c138c7d 100644 --- a/noir/noir-repo/tooling/backend_interface/Cargo.toml +++ b/noir/noir-repo/tooling/backend_interface/Cargo.toml @@ -13,6 +13,7 @@ license.workspace = true acvm.workspace = true dirs.workspace = true thiserror.workspace = true +serde.workspace = true serde_json.workspace = true bb_abstraction_leaks.workspace = true tracing.workspace = true diff --git a/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs b/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs index d30c5454650..47932f26a65 100644 --- a/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs +++ b/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs @@ -13,12 +13,12 @@ pub(crate) struct GatesCommand { pub(crate) bytecode_path: PathBuf, } -#[derive(Deserialize, Clone, Debug)] +#[derive(Deserialize)] struct GatesResponse { functions: Vec, } -#[derive(Deserialize, Clone, Debug)] +#[derive(Deserialize)] pub struct CircuitReport { pub acir_opcodes: u32, pub circuit_size: u32, From 33ad37816e4a53cf3b83f064167851d9056985c3 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Wed, 8 May 2024 20:13:08 +0000 Subject: [PATCH 13/15] add field to AcirFormat for gcc build? --- .../src/barretenberg/dsl/acir_format/acir_format.test.cpp | 6 ++++++ .../barretenberg/dsl/acir_format/bigint_constraint.test.cpp | 5 +++++ .../barretenberg/dsl/acir_format/block_constraint.test.cpp | 1 + .../src/barretenberg/dsl/acir_format/ec_operations.test.cpp | 1 + .../barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp | 3 +++ .../barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp | 4 ++++ .../dsl/acir_format/poseidon2_constraint.test.cpp | 1 + .../dsl/acir_format/recursion_constraint.test.cpp | 2 ++ .../barretenberg/dsl/acir_format/sha256_constraint.test.cpp | 1 + 9 files changed, 24 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp index 2d23b057c64..038db2a28f9 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp @@ -32,6 +32,7 @@ TEST_F(AcirFormatTests, TestASingleConstraintNoPubInputs) AcirFormat constraint_system{ .varnum = 4, .recursive = false, + .num_acir_opcodes = 1, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, @@ -149,6 +150,7 @@ TEST_F(AcirFormatTests, TestLogicGateFromNoirCircuit) AcirFormat constraint_system{ .varnum = 6, .recursive = false, + .num_acir_opcodes = 7, .public_inputs = { 1 }, .logic_constraints = { logic_constraint }, .range_constraints = { range_a, range_b }, @@ -218,6 +220,7 @@ TEST_F(AcirFormatTests, TestSchnorrVerifyPass) }; AcirFormat constraint_system{ .varnum = 81, .recursive = false, + .num_acir_opcodes = 75, .public_inputs = {}, .logic_constraints = {}, .range_constraints = range_constraints, @@ -314,6 +317,7 @@ TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange) AcirFormat constraint_system{ .varnum = 81, .recursive = false, + .num_acir_opcodes = 75, .public_inputs = {}, .logic_constraints = {}, .range_constraints = range_constraints, @@ -429,6 +433,7 @@ TEST_F(AcirFormatTests, TestVarKeccak) AcirFormat constraint_system{ .varnum = 36, .recursive = false, + .num_acir_opcodes = 6, .public_inputs = {}, .logic_constraints = {}, .range_constraints = { range_a, range_b, range_c, range_d }, @@ -477,6 +482,7 @@ TEST_F(AcirFormatTests, TestKeccakPermutation) AcirFormat constraint_system{ .varnum = 51, .recursive = false, + .num_acir_opcodes = 1, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp index 863737703ef..1cc86262bd1 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp @@ -169,6 +169,7 @@ TEST_F(BigIntTests, TestBigIntConstraintMultiple) AcirFormat constraint_system{ .varnum = static_cast(witness.size() + 1), .recursive = false, + .num_acir_opcodes = 5, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, @@ -238,6 +239,7 @@ TEST_F(BigIntTests, TestBigIntConstraintSimple) AcirFormat constraint_system{ .varnum = 5, .recursive = false, + .num_acir_opcodes = 3, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, @@ -292,6 +294,7 @@ TEST_F(BigIntTests, TestBigIntConstraintReuse) AcirFormat constraint_system{ .varnum = static_cast(witness.size() + 1), .recursive = false, + .num_acir_opcodes = 5, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, @@ -350,6 +353,7 @@ TEST_F(BigIntTests, TestBigIntConstraintReuse2) AcirFormat constraint_system{ .varnum = static_cast(witness.size() + 1), .recursive = false, + .num_acir_opcodes = 5, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, @@ -429,6 +433,7 @@ TEST_F(BigIntTests, TestBigIntDIV) AcirFormat constraint_system{ .varnum = 5, .recursive = false, + .num_acir_opcodes = 4, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp index 7cb3e5955bd..5d649d8feb3 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp @@ -111,6 +111,7 @@ TEST_F(UltraPlonkRAM, TestBlockConstraint) AcirFormat constraint_system{ .varnum = static_cast(num_variables), .recursive = false, + .num_acir_opcodes = 7, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.test.cpp index fb676af0a8b..65be4aaae55 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.test.cpp @@ -51,6 +51,7 @@ TEST_F(EcOperations, TestECOperations) AcirFormat constraint_system{ .varnum = static_cast(num_variables + 1), .recursive = false, + .num_acir_opcodes = 1, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp index 20dddfe4abe..61782002c85 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp @@ -91,6 +91,7 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintSucceed) AcirFormat constraint_system{ .varnum = static_cast(num_variables), .recursive = false, + .num_acir_opcodes = 1, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, @@ -141,6 +142,7 @@ TEST_F(ECDSASecp256k1, TestECDSACompilesForVerifier) AcirFormat constraint_system{ .varnum = static_cast(num_variables), .recursive = false, + .num_acir_opcodes = 1, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, @@ -186,6 +188,7 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintFail) AcirFormat constraint_system{ .varnum = static_cast(num_variables), .recursive = false, + .num_acir_opcodes = 1, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp index 6217149fdf0..de1d0931d8c 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp @@ -125,6 +125,7 @@ TEST(ECDSASecp256r1, test_hardcoded) AcirFormat constraint_system{ .varnum = static_cast(num_variables), .recursive = false, + .num_acir_opcodes = 1, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, @@ -177,6 +178,7 @@ TEST(ECDSASecp256r1, TestECDSAConstraintSucceed) AcirFormat constraint_system{ .varnum = static_cast(num_variables), .recursive = false, + .num_acir_opcodes = 1, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, @@ -227,6 +229,7 @@ TEST(ECDSASecp256r1, TestECDSACompilesForVerifier) AcirFormat constraint_system{ .varnum = static_cast(num_variables), .recursive = false, + .num_acir_opcodes = 1, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, @@ -272,6 +275,7 @@ TEST(ECDSASecp256r1, TestECDSAConstraintFail) AcirFormat constraint_system{ .varnum = static_cast(num_variables), .recursive = false, + .num_acir_opcodes = 1, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.test.cpp index d35a9d36974..4922c63cd69 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.test.cpp @@ -31,6 +31,7 @@ TEST_F(Poseidon2Tests, TestPoseidon2Permutation) AcirFormat constraint_system{ .varnum = 9, .recursive = false, + .num_acir_opcodes = 1, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp index 0b12a411951..b837f94ba2a 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp @@ -83,6 +83,7 @@ Builder create_inner_circuit() AcirFormat constraint_system{ .varnum = 6, .recursive = true, + .num_acir_opcodes = 7, .public_inputs = { 1, 2 }, .logic_constraints = { logic_constraint }, .range_constraints = { range_a, range_b }, @@ -241,6 +242,7 @@ Builder create_outer_circuit(std::vector& inner_circuits) AcirFormat constraint_system{ .varnum = static_cast(witness.size()), .recursive = false, + .num_acir_opcodes = static_cast(recursion_constraints.size()), .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.test.cpp index 4b78a9550e7..5af032bedd1 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.test.cpp @@ -33,6 +33,7 @@ TEST_F(Sha256Tests, TestSha256Compression) AcirFormat constraint_system{ .varnum = 34, .recursive = false, + .num_acir_opcodes = 1, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, From e527d25a5c3d979281c2f215b1842e4a46808bfe Mon Sep 17 00:00:00 2001 From: Tom French Date: Wed, 8 May 2024 22:52:54 +0100 Subject: [PATCH 14/15] chore: fix tests --- .../test-binaries/mock_backend/src/gates_cmd.rs | 4 +++- noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/gates_cmd.rs b/noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/gates_cmd.rs index 3cc397d3292..eba39bbc031 100644 --- a/noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/gates_cmd.rs +++ b/noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/gates_cmd.rs @@ -14,5 +14,7 @@ pub(crate) struct GatesCommand { pub(crate) fn run(args: GatesCommand) { assert!(args.bytecode_path.is_file(), "Could not find bytecode file at provided path"); - std::io::stdout().write_all(&0u64.to_le_bytes()).unwrap(); + let response: &str = r#"{ "functions": [{"acir_opcodes": 123, "circuit_size": 123 }] }"#; + + std::io::stdout().write_all(response.as_bytes()).unwrap(); } diff --git a/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs b/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs index def63714f57..f8f645d3c3a 100644 --- a/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs +++ b/noir/noir-repo/tooling/nargo_cli/src/cli/info_cmd.rs @@ -297,10 +297,11 @@ fn count_opcodes_and_gates_in_program( .functions .into_par_iter() .enumerate() - .map(|(i, _)| -> Result<_, BackendError> { + .map(|(i, function)| -> Result<_, BackendError> { Ok(FunctionInfo { name: compiled_program.names[i].clone(), - acir_opcodes: program_circuit_sizes[i].acir_opcodes as usize, + // Required while mock backend doesn't return correct circuit size. + acir_opcodes: function.opcodes.len(), circuit_size: program_circuit_sizes[i].circuit_size, }) }) From ca9b94c5e836f367aa80a8c884592e86c3d39b96 Mon Sep 17 00:00:00 2001 From: Tom French Date: Wed, 8 May 2024 23:35:24 +0100 Subject: [PATCH 15/15] chore: update test --- noir/noir-repo/tooling/backend_interface/src/cli/gates.rs | 4 ++-- .../test-binaries/mock_backend/src/gates_cmd.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs b/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs index 47932f26a65..9e12596bfd7 100644 --- a/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs +++ b/noir/noir-repo/tooling/backend_interface/src/cli/gates.rs @@ -63,8 +63,8 @@ fn gate_command() -> Result<(), BackendError> { let output = gate_command.run(backend.binary_path())?; // Mock backend always returns zero gates. assert_eq!(output.len(), 1); - assert_eq!(output[0].acir_opcodes, 0); - assert_eq!(output[0].circuit_size, 0); + assert_eq!(output[0].acir_opcodes, 123); + assert_eq!(output[0].circuit_size, 125); Ok(()) } diff --git a/noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/gates_cmd.rs b/noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/gates_cmd.rs index eba39bbc031..0cebfbca42d 100644 --- a/noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/gates_cmd.rs +++ b/noir/noir-repo/tooling/backend_interface/test-binaries/mock_backend/src/gates_cmd.rs @@ -14,7 +14,7 @@ pub(crate) struct GatesCommand { pub(crate) fn run(args: GatesCommand) { assert!(args.bytecode_path.is_file(), "Could not find bytecode file at provided path"); - let response: &str = r#"{ "functions": [{"acir_opcodes": 123, "circuit_size": 123 }] }"#; + let response: &str = r#"{ "functions": [{"acir_opcodes": 123, "circuit_size": 125 }] }"#; std::io::stdout().write_all(response.as_bytes()).unwrap(); }