From 1e399f3130e62e33095cd8c2e82bef0a7cc13c4b Mon Sep 17 00:00:00 2001 From: guipublic Date: Mon, 4 Dec 2023 18:36:26 +0000 Subject: [PATCH 1/8] new only-acir option --- compiler/noirc_driver/src/lib.rs | 3 +++ test_programs/rebuild.sh | 15 +-------------- tooling/nargo/src/constants.rs | 2 +- tooling/nargo_cli/src/cli/compile_cmd.rs | 19 ++++++++++++++----- tooling/nargo_cli/src/cli/fs/program.rs | 14 ++++++++++++++ 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 93ed26fb91a..9697e2a88e5 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -61,6 +61,9 @@ pub struct CompileOptions { /// Suppress warnings #[arg(long, conflicts_with = "deny_warnings")] pub silence_warnings: bool, + + #[arg(long)] + pub only_acir: bool, } /// Helper type used to signify where only warnings are expected in file diagnostics diff --git a/test_programs/rebuild.sh b/test_programs/rebuild.sh index d89402fb1cf..a1e0e41d7c5 100755 --- a/test_programs/rebuild.sh +++ b/test_programs/rebuild.sh @@ -27,20 +27,7 @@ for dir in $base_path/*; do if [ -d ./target/ ]; then rm -r ./target/ fi - nargo compile && nargo execute witness - - # Rename witness.tr to witness.gz - if [ -f ./target/witness.tr ]; then - mv ./target/witness.tr ./target/witness.gz - fi - - # Extract bytecode field from JSON, base64 decode it, and save it to the target directory - if [ -f ./target/${dir_name}.json ]; then - jq -r '.bytecode' ./target/${dir_name}.json | base64 -d > ./target/acir.gz - fi - - # Delete the JSON file after extracting bytecode field - rm ./target/${dir_name}.json + cargo run compile --only-acir && cargo run execute witness # Clear the target directory in acir_artifacts if [ -d "$current_dir/acir_artifacts/$dir_name/target" ]; then diff --git a/tooling/nargo/src/constants.rs b/tooling/nargo/src/constants.rs index 5e448277694..ff8da403c69 100644 --- a/tooling/nargo/src/constants.rs +++ b/tooling/nargo/src/constants.rs @@ -20,4 +20,4 @@ pub const PKG_FILE: &str = "Nargo.toml"; /// The extension for files containing circuit proofs. pub const PROOF_EXT: &str = "proof"; /// The extension for files containing proof witnesses. -pub const WITNESS_EXT: &str = "tr"; +pub const WITNESS_EXT: &str = "gz"; diff --git a/tooling/nargo_cli/src/cli/compile_cmd.rs b/tooling/nargo_cli/src/cli/compile_cmd.rs index 69533292bbd..8976dec2348 100644 --- a/tooling/nargo_cli/src/cli/compile_cmd.rs +++ b/tooling/nargo_cli/src/cli/compile_cmd.rs @@ -24,6 +24,7 @@ use clap::Args; use crate::backends::Backend; use crate::errors::CliError; +use super::fs::program::only_acir; use super::fs::program::{ read_debug_artifact_from_file, read_program_from_file, save_contract_to_file, save_debug_artifact_to_file, save_program_to_file, @@ -230,8 +231,8 @@ fn compile_program( let optimized_program = nargo::ops::optimize_program(program, np_language, &is_opcode_supported_pedersen_hash) .expect("Backend does not support an opcode that is in the IR"); - - save_program(optimized_program.clone(), package, &workspace.target_directory_path()); + let only_acir = compile_options.only_acir; + save_program(optimized_program.clone(), package, &workspace.target_directory_path(), only_acir); (context.file_manager, Ok((optimized_program, warnings))) } @@ -259,7 +260,12 @@ fn compile_contract( (context.file_manager, Ok((optimized_contract, warnings))) } -fn save_program(program: CompiledProgram, package: &Package, circuit_dir: &Path) { +fn save_program( + program: CompiledProgram, + package: &Package, + circuit_dir: &Path, + only_acir_opt: bool, +) { let preprocessed_program = PreprocessedProgram { hash: program.hash, backend: String::from(BACKEND_IDENTIFIER), @@ -267,8 +273,11 @@ fn save_program(program: CompiledProgram, package: &Package, circuit_dir: &Path) noir_version: program.noir_version, bytecode: program.circuit, }; - - save_program_to_file(&preprocessed_program, &package.name, circuit_dir); + if only_acir_opt { + only_acir(&preprocessed_program, circuit_dir); + } else { + save_program_to_file(&preprocessed_program, &package.name, circuit_dir); + } let debug_artifact = DebugArtifact { debug_symbols: vec![program.debug], diff --git a/tooling/nargo_cli/src/cli/fs/program.rs b/tooling/nargo_cli/src/cli/fs/program.rs index e82f2d55264..0254dac5d81 100644 --- a/tooling/nargo_cli/src/cli/fs/program.rs +++ b/tooling/nargo_cli/src/cli/fs/program.rs @@ -1,5 +1,6 @@ use std::path::{Path, PathBuf}; +use acvm::acir::circuit::Circuit; use nargo::artifacts::{ contract::PreprocessedContract, debug::DebugArtifact, program::PreprocessedProgram, }; @@ -18,6 +19,19 @@ pub(crate) fn save_program_to_file>( save_build_artifact_to_file(compiled_program, &circuit_name, circuit_dir) } +/// Writes the bytecode as acir.gz (without uuencoding) +pub(crate) fn only_acir>( + compiled_program: &PreprocessedProgram, + 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 bytes = Circuit::serialize_circuit(&compiled_program.bytecode); + write_to_file(&bytes, &circuit_path); + + circuit_path +} + pub(crate) fn save_contract_to_file>( compiled_contract: &PreprocessedContract, circuit_name: &str, From a5562e1b0e39a614d042a209ec1b204692e0ed0d Mon Sep 17 00:00:00 2001 From: guipublic Date: Mon, 4 Dec 2023 18:45:33 +0000 Subject: [PATCH 2/8] update docs --- docs/docs/nargo/01_commands.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/docs/nargo/01_commands.md b/docs/docs/nargo/01_commands.md index 65e2bdb44e3..cdb895d2284 100644 --- a/docs/docs/nargo/01_commands.md +++ b/docs/docs/nargo/01_commands.md @@ -98,15 +98,16 @@ You can also use "build" as an alias for compile (e.g. `nargo build`). ### Options -| Option | Description | -| --------------------- | ------------------------------------------------------------ | -| `--include-keys` | Include Proving and Verification keys in the build artifacts | -| `--package ` | The name of the package to compile | -| `--workspace` | Compile all packages in the workspace | -| `--print-acir` | Display the ACIR for compiled circuit | -| `--deny-warnings` | Treat all warnings as errors | -| `--silence-warnings` | Suppress warnings | -| `-h, --help` | Print help | +| Option | Description | +| --------------------- | ----------------------------------------------------------------------------| +| `--include-keys` | Include Proving and Verification keys in the build artifacts | +| `--package ` | The name of the package to compile | +| `--workspace` | Compile all packages in the workspace | +| `--print-acir` | Display the ACIR for compiled circuit | +| `--deny-warnings` | Treat all warnings as errors | +| `--silence-warnings` | Suppress warnings | +| `--only-acir` | generates ACIR representation into acir.gz, instead of JSON build artifact | +| `-h, --help` | Print help | ## `nargo new ` From 6dad4ef088fbcd5254d02e9402f3e7001bbb2aca Mon Sep 17 00:00:00 2001 From: guipublic Date: Fri, 8 Dec 2023 13:35:50 +0000 Subject: [PATCH 3/8] add doc comment --- compiler/noirc_driver/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 40e1a86d914..517a764058e 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -62,6 +62,7 @@ pub struct CompileOptions { #[arg(long, conflicts_with = "deny_warnings")] pub silence_warnings: bool, + /// Output ACIR gzipped bytecode, instead of the json atrefact #[arg(long)] pub only_acir: bool, } From a6ddbaa352ff83b98590fae23f0101e0ab7b20ca Mon Sep 17 00:00:00 2001 From: guipublic Date: Mon, 11 Dec 2023 11:24:19 +0000 Subject: [PATCH 4/8] typo in comment --- compiler/noirc_driver/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 517a764058e..62215b207a5 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -62,7 +62,7 @@ pub struct CompileOptions { #[arg(long, conflicts_with = "deny_warnings")] pub silence_warnings: bool, - /// Output ACIR gzipped bytecode, instead of the json atrefact + /// Output ACIR gzipped bytecode instead of the JSON artefact #[arg(long)] pub only_acir: bool, } From 2148be9c6cb4184cd2f73d7709c15af3693a3a74 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 12 Dec 2023 23:13:41 +0000 Subject: [PATCH 5/8] Update tooling/nargo_cli/src/cli/fs/program.rs --- tooling/nargo_cli/src/cli/fs/program.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/nargo_cli/src/cli/fs/program.rs b/tooling/nargo_cli/src/cli/fs/program.rs index 0254dac5d81..807df25ba48 100644 --- a/tooling/nargo_cli/src/cli/fs/program.rs +++ b/tooling/nargo_cli/src/cli/fs/program.rs @@ -19,7 +19,7 @@ pub(crate) fn save_program_to_file>( save_build_artifact_to_file(compiled_program, &circuit_name, circuit_dir) } -/// Writes the bytecode as acir.gz (without uuencoding) +/// Writes the bytecode as acir.gz pub(crate) fn only_acir>( compiled_program: &PreprocessedProgram, circuit_dir: P, From 943afc78fa69e69762a47ac76d2e27bfe699c729 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Wed, 13 Dec 2023 14:12:37 +0000 Subject: [PATCH 6/8] Update docs/docs/reference/nargo_commands.md --- docs/docs/reference/nargo_commands.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/docs/reference/nargo_commands.md b/docs/docs/reference/nargo_commands.md index b02c9c25a4b..1c5acf04f64 100644 --- a/docs/docs/reference/nargo_commands.md +++ b/docs/docs/reference/nargo_commands.md @@ -106,7 +106,6 @@ You can also use "build" as an alias for compile (e.g. `nargo build`). | `--print-acir` | Display the ACIR for compiled circuit | | `--deny-warnings` | Treat all warnings as errors | | `--silence-warnings` | Suppress warnings | -| `--only-acir` | generates ACIR representation into acir.gz, instead of JSON build artifact | | `-h, --help` | Print help | ## `nargo new ` From c07f7752e381d2694440de962e746a56ef367712 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Wed, 13 Dec 2023 14:13:48 +0000 Subject: [PATCH 7/8] Update docs/docs/reference/nargo_commands.md --- docs/docs/reference/nargo_commands.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/reference/nargo_commands.md b/docs/docs/reference/nargo_commands.md index 1c5acf04f64..ed46b0c1c88 100644 --- a/docs/docs/reference/nargo_commands.md +++ b/docs/docs/reference/nargo_commands.md @@ -100,7 +100,7 @@ You can also use "build" as an alias for compile (e.g. `nargo build`). ### Options | Option | Description | -| --------------------- | ----------------------------------------------------------------------------| +| --------------------- | ------------------------------------------------------------ | | `--package ` | The name of the package to compile | | `--workspace` | Compile all packages in the workspace | | `--print-acir` | Display the ACIR for compiled circuit | From 34134f137d6f5b5b54a6dd8e3e81ae936257e193 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Wed, 13 Dec 2023 14:15:17 +0000 Subject: [PATCH 8/8] revert all changes to docs/command --- docs/docs/reference/nargo_commands.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/docs/reference/nargo_commands.md b/docs/docs/reference/nargo_commands.md index ed46b0c1c88..239e88d9691 100644 --- a/docs/docs/reference/nargo_commands.md +++ b/docs/docs/reference/nargo_commands.md @@ -99,14 +99,14 @@ You can also use "build" as an alias for compile (e.g. `nargo build`). ### Options -| Option | Description | +| Option | Description | | --------------------- | ------------------------------------------------------------ | -| `--package ` | The name of the package to compile | -| `--workspace` | Compile all packages in the workspace | -| `--print-acir` | Display the ACIR for compiled circuit | -| `--deny-warnings` | Treat all warnings as errors | -| `--silence-warnings` | Suppress warnings | -| `-h, --help` | Print help | +| `--package ` | The name of the package to compile | +| `--workspace` | Compile all packages in the workspace | +| `--print-acir` | Display the ACIR for compiled circuit | +| `--deny-warnings` | Treat all warnings as errors | +| `--silence-warnings` | Suppress warnings | +| `-h, --help` | Print help | ## `nargo new `