From 8079f601a23219ddd96f01064d0c31c6e8109471 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Thu, 9 May 2024 12:12:33 +0100 Subject: [PATCH] chore(dsl): Update backend gateCount command to query a Program in a single request (#6228) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves https://github.com/AztecProtocol/aztec-packages/issues/6168 This PR does a very minor update to simply now go through the entire list of functions contained inside of a Program and generate a basic circuit report for each functions. Currently `nargo info` now takes in a JSON report that it works with instead of an individual printed gate count. This PR also does some initial work on making a gate report that is ready for noir-lang/noir-gates-diff. This is yet to be updated but has most of the initial skeleton needed to get a gates report for an entire workspace. Also, once https://github.com/noir-lang/noir/pull/4975 is merged and synced into this repo we can remove the `bb info` command and rename `bb gates` -> `bb info` Nargo info still works as expected: Screenshot 2024-05-08 at 2 55 32 PM --------- Co-authored-by: Tom French --- barretenberg/cpp/src/barretenberg/bb/main.cpp | 38 ++++++++++++++---- .../dsl/acir_format/acir_format.hpp | 2 + .../dsl/acir_format/acir_format.test.cpp | 6 +++ .../acir_format/acir_to_constraint_buf.hpp | 1 + .../acir_format/bigint_constraint.test.cpp | 5 +++ .../dsl/acir_format/block_constraint.test.cpp | 1 + .../dsl/acir_format/ec_operations.test.cpp | 1 + .../dsl/acir_format/ecdsa_secp256k1.test.cpp | 3 ++ .../dsl/acir_format/ecdsa_secp256r1.test.cpp | 4 ++ .../acir_format/poseidon2_constraint.test.cpp | 1 + .../acir_format/recursion_constraint.test.cpp | 2 + .../acir_format/sha256_constraint.test.cpp | 1 + noir-projects/gates_report.sh | 39 +++++++++++++++++++ noir/noir-repo/Cargo.lock | 1 + .../tooling/backend_interface/Cargo.toml | 1 + .../backend_interface/src/cli/gates.rs | 32 ++++++++------- .../tooling/backend_interface/src/cli/mod.rs | 2 + .../backend_interface/src/proof_system.rs | 9 +++-- .../mock_backend/src/gates_cmd.rs | 4 +- .../tooling/nargo_cli/src/cli/info_cmd.rs | 18 +++++---- 20 files changed, 139 insertions(+), 32 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 9db639ea0a5..820cc522ad7 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -296,19 +296,43 @@ 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) { - 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(); + // 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 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, ","); + } - writeUint64AsRawBytesToStdout(static_cast(gate_count)); - vinfo("gate count: ", gate_count); + functions_string = format(functions_string, result_string); + + 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); } /** 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_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/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/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 = {}, diff --git a/noir-projects/gates_report.sh b/noir-projects/gates_report.sh new file mode 100755 index 00000000000..affbf07d1f4 --- /dev/null +++ b/noir-projects/gates_report.sh @@ -0,0 +1,39 @@ +#!/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. +# 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 + +# 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/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 aca05f0232a..9e12596bfd7 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)] +struct GatesResponse { + functions: Vec, +} + +#[derive(Deserialize)] +pub struct CircuitReport { + pub acir_opcodes: u32, + pub circuit_size: u32, +} + 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") @@ -25,19 +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 gates_bytes: [u8; EXPECTED_BYTES] = - output.stdout.as_slice().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); + let gates_info: GatesResponse = + serde_json::from_slice(&output.stdout).expect("Backend should return valid json"); - Ok(value as u32) + Ok(gates_info.functions) } } @@ -58,7 +62,9 @@ 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].acir_opcodes, 123); + assert_eq!(output[0].circuit_size, 125); Ok(()) } 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 df43bd5cc2f..16a9517e129 100644 --- a/noir/noir-repo/tooling/backend_interface/src/cli/mod.rs +++ b/noir/noir-repo/tooling/backend_interface/src/cli/mod.rs @@ -18,6 +18,8 @@ pub(crate) use version::VersionCommand; pub(crate) use vk_as_fields::VkAsFieldsCommand; pub(crate) use write_vk::WriteVkCommand; +pub(crate) 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 20a6dcf70f1..ffd46acef0e 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, ProofAsFieldsCommand, ProveCommand, VerifyCommand, VkAsFieldsCommand, - WriteVkCommand, + CircuitReport, GatesCommand, ProofAsFieldsCommand, ProveCommand, VerifyCommand, + VkAsFieldsCommand, WriteVkCommand, }; use crate::{Backend, BackendError}; impl Backend { - pub fn get_exact_circuit_size(&self, program: &Program) -> Result { + 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/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..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,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": 125 }] }"#; + + 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 1ae2d5db104..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 @@ -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; @@ -283,10 +283,15 @@ impl From for Vec { fn count_opcodes_and_gates_in_program( backend: &Backend, - compiled_program: ProgramArtifact, + mut compiled_program: ProgramArtifact, 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.bytecode.unconstrained_functions.clear(); + + let program_circuit_sizes = backend.get_exact_circuit_sizes(&compiled_program.bytecode)?; let functions = compiled_program .bytecode .functions @@ -295,12 +300,9 @@ fn count_opcodes_and_gates_in_program( .map(|(i, function)| -> Result<_, BackendError> { Ok(FunctionInfo { name: compiled_program.names[i].clone(), + // Required while mock backend doesn't return correct circuit size. 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].circuit_size, }) }) .collect::>()?; @@ -321,7 +323,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_sizes(&function.bytecode)?[0].circuit_size, }) }) .collect::>()?;