Skip to content

Commit

Permalink
feat(cli): add noir-execute binary (#7384)
Browse files Browse the repository at this point in the history
Co-authored-by: Tom French <[email protected]>
Co-authored-by: Tom French <[email protected]>
  • Loading branch information
3 people authored Feb 19, 2025
1 parent 40184eb commit fdfe2bf
Show file tree
Hide file tree
Showing 26 changed files with 644 additions and 188 deletions.
26 changes: 25 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ members = [
"tooling/noirc_abi",
"tooling/noirc_abi_wasm",
"tooling/acvm_cli",
"tooling/artifact_cli",
"tooling/profiler",
"tooling/inspector",
# ACVM
Expand All @@ -40,6 +41,7 @@ members = [
default-members = [
"tooling/nargo_cli",
"tooling/acvm_cli",
"tooling/artifact_cli",
"tooling/profiler",
"tooling/inspector",
]
Expand Down Expand Up @@ -91,6 +93,7 @@ noir_debugger = { path = "tooling/debugger" }
noirc_abi = { path = "tooling/noirc_abi" }
noirc_artifacts = { path = "tooling/noirc_artifacts" }
noirc_artifacts_info = { path = "tooling/noirc_artifacts_info" }
noir_artifact_cli = { path = "tooling/artifact_cli" }

# Arkworks
ark-bn254 = { version = "^0.5.0", default-features = false, features = [
Expand Down
1 change: 1 addition & 0 deletions acvm-repo/acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ impl<F: for<'a> Deserialize<'a>> Program<F> {
.map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidInput, err))
}

/// Deserialize bytecode.
pub fn deserialize_program(serialized_circuit: &[u8]) -> std::io::Result<Self> {
Program::read(serialized_circuit)
}
Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_errors/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ pub fn report_all<'files>(
}

impl FileDiagnostic {
/// Print the report; return true if it was an error.
pub fn report<'files>(
&self,
files: &'files impl Files<'files, FileId = fm::FileId>,
Expand Down
11 changes: 6 additions & 5 deletions tooling/acvm_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ name = "acvm"
path = "src/main.rs"

[dependencies]
thiserror.workspace = true
toml.workspace = true
color-eyre.workspace = true
clap.workspace = true
acvm.workspace = true
nargo.workspace = true
const_format.workspace = true
bn254_blackbox_solver.workspace = true
toml.workspace = true

acir.workspace = true
acvm.workspace = true
bn254_blackbox_solver.workspace = true
nargo.workspace = true
noir_artifact_cli.workspace = true

# Logs
tracing-subscriber.workspace = true
Expand Down
18 changes: 10 additions & 8 deletions tooling/acvm_cli/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::io::{self, Write};
use std::path::PathBuf;

use acir::circuit::Program;
use acir::native_types::{WitnessMap, WitnessStack};
Expand All @@ -7,11 +8,12 @@ use bn254_blackbox_solver::Bn254BlackBoxSolver;
use clap::Args;
use nargo::PrintOutput;

use crate::cli::fs::inputs::{read_bytecode_from_file, read_inputs_from_file};
use crate::errors::CliError;
use nargo::{foreign_calls::DefaultForeignCallBuilder, ops::execute_program};
use noir_artifact_cli::errors::CliError;
use noir_artifact_cli::fs::artifact::read_bytecode_from_file;
use noir_artifact_cli::fs::witness::save_witness_to_dir;

use super::fs::witness::{create_output_witness_string, save_witness_to_dir};
use crate::fs::witness::{create_output_witness_string, read_witness_from_file};

/// Executes a circuit to calculate its return value
#[derive(Debug, Clone, Args)]
Expand All @@ -30,7 +32,7 @@ pub(crate) struct ExecuteCommand {

/// The working directory
#[clap(long, short)]
working_directory: String,
working_directory: PathBuf,

/// Set to print output witness to stdout
#[clap(long, short, action)]
Expand All @@ -45,9 +47,9 @@ pub(crate) struct ExecuteCommand {

fn run_command(args: ExecuteCommand) -> Result<String, CliError> {
let bytecode = read_bytecode_from_file(&args.working_directory, &args.bytecode)?;
let circuit_inputs = read_inputs_from_file(&args.working_directory, &args.input_witness)?;
let input_witness = read_witness_from_file(&args.working_directory.join(&args.input_witness))?;
let output_witness =
execute_program_from_witness(circuit_inputs, &bytecode, args.pedantic_solving)?;
execute_program_from_witness(input_witness, &bytecode, args.pedantic_solving)?;
assert_eq!(output_witness.length(), 1, "ACVM CLI only supports a witness stack of size 1");
let output_witness_string = create_output_witness_string(
&output_witness.peek().expect("Should have a witness stack item").witness,
Expand Down Expand Up @@ -76,8 +78,8 @@ pub(crate) fn execute_program_from_witness(
bytecode: &[u8],
pedantic_solving: bool,
) -> Result<WitnessStack<FieldElement>, CliError> {
let program: Program<FieldElement> = Program::deserialize_program(bytecode)
.map_err(|_| CliError::CircuitDeserializationError())?;
let program: Program<FieldElement> =
Program::deserialize_program(bytecode).map_err(CliError::CircuitDeserializationError)?;
execute_program(
&program,
inputs_map,
Expand Down
54 changes: 0 additions & 54 deletions tooling/acvm_cli/src/cli/fs/inputs.rs

This file was deleted.

2 changes: 0 additions & 2 deletions tooling/acvm_cli/src/cli/fs/mod.rs

This file was deleted.

63 changes: 0 additions & 63 deletions tooling/acvm_cli/src/cli/fs/witness.rs

This file was deleted.

1 change: 0 additions & 1 deletion tooling/acvm_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use color_eyre::eyre;
use const_format::formatcp;

mod execute_cmd;
mod fs;

const ACVM_VERSION: &str = env!("CARGO_PKG_VERSION");

Expand Down
50 changes: 0 additions & 50 deletions tooling/acvm_cli/src/errors.rs

This file was deleted.

1 change: 1 addition & 0 deletions tooling/acvm_cli/src/fs/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod witness;
Loading

1 comment on commit fdfe2bf

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: fdfe2bf Previous: d0d04e8 Ratio
AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_reset-kernel-lib 11 s 9 s 1.22

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

Please sign in to comment.