Skip to content

Commit

Permalink
chore: resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
0xYYY committed Feb 12, 2023
2 parents 58ad193 + 1b80f55 commit ed2c06d
Show file tree
Hide file tree
Showing 52 changed files with 1,105 additions and 891 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ name: Rust

on: [push, pull_request]

# This will cancel previous runs when a branch or PR is updated
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref || github.run_id }}
cancel-in-progress: true

jobs:
check_n_test:
name: cargo check & test
test:
name: Cargo test
uses: noir-lang/.github/.github/workflows/rust-test.yml@main

clippy:
name: cargo clippy
name: Cargo clippy
uses: noir-lang/.github/.github/workflows/rust-clippy.yml@main

format:
name: cargo fmt
name: Cargo fmt
uses: noir-lang/.github/.github/workflows/rust-format.yml@main

spellcheck:
name: spellcheck
name: Spellcheck
uses: noir-lang/.github/.github/workflows/spellcheck.yml@main
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ version = "0.1.1"
# x-release-please-end
authors = ["The Noir Team <kevtheappdev@gmail.com>"]
edition = "2021"
rust-version = "1.64"
rust-version = "1.66"

[workspace.dependencies]
acvm = "0.4.1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Concretely the following items are on the road map:

## Minimum Rust version

This crate's minimum supported rustc version is 1.64.0.
This crate's minimum supported rustc version is 1.66.0.

## License

Expand Down
4 changes: 2 additions & 2 deletions crates/nargo/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ fn rerun_if_stdlib_changes(directory: &Path) {

fn check_rustc_version() {
assert!(
version().unwrap() >= Version::parse("1.6.4").unwrap(),
"The minimal supported rustc version is 1.64.0."
version().unwrap() >= Version::parse("1.66.0").unwrap(),
"The minimal supported rustc version is 1.66.0."
);
}

Expand Down
6 changes: 4 additions & 2 deletions crates/nargo/src/cli/check_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ pub(crate) fn run(args: ArgMatches) -> Result<(), CliError> {
let args = args.subcommand_matches("check").unwrap();
let allow_warnings = args.is_present("allow-warnings");

let package_dir = std::env::current_dir().unwrap();
check_from_path(package_dir, allow_warnings)?;
let program_dir =
args.value_of("path").map_or_else(|| std::env::current_dir().unwrap(), PathBuf::from);

check_from_path(program_dir, allow_warnings)?;
println!("Constraint system successfully built!");
Ok(())
}
Expand Down
7 changes: 4 additions & 3 deletions crates/nargo/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ pub(crate) fn run(args: ArgMatches) -> Result<(), CliError> {
let circuit_name = args.value_of("circuit_name").unwrap();
let witness = args.is_present("witness");
let allow_warnings = args.is_present("allow-warnings");
let program_dir =
args.value_of("path").map_or_else(|| std::env::current_dir().unwrap(), PathBuf::from);

let current_dir = std::env::current_dir().unwrap();
let mut circuit_path = PathBuf::new();
let mut circuit_path = program_dir.clone();
circuit_path.push(TARGET_DIR);

generate_circuit_and_witness_to_disk(
circuit_name,
current_dir,
program_dir,
circuit_path,
witness,
allow_warnings,
Expand Down
18 changes: 10 additions & 8 deletions crates/nargo/src/cli/contract_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
use std::path::PathBuf;

use super::{create_named_dir, write_to_file};
use crate::{cli::compile_cmd::compile_circuit, constants::CONTRACT_DIR, errors::CliError};
use acvm::SmartContract;
use clap::ArgMatches;

pub(crate) fn run(args: ArgMatches) -> Result<(), CliError> {
let cmd = args.subcommand_matches("contract").unwrap();

let package_dir = match cmd.value_of("path") {
Some(path) => std::path::PathBuf::from(path),
None => std::env::current_dir().unwrap(),
};
let args = args.subcommand_matches("contract").unwrap();

let allow_warnings = args.is_present("allow-warnings");
let compiled_program = compile_circuit(package_dir, false, allow_warnings)?;
let program_dir =
args.value_of("path").map_or_else(|| std::env::current_dir().unwrap(), PathBuf::from);

let compiled_program = compile_circuit(program_dir.clone(), false, allow_warnings)?;

let backend = crate::backends::ConcreteBackend;
let smart_contract_string = backend.eth_contract_from_cs(compiled_program.circuit);

let mut contract_path = create_named_dir(CONTRACT_DIR.as_ref(), "contract");
let mut contract_dir = program_dir;
contract_dir.push(CONTRACT_DIR);
let mut contract_path = create_named_dir(contract_dir.as_ref(), "contract");
contract_path.push("plonk_vk");
contract_path.set_extension("sol");

Expand Down
21 changes: 7 additions & 14 deletions crates/nargo/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use noirc_driver::CompiledProgram;
use super::{create_named_dir, read_inputs_from_file, write_to_file};
use super::{InputMap, WitnessMap};
use crate::{
cli::compile_cmd::compile_circuit,
constants::{PROVER_INPUT_FILE, TARGET_DIR, WITNESS_EXT},
errors::CliError,
};
Expand All @@ -21,14 +22,18 @@ pub(crate) fn run(args: ArgMatches) -> Result<(), CliError> {
let witness_name = args.value_of("witness_name");
let show_ssa = args.is_present("show-ssa");
let allow_warnings = args.is_present("allow-warnings");
let (return_value, solved_witness) = execute(show_ssa, allow_warnings)?;
let program_dir =
args.value_of("path").map_or_else(|| std::env::current_dir().unwrap(), PathBuf::from);

let compiled_program = compile_circuit(&program_dir, show_ssa, allow_warnings)?;
let (return_value, solved_witness) = execute_program(&program_dir, &compiled_program)?;

println!("Circuit witness successfully solved");
if let Some(return_value) = return_value {
println!("Circuit output: {return_value:?}");
}
if let Some(witness_name) = witness_name {
let mut witness_dir = std::env::current_dir().unwrap();
let mut witness_dir = program_dir;
witness_dir.push(TARGET_DIR);

let witness_path = save_witness_to_dir(solved_witness, witness_name, witness_dir)?;
Expand All @@ -42,18 +47,6 @@ pub(crate) fn run(args: ArgMatches) -> Result<(), CliError> {
/// So when we add witness values, their index start from 1.
const WITNESS_OFFSET: u32 = 1;

fn execute(
show_ssa: bool,
allow_warnings: bool,
) -> Result<(Option<InputValue>, WitnessMap), CliError> {
let current_dir = std::env::current_dir().unwrap();

let compiled_program =
super::compile_cmd::compile_circuit(&current_dir, show_ssa, allow_warnings)?;

execute_program(current_dir, &compiled_program)
}

pub(crate) fn execute_program<P: AsRef<Path>>(
inputs_dir: P,
compiled_program: &CompiledProgram,
Expand Down
10 changes: 4 additions & 6 deletions crates/nargo/src/cli/gates_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use acvm::ProofSystemCompiler;
use clap::ArgMatches;
use std::path::Path;
use std::path::{Path, PathBuf};

use crate::cli::compile_cmd::compile_circuit;
use crate::errors::CliError;
Expand All @@ -9,12 +9,10 @@ pub(crate) fn run(args: ArgMatches) -> Result<(), CliError> {
let args = args.subcommand_matches("gates").unwrap();
let show_ssa = args.is_present("show-ssa");
let allow_warnings = args.is_present("allow-warnings");
count_gates(show_ssa, allow_warnings)
}
let program_dir =
args.value_of("path").map_or_else(|| std::env::current_dir().unwrap(), PathBuf::from);

pub fn count_gates(show_ssa: bool, allow_warnings: bool) -> Result<(), CliError> {
let current_dir = std::env::current_dir().unwrap();
count_gates_with_path(current_dir, show_ssa, allow_warnings)
count_gates_with_path(program_dir, show_ssa, allow_warnings)
}

pub fn count_gates_with_path<P: AsRef<Path>>(
Expand Down
5 changes: 3 additions & 2 deletions crates/nargo/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ pub fn start_cli() {
.arg(
Arg::with_name("witness_name")
.long("witness_name")
.help("Write the execution witness to named file"),
.help("Write the execution witness to named file")
.takes_value(true),
)
.arg(show_ssa)
.arg(allow_warnings),
Expand Down Expand Up @@ -183,7 +184,7 @@ pub fn read_inputs_from_file<P: AsRef<Path>>(
dir_path
};
if !file_path.exists() {
return Err(CliError::MissingTomlFile(file_path));
return Err(CliError::MissingTomlFile(file_name.to_owned(), file_path));
}

let input_string = std::fs::read_to_string(file_path).unwrap();
Expand Down
9 changes: 4 additions & 5 deletions crates/nargo/src/cli/new_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ use crate::{

use super::{create_named_dir, write_to_file};
use clap::ArgMatches;
use std::path::Path;
use std::path::{Path, PathBuf};

pub(crate) fn run(args: ArgMatches) -> Result<(), CliError> {
let cmd = args.subcommand_matches("new").unwrap();

let package_name = cmd.value_of("package_name").unwrap();

let mut package_dir = match cmd.value_of("path") {
Some(path) => std::path::PathBuf::from(path),
None => std::env::current_dir().unwrap(),
};
let mut package_dir =
args.value_of("path").map_or_else(|| std::env::current_dir().unwrap(), PathBuf::from);

package_dir.push(Path::new(package_name));
if package_dir.exists() {
return Err(CliError::DestinationAlreadyExists(package_dir));
Expand Down
11 changes: 4 additions & 7 deletions crates/nargo/src/cli/prove_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ pub(crate) fn run(args: ArgMatches) -> Result<(), CliError> {
let show_ssa = args.is_present("show-ssa");
let allow_warnings = args.is_present("allow-warnings");

prove(proof_name, show_ssa, allow_warnings)
}

fn prove(proof_name: Option<&str>, show_ssa: bool, allow_warnings: bool) -> Result<(), CliError> {
let current_dir = std::env::current_dir().unwrap();
let program_dir =
args.value_of("path").map_or_else(|| std::env::current_dir().unwrap(), PathBuf::from);

let mut proof_dir = PathBuf::new();
let mut proof_dir = program_dir.clone();
proof_dir.push(PROOFS_DIR);

prove_with_path(proof_name, current_dir, proof_dir, show_ssa, allow_warnings)?;
prove_with_path(proof_name, program_dir, proof_dir, show_ssa, allow_warnings)?;

Ok(())
}
Expand Down
16 changes: 11 additions & 5 deletions crates/nargo/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use std::{collections::BTreeMap, io::Write};
use std::{
collections::BTreeMap,
io::Write,
path::{Path, PathBuf},
};

use acvm::{PartialWitnessGenerator, ProofSystemCompiler};
use clap::ArgMatches;
Expand All @@ -14,14 +18,16 @@ pub(crate) fn run(args: ArgMatches) -> Result<(), CliError> {
let args = args.subcommand_matches("test").unwrap();
let test_name = args.value_of("test_name").unwrap_or("");
let allow_warnings = args.is_present("allow-warnings");
run_tests(test_name, allow_warnings)
let program_dir =
args.value_of("path").map_or_else(|| std::env::current_dir().unwrap(), PathBuf::from);

run_tests(&program_dir, test_name, allow_warnings)
}

fn run_tests(test_name: &str, allow_warnings: bool) -> Result<(), CliError> {
fn run_tests(program_dir: &Path, test_name: &str, allow_warnings: bool) -> Result<(), CliError> {
let backend = crate::backends::ConcreteBackend;

let package_dir = std::env::current_dir().unwrap();
let mut driver = Resolver::resolve_root_config(&package_dir, backend.np_language())?;
let mut driver = Resolver::resolve_root_config(program_dir, backend.np_language())?;
add_std_lib(&mut driver);

if driver.check_crate(allow_warnings).is_err() {
Expand Down
22 changes: 9 additions & 13 deletions crates/nargo/src/cli/verify_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,29 @@ use clap::ArgMatches;
use noirc_abi::errors::AbiError;
use noirc_abi::input_parser::Format;
use noirc_driver::CompiledProgram;
use std::{collections::BTreeMap, path::Path, path::PathBuf};
use std::{
collections::BTreeMap,
path::{Path, PathBuf},
};

pub(crate) fn run(args: ArgMatches) -> Result<(), CliError> {
let args = args.subcommand_matches("verify").unwrap();

let proof_name = args.value_of("proof").unwrap();
let mut proof_path = std::path::PathBuf::new();
proof_path.push(Path::new(PROOFS_DIR));
let program_dir =
args.value_of("path").map_or_else(|| std::env::current_dir().unwrap(), PathBuf::from);

let mut proof_path = program_dir.clone();
proof_path.push(Path::new(PROOFS_DIR));
proof_path.push(Path::new(proof_name));
proof_path.set_extension(PROOF_EXT);

let allow_warnings = args.is_present("allow-warnings");
let result = verify(proof_name, allow_warnings)?;
let result = verify_with_path(program_dir, proof_path, false, allow_warnings)?;
println!("Proof verified : {result}\n");
Ok(())
}

fn verify(proof_name: &str, allow_warnings: bool) -> Result<bool, CliError> {
let current_dir = std::env::current_dir().unwrap();
let mut proof_path = PathBuf::new(); //or cur_dir?
proof_path.push(PROOFS_DIR);
proof_path.push(Path::new(proof_name));
proof_path.set_extension(PROOF_EXT);
verify_with_path(&current_dir, &proof_path, false, allow_warnings)
}

pub fn verify_with_path<P: AsRef<Path>>(
program_dir: P,
proof_path: P,
Expand Down
6 changes: 4 additions & 2 deletions crates/nargo/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ pub enum CliError {
PathNotValid(PathBuf),
#[error("Error: could not parse proof data ({0})")]
ProofNotValid(FromHexError),
#[error("cannot find input file located at {0:?}, run nargo build to generate the missing Prover and/or Verifier toml files")]
MissingTomlFile(PathBuf),
#[error(
" Error: cannot find {0}.toml file.\n Expected location: {1:?} \n Please generate this file at the expected location."
)]
MissingTomlFile(String, PathBuf),
}

impl From<OpcodeResolutionError> for CliError {
Expand Down
35 changes: 35 additions & 0 deletions crates/nargo/tests/test_data/generics/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,45 @@ fn foo<T>(bar: Bar<T>) {
constrain bar.one == bar.two;
}

struct BigInt<N> {
limbs: [u32; N],
}

impl<N> BigInt<N> {
// `N` is in scope of all methods in the impl
fn first(first: BigInt<N>, second: BigInt<N>) -> Self {
constrain first.limbs != second.limbs;
first
}

fn second(first: BigInt<N>, second: Self) -> Self {
constrain first.limbs != second.limbs;
second
}
}

impl Bar<Field> {
fn get_other(self) -> Field {
self.other
}
}

fn main(x: Field, y: Field) {
let bar1: Bar<Field> = Bar { one: x, two: y, other: 0 };
let bar2 = Bar { one: x, two: y, other: [0] };

foo(bar1);
foo(bar2);

// Test generic impls
let int1 = BigInt { limbs: [1] };
let int2 = BigInt { limbs: [2] };
let BigInt { limbs } = int1.second(int2).first(int1);
constrain limbs == int2.limbs;

// Test impl exclusively for Bar<Field>
constrain bar1.get_other() == bar1.other;

// Expected type error
// constrain bar2.get_other() == bar2.other;
}
Loading

0 comments on commit ed2c06d

Please sign in to comment.