diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 710e88b34df..1fb1def7ce1 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -7,7 +7,9 @@ "jnoortheen.nix-ide", "rust-lang.rust-analyzer", "redhat.vscode-yaml", - "esbenp.prettier-vscode" + "esbenp.prettier-vscode", + // Spell checking + "streetsidesoftware.code-spell-checker", ], // List of extensions recommended by VS Code that should not be recommended for users of this workspace. "unwantedRecommendations": [] diff --git a/CHANGELOG.md b/CHANGELOG.md index b9bea13b5e0..a56f9490edb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -157,7 +157,7 @@ * Fix `update_acir` deleting all debug information ([#2643](https://github.com/noir-lang/noir/issues/2643)) ([a8a5395](https://github.com/noir-lang/noir/commit/a8a5395f357ef26890af526f417418c49b032d17)) * Fix compilation using `aztec` feature flag ([#2663](https://github.com/noir-lang/noir/issues/2663)) ([7f6fe46](https://github.com/noir-lang/noir/commit/7f6fe46f8bc00f24ff8d14b3a517e27b50db4ee5)) * Implement auto-dereferencing when calling methods ([#2581](https://github.com/noir-lang/noir/issues/2581)) ([3c731b1](https://github.com/noir-lang/noir/commit/3c731b11b31b8556eeebc4fe59b68609aa96c463)) -* Initialise arrays returned by brillig ([#2048](https://github.com/noir-lang/noir/issues/2048)) ([788dfb4](https://github.com/noir-lang/noir/commit/788dfb45e025786b13035d4c3d6ccf1e1614ef2f)) +* Initialize arrays returned by brillig ([#2048](https://github.com/noir-lang/noir/issues/2048)) ([788dfb4](https://github.com/noir-lang/noir/commit/788dfb45e025786b13035d4c3d6ccf1e1614ef2f)) * Remove duplicate file extension in stack trace ([#2655](https://github.com/noir-lang/noir/issues/2655)) ([1114871](https://github.com/noir-lang/noir/commit/1114871d538767c053d71c67577890dd29f0b490)) * **ssa:** Slice mergers with multiple ifs ([#2597](https://github.com/noir-lang/noir/issues/2597)) ([6110638](https://github.com/noir-lang/noir/commit/6110638ec743616b9a3f38650838dda631a25efd)) * Support for conditional stores ([#2553](https://github.com/noir-lang/noir/issues/2553)) ([6e6d952](https://github.com/noir-lang/noir/commit/6e6d952c052a893e897eaa42b36d3a15426a4f78)) @@ -448,7 +448,7 @@ * Adding internal keyword ([#1873](https://github.com/noir-lang/noir/issues/1873)) ([7a85493](https://github.com/noir-lang/noir/commit/7a854937ca5a300ae05f335612d2ff72ce88b4b1)) * Allow arrays of arbitrary types in the program ABI ([#1651](https://github.com/noir-lang/noir/issues/1651)) ([811ede1](https://github.com/noir-lang/noir/commit/811ede19f2160d809904deffc09a51799448d8d6)) * Allow shadowing by default ([#2000](https://github.com/noir-lang/noir/issues/2000)) ([88a4f74](https://github.com/noir-lang/noir/commit/88a4f74a36704137d7de94e3791c2e6bea9319b5)) -* avoid unnecessary witness assignments in euclidian division / bound constraint ([#1989](https://github.com/noir-lang/noir/issues/1989)) ([c23257d](https://github.com/noir-lang/noir/commit/c23257d4bdd8d93b9219fd767de6d806e237ccea)) +* avoid unnecessary witness assignments in euclidean division / bound constraint ([#1989](https://github.com/noir-lang/noir/issues/1989)) ([c23257d](https://github.com/noir-lang/noir/commit/c23257d4bdd8d93b9219fd767de6d806e237ccea)) * **brillig_gen:** Return slices from foreign calls ([#1909](https://github.com/noir-lang/noir/issues/1909)) ([6fa3144](https://github.com/noir-lang/noir/commit/6fa3144b30ef908a350273fbfd950d5a247104b2)) * compile to brillig reachable acir fns ([#1919](https://github.com/noir-lang/noir/issues/1919)) ([2b4237d](https://github.com/noir-lang/noir/commit/2b4237d7ffc2a0246cdaa1b7d85cc1ef7d7b3eb1)) * dynamic arrays for experimental-ssa ([#1969](https://github.com/noir-lang/noir/issues/1969)) ([08d199a](https://github.com/noir-lang/noir/commit/08d199aa4daa2038ca01f5ad23376fec27950f9a)) @@ -860,8 +860,8 @@ * Optimize parser ([#869](https://github.com/noir-lang/noir/issues/869)) ([e927a39](https://github.com/noir-lang/noir/commit/e927a39dc3d6517f233509b8349dfd9c7f79471d)) * prevent inconsistent language usage in `Driver` ([48cda7a](https://github.com/noir-lang/noir/commit/48cda7a08b22afdde9f904632b502c53fb491ee6)) * prevent inconsistent language usage in `Driver` ([#881](https://github.com/noir-lang/noir/issues/881)) ([48cda7a](https://github.com/noir-lang/noir/commit/48cda7a08b22afdde9f904632b502c53fb491ee6)) -* properly initialise `Evaluator` in test ([#863](https://github.com/noir-lang/noir/issues/863)) ([bbb70bd](https://github.com/noir-lang/noir/commit/bbb70bdcc78041f5db9b74657cdcc92ad34c035b)) -* properly initialise Evaluator in test ([bbb70bd](https://github.com/noir-lang/noir/commit/bbb70bdcc78041f5db9b74657cdcc92ad34c035b)) +* properly initialize `Evaluator` in test ([#863](https://github.com/noir-lang/noir/issues/863)) ([bbb70bd](https://github.com/noir-lang/noir/commit/bbb70bdcc78041f5db9b74657cdcc92ad34c035b)) +* properly initialize Evaluator in test ([bbb70bd](https://github.com/noir-lang/noir/commit/bbb70bdcc78041f5db9b74657cdcc92ad34c035b)) * Remove uses of std::process::exit ([#963](https://github.com/noir-lang/noir/issues/963)) ([870ea46](https://github.com/noir-lang/noir/commit/870ea463583502db106d4c8b05ad5c02fb6f8428)) * **ssa:** fix the compile-time check for equality in acir-gen ([#904](https://github.com/noir-lang/noir/issues/904)) ([161e4fb](https://github.com/noir-lang/noir/commit/161e4fbfe17ef9ed6c237d6ea812a866fee2c74a)) diff --git a/Cargo.lock b/Cargo.lock index c0c3079f36b..86df9e1a13b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -819,6 +819,17 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" +[[package]] +name = "clipboard-win" +version = "4.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7191c27c2357d9b7ef96baac1773290d4ca63b24205b82a3fd8a0637afcf0362" +dependencies = [ + "error-code", + "str-buf", + "winapi", +] + [[package]] name = "codespan" version = "0.11.1" @@ -1340,6 +1351,21 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" +[[package]] +name = "easy-repl" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81d0001ed25c451c57f8d6724d448a6546a5d78bbac77a63a22e32c735b7ea16" +dependencies = [ + "anyhow", + "rustyline", + "rustyline-derive", + "shell-words", + "textwrap 0.15.2", + "thiserror", + "trie-rs", +] + [[package]] name = "ecdsa" version = "0.14.8" @@ -1399,6 +1425,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + [[package]] name = "enum-iterator" version = "0.7.0" @@ -1467,6 +1499,16 @@ dependencies = [ "libc", ] +[[package]] +name = "error-code" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21" +dependencies = [ + "libc", + "str-buf", +] + [[package]] name = "eyre" version = "0.6.8" @@ -1492,6 +1534,17 @@ dependencies = [ "instant", ] +[[package]] +name = "fd-lock" +version = "3.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef033ed5e9bad94e55838ca0ca906db0e043f517adda0c8b79c7a8c66c93c1b5" +dependencies = [ + "cfg-if", + "rustix 0.38.4", + "windows-sys 0.48.0", +] + [[package]] name = "ff" version = "0.12.1" @@ -1502,6 +1555,15 @@ dependencies = [ "subtle", ] +[[package]] +name = "fid-rs" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28658c0c3420305705adde833a0d2d614207507d013a5f25707553fb2ae2cd" +dependencies = [ + "rayon", +] + [[package]] name = "filetime" version = "0.2.22" @@ -2216,6 +2278,15 @@ version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +[[package]] +name = "louds-rs" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e16a91fb20f74b6d9a758a0103a2884af525a2fa34fbfe19f4b3c5482a4a54e9" +dependencies = [ + "fid-rs", +] + [[package]] name = "lsp-types" version = "0.88.0" @@ -2266,6 +2337,15 @@ dependencies = [ "libc", ] +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + [[package]] name = "memoffset" version = "0.8.0" @@ -2360,6 +2440,7 @@ dependencies = [ "nargo", "nargo_fmt", "nargo_toml", + "noir_debugger", "noir_lsp", "noirc_abi", "noirc_driver", @@ -2409,6 +2490,28 @@ dependencies = [ "url", ] +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "nix" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" +dependencies = [ + "bitflags 1.3.2", + "cc", + "cfg-if", + "libc", + "memoffset 0.6.5", +] + [[package]] name = "nix" version = "0.26.2" @@ -2421,6 +2524,17 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "noir_debugger" +version = "0.16.0" +dependencies = [ + "acvm", + "easy-repl", + "nargo", + "noirc_printable_type", + "thiserror", +] + [[package]] name = "noir_lsp" version = "0.16.0" @@ -2820,7 +2934,7 @@ dependencies = [ "inferno", "libc", "log", - "nix", + "nix 0.26.2", "once_cell", "parking_lot", "smallvec", @@ -3000,6 +3114,16 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + [[package]] name = "rand" version = "0.8.5" @@ -3409,6 +3533,40 @@ dependencies = [ "wait-timeout", ] +[[package]] +name = "rustyline" +version = "9.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db7826789c0e25614b03e5a54a0717a86f9ff6e6e5247f92b369472869320039" +dependencies = [ + "bitflags 1.3.2", + "cfg-if", + "clipboard-win", + "dirs-next", + "fd-lock", + "libc", + "log", + "memchr", + "nix 0.23.2", + "radix_trie", + "scopeguard", + "smallvec", + "unicode-segmentation", + "unicode-width", + "utf8parse", + "winapi", +] + +[[package]] +name = "rustyline-derive" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb35a55ab810b5c0fe31606fe9b47d1354e4dc519bec0a102655f78ea2b38057" +dependencies = [ + "quote", + "syn 1.0.109", +] + [[package]] name = "ryu" version = "1.0.15" @@ -3548,7 +3706,7 @@ dependencies = [ "phf", "serde", "serde-reflection", - "textwrap", + "textwrap 0.13.4", ] [[package]] @@ -3686,6 +3844,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shell-words" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" + [[package]] name = "shellexpand" version = "2.1.2" @@ -3830,6 +3994,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "str-buf" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" + [[package]] name = "str_stack" version = "0.1.0" @@ -3998,6 +4168,17 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7b3e525a49ec206798b40326a44121291b530c963cfb01018f63e135bac543d" +dependencies = [ + "smawk", + "unicode-linebreak", + "unicode-width", +] + [[package]] name = "thiserror" version = "1.0.43" @@ -4247,6 +4428,15 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "trie-rs" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5096c019d49566aff57593a06e401c7f588da84e9a575d0ed2ac0913f51928c0" +dependencies = [ + "louds-rs", +] + [[package]] name = "try-lock" version = "0.2.4" @@ -4277,6 +4467,12 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +[[package]] +name = "unicode-linebreak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" + [[package]] name = "unicode-normalization" version = "0.1.22" diff --git a/Cargo.toml b/Cargo.toml index e57c53afcc4..b0bb24ddb03 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ members = [ "tooling/backend_interface", "tooling/bb_abstraction_leaks", "tooling/lsp", + "tooling/debugger", "tooling/nargo", "tooling/nargo_fmt", "tooling/nargo_cli", @@ -54,6 +55,7 @@ nargo_fmt = { path = "tooling/nargo_fmt" } nargo_cli = { path = "tooling/nargo_cli" } nargo_toml = { path = "tooling/nargo_toml" } noir_lsp = { path = "tooling/lsp" } +noir_debugger = { path = "tooling/debugger" } noirc_abi = { path = "tooling/noirc_abi" } bb_abstraction_leaks = { path = "tooling/bb_abstraction_leaks" } noirc_driver = { path = "compiler/noirc_driver" } diff --git a/acvm-repo/acir/src/circuit/directives.rs b/acvm-repo/acir/src/circuit/directives.rs index 32c0bd6337a..a86eb525c1f 100644 --- a/acvm-repo/acir/src/circuit/directives.rs +++ b/acvm-repo/acir/src/circuit/directives.rs @@ -15,7 +15,7 @@ pub struct QuotientDirective { /// You can think of them as opcodes that allow one to use non-determinism /// In the future, this can be replaced with asm non-determinism blocks pub enum Directive { - //Performs euclidian division of a / b (as integers) and stores the quotient in q and the rest in r + //Performs euclidean division of a / b (as integers) and stores the quotient in q and the rest in r Quotient(QuotientDirective), //decomposition of a: a=\sum b[i]*radix^i where b is an array of witnesses < radix in little endian form diff --git a/compiler/fm/src/lib.rs b/compiler/fm/src/lib.rs index 5c5175499d8..d8a7bce4509 100644 --- a/compiler/fm/src/lib.rs +++ b/compiler/fm/src/lib.rs @@ -102,7 +102,7 @@ impl FileManager { let anchor_path = self.path(anchor).to_path_buf(); let anchor_dir = anchor_path.parent().unwrap(); - // if `anchor` is a `main.nr`, `lib.nr`, `mod.nr` or `{modname}.nr`, we check siblings of + // if `anchor` is a `main.nr`, `lib.nr`, `mod.nr` or `{mod_name}.nr`, we check siblings of // the anchor at `base/mod_name.nr`. let candidate = if should_check_siblings_for_module(&anchor_path, anchor_dir) { anchor_dir.join(format!("{mod_name}.{FILE_EXTENSION}")) diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_directive.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_directive.rs index 8b5ff8e9cbd..a07865073ff 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_directive.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_directive.rs @@ -40,7 +40,7 @@ pub(crate) fn directive_invert() -> GeneratedBrillig { /// Generates brillig bytecode which computes `a / b` and returns the quotient and remainder. /// -/// This is equivalent to the Noir (psuedo)code +/// This is equivalent to the Noir (pseudo)code /// /// ```ignore /// fn quotient(a: T, b: T) -> (T,T) { diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/variable_liveness.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/variable_liveness.rs index eeea627a308..d57196288bf 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/variable_liveness.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/variable_liveness.rs @@ -50,7 +50,7 @@ fn collect_variables_of_value(value_id: ValueId, dfg: &DataFlowGraph) -> Vec { vec![value_id] } - // Literal arrays are constants, but might use variable values to initialise. + // Literal arrays are constants, but might use variable values to initialize. Value::Array { array, .. } => { let mut value_ids = Vec::new(); diff --git a/compiler/noirc_evaluator/src/ssa.rs b/compiler/noirc_evaluator/src/ssa.rs index 47e5f0492a5..131cf30a510 100644 --- a/compiler/noirc_evaluator/src/ssa.rs +++ b/compiler/noirc_evaluator/src/ssa.rs @@ -116,10 +116,10 @@ pub fn create_circuit( let mut debug_info = DebugInfo::new(locations); // Perform any ACIR-level optimizations - let (optimized_ciruit, transformation_map) = acvm::compiler::optimize(circuit); + let (optimized_circuit, transformation_map) = acvm::compiler::optimize(circuit); debug_info.update_acir(transformation_map); - Ok((optimized_ciruit, debug_info, abi)) + Ok((optimized_circuit, debug_info, abi)) } // This is just a convenience object to bundle the ssa with `print_ssa_passes` for debug printing. diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index da0381d34be..d846ede566f 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -96,6 +96,8 @@ pub(crate) struct AcirContext { /// The vars object is an instance of the `TwoWayMap`, which provides a bidirectional mapping between `AcirVar` and `AcirVarData`. vars: HashMap, + constant_witnesses: HashMap, + /// An in-memory representation of ACIR. /// /// This struct will progressively be populated @@ -227,7 +229,16 @@ impl AcirContext { /// Converts an [`AcirVar`] to a [`Witness`] fn var_to_witness(&mut self, var: AcirVar) -> Result { let expression = self.var_to_expression(var)?; - Ok(self.acir_ir.get_or_create_witness(&expression)) + let witness = if let Some(constant) = expression.to_const() { + // Check if a witness has been assigned this value already, if so reuse it. + *self + .constant_witnesses + .entry(constant) + .or_insert_with(|| self.acir_ir.get_or_create_witness(&expression)) + } else { + self.acir_ir.get_or_create_witness(&expression) + }; + Ok(witness) } /// Converts an [`AcirVar`] to an [`Expression`] @@ -281,7 +292,7 @@ impl AcirContext { let inverted_var = self.add_data(AcirVarData::Const(constant.inverse())); // Check that the inverted var is valid. - // This check prevents invalid divisons by zero. + // This check prevents invalid divisions by zero. let should_be_one = self.mul_var(inverted_var, var)?; self.maybe_eq_predicate(should_be_one, predicate)?; @@ -300,7 +311,7 @@ impl AcirContext { let inverted_var = Self::expect_one_var(results); // Check that the inverted var is valid. - // This check prevents invalid divisons by zero. + // This check prevents invalid divisions by zero. let should_be_one = self.mul_var(inverted_var, var)?; self.maybe_eq_predicate(should_be_one, predicate)?; @@ -560,7 +571,7 @@ impl AcirContext { /// Returns the quotient and remainder such that lhs = rhs * quotient + remainder /// and |remainder| < |rhs| /// and remainder has the same sign than lhs - /// Note that this is not the euclidian division, where we have instead remainder < |rhs| + /// Note that this is not the euclidean division, where we have instead remainder < |rhs| fn signed_division_var( &mut self, lhs: AcirVar, @@ -616,7 +627,7 @@ impl AcirContext { } /// Returns an `AcirVar` which will be constrained to be lhs mod 2^{rhs} - /// In order to do this, we 'simply' perform euclidian division of lhs by 2^{rhs} + /// In order to do this, we 'simply' perform euclidean division of lhs by 2^{rhs} /// The remainder of the division is then lhs mod 2^{rhs} pub(crate) fn truncate_var( &mut self, diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs index ca60a41d143..3ce1c8893fa 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs @@ -358,8 +358,8 @@ impl GeneratedAcir { } /// Signed division lhs / rhs - /// We derive the signed division from the unsigned euclidian division. - /// note that this is not euclidian division! + /// We derive the signed division from the unsigned euclidean division. + /// note that this is not euclidean division! // if x is a signed integer, then sign(x)x >= 0 // so if a and b are signed integers, we can do the unsigned division: // sign(a)a = q1*sign(b)b + r1 @@ -821,7 +821,7 @@ impl GeneratedAcir { let two_max_bits: FieldElement = two.pow(&FieldElement::from(max_bits as i128)); let comparison_evaluation = (a - b) + two_max_bits; - // Euclidian division by 2^{max_bits} : 2^{max_bits} + a - b = q * 2^{max_bits} + r + // euclidean division by 2^{max_bits} : 2^{max_bits} + a - b = q * 2^{max_bits} + r // // 2^{max_bits} is of max_bits+1 bit size // If a>b, then a-b is less than 2^{max_bits} - 1, so 2^{max_bits} + a - b is less than 2^{max_bits} + 2^{max_bits} - 1 = 2^{max_bits+1} - 1 diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs index f748aa040a1..badc1e82d50 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs @@ -239,10 +239,19 @@ impl Instruction { pub(crate) fn has_side_effects(&self, dfg: &DataFlowGraph) -> bool { use Instruction::*; - match self { - Binary(_) - | Cast(_, _) + Binary(binary) => { + if matches!(binary.operator, BinaryOp::Div | BinaryOp::Mod) { + if let Some(rhs) = dfg.get_numeric_constant(binary.rhs) { + rhs == FieldElement::zero() + } else { + true + } + } else { + false + } + } + Cast(_, _) | Not(_) | Truncate { .. } | Allocate diff --git a/compiler/noirc_evaluator/src/ssa/ir/value.rs b/compiler/noirc_evaluator/src/ssa/ir/value.rs index 8c2a4e88ef3..c83609dec1f 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/value.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/value.rs @@ -50,7 +50,7 @@ pub(crate) enum Value { Intrinsic(Intrinsic), /// This Value refers to an external function in the IR. - /// ForeignFunction's always have the type Type::Function and have simlar semantics to Function, + /// ForeignFunction's always have the type Type::Function and have similar semantics to Function, /// other than generating different backend operations and being only accessible through Brillig. ForeignFunction(String), } diff --git a/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs b/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs index 342a47160d0..e5fffaccdd0 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs @@ -524,8 +524,8 @@ mod tests { // Since the mem2reg pass simplifies as it goes, the id of the allocate instruction result // is most likely no longer v0. We have to retrieve the new id here. - let alloca_id = func.dfg.instruction_results(instructions[0])[0]; - assert_eq!(ret_val_id, alloca_id); + let allocate_id = func.dfg.instruction_results(instructions[0])[0]; + assert_eq!(ret_val_id, allocate_id); } fn count_stores(block: BasicBlockId, dfg: &DataFlowGraph) -> usize { diff --git a/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs b/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs index d1031c98558..142e9f81397 100644 --- a/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs +++ b/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs @@ -863,7 +863,7 @@ impl SharedContext { /// and return this new id. pub(super) fn get_or_queue_function(&self, id: ast::FuncId) -> IrFunctionId { // Start a new block to guarantee the destructor for the map lock is released - // before map needs to be aquired again in self.functions.write() below + // before map needs to be acquired again in self.functions.write() below { let map = self.functions.read().expect("Failed to read self.functions"); if let Some(existing_id) = map.get(&id) { diff --git a/compiler/noirc_evaluator/src/ssa/ssa_gen/value.rs b/compiler/noirc_evaluator/src/ssa/ssa_gen/value.rs index e7bb515465b..d71d4e5604e 100644 --- a/compiler/noirc_evaluator/src/ssa/ssa_gen/value.rs +++ b/compiler/noirc_evaluator/src/ssa/ssa_gen/value.rs @@ -24,7 +24,7 @@ pub(super) enum Tree { /// /// Note that these values wrap the ValueIds /// used internally by functions in the ssa ir and should thus be isolated -/// to a given function. If used outisde their function of origin, the IDs +/// to a given function. If used outside their function of origin, the IDs /// would be invalid. #[derive(Debug, Clone)] pub(super) enum Value { diff --git a/compiler/noirc_frontend/src/ast/expression.rs b/compiler/noirc_frontend/src/ast/expression.rs index f8c67781a49..4c8e98a0d4d 100644 --- a/compiler/noirc_frontend/src/ast/expression.rs +++ b/compiler/noirc_frontend/src/ast/expression.rs @@ -480,7 +480,7 @@ impl Display for ExpressionKind { write!(f, "({})", elements.join(", ")) } Lambda(lambda) => lambda.fmt(f), - Parenthesized(subexpr) => write!(f, "({subexpr})"), + Parenthesized(sub_expr) => write!(f, "({sub_expr})"), Error => write!(f, "Error"), } } diff --git a/compiler/noirc_frontend/src/hir/aztec_library.rs b/compiler/noirc_frontend/src/hir/aztec_library.rs index c09835b2071..2d91840544c 100644 --- a/compiler/noirc_frontend/src/hir/aztec_library.rs +++ b/compiler/noirc_frontend/src/hir/aztec_library.rs @@ -591,7 +591,7 @@ fn abstract_return_values(func: &NoirFunction) -> Option { let last_statement = &func.def.body.0[len - 1]; // TODO: (length, type) => We can limit the size of the array returned to be limited by kernel size - // Doesnt need done until we have settled on a kernel size + // Doesn't need done until we have settled on a kernel size // TODO: support tuples here and in inputs -> convert into an issue // Check if the return type is an expression, if it is, we can handle it @@ -864,11 +864,11 @@ fn add_array_to_hasher(identifier: &Ident) -> Statement { fn add_field_to_hasher(identifier: &Ident) -> Statement { // `hasher.add({ident})` - let iden = variable_path(path(identifier.clone())); + let ident = variable_path(path(identifier.clone())); make_statement(StatementKind::Semi(method_call( variable("hasher"), // variable "add", // method name - vec![iden], // args + vec![ident], // args ))) } diff --git a/compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs b/compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs index 86cdd936b0d..a458814ce9e 100644 --- a/compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs +++ b/compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs @@ -303,7 +303,7 @@ impl DefCollector { errors.extend(collect_impls(context, crate_id, &def_collector.collected_impls)); // Bind trait impls to their trait. Collect trait functions, that have a - // default implementation, which hasn't been overriden. + // default implementation, which hasn't been overridden. errors.extend(collect_trait_impls( context, crate_id, @@ -499,17 +499,18 @@ fn add_method_to_struct_namespace( struct_type: &Shared, func_id: FuncId, name_ident: &Ident, + trait_id: TraitId, ) -> Result<(), DefCollectorErrorKind> { let struct_type = struct_type.borrow(); let type_module = struct_type.id.local_module_id(); let module = &mut current_def_map.modules[type_module.0]; - module.declare_function(name_ident.clone(), func_id).map_err(|(first_def, second_def)| { - DefCollectorErrorKind::Duplicate { + module.declare_trait_function(name_ident.clone(), func_id, trait_id).map_err( + |(first_def, second_def)| DefCollectorErrorKind::Duplicate { typ: DuplicateType::TraitImplementation, first_def, second_def, - } - }) + }, + ) } fn collect_trait_impl( @@ -550,6 +551,7 @@ fn collect_trait_impl( struct_type, *func_id, ast.name_ident(), + trait_id, ) { Ok(()) => {} Err(err) => { diff --git a/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs b/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs index 803ffbc41fe..ed48d7fbb51 100644 --- a/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs +++ b/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs @@ -251,7 +251,7 @@ impl<'a> ModCollector<'a> { types: Vec, krate: CrateId, ) -> Vec<(CompilationError, FileId)> { - let mut definiton_errors = vec![]; + let mut definition_errors = vec![]; for struct_definition in types { let name = struct_definition.name.clone(); @@ -265,7 +265,7 @@ impl<'a> ModCollector<'a> { let id = match self.push_child_module(&name, self.file_id, false, false) { Ok(local_id) => context.def_interner.new_struct(&unresolved, krate, local_id), Err(error) => { - definiton_errors.push((error.into(), self.file_id)); + definition_errors.push((error.into(), self.file_id)); continue; } }; @@ -280,13 +280,13 @@ impl<'a> ModCollector<'a> { first_def, second_def, }; - definiton_errors.push((error.into(), self.file_id)); + definition_errors.push((error.into(), self.file_id)); } // And store the TypeId -> StructType mapping somewhere it is reachable self.def_collector.collected_types.insert(id, unresolved); } - definiton_errors + definition_errors } /// Collect any type aliases definitions declared within the ast. @@ -514,7 +514,7 @@ impl<'a> ModCollector<'a> { }; errors.push((error.into(), location.file)); - let error2 = DefCollectorErrorKind::ModuleOrignallyDefined { + let error2 = DefCollectorErrorKind::ModuleOriginallyDefined { mod_name: mod_name.clone(), span: old_location.span, }; diff --git a/compiler/noirc_frontend/src/hir/def_collector/errors.rs b/compiler/noirc_frontend/src/hir/def_collector/errors.rs index 5cd18e7f4ae..4e7f8ad286b 100644 --- a/compiler/noirc_frontend/src/hir/def_collector/errors.rs +++ b/compiler/noirc_frontend/src/hir/def_collector/errors.rs @@ -56,7 +56,7 @@ pub enum DefCollectorErrorKind { #[error("Module is already part of the crate")] ModuleAlreadyPartOfCrate { mod_name: Ident, span: Span }, #[error("Module was originally declared here")] - ModuleOrignallyDefined { mod_name: Ident, span: Span }, + ModuleOriginallyDefined { mod_name: Ident, span: Span }, #[cfg(feature = "aztec")] #[error("Aztec dependency not found. Please add aztec as a dependency in your Cargo.toml")] AztecNotFound {}, @@ -189,7 +189,7 @@ impl From for Diagnostic { let secondary = String::new(); Diagnostic::simple_error(message, secondary, span) } - DefCollectorErrorKind::ModuleOrignallyDefined { mod_name, span } => { + DefCollectorErrorKind::ModuleOriginallyDefined { mod_name, span } => { let message = format!("Note: {mod_name} was originally declared here"); let secondary = String::new(); Diagnostic::simple_error(message, secondary, span) diff --git a/compiler/noirc_frontend/src/hir/def_map/item_scope.rs b/compiler/noirc_frontend/src/hir/def_map/item_scope.rs index 78375ab2bc0..42cca550651 100644 --- a/compiler/noirc_frontend/src/hir/def_map/item_scope.rs +++ b/compiler/noirc_frontend/src/hir/def_map/item_scope.rs @@ -1,5 +1,8 @@ use super::{namespace::PerNs, ModuleDefId, ModuleId}; -use crate::{node_interner::FuncId, Ident}; +use crate::{ + node_interner::{FuncId, TraitId}, + Ident, +}; use std::collections::{hash_map::Entry, HashMap}; #[derive(Debug, PartialEq, Eq, Copy, Clone)] @@ -9,8 +12,8 @@ pub enum Visibility { #[derive(Default, Debug, PartialEq, Eq)] pub struct ItemScope { - types: HashMap, - values: HashMap, + types: HashMap, (ModuleDefId, Visibility)>>, + values: HashMap, (ModuleDefId, Visibility)>>, defs: Vec, } @@ -20,8 +23,9 @@ impl ItemScope { &mut self, name: Ident, mod_def: ModuleDefId, + trait_id: Option, ) -> Result<(), (Ident, Ident)> { - self.add_item_to_namespace(name, mod_def)?; + self.add_item_to_namespace(name, mod_def, trait_id)?; self.defs.push(mod_def); Ok(()) } @@ -33,16 +37,26 @@ impl ItemScope { &mut self, name: Ident, mod_def: ModuleDefId, + trait_id: Option, ) -> Result<(), (Ident, Ident)> { - let add_item = |map: &mut HashMap| { - if let Entry::Occupied(o) = map.entry(name.clone()) { - let old_ident = o.key(); - Err((old_ident.clone(), name)) - } else { - map.insert(name, (mod_def, Visibility::Public)); - Ok(()) - } - }; + let add_item = + |map: &mut HashMap, (ModuleDefId, Visibility)>>| { + if let Entry::Occupied(mut o) = map.entry(name.clone()) { + let trait_hashmap = o.get_mut(); + if let Entry::Occupied(_) = trait_hashmap.entry(trait_id) { + let old_ident = o.key(); + Err((old_ident.clone(), name)) + } else { + trait_hashmap.insert(trait_id, (mod_def, Visibility::Public)); + Ok(()) + } + } else { + let mut trait_hashmap = HashMap::new(); + trait_hashmap.insert(trait_id, (mod_def, Visibility::Public)); + map.insert(name, trait_hashmap); + Ok(()) + } + }; match mod_def { ModuleDefId::ModuleId(_) => add_item(&mut self.types), @@ -55,7 +69,7 @@ impl ItemScope { } pub fn find_module_with_name(&self, mod_name: &Ident) -> Option<&ModuleId> { - let (module_def, _) = self.types.get(mod_name)?; + let (module_def, _) = self.types.get(mod_name)?.get(&None)?; match module_def { ModuleDefId::ModuleId(id) => Some(id), _ => None, @@ -63,7 +77,35 @@ impl ItemScope { } pub fn find_func_with_name(&self, func_name: &Ident) -> Option { - let (module_def, _) = self.values.get(func_name)?; + let trait_hashmap = self.values.get(func_name)?; + // methods introduced without trait take priority and hide methods with the same name that come from a trait + let a = trait_hashmap.get(&None); + match a { + Some((module_def, _)) => match module_def { + ModuleDefId::FunctionId(id) => Some(*id), + _ => None, + }, + None => { + if trait_hashmap.len() == 1 { + let (module_def, _) = trait_hashmap.get(trait_hashmap.keys().last()?)?; + match module_def { + ModuleDefId::FunctionId(id) => Some(*id), + _ => None, + } + } else { + // ambiguous name (multiple traits, containing the same function name) + None + } + } + } + } + + pub fn find_func_with_name_and_trait_id( + &self, + func_name: &Ident, + trait_id: &Option, + ) -> Option { + let (module_def, _) = self.values.get(func_name)?.get(trait_id)?; match module_def { ModuleDefId::FunctionId(id) => Some(*id), _ => None, @@ -71,18 +113,46 @@ impl ItemScope { } pub fn find_name(&self, name: &Ident) -> PerNs { - PerNs { types: self.types.get(name).cloned(), values: self.values.get(name).cloned() } + // Names, not associated with traits are searched first. If not found, we search for name, coming from a trait. + // If we find only one name from trait, we return it. If there are multiple traits, providing the same name, we return None. + let find_name_in = + |a: &HashMap, (ModuleDefId, Visibility)>>| { + if let Some(t) = a.get(name) { + if let Some(tt) = t.get(&None) { + Some(*tt) + } else if t.len() == 1 { + t.values().last().cloned() + } else { + None + } + } else { + None + } + }; + + PerNs { types: find_name_in(&self.types), values: find_name_in(&self.values) } + } + + pub fn find_name_for_trait_id(&self, name: &Ident, trait_id: &Option) -> PerNs { + PerNs { + types: if let Some(t) = self.types.get(name) { t.get(trait_id).cloned() } else { None }, + values: if let Some(v) = self.values.get(name) { + v.get(trait_id).cloned() + } else { + None + }, + } } pub fn definitions(&self) -> Vec { self.defs.clone() } - pub fn types(&self) -> &HashMap { + pub fn types(&self) -> &HashMap, (ModuleDefId, Visibility)>> { &self.types } - pub fn values(&self) -> &HashMap { + pub fn values(&self) -> &HashMap, (ModuleDefId, Visibility)>> { &self.values } diff --git a/compiler/noirc_frontend/src/hir/def_map/module_data.rs b/compiler/noirc_frontend/src/hir/def_map/module_data.rs index 5528312c0fc..29b11e92c01 100644 --- a/compiler/noirc_frontend/src/hir/def_map/module_data.rs +++ b/compiler/noirc_frontend/src/hir/def_map/module_data.rs @@ -41,16 +41,30 @@ impl ModuleData { } } - fn declare(&mut self, name: Ident, item_id: ModuleDefId) -> Result<(), (Ident, Ident)> { - self.scope.add_definition(name.clone(), item_id)?; + fn declare( + &mut self, + name: Ident, + item_id: ModuleDefId, + trait_id: Option, + ) -> Result<(), (Ident, Ident)> { + self.scope.add_definition(name.clone(), item_id, trait_id)?; // definitions is a subset of self.scope so it is expected if self.scope.define_func_def // returns without error, so will self.definitions.define_func_def. - self.definitions.add_definition(name, item_id) + self.definitions.add_definition(name, item_id, trait_id) } pub fn declare_function(&mut self, name: Ident, id: FuncId) -> Result<(), (Ident, Ident)> { - self.declare(name, id.into()) + self.declare(name, id.into(), None) + } + + pub fn declare_trait_function( + &mut self, + name: Ident, + id: FuncId, + trait_id: TraitId, + ) -> Result<(), (Ident, Ident)> { + self.declare(name, id.into(), Some(trait_id)) } pub fn remove_function(&mut self, name: &Ident) { @@ -59,11 +73,11 @@ impl ModuleData { } pub fn declare_global(&mut self, name: Ident, id: StmtId) -> Result<(), (Ident, Ident)> { - self.declare(name, id.into()) + self.declare(name, id.into(), None) } pub fn declare_struct(&mut self, name: Ident, id: StructId) -> Result<(), (Ident, Ident)> { - self.declare(name, ModuleDefId::TypeId(id)) + self.declare(name, ModuleDefId::TypeId(id), None) } pub fn declare_type_alias( @@ -71,11 +85,11 @@ impl ModuleData { name: Ident, id: TypeAliasId, ) -> Result<(), (Ident, Ident)> { - self.declare(name, id.into()) + self.declare(name, id.into(), None) } pub fn declare_trait(&mut self, name: Ident, id: TraitId) -> Result<(), (Ident, Ident)> { - self.declare(name, ModuleDefId::TraitId(id)) + self.declare(name, ModuleDefId::TraitId(id), None) } pub fn declare_child_module( @@ -83,7 +97,7 @@ impl ModuleData { name: Ident, child_id: ModuleId, ) -> Result<(), (Ident, Ident)> { - self.declare(name, child_id.into()) + self.declare(name, child_id.into(), None) } pub fn find_func_with_name(&self, name: &Ident) -> Option { @@ -91,7 +105,7 @@ impl ModuleData { } pub fn import(&mut self, name: Ident, id: ModuleDefId) -> Result<(), (Ident, Ident)> { - self.scope.add_item_to_namespace(name, id) + self.scope.add_item_to_namespace(name, id, None) } pub fn find_name(&self, name: &Ident) -> PerNs { @@ -99,12 +113,12 @@ impl ModuleData { } pub fn type_definitions(&self) -> impl Iterator + '_ { - self.definitions.types().values().map(|(id, _)| *id) + self.definitions.types().values().flat_map(|a| a.values().map(|(id, _)| *id)) } /// Return an iterator over all definitions defined within this module, /// excluding any type definitions. pub fn value_definitions(&self) -> impl Iterator + '_ { - self.definitions.values().values().map(|(id, _)| *id) + self.definitions.values().values().flat_map(|a| a.values().map(|(id, _)| *id)) } } diff --git a/compiler/noirc_frontend/src/hir/resolution/resolver.rs b/compiler/noirc_frontend/src/hir/resolution/resolver.rs index 97c71eedf4e..f9bf01c0957 100644 --- a/compiler/noirc_frontend/src/hir/resolution/resolver.rs +++ b/compiler/noirc_frontend/src/hir/resolution/resolver.rs @@ -1260,7 +1260,7 @@ impl<'a> Resolver<'a> { captures: lambda_context.captures, }) }), - ExpressionKind::Parenthesized(subexpr) => return self.resolve_expression(*subexpr), + ExpressionKind::Parenthesized(sub_expr) => return self.resolve_expression(*sub_expr), }; let expr_id = self.interner.push_expr(hir_expr); diff --git a/compiler/noirc_frontend/src/hir/type_check/expr.rs b/compiler/noirc_frontend/src/hir/type_check/expr.rs index b7e9fe953fd..27820922100 100644 --- a/compiler/noirc_frontend/src/hir/type_check/expr.rs +++ b/compiler/noirc_frontend/src/hir/type_check/expr.rs @@ -475,7 +475,7 @@ impl<'interner> TypeChecker<'interner> { arguments: Vec<(Type, ExprId, Span)>, span: Span, ) -> Type { - let (fntyp, param_len) = match method_ref { + let (fn_typ, param_len) = match method_ref { HirMethodReference::FuncId(func_id) => { if func_id == FuncId::dummy_id() { return Type::Error; @@ -504,7 +504,7 @@ impl<'interner> TypeChecker<'interner> { }); } - let (function_type, instantiation_bindings) = fntyp.instantiate(self.interner); + let (function_type, instantiation_bindings) = fn_typ.instantiate(self.interner); self.interner.store_instantiation_bindings(*function_ident_id, instantiation_bindings); self.interner.push_expr_type(function_ident_id, function_type.clone()); diff --git a/compiler/noirc_frontend/src/hir_def/expr.rs b/compiler/noirc_frontend/src/hir_def/expr.rs index 157e424bc95..42803378ccb 100644 --- a/compiler/noirc_frontend/src/hir_def/expr.rs +++ b/compiler/noirc_frontend/src/hir_def/expr.rs @@ -103,7 +103,7 @@ pub struct HirInfixExpression { pub rhs: ExprId, } -/// This is always a struct field access `mystruct.field` +/// This is always a struct field access `my_struct.field` /// and never a method call. The later is represented by HirMethodCallExpression. #[derive(Debug, Clone)] pub struct HirMemberAccess { @@ -155,7 +155,7 @@ pub enum HirMethodReference { /// Or a method can come from a Trait impl block, in which case /// the actual function called will depend on the instantiated type, - /// which can be only known during monomorphizaiton. + /// which can be only known during monomorphization. TraitMethodId(Type, TraitMethodId), } diff --git a/compiler/noirc_frontend/src/node_interner.rs b/compiler/noirc_frontend/src/node_interner.rs index 4f26f212afa..c4497331fae 100644 --- a/compiler/noirc_frontend/src/node_interner.rs +++ b/compiler/noirc_frontend/src/node_interner.rs @@ -126,7 +126,7 @@ pub struct NodeInterner { } /// All the information from a function that is filled out during definition collection rather than -/// name resolution. Resultingly, if information about a function is needed during name resolution, +/// name resolution. As a result, if information about a function is needed during name resolution, /// this is the only place where it is safe to retrieve it (where all fields are guaranteed to be initialized). pub struct FunctionModifiers { pub name: String, @@ -614,7 +614,7 @@ impl NodeInterner { id } - /// Push a function with the default modifiers and moduleid for testing + /// Push a function with the default modifiers and [`ModuleId`] for testing #[cfg(test)] pub fn push_test_function_definition(&mut self, name: String) -> FuncId { let id = self.push_fn(HirFunction::empty()); diff --git a/compiler/noirc_frontend/src/parser/parser.rs b/compiler/noirc_frontend/src/parser/parser.rs index 083646ceab0..6b43bd003f3 100644 --- a/compiler/noirc_frontend/src/parser/parser.rs +++ b/compiler/noirc_frontend/src/parser/parser.rs @@ -346,10 +346,10 @@ fn nothing() -> impl NoirParser { } fn self_parameter() -> impl NoirParser<(Pattern, UnresolvedType, Visibility)> { - let refmut_pattern = just(Token::Ampersand).then_ignore(keyword(Keyword::Mut)); + let mut_ref_pattern = just(Token::Ampersand).then_ignore(keyword(Keyword::Mut)); let mut_pattern = keyword(Keyword::Mut); - refmut_pattern + mut_ref_pattern .or(mut_pattern) .map_with_span(|token, span| (token, span)) .or_not() @@ -935,7 +935,7 @@ fn assign_operator() -> impl NoirParser { let shorthand_operators = right_shift_operator().or(one_of(shorthand_operators)); let shorthand_syntax = shorthand_operators.then_ignore(just(Token::Assign)); - // Since >> is lexed as two separate greater-thans, >>= is lexed as > >=, so + // Since >> is lexed as two separate "greater-than"s, >>= is lexed as > >=, so // we need to account for that case here as well. let right_shift_fix = just(Token::Greater).then(just(Token::GreaterEqual)).map(|_| Token::ShiftRight); @@ -1554,8 +1554,8 @@ where literal(), )) .map_with_span(Expression::new) - .or(parenthesized(expr_parser.clone()).map_with_span(|subexpr, span| { - Expression::new(ExpressionKind::Parenthesized(subexpr.into()), span) + .or(parenthesized(expr_parser.clone()).map_with_span(|sub_expr, span| { + Expression::new(ExpressionKind::Parenthesized(sub_expr.into()), span) })) .or(tuple(expr_parser)) .labelled(ParsingRuleLabel::Atom) diff --git a/compiler/noirc_frontend/src/tests.rs b/compiler/noirc_frontend/src/tests.rs index 87adc9d83a8..91fce8d8862 100644 --- a/compiler/noirc_frontend/src/tests.rs +++ b/compiler/noirc_frontend/src/tests.rs @@ -327,29 +327,29 @@ mod test { // wrong trait name method should not compile impl Default for Foo { - fn doesnt_exist(x: Field, y: Field) -> Self { + fn does_not_exist(x: Field, y: Field) -> Self { Self { bar: x, array: [x,y] } } } fn main() { }"; - let compilator_errors = get_program_errors(src); - assert!(!has_parser_error(&compilator_errors)); + let compilation_errors = get_program_errors(src); + assert!(!has_parser_error(&compilation_errors)); assert!( - compilator_errors.len() == 1, + compilation_errors.len() == 1, "Expected 1 compilation error, got: {:?}", - compilator_errors + compilation_errors ); - for (err, _file_id) in compilator_errors { + for (err, _file_id) in compilation_errors { match &err { CompilationError::DefinitionError(DefCollectorErrorKind::MethodNotInTrait { trait_name, impl_method, }) => { assert_eq!(trait_name, "Default"); - assert_eq!(impl_method, "doesnt_exist"); + assert_eq!(impl_method, "does_not_exist"); } _ => { panic!("No other errors are expected! Found = {:?}", err); @@ -1057,7 +1057,7 @@ mod test { println(f"I want to print {0}"); let new_val = 10; - println(f"randomstring{new_val}{new_val}"); + println(f"random_string{new_val}{new_val}"); } fn println(x : T) -> T { x @@ -1088,7 +1088,7 @@ mod test { assert!( a == "println(string)" || a == "println(f\"I want to print {0}\")" - || a == "println(f\"randomstring{new_val}{new_val}\")" + || a == "println(f\"random_string{new_val}{new_val}\")" ); } _ => unimplemented!(), diff --git a/cspell.json b/cspell.json index 79699391423..a667fc6d7aa 100644 --- a/cspell.json +++ b/cspell.json @@ -1,38 +1,63 @@ { "version": "0.2", "words": [ - // In code - // "aarch", + "acir", + "acvm", "aeiou", - "arraysort", "arithmetization", "arity", + "arkworks", + "arraysort", "barretenberg", + "bincode", + "bindgen", + "bitand", "blackbox", "brillig", + "callsite", + "callsites", + "canonicalize", + "castable", + "chumsky", + "clippy", "codegen", + "codegens", "coeff", "combinators", "comptime", "cranelift", "deflatten", "deflattened", + "deflattening", + "defunctionalization", "defunctionalize", "defunctionalized", - "defunctionalization", + "deque", "desugared", + "direnv", "eddsa", "endianness", + "envrc", "Flamegraph", + "flate", + "fmtstr", + "foldl", "forall", "foralls", + "formatcp", + "fxhash", + "getrandom", + "gloo", "Guillaume", + "hasher", + "hexdigit", "higher-kinded", "Hindley-Milner", "idents", "impls", "injective", + "Inlines", "interner", "intrinsics", "jmp", @@ -50,63 +75,48 @@ "monomorphizer", "monomorphizes", "nand", + "nargo", + "nixpkgs", + "noirc", + "noirup", "pedersen", "peekable", + "plonkc", "pprof", "preprocess", "prettytable", "printstd", "pseudocode", + "rustc", + "rustup", "schnorr", "sdiv", + "secp256k1", + "secp256r1", "signedness", + "smol", + "splitn", "srem", "stdlib", "struct", "subexpression", + "subshell", "subtyping", + "tempdir", + "tempfile", + "termcolor", + "thiserror", + "tslog", + "typecheck", + "typechecked", "typevar", "typevars", "udiv", "uninstantiated", "unnormalized", + "unoptimized", "urem", "vecmap", - "direnv", - "nixpkgs", - "envrc", - "subshell", - // Dependencies - // - "acir", - "acvm", - "arkworks", - "bincode", - "bindgen", - "bitand", - "canonicalize", - "chumsky", - "clippy", - "deque", - "flate", - "foldl", - "formatcp", - "fxhash", - "gloo", - "hasher", - "hexdigit", - "nargo", - "noirc", - "noirup", - "plonkc", - "rustc", - "rustup", - "secp256k1", - "secp256r1", - "smol", - "tempdir", - "tempfile", - "termcolor", - "thiserror" + "wasi" ] } diff --git a/deny.toml b/deny.toml index 5d5b0e34d0f..e19406592d8 100644 --- a/deny.toml +++ b/deny.toml @@ -58,6 +58,8 @@ allow = [ "LicenseRef-rustls-webpki", # bitmaps 2.1.0, generational-arena 0.2.9,im 15.1.0 "MPL-2.0", + # Boost Software License + "BSL-1.0" ] # Allow 1 or more licenses on a per-crate basis, so that particular licenses diff --git a/tooling/debugger/Cargo.toml b/tooling/debugger/Cargo.toml new file mode 100644 index 00000000000..5b8248345a0 --- /dev/null +++ b/tooling/debugger/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "noir_debugger" +description = "Debugger for Noir" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +acvm.workspace = true +nargo.workspace = true +noirc_printable_type.workspace = true +thiserror.workspace = true +easy-repl = "0.2.1" \ No newline at end of file diff --git a/tooling/debugger/src/lib.rs b/tooling/debugger/src/lib.rs new file mode 100644 index 00000000000..ed9fe08ca97 --- /dev/null +++ b/tooling/debugger/src/lib.rs @@ -0,0 +1,178 @@ +use acvm::acir::circuit::OpcodeLocation; +use acvm::pwg::{ACVMStatus, ErrorLocation, OpcodeResolutionError, ACVM}; +use acvm::BlackBoxFunctionSolver; +use acvm::{acir::circuit::Circuit, acir::native_types::WitnessMap}; + +use nargo::artifacts::debug::DebugArtifact; +use nargo::errors::ExecutionError; +use nargo::NargoError; + +use nargo::ops::ForeignCallExecutor; + +use easy_repl::{command, CommandStatus, Critical, Repl}; +use std::cell::{Cell, RefCell}; + +enum SolveResult { + Done, + Ok, +} + +struct DebugContext<'backend, B: BlackBoxFunctionSolver> { + acvm: Option>, + debug_artifact: DebugArtifact, + foreign_call_executor: ForeignCallExecutor, + circuit: Circuit, + show_output: bool, +} + +impl<'backend, B: BlackBoxFunctionSolver> DebugContext<'backend, B> { + fn step_opcode(&mut self) -> Result { + let solver_status = self.acvm.as_mut().unwrap().solve_opcode(); + + match solver_status { + ACVMStatus::Solved => Ok(SolveResult::Done), + ACVMStatus::InProgress => Ok(SolveResult::Ok), + ACVMStatus::Failure(error) => { + let call_stack = match &error { + OpcodeResolutionError::UnsatisfiedConstrain { + opcode_location: ErrorLocation::Resolved(opcode_location), + } => Some(vec![*opcode_location]), + OpcodeResolutionError::BrilligFunctionFailed { call_stack, .. } => { + Some(call_stack.clone()) + } + _ => None, + }; + + Err(NargoError::ExecutionError(match call_stack { + Some(call_stack) => { + if let Some(assert_message) = self.circuit.get_assert_message( + *call_stack.last().expect("Call stacks should not be empty"), + ) { + ExecutionError::AssertionFailed(assert_message.to_owned(), call_stack) + } else { + ExecutionError::SolvingError(error) + } + } + None => ExecutionError::SolvingError(error), + })) + } + ACVMStatus::RequiresForeignCall(foreign_call) => { + let foreign_call_result = + self.foreign_call_executor.execute(&foreign_call, self.show_output)?; + self.acvm.as_mut().unwrap().resolve_pending_foreign_call(foreign_call_result); + Ok(SolveResult::Ok) + } + } + } + + fn show_current_vm_status(&self) { + let acvm = self.acvm.as_ref().unwrap(); + let ip = acvm.instruction_pointer(); + let opcodes = acvm.opcodes(); + if ip >= opcodes.len() { + println!("Finished execution"); + } else { + println!("Stopped at opcode {}: {}", ip, opcodes[ip]); + Self::show_source_code_location(&OpcodeLocation::Acir(ip), &self.debug_artifact); + } + } + + fn show_source_code_location(location: &OpcodeLocation, debug_artifact: &DebugArtifact) { + let locations = debug_artifact.debug_symbols[0].opcode_location(location); + if let Some(locations) = locations { + for loc in locations { + let file = &debug_artifact.file_map[&loc.file]; + let source = &file.source.as_str(); + let start = loc.span.start() as usize; + let end = loc.span.end() as usize; + println!("At {}.nr:{start}-{end}", file.path.as_path().display()); + println!("\n{}\n", &source[start..end]); + } + } + } + + fn cont(&mut self) -> Result { + loop { + match self.step_opcode()? { + SolveResult::Done => break, + SolveResult::Ok => {} + } + } + Ok(SolveResult::Done) + } + + fn finalize(&mut self) -> WitnessMap { + self.acvm.take().unwrap().finalize() + } +} + +fn map_command_status(result: SolveResult) -> CommandStatus { + match result { + SolveResult::Ok => CommandStatus::Done, + SolveResult::Done => CommandStatus::Quit, + } +} + +pub fn debug_circuit( + blackbox_solver: &B, + circuit: Circuit, + debug_artifact: DebugArtifact, + initial_witness: WitnessMap, + show_output: bool, +) -> Result, NargoError> { + let opcodes = circuit.opcodes.clone(); + + let context = RefCell::new(DebugContext { + acvm: Some(ACVM::new(blackbox_solver, &opcodes, initial_witness)), + foreign_call_executor: ForeignCallExecutor::default(), + circuit, + debug_artifact, + show_output, + }); + let ref_step = &context; + let ref_cont = &context; + + let solved = Cell::new(false); + + context.borrow().show_current_vm_status(); + + let handle_result = |result| { + solved.set(matches!(result, SolveResult::Done)); + Ok(map_command_status(result)) + }; + + let mut repl = Repl::builder() + .add( + "s", + command! { + "step to the next opcode", + () => || { + let result = ref_step.borrow_mut().step_opcode().into_critical()?; + ref_step.borrow().show_current_vm_status(); + handle_result(result) + } + }, + ) + .add( + "c", + command! { + "continue execution until the end of the program", + () => || { + println!("(Continuing execution...)"); + let result = ref_cont.borrow_mut().cont().into_critical()?; + handle_result(result) + } + }, + ) + .build() + .expect("Failed to initialize debugger repl"); + + repl.run().expect("Debugger error"); + + if solved.get() { + let solved_witness = context.borrow_mut().finalize(); + Ok(Some(solved_witness)) + } else { + Ok(None) + } +} diff --git a/tooling/nargo/src/ops/foreign_calls.rs b/tooling/nargo/src/ops/foreign_calls.rs index e44ab1732c9..4d20a0bd4f0 100644 --- a/tooling/nargo/src/ops/foreign_calls.rs +++ b/tooling/nargo/src/ops/foreign_calls.rs @@ -89,7 +89,7 @@ impl MockedCall { } #[derive(Debug, Default)] -pub(crate) struct ForeignCallExecutor { +pub struct ForeignCallExecutor { /// Mocks have unique ids used to identify them in Noir, allowing to update or remove them. last_mock_id: usize, /// The registered mocks @@ -97,7 +97,7 @@ pub(crate) struct ForeignCallExecutor { } impl ForeignCallExecutor { - pub(crate) fn execute( + pub fn execute( &mut self, foreign_call: &ForeignCallWaitInfo, show_output: bool, diff --git a/tooling/nargo/src/ops/mod.rs b/tooling/nargo/src/ops/mod.rs index f789455577c..491320482cf 100644 --- a/tooling/nargo/src/ops/mod.rs +++ b/tooling/nargo/src/ops/mod.rs @@ -1,4 +1,5 @@ pub use self::execute::execute_circuit; +pub use self::foreign_calls::ForeignCallExecutor; pub use self::optimize::{optimize_contract, optimize_program}; pub use self::test::{run_test, TestStatus}; diff --git a/tooling/nargo_cli/Cargo.toml b/tooling/nargo_cli/Cargo.toml index d90aa0ca2ab..cb824b41428 100644 --- a/tooling/nargo_cli/Cargo.toml +++ b/tooling/nargo_cli/Cargo.toml @@ -26,6 +26,7 @@ nargo.workspace = true nargo_fmt.workspace = true nargo_toml.workspace = true noir_lsp.workspace = true +noir_debugger.workspace = true noirc_driver.workspace = true noirc_frontend.workspace = true noirc_abi.workspace = true diff --git a/tooling/nargo_cli/src/cli/debug_cmd.rs b/tooling/nargo_cli/src/cli/debug_cmd.rs new file mode 100644 index 00000000000..5dcb2c7bdec --- /dev/null +++ b/tooling/nargo_cli/src/cli/debug_cmd.rs @@ -0,0 +1,129 @@ +use acvm::acir::native_types::WitnessMap; +use clap::Args; + +use nargo::artifacts::debug::DebugArtifact; +use nargo::constants::PROVER_INPUT_FILE; +use nargo::package::Package; +use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection}; +use noirc_abi::input_parser::{Format, InputValue}; +use noirc_abi::InputMap; +use noirc_driver::{CompileOptions, CompiledProgram}; +use noirc_frontend::graph::CrateName; + +use super::compile_cmd::compile_bin_package; +use super::fs::{inputs::read_inputs_from_file, witness::save_witness_to_dir}; +use super::NargoConfig; +use crate::backends::Backend; +use crate::errors::CliError; + +/// Executes a circuit in debug mode +#[derive(Debug, Clone, Args)] +pub(crate) struct DebugCommand { + /// Write the execution witness to named file + witness_name: Option, + + /// The name of the toml file which contains the inputs for the prover + #[clap(long, short, default_value = PROVER_INPUT_FILE)] + prover_name: String, + + /// The name of the package to execute + #[clap(long)] + package: Option, + + #[clap(flatten)] + compile_options: CompileOptions, +} + +pub(crate) fn run( + backend: &Backend, + args: DebugCommand, + config: NargoConfig, +) -> Result<(), CliError> { + 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)?; + let target_dir = &workspace.target_directory_path(); + let (np_language, opcode_support) = backend.get_backend_info()?; + + let Some(package) = workspace.into_iter().find(|p| p.is_binary()) else { + println!( + "No matching binary packages found in workspace. Only binary packages can be debugged." + ); + return Ok(()); + }; + + let compiled_program = compile_bin_package( + &workspace, + package, + &args.compile_options, + true, + np_language, + &|opcode| opcode_support.is_opcode_supported(opcode), + )?; + + println!("[{}] Starting debugger", package.name); + let (return_value, solved_witness) = + debug_program_and_decode(compiled_program, package, &args.prover_name)?; + + if let Some(solved_witness) = solved_witness { + println!("[{}] Circuit witness successfully solved", package.name); + + if let Some(return_value) = return_value { + println!("[{}] Circuit output: {return_value:?}", package.name); + } + + if let Some(witness_name) = &args.witness_name { + let witness_path = save_witness_to_dir(solved_witness, witness_name, target_dir)?; + + println!("[{}] Witness saved to {}", package.name, witness_path.display()); + } + } else { + println!("Debugger execution halted."); + } + + Ok(()) +} + +fn debug_program_and_decode( + program: CompiledProgram, + package: &Package, + prover_name: &str, +) -> Result<(Option, Option), CliError> { + // Parse the initial witness values from Prover.toml + let (inputs_map, _) = + read_inputs_from_file(&package.root_dir, prover_name, Format::Toml, &program.abi)?; + let solved_witness = debug_program(&program, &inputs_map)?; + let public_abi = program.abi.public_abi(); + + match solved_witness { + Some(witness) => { + let (_, return_value) = public_abi.decode(&witness)?; + Ok((return_value, Some(witness))) + } + None => Ok((None, None)), + } +} + +pub(crate) fn debug_program( + compiled_program: &CompiledProgram, + inputs_map: &InputMap, +) -> Result, CliError> { + #[allow(deprecated)] + let blackbox_solver = barretenberg_blackbox_solver::BarretenbergSolver::new(); + + let initial_witness = compiled_program.abi.encode(inputs_map, None)?; + + let debug_artifact = DebugArtifact { + debug_symbols: vec![compiled_program.debug.clone()], + file_map: compiled_program.file_map.clone(), + }; + + noir_debugger::debug_circuit( + &blackbox_solver, + compiled_program.circuit.clone(), + debug_artifact, + initial_witness, + true, + ) + .map_err(CliError::from) +} diff --git a/tooling/nargo_cli/src/cli/mod.rs b/tooling/nargo_cli/src/cli/mod.rs index 9e832317331..a0ef778e1a5 100644 --- a/tooling/nargo_cli/src/cli/mod.rs +++ b/tooling/nargo_cli/src/cli/mod.rs @@ -13,6 +13,7 @@ mod backend_cmd; mod check_cmd; mod codegen_verifier_cmd; mod compile_cmd; +mod debug_cmd; mod execute_cmd; mod fmt_cmd; mod info_cmd; @@ -61,6 +62,8 @@ enum NargoCommand { New(new_cmd::NewCommand), Init(init_cmd::InitCommand), Execute(execute_cmd::ExecuteCommand), + #[command(hide = true)] // Hidden while the feature is being built out + Debug(debug_cmd::DebugCommand), Prove(prove_cmd::ProveCommand), Verify(verify_cmd::VerifyCommand), Test(test_cmd::TestCommand), @@ -95,6 +98,7 @@ pub(crate) fn start_cli() -> eyre::Result<()> { NargoCommand::Init(args) => init_cmd::run(&backend, args, config), NargoCommand::Check(args) => check_cmd::run(&backend, args, config), NargoCommand::Compile(args) => compile_cmd::run(&backend, args, config), + NargoCommand::Debug(args) => debug_cmd::run(&backend, args, config), NargoCommand::Execute(args) => execute_cmd::run(&backend, args, config), NargoCommand::Prove(args) => prove_cmd::run(&backend, args, config), NargoCommand::Verify(args) => verify_cmd::run(&backend, args, config), diff --git a/tooling/nargo_cli/tests/acir_artifacts/7_function/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/7_function/target/acir.gz index f9b082601da..d08ebb1a635 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/7_function/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/7_function/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/7_function/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/7_function/target/witness.gz index 16bf4f6d241..250f96eab04 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/7_function/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/7_function/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/array_dynamic/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/array_dynamic/target/acir.gz index 0b3e4a92f7d..1b4f0912b08 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/array_dynamic/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/array_dynamic/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/array_dynamic/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/array_dynamic/target/witness.gz index bcff7d4d164..41a4ec0817e 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/array_dynamic/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/array_dynamic/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/brillig_keccak/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/brillig_keccak/target/acir.gz index 412739be315..ae815259717 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/brillig_keccak/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/brillig_keccak/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/brillig_keccak/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/brillig_keccak/target/witness.gz index c87ba79eebb..95b5064a5a7 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/brillig_keccak/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/brillig_keccak/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/brillig_unitialised_arrays/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/brillig_unitialised_arrays/target/acir.gz index 126b6921cec..4ab33919248 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/brillig_unitialised_arrays/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/brillig_unitialised_arrays/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/brillig_unitialised_arrays/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/brillig_unitialised_arrays/target/witness.gz index 04400be9ee0..869536a1d98 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/brillig_unitialised_arrays/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/brillig_unitialised_arrays/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/conditional_1/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/conditional_1/target/acir.gz index 968b21e7189..0bad56713bd 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/conditional_1/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/conditional_1/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/conditional_1/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/conditional_1/target/witness.gz index a115ee9030d..bd0870eefc9 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/conditional_1/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/conditional_1/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/eddsa/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/eddsa/target/acir.gz index 196aabc526a..049b7326ea8 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/eddsa/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/eddsa/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/eddsa/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/eddsa/target/witness.gz index 4c8692be198..fcce3069d87 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/eddsa/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/eddsa/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/higher_order_functions/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/higher_order_functions/target/acir.gz index 4b9c9d7809b..53bbd84e74c 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/higher_order_functions/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/higher_order_functions/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/higher_order_functions/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/higher_order_functions/target/witness.gz index 24e406b8e19..3998fbc8d59 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/higher_order_functions/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/higher_order_functions/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/merkle_insert/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/merkle_insert/target/acir.gz index ab7634a7fc3..5db7b8b1539 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/merkle_insert/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/merkle_insert/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/merkle_insert/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/merkle_insert/target/witness.gz index 1e07d49707f..7fdb4d1f9e5 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/merkle_insert/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/merkle_insert/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/nested_array_dynamic/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/nested_array_dynamic/target/acir.gz index 943031c5395..8eb05c0382d 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/nested_array_dynamic/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/nested_array_dynamic/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/nested_array_dynamic/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/nested_array_dynamic/target/witness.gz index 4223eeac6a5..d5dc73c9bb4 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/nested_array_dynamic/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/nested_array_dynamic/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/nested_slice_dynamic/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/nested_slice_dynamic/target/acir.gz index e310c2ef5f4..d76d3a08041 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/nested_slice_dynamic/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/nested_slice_dynamic/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/nested_slice_dynamic/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/nested_slice_dynamic/target/witness.gz index 420a60972ef..8d168b8c19c 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/nested_slice_dynamic/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/nested_slice_dynamic/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/regression/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/regression/target/acir.gz index 24041fec211..be72e6abb75 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/regression/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/regression/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/regression/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/regression/target/witness.gz index 318510c88ba..10c1c42caa0 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/regression/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/regression/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/regression_mem_op_predicate/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/regression_mem_op_predicate/target/acir.gz index 16965abd48e..403c0dd43f1 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/regression_mem_op_predicate/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/regression_mem_op_predicate/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/regression_mem_op_predicate/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/regression_mem_op_predicate/target/witness.gz index 3053e96f194..e8dc551cf13 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/regression_mem_op_predicate/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/regression_mem_op_predicate/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/schnorr/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/schnorr/target/acir.gz index cc794942cd7..84a646ab241 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/schnorr/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/schnorr/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/schnorr/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/schnorr/target/witness.gz index 220528da93b..ebc1ed7f713 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/schnorr/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/schnorr/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/sha2_blocks/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/sha2_blocks/target/acir.gz index cc0dc0cc78b..3c21d9a4bf8 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/sha2_blocks/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/sha2_blocks/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/sha2_blocks/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/sha2_blocks/target/witness.gz index 047cdabc9d1..40ca3d3f63f 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/sha2_blocks/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/sha2_blocks/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/sha2_byte/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/sha2_byte/target/acir.gz index 71ae2bd569c..b285f9c24e5 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/sha2_byte/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/sha2_byte/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/sha2_byte/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/sha2_byte/target/witness.gz index 28ddaf1a750..66d8125a852 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/sha2_byte/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/sha2_byte/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/simple_radix/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/simple_radix/target/acir.gz index 19ad7d0a006..78096c19e45 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/simple_radix/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/simple_radix/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/simple_radix/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/simple_radix/target/witness.gz index 9244709bf3c..6ecc30eb054 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/simple_radix/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/simple_radix/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/simple_shield/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/simple_shield/target/acir.gz index 8e165c3f630..8fbb88d62bd 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/simple_shield/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/simple_shield/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/simple_shield/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/simple_shield/target/witness.gz index 4e3f141fe9d..1a33f9f79e2 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/simple_shield/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/simple_shield/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/slice_dynamic_index/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/slice_dynamic_index/target/acir.gz index df3483f66ed..f53fbca1f59 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/slice_dynamic_index/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/slice_dynamic_index/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/slice_dynamic_index/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/slice_dynamic_index/target/witness.gz index ae96aeabb25..0075dd044dc 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/slice_dynamic_index/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/slice_dynamic_index/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/slices/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/slices/target/acir.gz index 0c39fad5068..b8a2b19d38b 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/slices/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/slices/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/slices/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/slices/target/witness.gz index 5409247091e..d9d8d036339 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/slices/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/slices/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/to_be_bytes/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/to_be_bytes/target/acir.gz index 276caef638e..f0742c6cf2b 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/to_be_bytes/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/to_be_bytes/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/to_be_bytes/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/to_be_bytes/target/witness.gz index 7898336ec9a..9ffa155a84f 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/to_be_bytes/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/to_be_bytes/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/to_bytes_consistent/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/to_bytes_consistent/target/acir.gz index 7e4f0cdf5ac..a69c76b3198 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/to_bytes_consistent/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/to_bytes_consistent/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/to_bytes_consistent/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/to_bytes_consistent/target/witness.gz index b3fe95bf63a..3b931590419 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/to_bytes_consistent/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/to_bytes_consistent/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/to_bytes_integration/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/to_bytes_integration/target/acir.gz index d74b872cdae..4e34c8da2d1 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/to_bytes_integration/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/to_bytes_integration/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/to_bytes_integration/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/to_bytes_integration/target/witness.gz index b80f5c9a39b..b25db55391c 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/to_bytes_integration/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/to_bytes_integration/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/to_le_bytes/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/to_le_bytes/target/acir.gz index 5b6d109ebff..1445a969536 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/to_le_bytes/target/acir.gz and b/tooling/nargo_cli/tests/acir_artifacts/to_le_bytes/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/to_le_bytes/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/to_le_bytes/target/witness.gz index d8fbf4bea37..b3948caad12 100644 Binary files a/tooling/nargo_cli/tests/acir_artifacts/to_le_bytes/target/witness.gz and b/tooling/nargo_cli/tests/acir_artifacts/to_le_bytes/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/trait_associated_member_names_clashes/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/trait_associated_member_names_clashes/target/acir.gz new file mode 100644 index 00000000000..2639a2e0809 Binary files /dev/null and b/tooling/nargo_cli/tests/acir_artifacts/trait_associated_member_names_clashes/target/acir.gz differ diff --git a/tooling/nargo_cli/tests/acir_artifacts/trait_associated_member_names_clashes/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/trait_associated_member_names_clashes/target/witness.gz new file mode 100644 index 00000000000..4e90289d5e1 Binary files /dev/null and b/tooling/nargo_cli/tests/acir_artifacts/trait_associated_member_names_clashes/target/witness.gz differ diff --git a/tooling/nargo_cli/tests/compile_failure/constant_return/src/main.nr b/tooling/nargo_cli/tests/compile_failure/constant_return/src/main.nr index 4cc6c739181..4972d514860 100644 --- a/tooling/nargo_cli/tests/compile_failure/constant_return/src/main.nr +++ b/tooling/nargo_cli/tests/compile_failure/constant_return/src/main.nr @@ -4,4 +4,4 @@ // a test before ACIR gen optimizes this test. fn main(_x : Field) -> pub Field { 5 -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/compile_success_empty/instruction_deduplication/src/main.nr b/tooling/nargo_cli/tests/compile_success_empty/instruction_deduplication/src/main.nr index 43a6da8d6e4..09aa8ee47f2 100644 --- a/tooling/nargo_cli/tests/compile_success_empty/instruction_deduplication/src/main.nr +++ b/tooling/nargo_cli/tests/compile_success_empty/instruction_deduplication/src/main.nr @@ -1,5 +1,5 @@ fn main(x : Field) { // This is a regression test for #2450. - // The compiler should recognise that the `(x as u32)` instructions are duplicates and so have the same output. + // The compiler should recognize that the `(x as u32)` instructions are duplicates and so have the same output. assert(x as u32 == x as u32); } diff --git a/tooling/nargo_cli/tests/execution_success/1327_concrete_in_generic/src/main.nr b/tooling/nargo_cli/tests/execution_success/1327_concrete_in_generic/src/main.nr index d868ff1ef83..368d4811e45 100644 --- a/tooling/nargo_cli/tests/execution_success/1327_concrete_in_generic/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/1327_concrete_in_generic/src/main.nr @@ -1,9 +1,8 @@ // --- - - fn new_concrete_c_over_d() -> C { - let d_method_interface = get_d_method_interface(); - C::new(d_method_interface) - } +fn new_concrete_c_over_d() -> C { + let d_method_interface = get_d_method_interface(); + C::new(d_method_interface) +} // --- @@ -54,25 +53,24 @@ d: Field, } - fn d_method(input: D) -> Field { - input.d * input.d - } +fn d_method(input: D) -> Field { + input.d * input.d +} - fn get_d_method_interface() -> MethodInterface { - MethodInterface { +fn get_d_method_interface() -> MethodInterface { + MethodInterface { some_method_on_t_d: d_method, } - } - -// --- +} - fn main(input: Field) -> pub Field { - let b: B> = B::new(new_concrete_c_over_d); - let c: C = b.get_t_c(); // Singleton - let d: D = D { d: input }; // Note - let output = c.call_method_of_t_d(d); - - output - } +// --- +fn main(input: Field) -> pub Field { + let b: B> = B::new(new_concrete_c_over_d); + let c: C = b.get_t_c(); // Singleton + let d: D = D { d: input }; // Note + let output = c.call_method_of_t_d(d); + + output +} // --- diff --git a/tooling/nargo_cli/tests/execution_success/5_over/src/main.nr b/tooling/nargo_cli/tests/execution_success/5_over/src/main.nr index fa50fbe7c14..42f339533aa 100644 --- a/tooling/nargo_cli/tests/execution_success/5_over/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/5_over/src/main.nr @@ -6,6 +6,6 @@ fn main(mut x: u32, y: u32) { x = std::wrapping_mul(x,x); assert(y == x); - let c:u3 = 2; + let c: u3 = 2; assert(c > x as u3); } diff --git a/tooling/nargo_cli/tests/execution_success/6_array/src/main.nr b/tooling/nargo_cli/tests/execution_success/6_array/src/main.nr index 8d029943d81..44a5363f8bc 100644 --- a/tooling/nargo_cli/tests/execution_success/6_array/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/6_array/src/main.nr @@ -1,6 +1,6 @@ use dep::std; -//Basic tests for arrays -fn main(x: [u32; 5], y: [u32; 5], mut z: u32, t: u32) { +//Basic tests for arrays +fn main(x: [u32; 5], y: [u32; 5], mut z: u32, t: u32) { let mut c = 2301; z = y[4]; //Test 1: diff --git a/tooling/nargo_cli/tests/execution_success/7_function/src/main.nr b/tooling/nargo_cli/tests/execution_success/7_function/src/main.nr index c664a791636..8fd85fa31cf 100644 --- a/tooling/nargo_cli/tests/execution_success/7_function/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/7_function/src/main.nr @@ -1,11 +1,11 @@ -//Tests for function calling +//Tests for function calling fn f1(mut x: Field) -> Field { x = x + 1; x = f2(x); x } -fn f2(mut x: Field) -> Field{ +fn f2(mut x: Field) -> Field { x += 2; x } @@ -22,7 +22,7 @@ fn test1(mut a: Field) { assert(a == 4); } -fn test2(z: Field, t: u32 ) { +fn test2(z: Field, t: u32 ) { let a = z + t as Field; assert(a == 64); let e = pow(z, t as Field); @@ -78,15 +78,12 @@ fn test_multiple5(a: (u32, u32)) { assert(a.0 == a.1+2); } - fn test_multiple6(a: my2, b: my_struct, c: (my2, my_struct)) { test_multiple4(a.aa); test_multiple5((b.a, b.b)); assert(c.0.aa.a == c.1.a); } - - fn foo(a: [Field; N]) -> [Field; N] { a } @@ -95,7 +92,7 @@ fn bar() -> [Field; 1] { foo([0]) } -fn main(x: u32 , y: u32 , a: Field, arr1: [u32; 9], arr2: [u32; 9]) { +fn main(x: u32 , y: u32 , a: Field, arr1: [u32; 9], arr2: [u32; 9]) { let mut ss: my_struct = my_struct { b: x, a: x+2, }; test_multiple4(ss); test_multiple5((ss.a,ss.b)); @@ -106,13 +103,13 @@ fn main(x: u32 , y: u32 , a: Field, arr1: [u32; 9], arr2: [u32; 9]) { ss.a = 61; test_multiple6(my, ss, (my,ss)); - let my_block = { + let my_block = { let mut ab = f2(a); ab = ab + a; (x,ab) }; assert(my_block.1 == 4); - + test0(a); test1(a); test2(x as Field, y); diff --git a/tooling/nargo_cli/tests/execution_success/arithmetic_binary_operations/src/main.nr b/tooling/nargo_cli/tests/execution_success/arithmetic_binary_operations/src/main.nr index 78c91818345..8fb7bcdbeb2 100644 --- a/tooling/nargo_cli/tests/execution_success/arithmetic_binary_operations/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/arithmetic_binary_operations/src/main.nr @@ -12,4 +12,4 @@ fn main(x : Field, y : Field, z : Field) -> pub Field { let c = b * z; // 2 * 5 = 10 let d = c / a; // 10 / 6 (This uses field inversion, so we test it by multiplying by `a`) d * a -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/array_dynamic/src/main.nr b/tooling/nargo_cli/tests/execution_success/array_dynamic/src/main.nr index db8f10b27e9..14b6f7d3b85 100644 --- a/tooling/nargo_cli/tests/execution_success/array_dynamic/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/array_dynamic/src/main.nr @@ -1,4 +1,3 @@ - fn main(x: [u32; 5], mut z: u32, t: u32, index: [Field;5], index2: [Field;5], offset: Field, sublen: Field) { let idx = (z - 5*t - 5) as Field; //dynamic array test diff --git a/tooling/nargo_cli/tests/execution_success/assert_statement/src/main.nr b/tooling/nargo_cli/tests/execution_success/assert_statement/src/main.nr index 3209f5b944b..f9359ded812 100644 --- a/tooling/nargo_cli/tests/execution_success/assert_statement/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/assert_statement/src/main.nr @@ -1,7 +1,7 @@ // Tests a very simple program. // // The features being tested is assertion -fn main(x : Field, y : pub Field) { +fn main(x : Field, y : pub Field) { assert(x == y, "x and y are not equal"); assert_eq(x, y, "x and y are not equal"); } diff --git a/tooling/nargo_cli/tests/execution_success/bit_and/src/main.nr b/tooling/nargo_cli/tests/execution_success/bit_and/src/main.nr index f4805960a33..35671abea63 100644 --- a/tooling/nargo_cli/tests/execution_success/bit_and/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/bit_and/src/main.nr @@ -15,4 +15,4 @@ fn main(x : Field, y : Field) { let y_as_u11 = y as u11; assert((x_as_u11 & y_as_u11) == x_as_u11); } - + diff --git a/tooling/nargo_cli/tests/execution_success/bit_shifts_comptime/src/main.nr b/tooling/nargo_cli/tests/execution_success/bit_shifts_comptime/src/main.nr index e4ca1bd92cc..209861e74fa 100644 --- a/tooling/nargo_cli/tests/execution_success/bit_shifts_comptime/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/bit_shifts_comptime/src/main.nr @@ -1,6 +1,6 @@ fn main(x: u64) { - let two: u64 = 2; - let three: u64 = 3; + let two: u64 = 2; + let three: u64 = 3; // shifts on constant values assert(two << 2 == 8); @@ -11,13 +11,13 @@ fn main(x: u64) { assert(x << 1 == 128); assert(x >> 2 == 16); - regression_2250(); + regression_2250(); } fn regression_2250() { - let a: u1 = 1 >> 1; + let a: u1 = 1 >> 1; assert(a == 0); - - let b: u32 = 1 >> 32; + + let b: u32 = 1 >> 32; assert(b == 0); -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/bool_not/src/main.nr b/tooling/nargo_cli/tests/execution_success/bool_not/src/main.nr index a0afe770121..935d8cc074d 100644 --- a/tooling/nargo_cli/tests/execution_success/bool_not/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/bool_not/src/main.nr @@ -1,4 +1,4 @@ fn main(x: u1) { assert(!x == 0); } - + diff --git a/tooling/nargo_cli/tests/execution_success/bool_or/src/main.nr b/tooling/nargo_cli/tests/execution_success/bool_or/src/main.nr index 87d7e870063..6cb959e61e6 100644 --- a/tooling/nargo_cli/tests/execution_success/bool_or/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/bool_or/src/main.nr @@ -3,4 +3,4 @@ fn main(x: u1, y: u1) { assert(x | y | x == 1); } - + diff --git a/tooling/nargo_cli/tests/execution_success/brillig_acir_as_brillig/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_acir_as_brillig/src/main.nr index 9d4c5da9dc4..da5982dcd04 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_acir_as_brillig/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_acir_as_brillig/src/main.nr @@ -1,5 +1,4 @@ - -fn main(x: u32) { +fn main(x: u32) { assert(entry_point(x) == 2); swap_entry_point(x, x + 1); assert(deep_entry_point(x) == 4); diff --git a/tooling/nargo_cli/tests/execution_success/brillig_arrays/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_arrays/src/main.nr index a2b64100918..e535b6001a4 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_arrays/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_arrays/src/main.nr @@ -1,8 +1,7 @@ // Tests a very simple program. // // The features being tested are array reads and writes - -fn main(x: [Field; 3]) { +fn main(x: [Field; 3]) { read_array(x); read_write_array(x); } diff --git a/tooling/nargo_cli/tests/execution_success/brillig_assert/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_assert/src/main.nr index 632c72f2393..d17c0b4f991 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_assert/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_assert/src/main.nr @@ -1,7 +1,7 @@ // Tests a very simple program. // // The features being tested is using assert on brillig -fn main(x: Field) { +fn main(x: Field) { assert(1 == conditional(x as bool)); } diff --git a/tooling/nargo_cli/tests/execution_success/brillig_calls/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_calls/src/main.nr index fed84f80545..656d241d2f5 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_calls/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_calls/src/main.nr @@ -1,7 +1,7 @@ // Tests a very simple program. // // The features being tested is brillig calls -fn main(x: u32) { +fn main(x: u32) { assert(entry_point(x) == 2); swap_entry_point(x, x + 1); assert(deep_entry_point(x) == 4); diff --git a/tooling/nargo_cli/tests/execution_success/brillig_calls_array/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_calls_array/src/main.nr index 3af825c38f9..d5702ac4f82 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_calls_array/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_calls_array/src/main.nr @@ -1,7 +1,7 @@ // Tests a very simple program. // // The features being tested is brillig calls passing arrays around -fn main(x: [u32; 3]) { +fn main(x: [u32; 3]) { assert(entry_point(x) == 9); another_entry_point(x); } diff --git a/tooling/nargo_cli/tests/execution_success/brillig_calls_conditionals/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_calls_conditionals/src/main.nr index 4d4eba01f05..0a1718d0171 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_calls_conditionals/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_calls_conditionals/src/main.nr @@ -1,7 +1,7 @@ // Tests a very simple program. // // The features being tested is brillig calls with conditionals -fn main(x: [u32; 3]) { +fn main(x: [u32; 3]) { assert(entry_point(x[0]) == 7); assert(entry_point(x[1]) == 8); assert(entry_point(x[2]) == 9); @@ -29,7 +29,7 @@ unconstrained fn entry_point(x: u32) -> u32 { result = inner_2(); } else if x == 3 { result = inner_3(); - } + } result } diff --git a/tooling/nargo_cli/tests/execution_success/brillig_conditional/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_conditional/src/main.nr index 96e5217ca65..a3d92ab58e9 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_conditional/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_conditional/src/main.nr @@ -1,7 +1,7 @@ // Tests a very simple program. // // The features being tested is basic conditonal on brillig -fn main(x: Field) { +fn main(x: Field) { assert(4 == conditional(x == 1)); } diff --git a/tooling/nargo_cli/tests/execution_success/brillig_fns_as_values/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_fns_as_values/src/main.nr index d0985a9012d..5f8435825f6 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_fns_as_values/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_fns_as_values/src/main.nr @@ -2,7 +2,7 @@ struct MyStruct { operation: fn (u32) -> u32, } -fn main(x: u32) { +fn main(x: u32) { assert(wrapper(increment, x) == x + 1); assert(wrapper(increment_acir, x) == x + 1); assert(wrapper(decrement, x) == x - 1); diff --git a/tooling/nargo_cli/tests/execution_success/brillig_identity_function/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_identity_function/src/main.nr index f711c5e86ba..ca646140f21 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_identity_function/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_identity_function/src/main.nr @@ -6,7 +6,7 @@ struct myStruct { // Tests a very simple program. // // The features being tested is the identity function in Brillig -fn main(x : Field) { +fn main(x : Field) { assert(x == identity(x)); // TODO: add support for array comparison let arr = identity_array([x, x]); @@ -21,13 +21,13 @@ fn main(x : Field) { } unconstrained fn identity(x : Field) -> Field { - x + x } unconstrained fn identity_array(arr : [Field; 2]) -> [Field; 2] { - arr + arr } unconstrained fn identity_struct(s : myStruct) -> myStruct { - s + s } diff --git a/tooling/nargo_cli/tests/execution_success/brillig_keccak/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_keccak/src/main.nr index fcc2a772d10..46c2a59f6b6 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_keccak/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_keccak/src/main.nr @@ -9,7 +9,7 @@ fn main(x: Field, result: [u8; 32]) { let digest = keccak256([x as u8], 1); assert(digest == result); - //#1399: variable meesage size + //#1399: variable meesage size let message_size = 4; let hash_a = keccak256([1,2,3,4], message_size); let hash_b = keccak256([1,2,3,4,0,0,0,0], message_size); diff --git a/tooling/nargo_cli/tests/execution_success/brillig_loop/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_loop/src/main.nr index e469248239e..05d35469342 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_loop/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_loop/src/main.nr @@ -1,7 +1,7 @@ // Tests a very simple program. // // The features being tested is basic looping on brillig -fn main(sum: u32){ +fn main(sum: u32) { assert(loop(4) == sum); assert(plain_loop() == sum); } diff --git a/tooling/nargo_cli/tests/execution_success/brillig_not/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_not/src/main.nr index 0466649f67c..34ed2199902 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_not/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_not/src/main.nr @@ -1,7 +1,7 @@ // Tests a very simple Brillig function. // // The features being tested is not instruction on brillig -fn main(x: Field, y : Field) { +fn main(x: Field, y : Field) { assert(false == not_operator(x as bool)); assert(true == not_operator(y as bool)); } diff --git a/tooling/nargo_cli/tests/execution_success/brillig_oracle/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_oracle/src/main.nr index 84dcb1a0915..ece23996a65 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_oracle/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_oracle/src/main.nr @@ -1,7 +1,7 @@ use dep::std::slice; // Tests oracle usage in brillig/unconstrained functions -fn main(x: Field) { +fn main(x: Field) { get_number_sequence_wrapper(20); } diff --git a/tooling/nargo_cli/tests/execution_success/brillig_pedersen/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_pedersen/src/main.nr index d41a7bd95ef..24de7f0ac83 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_pedersen/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_pedersen/src/main.nr @@ -14,4 +14,4 @@ unconstrained fn main(x: Field, y: Field, salt: Field, out_x: Field, out_y: Fiel let hash = std::hash::pedersen_with_separator([state], 0); assert(std::hash::pedersen_with_separator([43], 0)[0] == hash[0]); } - + diff --git a/tooling/nargo_cli/tests/execution_success/brillig_recursion/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_recursion/src/main.nr index 974d26165b6..43d1034fbbf 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_recursion/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_recursion/src/main.nr @@ -1,7 +1,7 @@ // Tests a very simple program. // // The feature being tested is brillig recursion -fn main(x: u32) { +fn main(x: u32) { assert(fibonacci(x) == 55); } diff --git a/tooling/nargo_cli/tests/execution_success/brillig_scalar_mul/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_scalar_mul/src/main.nr index 8383c7fd2e5..b95a8d4ef4a 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_scalar_mul/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_scalar_mul/src/main.nr @@ -8,15 +8,15 @@ unconstrained fn main( b_pub_x: pub Field, b_pub_y: pub Field ) { - let mut priv_key = a; - let mut pub_x: Field = a_pub_x; - let mut pub_y: Field = a_pub_y; - if a != 1 { // Change `a` in Prover.toml to test input `b` + let mut priv_key = a; + let mut pub_x: Field = a_pub_x; + let mut pub_y: Field = a_pub_y; + if a != 1 { // Change `a` in Prover.toml to test input `b` priv_key = b; pub_x = b_pub_x; pub_y = b_pub_y; } - let res = std::scalar_mul::fixed_base_embedded_curve(priv_key, 0); + let res = std::scalar_mul::fixed_base_embedded_curve(priv_key, 0); assert(res[0] == pub_x); assert(res[1] == pub_y); } diff --git a/tooling/nargo_cli/tests/execution_success/brillig_to_bytes_integration/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_to_bytes_integration/src/main.nr index 08986867dfc..775d1e512d9 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_to_bytes_integration/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_to_bytes_integration/src/main.nr @@ -1,6 +1,6 @@ use dep::std; -unconstrained fn main(x : Field, _y: Field) { +unconstrained fn main(x : Field, _y: Field) { // The result of this byte array will be big-endian let y: Field = 2040124; let be_byte_array = y.to_be_bytes(31); @@ -23,5 +23,5 @@ unconstrained fn main(x : Field, _y: Field) { assert(z_bits[0] == 0); assert(p_bits[100] == z_bits[100]); - _y.to_le_bits(std::field::modulus_num_bits() as u32); + _y.to_le_bits(std::field::modulus_num_bits() as u32); } diff --git a/tooling/nargo_cli/tests/execution_success/brillig_top_level/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_top_level/src/main.nr index 4a781e89d78..6dfd98b2c3e 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_top_level/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_top_level/src/main.nr @@ -1,7 +1,6 @@ // Tests a very simple program. // // The feature being tested is brillig as the entry point. - unconstrained fn main(array: [Field; 3], x: pub Field) -> pub [Field; 2] { [array[x], array[x + 1]] } diff --git a/tooling/nargo_cli/tests/execution_success/brillig_unitialised_arrays/src/main.nr b/tooling/nargo_cli/tests/execution_success/brillig_unitialised_arrays/src/main.nr index 4f24e179124..5ec657b0d35 100644 --- a/tooling/nargo_cli/tests/execution_success/brillig_unitialised_arrays/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/brillig_unitialised_arrays/src/main.nr @@ -1,5 +1,4 @@ - -fn main(x: Field, y: Field) -> pub Field { +fn main(x: Field, y: Field) -> pub Field { let notes = create_notes(x, y); sum_x(notes, x, y) } diff --git a/tooling/nargo_cli/tests/execution_success/cast_bool/src/main.nr b/tooling/nargo_cli/tests/execution_success/cast_bool/src/main.nr index 57af8120b33..422d3b98f83 100644 --- a/tooling/nargo_cli/tests/execution_success/cast_bool/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/cast_bool/src/main.nr @@ -3,4 +3,4 @@ fn main(x: Field, y: Field) { let t = z as u8; assert(t == 1); } - + diff --git a/tooling/nargo_cli/tests/execution_success/closures_mut_ref/src/main.nr b/tooling/nargo_cli/tests/execution_success/closures_mut_ref/src/main.nr index 2888745a96e..99de3dd31e4 100644 --- a/tooling/nargo_cli/tests/execution_success/closures_mut_ref/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/closures_mut_ref/src/main.nr @@ -28,4 +28,4 @@ fn issue_2120() { assert(*x1 == 44); set_x1(*x1); assert(*x1 == 44); -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/conditional_1/src/main.nr b/tooling/nargo_cli/tests/execution_success/conditional_1/src/main.nr index 4d1eeae0fe7..176106ba890 100644 --- a/tooling/nargo_cli/tests/execution_success/conditional_1/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/conditional_1/src/main.nr @@ -1,6 +1,6 @@ use dep::std; -fn sort(mut a: [u32; 4]) -> [u32; 4] { +fn sort(mut a: [u32; 4]) -> [u32; 4] { for i in 1..4 { for j in 0..i { if a[i] < a[j] { @@ -13,13 +13,11 @@ fn sort(mut a: [u32; 4]) -> [u32; 4] { a } - fn must_be_zero(x: u8) { assert(x == 0); } -fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ - +fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]) { //Test case for short-circuit let mut data = [0 as u32; 32]; let mut ba = a; @@ -96,5 +94,4 @@ fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ } } assert(x == 0); - -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/conditional_2/src/main.nr b/tooling/nargo_cli/tests/execution_success/conditional_2/src/main.nr index af5b46c003e..70237d4b638 100644 --- a/tooling/nargo_cli/tests/execution_success/conditional_2/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/conditional_2/src/main.nr @@ -1,6 +1,5 @@ use dep::std; - fn must_be_zero(x: u8) { assert(x == 0); } @@ -17,7 +16,6 @@ fn test4() -> [u32; 4] { } fn main(a: u32, mut c: [u32; 4]) { - test3(1); if a == 0 { diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_421/src/main.nr b/tooling/nargo_cli/tests/execution_success/conditional_regression_421/src/main.nr index b31cf761be8..60052c20610 100644 --- a/tooling/nargo_cli/tests/execution_success/conditional_regression_421/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_421/src/main.nr @@ -1,4 +1,4 @@ -fn main(a: u32, mut c: [u32; 4]){ +fn main(a: u32, mut c: [u32; 4]) { //Issue reported in #421 if a == c[0] { assert(c[0] == 0); diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_547/src/main.nr b/tooling/nargo_cli/tests/execution_success/conditional_regression_547/src/main.nr index 1bd69f03ea7..41ccbb00a2a 100644 --- a/tooling/nargo_cli/tests/execution_success/conditional_regression_547/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_547/src/main.nr @@ -12,8 +12,7 @@ fn main(x: Field) -> pub Field { x + safe_inverse(0) } -fn safe_inverse(n: Field) -> Field -{ +fn safe_inverse(n: Field) -> Field { if n == 0 { 0 } diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_579/src/main.nr b/tooling/nargo_cli/tests/execution_success/conditional_regression_579/src/main.nr index ae1d11eef77..a479a7a6fbf 100644 --- a/tooling/nargo_cli/tests/execution_success/conditional_regression_579/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_579/src/main.nr @@ -1,4 +1,4 @@ -fn main(){ +fn main() { //Regression for Issue #579 let result1_true = test(true); assert(result1_true.array_param[0] == 1); @@ -19,7 +19,7 @@ impl MyStruct579 { } fn test(flag: bool) -> MyStruct579 { - let mut my_struct = MyStruct579::new([0; 2]); + let mut my_struct = MyStruct579::new([0; 2]); if flag == true { my_struct= MyStruct579::new([1; 2]); diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_661/src/main.nr b/tooling/nargo_cli/tests/execution_success/conditional_regression_661/src/main.nr index 375b49cc27b..efdc1ddbce4 100644 --- a/tooling/nargo_cli/tests/execution_success/conditional_regression_661/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_661/src/main.nr @@ -1,6 +1,6 @@ -fn main(a: u32, mut c: [u32; 4]){ +fn main(a: u32, mut c: [u32; 4]) { // Regression for issue #661: - let mut c_661 :[u32;1]=[0]; + let mut c_661: [u32; 1] = [0]; if a > 5 { c_661 = issue_661_foo(issue_661_bar(c), a); } else { @@ -16,13 +16,12 @@ fn test5(a : u32) { } } - fn issue_661_foo(array: [u32;4], b:u32) ->[u32;1] { [array[0] + b] } fn issue_661_bar(a : [u32;4]) ->[u32;4] { - let mut b:[u32;4] = [0;4]; + let mut b: [u32; 4] = [0;4]; b[0]=a[0]+1; b } diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_short_circuit/src/main.nr b/tooling/nargo_cli/tests/execution_success/conditional_regression_short_circuit/src/main.nr index 4fb4c37a1ab..57387ed5052 100644 --- a/tooling/nargo_cli/tests/execution_success/conditional_regression_short_circuit/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_short_circuit/src/main.nr @@ -1,6 +1,6 @@ use dep::std; -fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ +fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]) { //regression for short-circuit2 if 35 == a { assert(false); @@ -14,8 +14,6 @@ fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){ call_intrinsic(x, result); } - - fn foo() { let mut x = 1; x /= 0; @@ -27,7 +25,6 @@ fn bar(x:Field) { } } - fn call_intrinsic(x: [u8; 5], result: [u8; 32]) { let mut digest = std::hash::sha256(x); digest[0] = 5 as u8; @@ -38,4 +35,4 @@ fn call_intrinsic(x: [u8; 5], result: [u8; 32]) { fn test4() -> [u32; 4] { let b: [u32; 4] = [1,2,3,4]; b -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/conditional_regression_to_bits/src/main.nr b/tooling/nargo_cli/tests/execution_success/conditional_regression_to_bits/src/main.nr index 8c612ca0eb2..e5450334c5e 100644 --- a/tooling/nargo_cli/tests/execution_success/conditional_regression_to_bits/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/conditional_regression_to_bits/src/main.nr @@ -1,8 +1,6 @@ use dep::std; - fn main() { - //Regression for to_le_bits() constant evaluation // binary array representation of u8 1 let arr: [u8; 2] = [1, 2]; @@ -26,7 +24,5 @@ fn main() { } } assert(c1 == 1); - - } diff --git a/tooling/nargo_cli/tests/execution_success/debug_logs/src/main.nr b/tooling/nargo_cli/tests/execution_success/debug_logs/src/main.nr index f17e20fac3d..23c6b8a76d4 100644 --- a/tooling/nargo_cli/tests/execution_success/debug_logs/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/debug_logs/src/main.nr @@ -25,12 +25,12 @@ fn main(x : Field, y : pub Field) { std::println(x); std::println([x, y]); - + let foo = fooStruct { my_struct: s, foo: 15 }; std::println(f"s: {s}, foo: {foo}"); std::println(f"x: 0, y: 1"); - + let s_2 = myStruct { x: 20, y: 30 }; std::println(f"s1: {s}, s2: {s_2}"); @@ -67,7 +67,7 @@ struct fooStruct { fn regression_2906() { let array_two_vals = [1, 2]; - dep::std::println(f"array_two_vals: {array_two_vals}"); + dep::std::println(f"array_two_vals: {array_two_vals}"); let label_two_vals = "12"; dep::std::println(f"label_two_vals: {label_two_vals}"); @@ -79,4 +79,4 @@ fn regression_2906() { dep::std::println(f"label_five_vals: {label_five_vals}"); dep::std::println(f"array_five_vals: {array_five_vals}, label_five_vals: {label_five_vals}"); -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/diamond_deps_0/src/main.nr b/tooling/nargo_cli/tests/execution_success/diamond_deps_0/src/main.nr index f01491171bb..1c4dba1c791 100644 --- a/tooling/nargo_cli/tests/execution_success/diamond_deps_0/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/diamond_deps_0/src/main.nr @@ -4,4 +4,4 @@ use dep::dep2::RESOLVE_THIS; fn main(x : Field, y : pub Field) -> pub Field { call_dep1_then_dep2(x, y) + call_dep2(x, y) + RESOLVE_THIS -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/double_verify_proof/src/main.nr b/tooling/nargo_cli/tests/execution_success/double_verify_proof/src/main.nr index 39b8c142ace..c679730e3c0 100644 --- a/tooling/nargo_cli/tests/execution_success/double_verify_proof/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/double_verify_proof/src/main.nr @@ -23,7 +23,7 @@ fn main( key_hash, output_aggregation_object_a ); - + let mut output = [0; 16]; for i in 0..16 { output[i] = output_aggregation_object[i]; diff --git a/tooling/nargo_cli/tests/execution_success/ecdsa_secp256k1/src/main.nr b/tooling/nargo_cli/tests/execution_success/ecdsa_secp256k1/src/main.nr index 2512531cb04..5af8008f291 100644 --- a/tooling/nargo_cli/tests/execution_success/ecdsa_secp256k1/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/ecdsa_secp256k1/src/main.nr @@ -2,9 +2,9 @@ use dep::std; fn main(message : [u8;38],hashed_message : [u8;32], pub_key_x : [u8;32], pub_key_y : [u8;32], signature : [u8;64]) { // Hash the message, since secp256k1 expects a hashed_message - let expected= std::hash::sha256(message); + let expected = std::hash::sha256(message); assert(hashed_message == expected); - let valid_signature = std::ecdsa_secp256k1::verify_signature(pub_key_x, pub_key_y, signature, hashed_message); + let valid_signature = std::ecdsa_secp256k1::verify_signature(pub_key_x, pub_key_y, signature, hashed_message); assert(valid_signature); } diff --git a/tooling/nargo_cli/tests/execution_success/ecdsa_secp256r1/src/main.nr b/tooling/nargo_cli/tests/execution_success/ecdsa_secp256r1/src/main.nr index e81d84fd902..eda78cd81a6 100644 --- a/tooling/nargo_cli/tests/execution_success/ecdsa_secp256r1/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/ecdsa_secp256r1/src/main.nr @@ -1,6 +1,6 @@ use dep::std; fn main(hashed_message : [u8;32], pub_key_x : [u8;32], pub_key_y : [u8;32], signature : [u8;64]) { - let valid_signature = std::ecdsa_secp256r1::verify_signature(pub_key_x, pub_key_y, signature, hashed_message); + let valid_signature = std::ecdsa_secp256r1::verify_signature(pub_key_x, pub_key_y, signature, hashed_message); assert(valid_signature); } diff --git a/tooling/nargo_cli/tests/execution_success/generics/src/main.nr b/tooling/nargo_cli/tests/execution_success/generics/src/main.nr index 4c87bc685f1..9a1effcd318 100644 --- a/tooling/nargo_cli/tests/execution_success/generics/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/generics/src/main.nr @@ -49,7 +49,6 @@ fn main(x: Field, y: Field) { // Expected type error // assert(bar2.get_other() == bar2.other); - let one = x; let two = y; let nested_generics: Bar> = Bar { one, two, other: Bar { one, two, other: 0 } }; diff --git a/tooling/nargo_cli/tests/execution_success/global_consts/src/foo/bar.nr b/tooling/nargo_cli/tests/execution_success/global_consts/src/foo/bar.nr index b839ff28ac6..b4b43442cc8 100644 --- a/tooling/nargo_cli/tests/execution_success/global_consts/src/foo/bar.nr +++ b/tooling/nargo_cli/tests/execution_success/global_consts/src/foo/bar.nr @@ -2,4 +2,4 @@ global N: Field = 5; pub fn from_bar(x : Field) -> Field { x * N -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/global_consts/src/main.nr b/tooling/nargo_cli/tests/execution_success/global_consts/src/main.nr index e741de50c86..0c3a4fcd771 100644 --- a/tooling/nargo_cli/tests/execution_success/global_consts/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/global_consts/src/main.nr @@ -19,7 +19,7 @@ global VALS: [Test; 1] = [Test { v: 100 }]; global NESTED = [VALS, VALS]; fn main(a: [Field; M + N - N], b: [Field; 30 + N / 2], c : pub [Field; foo::MAGIC_NUMBER], d: [Field; foo::bar::N]) { - let test_struct = Dummy { x: d, y: c }; + let test_struct = Dummy { x: d, y: c }; for i in 0..foo::MAGIC_NUMBER { assert(c[i] == foo::MAGIC_NUMBER); @@ -28,12 +28,12 @@ fn main(a: [Field; M + N - N], b: [Field; 30 + N / 2], c : pub [Field; foo::MAGI } assert(N != M); - - let expected: u32 = 42; + + let expected: u32 = 42; assert(foo::TYPE_INFERRED == expected); - let mut y = 5; - let mut x = M; + let mut y = 5; + let mut x = M; for i in 0..N*N { let M: Field = 10; x = M; @@ -43,34 +43,34 @@ fn main(a: [Field; M + N - N], b: [Field; 30 + N / 2], c : pub [Field; foo::MAGI assert(y == 24); assert(x == 10); - let q = multiplyByM(3); + let q = multiplyByM(3); assert(q == 96); - arrays_neq(a, b); + arrays_neq(a, b); - let t: [Field; T_LEN] = [N, M]; + let t: [Field; T_LEN] = [N, M]; assert(t[1] == 32); assert(15 == mysubmodule::my_helper()); - - let add_submodules_N = mysubmodule::N + foo::bar::N; + + let add_submodules_N = mysubmodule::N + foo::bar::N; assert(15 == add_submodules_N); - let add_from_bar_N = mysubmodule::N + foo::bar::from_bar(1); + let add_from_bar_N = mysubmodule::N + foo::bar::from_bar(1); assert(15 == add_from_bar_N); // Example showing an array filled with (mysubmodule::N + 2) 0's - let sugared = [0; mysubmodule::N + 2]; + let sugared = [0; mysubmodule::N + 2]; assert(sugared[mysubmodule::N + 1] == 0); - let arr: [Field; mysubmodule::N] = [N; 10]; + let arr: [Field; mysubmodule::N] = [N; 10]; assert((arr[0] == 5) & (arr[9] == 5)); - foo::from_foo(d); - baz::from_baz(c); + foo::from_foo(d); + baz::from_baz(c); } fn multiplyByM(x: Field) -> Field { - x * M + x * M } fn arrays_neq(a: [Field; M], b: [Field; M]) { diff --git a/tooling/nargo_cli/tests/execution_success/if_else_chain/src/main.nr b/tooling/nargo_cli/tests/execution_success/if_else_chain/src/main.nr index f83ba2dde0e..9fd5fbfd3d3 100644 --- a/tooling/nargo_cli/tests/execution_success/if_else_chain/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/if_else_chain/src/main.nr @@ -1,4 +1,4 @@ -fn main(a: u32, mut c: [u32; 4]){ +fn main(a: u32, mut c: [u32; 4]) { if a == c[0] { assert(c[0] == 0); } else if a == c[1] { diff --git a/tooling/nargo_cli/tests/execution_success/import/src/import.nr b/tooling/nargo_cli/tests/execution_success/import/src/import.nr index 3dfa96992ad..4df05bbc288 100644 --- a/tooling/nargo_cli/tests/execution_success/import/src/import.nr +++ b/tooling/nargo_cli/tests/execution_success/import/src/import.nr @@ -1,4 +1,3 @@ - pub fn hello(x : Field) -> Field { x -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/integer_array_indexing/src/main.nr b/tooling/nargo_cli/tests/execution_success/integer_array_indexing/src/main.nr index 1e0ec518b9f..1698c68161b 100644 --- a/tooling/nargo_cli/tests/execution_success/integer_array_indexing/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/integer_array_indexing/src/main.nr @@ -1,12 +1,10 @@ global ARRAY_LEN: u32 = 3; fn main(arr: [Field; ARRAY_LEN], x: u32) -> pub Field { - let mut value = arr[ARRAY_LEN - 1]; value += arr[0 as u32]; value += arr[1 as Field]; - value + (x as Field) - + value + x as Field } diff --git a/tooling/nargo_cli/tests/execution_success/keccak256/src/main.nr b/tooling/nargo_cli/tests/execution_success/keccak256/src/main.nr index ba3ed7d07af..9bca6a7c1bf 100644 --- a/tooling/nargo_cli/tests/execution_success/keccak256/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/keccak256/src/main.nr @@ -8,7 +8,7 @@ fn main(x: Field, result: [u8; 32]) { let digest = std::hash::keccak256([x as u8], 1); assert(digest == result); - //#1399: variable meesage size + //#1399: variable meesage size let message_size = 4; let hash_a = std::hash::keccak256([1,2,3,4], message_size); let hash_b = std::hash::keccak256([1,2,3,4,0,0,0,0], message_size); diff --git a/tooling/nargo_cli/tests/execution_success/mock_oracle/src/main.nr b/tooling/nargo_cli/tests/execution_success/mock_oracle/src/main.nr index 405f34a4a70..07553f05d6c 100644 --- a/tooling/nargo_cli/tests/execution_success/mock_oracle/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/mock_oracle/src/main.nr @@ -8,7 +8,7 @@ struct Point { #[oracle(foo)] unconstrained fn foo_oracle(_point: Point, _array: [Field; 4]) -> Field {} -unconstrained fn main() { +unconstrained fn main() { let array = [1,2,3,4]; let another_array = [4,3,2,1]; let point = Point { diff --git a/tooling/nargo_cli/tests/execution_success/modules/src/foo.nr b/tooling/nargo_cli/tests/execution_success/modules/src/foo.nr index 1f10d8ddd8d..4df05bbc288 100644 --- a/tooling/nargo_cli/tests/execution_success/modules/src/foo.nr +++ b/tooling/nargo_cli/tests/execution_success/modules/src/foo.nr @@ -1,3 +1,3 @@ pub fn hello(x : Field) -> Field { x -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/modules_more/src/foo/bar.nr b/tooling/nargo_cli/tests/execution_success/modules_more/src/foo/bar.nr index 4f459b040d6..3d07fd9b72f 100644 --- a/tooling/nargo_cli/tests/execution_success/modules_more/src/foo/bar.nr +++ b/tooling/nargo_cli/tests/execution_success/modules_more/src/foo/bar.nr @@ -1,3 +1,3 @@ pub fn from_bar(x : Field) -> Field { x -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/modulus/src/main.nr b/tooling/nargo_cli/tests/execution_success/modulus/src/main.nr index 6dda450df5d..e8d0cc0541a 100644 --- a/tooling/nargo_cli/tests/execution_success/modulus/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/modulus/src/main.nr @@ -4,7 +4,7 @@ fn main(bn254_modulus_be_bytes : [u8; 32], bn254_modulus_be_bits : [u1; 254]) { let modulus_size = std::field::modulus_num_bits(); // NOTE: The constraints used in this circuit will only work when testing nargo with the plonk bn254 backend assert(modulus_size == 254); - + let modulus_be_byte_array = std::field::modulus_be_bytes(); for i in 0..32 { assert(modulus_be_byte_array[i] == bn254_modulus_be_bytes[i]); diff --git a/tooling/nargo_cli/tests/execution_success/nested_array_dynamic/src/main.nr b/tooling/nargo_cli/tests/execution_success/nested_array_dynamic/src/main.nr index 5f15905dfba..5538c08d778 100644 --- a/tooling/nargo_cli/tests/execution_success/nested_array_dynamic/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/nested_array_dynamic/src/main.nr @@ -24,7 +24,7 @@ fn main(mut x : [Foo; 4], y : pub Field) { assert(x[y].b == [11, 12, 23]); assert(x[y].bar.inner == [109, 110, 111]); - // Check dynamic array set + // Check dynamic array set if y != 2 { x[y].a = 50; } else { diff --git a/tooling/nargo_cli/tests/execution_success/nested_slice_dynamic/src/main.nr b/tooling/nargo_cli/tests/execution_success/nested_slice_dynamic/src/main.nr index d4740902a52..a2de5141786 100644 --- a/tooling/nargo_cli/tests/execution_success/nested_slice_dynamic/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/nested_slice_dynamic/src/main.nr @@ -46,4 +46,4 @@ fn main(y : Field) { assert(x[y - 2].bar.inner == [103, 104, 105]); assert(x[y - 1].bar.inner == [106, 107, 108]); assert(x[y].bar.inner == [109, 110, 111]); -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/pedersen_check/src/main.nr b/tooling/nargo_cli/tests/execution_success/pedersen_check/src/main.nr index 37fc3f61188..0e5c6b2c5b4 100644 --- a/tooling/nargo_cli/tests/execution_success/pedersen_check/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/pedersen_check/src/main.nr @@ -14,4 +14,4 @@ fn main(x: Field, y: Field, salt: Field, out_x: Field, out_y: Field ) { let hash = std::hash::pedersen([state]); assert(std::hash::pedersen([43])[0] == hash[0]); } - + diff --git a/tooling/nargo_cli/tests/execution_success/poseidon_bn254_hash/src/main.nr b/tooling/nargo_cli/tests/execution_success/poseidon_bn254_hash/src/main.nr index 37621c732a8..3d30ebad279 100644 --- a/tooling/nargo_cli/tests/execution_success/poseidon_bn254_hash/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/poseidon_bn254_hash/src/main.nr @@ -1,7 +1,6 @@ use dep::std::hash::poseidon; -fn main(x1: [Field; 2], y1: pub Field, x2: [Field; 4], y2: pub Field) -{ +fn main(x1: [Field; 2], y1: pub Field, x2: [Field; 4], y2: pub Field) { let hash1 = poseidon::bn254::hash_2(x1); assert(hash1 == y1); diff --git a/tooling/nargo_cli/tests/execution_success/poseidonsponge_x5_254/src/main.nr b/tooling/nargo_cli/tests/execution_success/poseidonsponge_x5_254/src/main.nr index 3addc1cec97..6d75dcccc66 100644 --- a/tooling/nargo_cli/tests/execution_success/poseidonsponge_x5_254/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/poseidonsponge_x5_254/src/main.nr @@ -1,8 +1,7 @@ use dep::std::hash::poseidon; -fn main(x: [Field; 7]) -{ - // Test optimised sponge +fn main(x: [Field; 7]) { + // Test optimized sponge let result = poseidon::bn254::sponge(x); assert(result == 0x080ae1669d62f0197190573d4a325bfb8d8fc201ce3127cbac0c47a7ac81ac48); diff --git a/tooling/nargo_cli/tests/execution_success/references/src/main.nr b/tooling/nargo_cli/tests/execution_success/references/src/main.nr index be02f2b10d6..5265519f2a8 100644 --- a/tooling/nargo_cli/tests/execution_success/references/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/references/src/main.nr @@ -162,7 +162,7 @@ fn regression_2218_if_inner_else(x: Field, y: Field) { fn regression_2218_else(x: Field, y: Field) { let value = regression_2218(x, y); - assert(value == 20); + assert(value == 20); } fn regression_2218_loop(x: Field, y: Field) { @@ -215,7 +215,7 @@ fn regression_2218_loop(x: Field, y: Field) { assert(*q1 == 20); } } - assert(*q1 == 2); + assert(*q1 == 2); if x != y { for _ in 0..5 { @@ -234,7 +234,7 @@ fn regression_2218_loop(x: Field, y: Field) { *q2 = 20; assert(*q1 == 20); } - assert(*q1 == 2); + assert(*q1 == 2); } // This is more a feature test than a proper regression. diff --git a/tooling/nargo_cli/tests/execution_success/regression/src/main.nr b/tooling/nargo_cli/tests/execution_success/regression/src/main.nr index 4ae4f6a91f1..010468a450a 100644 --- a/tooling/nargo_cli/tests/execution_success/regression/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/regression/src/main.nr @@ -1,15 +1,14 @@ global NIBBLE_LENGTH: Field = 16; -fn compact_decode(input: [u8; N], length: Field) -> ([u4; NIBBLE_LENGTH], Field) -{ +fn compact_decode(input: [u8; N], length: Field) -> ([u4; NIBBLE_LENGTH], Field) { assert(2*input.len() as u64 <= NIBBLE_LENGTH as u64); assert(length as u64 <= input.len() as u64); - + let mut nibble = [0 as u4; NIBBLE_LENGTH]; let first_nibble = (input[0] >> 4) as u4; let parity = first_nibble as u1; - + if parity == 1 { nibble[0] = (input[0] & 0x0f) as u4; @@ -41,8 +40,7 @@ fn compact_decode(input: [u8; N], length: Field) -> ([u4; NIBBLE_LENGTH], Fie out } -fn enc(value: [u8; N], value_length: Field) -> ([u8; 32], Field) -{ +fn enc(value: [u8; N], value_length: Field) -> ([u8; 32], Field) { assert(value.len() as u8 >= value_length as u8); let mut out_value = [0; 32]; if value_length == 0 @@ -90,16 +88,14 @@ fn bitshift_variable(idx: u64) -> u64 { bits } - -fn main(x: [u8; 5], z: Field) -{ +fn main(x: [u8; 5], z: Field) { //Issue 1144 - let (nib, len) = compact_decode(x,z); + let (nib, len) = compact_decode(x,z); assert(len == 5); assert([nib[0], nib[1], nib[2], nib[3], nib[4]] == [15, 1, 12, 11, 8]); // Issue 1169 - let val1 = [0xb8,0x8f,0x61,0xe6,0xfb,0xda,0x83,0xfb,0xff,0xfa,0xbe,0x36,0x41,0x12,0x13,0x74,0x80,0x39,0x80,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]; + let val1 = [0xb8,0x8f,0x61,0xe6,0xfb,0xda,0x83,0xfb,0xff,0xfa,0xbe,0x36,0x41,0x12,0x13,0x74,0x80,0x39,0x80,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]; let val1_length = 20; let enc_val1 = enc(val1,val1_length); @@ -112,9 +108,8 @@ fn main(x: [u8; 5], z: Field) assert(result_0 == 1); let result_4 = bitshift_literal_4(); assert(result_4 == 16); - let result_0 = bitshift_variable(0); + let result_0 = bitshift_variable(0); assert(result_0 == 1); let result_4 = bitshift_variable(4); assert(result_4 == 16); - } diff --git a/tooling/nargo_cli/tests/execution_success/regression_mem_op_predicate/src/main.nr b/tooling/nargo_cli/tests/execution_success/regression_mem_op_predicate/src/main.nr index a592e2b62b4..368ca50397f 100644 --- a/tooling/nargo_cli/tests/execution_success/regression_mem_op_predicate/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/regression_mem_op_predicate/src/main.nr @@ -1,8 +1,8 @@ fn main(mut x: [u32; 5], idx: Field) { // We should not hit out of bounds here as we have a predicate // that should not be hit - if idx as u32 < 3 { + if idx as u32 < 3 { x[idx] = 10; } assert(x[4] == 111); -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/scalar_mul/src/main.nr b/tooling/nargo_cli/tests/execution_success/scalar_mul/src/main.nr index 37f3ac410f0..87641b407d6 100644 --- a/tooling/nargo_cli/tests/execution_success/scalar_mul/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/scalar_mul/src/main.nr @@ -8,15 +8,15 @@ fn main( b_pub_x: pub Field, b_pub_y: pub Field ) { - let mut priv_key = a; - let mut pub_x: Field = a_pub_x; - let mut pub_y: Field = a_pub_y; - if a != 1 { // Change `a` in Prover.toml to test input `b` + let mut priv_key = a; + let mut pub_x: Field = a_pub_x; + let mut pub_y: Field = a_pub_y; + if a != 1 { // Change `a` in Prover.toml to test input `b` priv_key = b; pub_x = b_pub_x; pub_y = b_pub_y; } - let res = std::scalar_mul::fixed_base_embedded_curve(priv_key, 0); + let res = std::scalar_mul::fixed_base_embedded_curve(priv_key, 0); assert(res[0] == pub_x); assert(res[1] == pub_y); } diff --git a/tooling/nargo_cli/tests/execution_success/sha2_blocks/src/main.nr b/tooling/nargo_cli/tests/execution_success/sha2_blocks/src/main.nr index fcdcdb8684f..52891d18de2 100644 --- a/tooling/nargo_cli/tests/execution_success/sha2_blocks/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/sha2_blocks/src/main.nr @@ -1,22 +1,21 @@ // Test Noir implementations of SHA256 and SHA512 on one- and two-block (padded) messages. use dep::std; -fn main(x: [u8; 3], result256: [u8; 32], result512: [u8; 64]) -{ +fn main(x: [u8; 3], result256: [u8; 32], result512: [u8; 64]) { // One-block tests. - let mut digest256 = std::sha256::digest(x); + let mut digest256 = std::sha256::digest(x); assert(digest256 == result256); - let mut digest512 = std::sha512::digest(x); + let mut digest512 = std::sha512::digest(x); assert(digest512 == result512); // Two-block SHA256 test. Taken from https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA256.pdf - let y: [u8; 56] = [97,98,99,100,98,99,100,101,99,100,101,102,100,101,102,103,101,102,103,104,102,103,104,105,103,104,105,106,104,105,106,107,105,106,107,108,106,107,108,109,107,108,109,110,108,109,110,111,109,110,111,112,110,111,112,113]; // "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" + let y: [u8; 56] = [97,98,99,100,98,99,100,101,99,100,101,102,100,101,102,103,101,102,103,104,102,103,104,105,103,104,105,106,104,105,106,107,105,106,107,108,106,107,108,109,107,108,109,110,108,109,110,111,109,110,111,112,110,111,112,113]; // "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" digest256 = std::sha256::digest(y); assert(digest256 == [36,141,106,97,210,6,56,184,229,192,38,147,12,62,96,57,163,60,228,89,100,255,33,103,246,236,237,212,25,219,6,193]); // Two-block SHA256 test. Taken from https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512.pdf - let z: [u8; 112] = [97,98,99,100,101,102,103,104,98,99,100,101,102,103,104,105,99,100,101,102,103,104,105,106,100,101,102,103,104,105,106,107,101,102,103,104,105,106,107,108,102,103,104,105,106,107,108,109,103,104,105,106,107,108,109,110,104,105,106,107,108,109,110,111,105,106,107,108,109,110,111,112,106,107,108,109,110,111,112,113,107,108,109,110,111,112,113,114,108,109,110,111,112,113,114,115,109,110,111,112,113,114,115,116,110,111,112,113,114,115,116,117]; // "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" + let z: [u8; 112] = [97,98,99,100,101,102,103,104,98,99,100,101,102,103,104,105,99,100,101,102,103,104,105,106,100,101,102,103,104,105,106,107,101,102,103,104,105,106,107,108,102,103,104,105,106,107,108,109,103,104,105,106,107,108,109,110,104,105,106,107,108,109,110,111,105,106,107,108,109,110,111,112,106,107,108,109,110,111,112,113,107,108,109,110,111,112,113,114,108,109,110,111,112,113,114,115,109,110,111,112,113,114,115,116,110,111,112,113,114,115,116,117]; // "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" digest512 = std::sha512::digest(z); assert(digest512 == [142,149,155,117,218,227,19,218,140,244,247,40,20,252,20,63,143,119,121,198,235,159,127,161,114,153,174,173,182,136,144,24,80,29,40,158,73,0,247,228,51,27,153,222,196,181,67,58,199,211,41,238,182,221,38,84,94,150,229,91,135,75,233,9]); } diff --git a/tooling/nargo_cli/tests/execution_success/sha2_byte/src/main.nr b/tooling/nargo_cli/tests/execution_success/sha2_byte/src/main.nr index a7cc9daebb9..6470ccd8379 100644 --- a/tooling/nargo_cli/tests/execution_success/sha2_byte/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/sha2_byte/src/main.nr @@ -1,11 +1,10 @@ // Test Noir implementations of SHA256 and SHA512 on a one-byte message. use dep::std; -fn main(x: Field, result256: [u8; 32], result512: [u8; 64]) -{ - let digest256 = std::sha256::digest([x as u8]); +fn main(x: Field, result256: [u8; 32], result512: [u8; 64]) { + let digest256 = std::sha256::digest([x as u8]); assert(digest256 == result256); - let digest512 = std::sha512::digest([x as u8]); + let digest512 = std::sha512::digest([x as u8]); assert(digest512 == result512); } diff --git a/tooling/nargo_cli/tests/execution_success/simple_array_param/src/main.nr b/tooling/nargo_cli/tests/execution_success/simple_array_param/src/main.nr index 8dc9b138496..60978bab519 100644 --- a/tooling/nargo_cli/tests/execution_success/simple_array_param/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/simple_array_param/src/main.nr @@ -1,7 +1,6 @@ // This program tests: // - the allocation of virtual arrays for array params to main // - load instructions for such arrays - fn main(xs : [Field; 2]) -> pub Field { xs[1] } diff --git a/tooling/nargo_cli/tests/execution_success/simple_comparison/src/main.nr b/tooling/nargo_cli/tests/execution_success/simple_comparison/src/main.nr index 671ea6cf35e..f224b8a9bee 100644 --- a/tooling/nargo_cli/tests/execution_success/simple_comparison/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/simple_comparison/src/main.nr @@ -1,6 +1,6 @@ // Tests a very simple program. // // The features being tested is comparison -fn main(x : Field, y : Field) { +fn main(x : Field, y : Field) { assert(x as u32 < y as u32); -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/simple_mut/src/main.nr b/tooling/nargo_cli/tests/execution_success/simple_mut/src/main.nr index 502aceac546..bba0eca5fab 100644 --- a/tooling/nargo_cli/tests/execution_success/simple_mut/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/simple_mut/src/main.nr @@ -1,5 +1,4 @@ // A simple program to test mutable variables - fn main(x : Field) -> pub Field { let mut y = 2; y += x; diff --git a/tooling/nargo_cli/tests/execution_success/simple_not/src/main.nr b/tooling/nargo_cli/tests/execution_success/simple_not/src/main.nr index 0069932cf24..4b17fd91eca 100644 --- a/tooling/nargo_cli/tests/execution_success/simple_not/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/simple_not/src/main.nr @@ -1,4 +1,4 @@ // A simple program for testing the NOT op fn main(x : bool) -> pub bool { !x -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/simple_program_addition/src/main.nr b/tooling/nargo_cli/tests/execution_success/simple_program_addition/src/main.nr index 59b03556d94..082d9b5071f 100644 --- a/tooling/nargo_cli/tests/execution_success/simple_program_addition/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/simple_program_addition/src/main.nr @@ -2,4 +2,4 @@ // a binary operation. fn main(x : Field) -> pub Field { x + 1 -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/simple_radix/src/main.nr b/tooling/nargo_cli/tests/execution_success/simple_radix/src/main.nr index 9ce6d86f13a..67268a932a3 100644 --- a/tooling/nargo_cli/tests/execution_success/simple_radix/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/simple_radix/src/main.nr @@ -1,5 +1,4 @@ // Simple program to test to_radix - fn main(x : Field) { let bits = x.to_le_bits(3); assert(bits[0] == 0); diff --git a/tooling/nargo_cli/tests/execution_success/simple_shift_left_right/src/main.nr b/tooling/nargo_cli/tests/execution_success/simple_shift_left_right/src/main.nr index f12b2d8bf20..517ef429458 100644 --- a/tooling/nargo_cli/tests/execution_success/simple_shift_left_right/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/simple_shift_left_right/src/main.nr @@ -1,7 +1,7 @@ // Tests a very simple program. // // The features being tested are left and right shifts. -fn main(x : u32) { +fn main(x : u32) { let z = x >> 4; let t = x << 4; assert(z == t >> 8); diff --git a/tooling/nargo_cli/tests/execution_success/slice_dynamic_index/src/main.nr b/tooling/nargo_cli/tests/execution_success/slice_dynamic_index/src/main.nr index 724f3f16184..3f3177b1b5a 100644 --- a/tooling/nargo_cli/tests/execution_success/slice_dynamic_index/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/slice_dynamic_index/src/main.nr @@ -9,7 +9,7 @@ fn regression_dynamic_slice_index(x: Field, y: Field) { slice = slice.push_back(i); } assert(slice.len() == 5); - + dynamic_slice_index_set_if(slice, x, y); dynamic_slice_index_set_else(slice, x, y); dynamic_slice_index_set_nested_if_else_else(slice, x, y); @@ -92,7 +92,6 @@ fn dynamic_slice_index_else(mut slice: [Field], x: Field) { assert(slice[4] == 2); } - fn dynamic_slice_merge_if(mut slice: [Field], x: Field) { if x as u32 < 10 { assert(slice[x] == 4); @@ -250,7 +249,6 @@ fn dynamic_slice_merge_two_ifs(mut slice: [Field], x: Field) { assert(slice[slice.len() - 1] == 20); } - fn dynamic_slice_merge_mutate_between_ifs(mut slice: [Field], x: Field, y: Field) { if x != y { slice[x] = 50; @@ -312,4 +310,3 @@ fn dynamic_slice_merge_push_then_pop(mut slice: [Field], x: Field, y: Field) { assert(elem == y); } - diff --git a/tooling/nargo_cli/tests/execution_success/slices/src/main.nr b/tooling/nargo_cli/tests/execution_success/slices/src/main.nr index f9069a48e39..e027c0f5ea2 100644 --- a/tooling/nargo_cli/tests/execution_success/slices/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/slices/src/main.nr @@ -116,7 +116,7 @@ fn merge_slices_if(x: Field, y: Field) { assert(slice[5] == 15); assert(slice[6] == 50); assert(slice[7] == 60); - + merge_slices_push_then_pop(x, y); let slice = merge_slices_push_then_insert(x, y); @@ -199,7 +199,7 @@ fn merge_slices_mutate_two_ifs(x: Field, y: Field) -> [Field] { slice = slice.push_back(15); slice = slice.push_back(30); - + slice } @@ -213,7 +213,7 @@ fn merge_slices_mutate_between_ifs(x: Field, y: Field) -> [Field] { } slice = slice.push_back(30); - + if x == 20 { slice = slice.push_back(20); } diff --git a/tooling/nargo_cli/tests/execution_success/strings/src/main.nr b/tooling/nargo_cli/tests/execution_success/strings/src/main.nr index 1d401260179..02e2fa678cd 100644 --- a/tooling/nargo_cli/tests/execution_success/strings/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/strings/src/main.nr @@ -57,7 +57,7 @@ fn failed_constraint(hex_as_field: Field) { // evaluated at compile time. // When this method is called from a test method or with constant values // a `Failed constraint` compile error will be caught before this `println` - // is executed as the input will be a constant. + // is executed as the input will be a constant. std::println(hex_as_field); assert(hex_as_field != 0x41); } diff --git a/tooling/nargo_cli/tests/execution_success/struct_array_inputs/src/main.nr b/tooling/nargo_cli/tests/execution_success/struct_array_inputs/src/main.nr index de317fe35e7..4a367558671 100644 --- a/tooling/nargo_cli/tests/execution_success/struct_array_inputs/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/struct_array_inputs/src/main.nr @@ -5,4 +5,4 @@ struct Foo { fn main(foos: [Foo; 3]) -> pub Field { foos[2].bar + foos[2].baz -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/struct_inputs/src/foo.nr b/tooling/nargo_cli/tests/execution_success/struct_inputs/src/foo.nr index 281769cfb07..ea3a6bbe25f 100644 --- a/tooling/nargo_cli/tests/execution_success/struct_inputs/src/foo.nr +++ b/tooling/nargo_cli/tests/execution_success/struct_inputs/src/foo.nr @@ -3,4 +3,4 @@ mod bar; struct fooStruct { bar_struct: bar::barStruct, baz: Field, -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/struct_inputs/src/foo/bar.nr b/tooling/nargo_cli/tests/execution_success/struct_inputs/src/foo/bar.nr index d1963f4a0a7..6d879326677 100644 --- a/tooling/nargo_cli/tests/execution_success/struct_inputs/src/foo/bar.nr +++ b/tooling/nargo_cli/tests/execution_success/struct_inputs/src/foo/bar.nr @@ -4,4 +4,4 @@ struct barStruct { val: Field, array: [Field; 2], message: str<5>, -} \ No newline at end of file +} diff --git a/tooling/nargo_cli/tests/execution_success/struct_inputs/src/main.nr b/tooling/nargo_cli/tests/execution_success/struct_inputs/src/main.nr index 68858d98998..96684d01a1d 100644 --- a/tooling/nargo_cli/tests/execution_success/struct_inputs/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/struct_inputs/src/main.nr @@ -22,7 +22,7 @@ fn main(x : Field, y : pub myStruct, z: pub foo::bar::barStruct, a: pub foo::foo assert(y.message == "hello"); assert(a.bar_struct.message == struct_from_bar.message); - + a.bar_struct.array[1] } diff --git a/tooling/nargo_cli/tests/execution_success/submodules/src/main.nr b/tooling/nargo_cli/tests/execution_success/submodules/src/main.nr index 47f80f1bd4d..813f3a26a20 100644 --- a/tooling/nargo_cli/tests/execution_success/submodules/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/submodules/src/main.nr @@ -12,4 +12,4 @@ mod mysubmodule { pub fn my_helper() {} } - + diff --git a/tooling/nargo_cli/tests/execution_success/to_bytes_integration/src/main.nr b/tooling/nargo_cli/tests/execution_success/to_bytes_integration/src/main.nr index f76df026db7..43a35f05488 100644 --- a/tooling/nargo_cli/tests/execution_success/to_bytes_integration/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/to_bytes_integration/src/main.nr @@ -1,6 +1,6 @@ use dep::std; -fn main(x : Field, a: Field) { +fn main(x : Field, a: Field) { let y: Field = 2040124; let be_byte_array = y.to_be_bytes(31); let le_byte_array = x.to_le_bytes(31); diff --git a/tooling/nargo_cli/tests/execution_success/to_le_bytes/src/main.nr b/tooling/nargo_cli/tests/execution_success/to_le_bytes/src/main.nr index 9d7eb403083..7155122b372 100644 --- a/tooling/nargo_cli/tests/execution_success/to_le_bytes/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/to_le_bytes/src/main.nr @@ -2,7 +2,7 @@ fn main(x : Field) -> pub [u8; 31] { // The result of this byte array will be little-endian let byte_array = x.to_le_bytes(31); assert(byte_array.len() == 31); - + let mut bytes = [0; 31]; for i in 0..31 { bytes[i] = byte_array[i]; diff --git a/tooling/nargo_cli/tests/execution_success/trait_associated_member_names_clashes/Nargo.toml b/tooling/nargo_cli/tests/execution_success/trait_associated_member_names_clashes/Nargo.toml new file mode 100644 index 00000000000..585dcde7351 --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/trait_associated_member_names_clashes/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "trait_associated_member_names_clashes" +type = "bin" +authors = [""] +compiler_version = "0.16.0" + +[dependencies] \ No newline at end of file diff --git a/tooling/nargo_cli/tests/execution_success/trait_associated_member_names_clashes/Prover.toml b/tooling/nargo_cli/tests/execution_success/trait_associated_member_names_clashes/Prover.toml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tooling/nargo_cli/tests/execution_success/trait_associated_member_names_clashes/src/main.nr b/tooling/nargo_cli/tests/execution_success/trait_associated_member_names_clashes/src/main.nr new file mode 100644 index 00000000000..412a75010f6 --- /dev/null +++ b/tooling/nargo_cli/tests/execution_success/trait_associated_member_names_clashes/src/main.nr @@ -0,0 +1,36 @@ +trait Trait1 { + fn tralala() -> Field; +} + +trait Trait2 { + fn tralala() -> Field; +} + +struct Struct1 { +} + +impl Struct1 { + fn tralala() -> Field { + 123456 + } +} + +impl Trait1 for Struct1 { + fn tralala() -> Field { + 111111 + } +} + +impl Trait2 for Struct1 { + fn tralala() -> Field { + 222222 + } +} + +fn main() { + // the struct impl takes priority over trait methods + assert(Struct1::tralala() == 123456); + // TODO: uncomment these, once we support the :: syntax + //assert(::tralala() == 111111); + //assert(::tralala() == 222222); +} diff --git a/tooling/nargo_cli/tests/execution_success/trait_multi_module_test/src/main.nr b/tooling/nargo_cli/tests/execution_success/trait_multi_module_test/src/main.nr index 63b6f08ed52..77c30ce602b 100644 --- a/tooling/nargo_cli/tests/execution_success/trait_multi_module_test/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/trait_multi_module_test/src/main.nr @@ -5,5 +5,4 @@ mod module4; mod module5; mod module6; -fn main() { -} +fn main() {} diff --git a/tooling/nargo_cli/tests/execution_success/tuples/src/main.nr b/tooling/nargo_cli/tests/execution_success/tuples/src/main.nr index bfc943dfc07..e836c66a0fa 100644 --- a/tooling/nargo_cli/tests/execution_success/tuples/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/tuples/src/main.nr @@ -7,7 +7,7 @@ fn main(x: Field, y: Field) { assert(a == 0); assert(b == 1); - let (u,v) = if x as u32 < 1 { + let (u, v) = if x as u32 < 1 { (x, x + 1) } else { (x + 1, x) diff --git a/tooling/nargo_cli/tests/execution_success/xor/src/main.nr b/tooling/nargo_cli/tests/execution_success/xor/src/main.nr index e893c938fc3..d4261aa786a 100644 --- a/tooling/nargo_cli/tests/execution_success/xor/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/xor/src/main.nr @@ -2,4 +2,4 @@ fn main(x : u32, y : pub u32) { let m = x ^ y; assert(m != 10); -} \ No newline at end of file +}