Skip to content

Commit

Permalink
fix: incorrect secondary file in LSP errors (noir-lang/noir#7347)
Browse files Browse the repository at this point in the history
chore: Basic test for MSM in Noir to catch performance improvements and regressions (noir-lang/noir#7341)
fix(cli): Only lock the packages selected in the workspace (noir-lang/noir#7345)
chore: remove some unused types and functions in the AST (noir-lang/noir#7339)
chore: remove foreign calls array from Brillig VM constructor (noir-lang/noir#7337)
chore(ci): Add Vecs and vecs to cspell (noir-lang/noir#7342)
chore: redo typo PR by osrm (noir-lang/noir#7238)
chore: Release Noir(1.0.0-beta.2) (noir-lang/noir#6914)
fix: lock git dependencies folder when resolving workspace (noir-lang/noir#7327)
fix: perform SSA constraints check on final SSA (noir-lang/noir#7334)
chore: remove misleading output from `nargo check` (noir-lang/noir#7329)
chore: fix warnings (noir-lang/noir#7330)
chore: normalize path displayed by `nargo new` (noir-lang/noir#7328)
chore: split acirgen into multiple modules (noir-lang/noir#7310)
chore: remove unnecessary constants (noir-lang/noir#7326)
  • Loading branch information
AztecBot committed Feb 12, 2025
2 parents d294efd + 6d10a4c commit 94abd0f
Show file tree
Hide file tree
Showing 17 changed files with 327 additions and 239 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
df0d72970a9d64d7bf6132b55142e26bb3720d73
5d782f020f6aec6aaa8a445c3a6a5fb9b275e3c6
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "multi_scalar_mul"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
scalars = ["0", "0", "0", "0", "0"]

[[points]]
is_infinite = "0"
x = "0x0000000000000000000000000000000000000000000000000000000000000001"
y = "0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272c"

[[points]]
is_infinite = "0"
x = "0x0000000000000000000000000000000000000000000000000000000000000001"
y = "0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272c"

[[points]]
is_infinite = "0"
x = "0x0000000000000000000000000000000000000000000000000000000000000001"
y = "0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272c"

[[points]]
is_infinite = "0"
x = "0x0000000000000000000000000000000000000000000000000000000000000001"
y = "0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272c"

[[points]]
is_infinite = "0"
x = "0x0000000000000000000000000000000000000000000000000000000000000001"
y = "0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272c"
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// This test provides a basic implementation of a MSM in Noir, that allows us to check
// performance improvements and regressions.
use std::embedded_curve_ops::embedded_curve_add_unsafe;
use std::embedded_curve_ops::EmbeddedCurvePoint;

// `main` must be marked unconstrained as the function uses `break` internally
unconstrained fn main(
points: [EmbeddedCurvePoint; 5],
scalars: [Field; 5],
) -> pub EmbeddedCurvePoint {
// EmbeddedCurveScalar are two 128-bit numbers
let mut acc = EmbeddedCurvePoint::point_at_infinity();
for i in 0..1 {
// These should probably be EmbeddedCurveScalars
// let full_scalar: Field = scalars[i].hi * 2.pow_32(128) + scalars[i].lo;
let full_scalar = scalars[i];
let full_scalar_bits: [u1; 254] = full_scalar.to_be_bits();
let mut index_of_msb = 0;
// Iterates in BE
for j in 0..254 {
if full_scalar_bits[j] == 1 {
index_of_msb = j;
break;
}
}

let mut temp = points[i];
let mut res = EmbeddedCurvePoint::point_at_infinity();
// When iterative backwards we want to go to bits.len() - 2
for j in 0..(254 - index_of_msb) {
let k = 253 - j;

// Add
if full_scalar_bits[k] == 1 {
res = embedded_curve_add_unsafe(res, temp);
}
// Double
temp = embedded_curve_add_unsafe(temp, temp);
}

acc = embedded_curve_add_unsafe(acc, res);
}
acc
}

2 changes: 1 addition & 1 deletion noir/noir-repo/tooling/lsp/src/notifications/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ fn secondary_to_related_information(
let secondary_file = secondary.file.unwrap_or(file_id);
let path = fm.path(secondary_file)?;
let uri = Url::from_file_path(path).ok()?;
let range = byte_span_to_range(files, file_id, secondary.span.into())?;
let range = byte_span_to_range(files, secondary_file, secondary.span.into())?;
let message = secondary.message;
Some(DiagnosticRelatedInformation { location: lsp_types::Location { uri, range }, message })
}
Expand Down
29 changes: 15 additions & 14 deletions noir/noir-repo/tooling/nargo_cli/src/cli/check_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ use fm::FileManager;
use iter_extended::btree_map;
use nargo::{
errors::CompileError, insert_all_files_for_workspace_into_file_manager, ops::report_errors,
package::Package, parse_all, prepare_package,
package::Package, parse_all, prepare_package, workspace::Workspace,
};
use nargo_toml::{get_package_manifest, resolve_workspace_from_toml};
use nargo_toml::PackageSelection;
use noirc_abi::{AbiParameter, AbiType, MAIN_RETURN_NAME};
use noirc_driver::{
check_crate, compute_function_abi, CompileOptions, CrateId, NOIR_ARTIFACT_VERSION_STRING,
};
use noirc_driver::{check_crate, compute_function_abi, CompileOptions, CrateId};
use noirc_frontend::{
hir::{Context, ParsedFiles},
monomorphization::monomorphize,
};

use super::NargoConfig;
use super::{fs::write_to_file, PackageOptions};
use super::{LockType, WorkspaceCommand};

/// Check a local package and all of its dependencies for errors
#[derive(Debug, Clone, Args)]
Expand All @@ -39,15 +37,18 @@ pub(crate) struct CheckCommand {
show_program_hash: bool,
}

pub(crate) fn run(args: CheckCommand, config: NargoConfig) -> Result<(), CliError> {
let toml_path = get_package_manifest(&config.program_dir)?;
let selection = args.package_options.package_selection();
let workspace = resolve_workspace_from_toml(
&toml_path,
selection,
Some(NOIR_ARTIFACT_VERSION_STRING.to_string()),
)?;
impl WorkspaceCommand for CheckCommand {
fn package_selection(&self) -> PackageSelection {
self.package_options.package_selection()
}
fn lock_type(&self) -> LockType {
// Creates a `Prover.toml` template if it doesn't exist, otherwise only writes if `allow_overwrite` is true,
// so it shouldn't lead to accidental conflicts. Doesn't produce compilation artifacts.
LockType::None
}
}

pub(crate) fn run(args: CheckCommand, workspace: Workspace) -> Result<(), CliError> {
let mut workspace_file_manager = workspace.new_file_manager();
insert_all_files_for_workspace_into_file_manager(&workspace, &mut workspace_file_manager);
let parsed_files = parse_all(&workspace_file_manager);
Expand Down
41 changes: 16 additions & 25 deletions noir/noir-repo/tooling/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use nargo::ops::{collect_errors, compile_contract, compile_program, report_error
use nargo::package::Package;
use nargo::workspace::Workspace;
use nargo::{insert_all_files_for_workspace_into_file_manager, parse_all};
use nargo_toml::{
get_package_manifest, resolve_workspace_from_toml, ManifestError, PackageSelection,
};
use nargo_toml::PackageSelection;
use noirc_driver::DEFAULT_EXPRESSION_WIDTH;
use noirc_driver::NOIR_ARTIFACT_VERSION_STRING;
use noirc_driver::{CompilationResult, CompileOptions, CompiledContract};
Expand All @@ -23,7 +21,7 @@ use notify_debouncer_full::new_debouncer;
use crate::errors::CliError;

use super::fs::program::{read_program_from_file, save_contract_to_file, save_program_to_file};
use super::{NargoConfig, PackageOptions};
use super::{LockType, PackageOptions, WorkspaceCommand};
use rayon::prelude::*;

/// Compile the program and its secret execution trace into ACIR format
Expand All @@ -40,36 +38,26 @@ pub(crate) struct CompileCommand {
watch: bool,
}

pub(crate) fn run(args: CompileCommand, config: NargoConfig) -> Result<(), CliError> {
let selection = args.package_options.package_selection();
let workspace = read_workspace(&config.program_dir, selection)?;
impl WorkspaceCommand for CompileCommand {
fn package_selection(&self) -> PackageSelection {
self.package_options.package_selection()
}

fn lock_type(&self) -> LockType {
LockType::Exclusive
}
}

pub(crate) fn run(args: CompileCommand, workspace: Workspace) -> Result<(), CliError> {
if args.watch {
watch_workspace(&workspace, &args.compile_options)
.map_err(|err| CliError::Generic(err.to_string()))?;
} else {
compile_workspace_full(&workspace, &args.compile_options)?;
}

Ok(())
}

/// Read a given program directory into a workspace.
fn read_workspace(
program_dir: &Path,
selection: PackageSelection,
) -> Result<Workspace, ManifestError> {
let toml_path = get_package_manifest(program_dir)?;

let workspace = resolve_workspace_from_toml(
&toml_path,
selection,
Some(NOIR_ARTIFACT_VERSION_STRING.to_owned()),
)?;

Ok(workspace)
}

/// Continuously recompile the workspace on any Noir file change event.
fn watch_workspace(workspace: &Workspace, compile_options: &CompileOptions) -> notify::Result<()> {
let (tx, rx) = std::sync::mpsc::channel();
Expand Down Expand Up @@ -334,8 +322,11 @@ mod tests {
use nargo_toml::PackageSelection;
use noirc_driver::{CompileOptions, CrateName};

use crate::cli::compile_cmd::{get_target_width, parse_workspace, read_workspace};
use crate::cli::test_cmd::formatters::diagnostic_to_string;
use crate::cli::{
compile_cmd::{get_target_width, parse_workspace},
read_workspace,
};

/// Try to find the directory that Cargo sets when it is running;
/// otherwise fallback to assuming the CWD is the root of the repository
Expand Down
4 changes: 1 addition & 3 deletions noir/noir-repo/tooling/nargo_cli/src/cli/dap_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ use super::debug_cmd::compile_bin_package_for_debugging;
use super::fs::inputs::read_inputs_from_file;
use crate::errors::CliError;

use super::NargoConfig;

use noir_debugger::errors::{DapError, LoadError};

#[derive(Debug, Clone, Args)]
Expand Down Expand Up @@ -255,7 +253,7 @@ fn run_preflight_check(
Ok(())
}

pub(crate) fn run(args: DapCommand, _config: NargoConfig) -> Result<(), CliError> {
pub(crate) fn run(args: DapCommand) -> Result<(), CliError> {
// When the --preflight-check flag is present, we run Noir's DAP server in "pre-flight mode", which test runs
// the DAP initialization code without actually starting the DAP server.
//
Expand Down
33 changes: 19 additions & 14 deletions noir/noir-repo/tooling/nargo_cli/src/cli/debug_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ use nargo::ops::{compile_program, compile_program_with_debug_instrumenter, repor
use nargo::package::{CrateName, Package};
use nargo::workspace::Workspace;
use nargo::{insert_all_files_for_workspace_into_file_manager, parse_all};
use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection};
use nargo_toml::PackageSelection;
use noirc_abi::input_parser::{Format, InputValue};
use noirc_abi::InputMap;
use noirc_driver::{
file_manager_with_stdlib, CompileOptions, CompiledProgram, NOIR_ARTIFACT_VERSION_STRING,
};
use noirc_driver::{file_manager_with_stdlib, CompileOptions, CompiledProgram};
use noirc_frontend::debug::DebugInstrumenter;
use noirc_frontend::hir::ParsedFiles;

use super::compile_cmd::get_target_width;
use super::fs::{inputs::read_inputs_from_file, witness::save_witness_to_dir};
use super::NargoConfig;
use super::{LockType, WorkspaceCommand};
use crate::errors::CliError;

/// Executes a circuit in debug mode
Expand Down Expand Up @@ -52,17 +50,24 @@ pub(crate) struct DebugCommand {
skip_instrumentation: Option<bool>,
}

pub(crate) fn run(args: DebugCommand, config: NargoConfig) -> Result<(), CliError> {
impl WorkspaceCommand for DebugCommand {
fn package_selection(&self) -> PackageSelection {
self.package
.as_ref()
.cloned()
.map_or(PackageSelection::DefaultOrAll, PackageSelection::Selected)
}

fn lock_type(&self) -> LockType {
// Always compiles fresh in-memory in debug mode, doesn't read or write the compilation artifacts.
// Reads the Prover.toml file and writes the witness at the end, but shouldn't conflict with others.
LockType::None
}
}

pub(crate) fn run(args: DebugCommand, workspace: Workspace) -> Result<(), CliError> {
let acir_mode = args.acir_mode;
let skip_instrumentation = args.skip_instrumentation.unwrap_or(acir_mode);

let toml_path = get_package_manifest(&config.program_dir)?;
let selection = args.package.map_or(PackageSelection::DefaultOrAll, PackageSelection::Selected);
let workspace = resolve_workspace_from_toml(
&toml_path,
selection,
Some(NOIR_ARTIFACT_VERSION_STRING.to_string()),
)?;
let target_dir = &workspace.target_directory_path();

let Some(package) = workspace.into_iter().find(|p| p.is_binary()) else {
Expand Down
27 changes: 16 additions & 11 deletions noir/noir-repo/tooling/nargo_cli/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ use nargo::constants::PROVER_INPUT_FILE;
use nargo::errors::try_to_diagnose_runtime_error;
use nargo::foreign_calls::DefaultForeignCallBuilder;
use nargo::package::Package;
use nargo::workspace::Workspace;
use nargo::PrintOutput;
use nargo_toml::{get_package_manifest, resolve_workspace_from_toml};
use nargo_toml::PackageSelection;
use noirc_abi::input_parser::{Format, InputValue};
use noirc_abi::InputMap;
use noirc_artifacts::debug::DebugArtifact;
use noirc_driver::{CompileOptions, CompiledProgram, NOIR_ARTIFACT_VERSION_STRING};
use noirc_driver::{CompileOptions, CompiledProgram};

use super::compile_cmd::compile_workspace_full;
use super::fs::{inputs::read_inputs_from_file, witness::save_witness_to_dir};
use super::{NargoConfig, PackageOptions};
use super::{LockType, PackageOptions, WorkspaceCommand};
use crate::cli::fs::program::read_program_from_file;
use crate::errors::CliError;

Expand Down Expand Up @@ -46,14 +47,18 @@ pub(crate) struct ExecuteCommand {
oracle_resolver: Option<String>,
}

pub(crate) fn run(args: ExecuteCommand, config: NargoConfig) -> Result<(), CliError> {
let toml_path = get_package_manifest(&config.program_dir)?;
let selection = args.package_options.package_selection();
let workspace = resolve_workspace_from_toml(
&toml_path,
selection,
Some(NOIR_ARTIFACT_VERSION_STRING.to_string()),
)?;
impl WorkspaceCommand for ExecuteCommand {
fn package_selection(&self) -> PackageSelection {
self.package_options.package_selection()
}

fn lock_type(&self) -> LockType {
// Compiles artifacts.
LockType::Exclusive
}
}

pub(crate) fn run(args: ExecuteCommand, workspace: Workspace) -> Result<(), CliError> {
let target_dir = &workspace.target_directory_path();

// Compile the full workspace in order to generate any build artifacts.
Expand Down
27 changes: 14 additions & 13 deletions noir/noir-repo/tooling/nargo_cli/src/cli/export_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ use nargo::package::Package;
use nargo::prepare_package;
use nargo::workspace::Workspace;
use nargo::{insert_all_files_for_workspace_into_file_manager, parse_all};
use nargo_toml::{get_package_manifest, resolve_workspace_from_toml};
use noirc_driver::{
compile_no_check, CompileOptions, CompiledProgram, NOIR_ARTIFACT_VERSION_STRING,
};
use nargo_toml::PackageSelection;
use noirc_driver::{compile_no_check, CompileOptions, CompiledProgram};

use clap::Args;

Expand All @@ -22,7 +20,7 @@ use crate::errors::CliError;
use super::check_cmd::check_crate_and_report_errors;

use super::fs::program::save_program_to_file;
use super::{NargoConfig, PackageOptions};
use super::{LockType, PackageOptions, WorkspaceCommand};

/// Exports functions marked with #[export] attribute
#[derive(Debug, Clone, Args)]
Expand All @@ -34,15 +32,18 @@ pub(crate) struct ExportCommand {
compile_options: CompileOptions,
}

pub(crate) fn run(args: ExportCommand, config: NargoConfig) -> Result<(), CliError> {
let toml_path = get_package_manifest(&config.program_dir)?;
let selection = args.package_options.package_selection();
let workspace = resolve_workspace_from_toml(
&toml_path,
selection,
Some(NOIR_ARTIFACT_VERSION_STRING.to_owned()),
)?;
impl WorkspaceCommand for ExportCommand {
fn package_selection(&self) -> PackageSelection {
self.package_options.package_selection()
}

fn lock_type(&self) -> LockType {
// Writes the exported functions.
LockType::Exclusive
}
}

pub(crate) fn run(args: ExportCommand, workspace: Workspace) -> Result<(), CliError> {
let mut workspace_file_manager = workspace.new_file_manager();
insert_all_files_for_workspace_into_file_manager(&workspace, &mut workspace_file_manager);
let parsed_files = parse_all(&workspace_file_manager);
Expand Down
Loading

0 comments on commit 94abd0f

Please sign in to comment.