From e3da71c25975d75318a5f984b54eeb8b55deef19 Mon Sep 17 00:00:00 2001 From: AztecBot Date: Fri, 13 Sep 2024 08:02:20 +0000 Subject: [PATCH 1/4] [1 changes] feat: implement LSP code action "Implement missing members" (https://github.com/noir-lang/noir/pull/6020) fix: use module name as line after which we'll insert auto-import (https://github.com/noir-lang/noir/pull/6025) feat: let `has_named_attribute` work for built-in attributes (https://github.com/noir-lang/noir/pull/6024) feat: impl Hash and Eq on more comptime types (https://github.com/noir-lang/noir/pull/6022) fix: Correctly print string tokens (https://github.com/noir-lang/noir/pull/6021) chore: Remove RC tracking in mem2reg (https://github.com/noir-lang/noir/pull/6019) feat: Add `Module::structs` (https://github.com/noir-lang/noir/pull/6017) feat: format trait impl functions (https://github.com/noir-lang/noir/pull/6016) fix: Try to move constant terms to one side for arithmetic generics (https://github.com/noir-lang/noir/pull/6008) --- .noir-sync-commit | 2 +- .../.github/scripts/cargo-binstall-install.sh | 7 +- .../.github/scripts/command-check.sh | 4 + .../acvm-repo/acir/src/circuit/opcodes.rs | 6 +- .../opcodes/black_box_function_call.rs | 36 +- noir/noir-repo/acvm-repo/acir/src/lib.rs | 1 + .../acir/tests/test_program_serialization.rs | 16 +- .../compiler/optimizers/redundant_range.rs | 42 +- .../acvm-repo/acvm/src/pwg/blackbox/bigint.rs | 2 +- .../src/pwg/blackbox/embedded_curve_ops.rs | 16 +- .../acvm-repo/acvm/src/pwg/blackbox/hash.rs | 9 +- .../acvm-repo/acvm/src/pwg/blackbox/logic.rs | 7 +- .../acvm-repo/acvm/src/pwg/blackbox/mod.rs | 8 +- .../acvm/src/pwg/blackbox/pedersen.rs | 4 +- .../acvm-repo/acvm/src/pwg/blackbox/range.rs | 5 +- .../src/pwg/blackbox/signature/schnorr.rs | 4 +- .../acvm-repo/acvm/src/pwg/blackbox/utils.rs | 4 +- noir/noir-repo/acvm-repo/acvm/src/pwg/mod.rs | 48 +- noir/noir-repo/acvm-repo/acvm/tests/solver.rs | 221 +++-- noir/noir-repo/acvm-repo/acvm_js/build.sh | 2 +- .../acvm-repo/acvm_js/src/execute.rs | 4 + .../acvm_js/test/shared/multi_scalar_mul.ts | 6 +- .../aztec_macros/src/transforms/events.rs | 36 +- .../src/transforms/note_interface.rs | 51 +- .../aztec_macros/src/utils/ast_utils.rs | 6 +- .../aztec_macros/src/utils/errors.rs | 2 +- .../aztec_macros/src/utils/parse_utils.rs | 18 +- .../brillig/brillig_gen/brillig_slice_ops.rs | 418 ++------- .../noirc_evaluator/src/brillig/brillig_ir.rs | 23 +- .../src/brillig/brillig_ir/entry_point.rs | 5 +- .../src/brillig/brillig_ir/procedures/mod.rs | 22 + .../procedures/prepare_vector_insert.rs | 134 +++ .../procedures/prepare_vector_push.rs | 111 +++ .../brillig_ir/procedures/vector_pop.rs | 113 +++ .../brillig_ir/procedures/vector_remove.rs | 134 +++ .../compiler/noirc_evaluator/src/errors.rs | 8 + .../src/ssa/acir_gen/acir_ir/acir_variable.rs | 15 +- .../noirc_evaluator/src/ssa/acir_gen/mod.rs | 1 - .../noirc_evaluator/src/ssa/opt/mem2reg.rs | 19 +- .../compiler/noirc_frontend/src/ast/traits.rs | 20 +- .../noirc_frontend/src/ast/visitor.rs | 42 +- .../noirc_frontend/src/elaborator/patterns.rs | 9 - .../src/elaborator/statements.rs | 7 + .../src/hir/comptime/interpreter.rs | 23 +- .../src/hir/comptime/interpreter/builtin.rs | 231 +++-- .../interpreter/builtin/builtin_helpers.rs | 52 +- .../noirc_frontend/src/hir/comptime/value.rs | 5 + .../src/hir/def_collector/dc_mod.rs | 10 +- .../src/hir/def_map/module_data.rs | 13 +- .../src/hir/resolution/errors.rs | 9 + .../noirc_frontend/src/hir_def/types.rs | 24 +- .../src/hir_def/types/arithmetic.rs | 42 +- .../noirc_frontend/src/lexer/token.rs | 64 +- .../src/parser/parser/traits.rs | 11 +- .../wasm/scripts/install_wasm-pack.sh | 7 +- noir/noir-repo/cspell.json | 1 + .../docs/noir/concepts/data_types/arrays.md | 8 +- .../docs/docs/noir/concepts/generics.md | 2 +- .../standard_library/meta/function_def.md | 11 + .../docs/noir/standard_library/meta/module.md | 31 +- .../docs/noir/standard_library/meta/op.md | 16 +- .../docs/noir/standard_library/meta/quoted.md | 1 + .../noir/standard_library/meta/struct_def.md | 11 + .../docs/noir/standard_library/meta/typ.md | 3 +- .../language_concepts/data_types/04_arrays.md | 4 +- .../language_concepts/data_types/04_arrays.md | 4 +- .../language_concepts/data_types/04_arrays.md | 4 +- .../language_concepts/data_types/04_arrays.md | 4 +- .../language_concepts/data_types/04_arrays.md | 4 +- .../language_concepts/data_types/04_arrays.md | 4 +- .../noir/syntax/data_types/arrays.md | 4 +- .../noir/concepts/data_types/arrays.md | 4 +- .../noir/concepts/data_types/arrays.md | 4 +- .../noir/concepts/data_types/arrays.md | 4 +- .../noir/concepts/data_types/arrays.md | 4 +- .../noir/concepts/data_types/arrays.md | 4 +- .../noir/concepts/data_types/arrays.md | 4 +- .../noir/concepts/data_types/arrays.md | 4 +- .../noir/concepts/data_types/arrays.md | 4 +- .../noir/concepts/data_types/arrays.md | 4 +- .../noir/concepts/data_types/arrays.md | 4 +- .../noir/concepts/data_types/arrays.md | 4 +- .../noir_stdlib/src/array/check_shuffle.nr | 116 +++ .../src/{array.nr => array/mod.nr} | 102 +-- .../noir_stdlib/src/array/quicksort.nr | 39 + noir/noir-repo/noir_stdlib/src/bigint.nr | 218 ++--- noir/noir-repo/noir_stdlib/src/cmp.nr | 94 +- .../src/collections/bounded_vec.nr | 4 +- .../noir_stdlib/src/collections/map.nr | 29 +- .../noir_stdlib/src/collections/umap.nr | 35 +- noir/noir-repo/noir_stdlib/src/convert.nr | 108 ++- noir/noir-repo/noir_stdlib/src/default.nr | 72 +- .../noir-repo/noir_stdlib/src/ec/montcurve.nr | 3 +- noir/noir-repo/noir_stdlib/src/ec/swcurve.nr | 12 +- noir/noir-repo/noir_stdlib/src/ec/tecurve.nr | 4 +- .../noir_stdlib/src/embedded_curve_ops.nr | 15 +- noir/noir-repo/noir_stdlib/src/hash/mimc.nr | 10 +- noir/noir-repo/noir_stdlib/src/hash/mod.nr | 50 +- .../noir_stdlib/src/hash/poseidon/mod.nr | 20 +- .../noir_stdlib/src/hash/poseidon2.nr | 8 +- .../noir_stdlib/src/meta/function_def.nr | 20 +- noir/noir-repo/noir_stdlib/src/meta/module.nr | 31 +- noir/noir-repo/noir_stdlib/src/meta/op.nr | 2 + noir/noir-repo/noir_stdlib/src/meta/quoted.nr | 8 + .../noir_stdlib/src/meta/struct_def.nr | 20 +- noir/noir-repo/noir_stdlib/src/meta/typ.nr | 9 + noir/noir-repo/noir_stdlib/src/ops/arith.nr | 324 +++++-- noir/noir-repo/noir_stdlib/src/ops/bit.nr | 352 +++++-- noir/noir-repo/noir_stdlib/src/option.nr | 8 +- noir/noir-repo/noir_stdlib/src/uint128.nr | 58 +- .../src/main.nr | 2 +- .../arithmetic_generics_underflow/src/main.nr | 2 +- .../Nargo.toml | 7 + .../src/main.nr | 26 + .../attributes_struct/src/main.nr | 7 +- .../comptime_function_definition/src/main.nr | 12 +- .../comptime_globals_regression/Nargo.toml | 7 + .../comptime_globals_regression/src/main.nr | 23 + .../comptime_module/src/main.nr | 14 +- .../comptime_trait_constraint/src/main.nr | 2 +- .../comptime_type/src/main.nr | 4 +- .../inject_context_attribute/src/main.nr | 2 +- .../no_duplicate_methods/src/main.nr | 8 +- .../regression_4635/src/main.nr | 2 +- .../serialize/src/main.nr | 6 +- .../trait_default_implementation/src/main.nr | 4 +- .../trait_function_calls/src/main.nr | 8 +- .../trait_impl_generics/src/main.nr | 16 +- .../trait_impl_with_where_clause/src/main.nr | 2 +- .../trait_multi_module_test/src/module6.nr | 2 +- .../trait_override_implementation/src/main.nr | 16 +- .../trait_static_methods/src/main.nr | 4 +- .../trait_where_clause/src/main.nr | 22 +- .../compile_success_empty/traits/src/main.nr | 4 +- .../execution_success/derive/src/main.nr | 2 +- .../higher_order_functions/src/main.nr | 2 +- .../execution_success/slice_regex/src/main.nr | 45 +- .../trait_impl_base_type/src/main.nr | 14 +- .../verify_honk_proof/Nargo.toml | 6 - .../verify_honk_proof/Prover.toml | 4 - .../verify_honk_proof/src/main.nr | 17 - .../tooling/fuzzer/src/dictionary/mod.rs | 33 +- noir/noir-repo/tooling/lsp/src/modules.rs | 71 +- .../tooling/lsp/src/requests/code_action.rs | 9 +- .../code_action/implement_missing_members.rs | 867 ++++++++++++++++++ .../requests/code_action/import_or_qualify.rs | 6 +- .../lsp/src/requests/code_action/tests.rs | 5 +- .../tooling/lsp/src/requests/completion.rs | 6 +- .../src/requests/completion/auto_import.rs | 6 +- .../lsp/src/requests/completion/tests.rs | 5 +- .../lsp/src/requests/document_symbol.rs | 10 +- .../tooling/lsp/src/requests/hover.rs | 39 +- noir/noir-repo/tooling/nargo/src/errors.rs | 4 + .../tooling/nargo/src/ops/execute.rs | 4 + noir/noir-repo/tooling/nargo/src/ops/test.rs | 12 +- .../tooling/nargo_fmt/src/visitor/item.rs | 44 +- .../tooling/nargo_fmt/tests/input/impl.nr | 2 +- .../noir_js_backend_barretenberg/package.json | 2 +- .../noir-repo/tooling/noirc_abi_wasm/build.sh | 2 +- noir/noir-repo/yarn.lock | 13 +- 160 files changed, 3921 insertions(+), 1577 deletions(-) create mode 100755 noir/noir-repo/.github/scripts/command-check.sh create mode 100644 noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/prepare_vector_insert.rs create mode 100644 noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/prepare_vector_push.rs create mode 100644 noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/vector_pop.rs create mode 100644 noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/vector_remove.rs create mode 100644 noir/noir-repo/noir_stdlib/src/array/check_shuffle.nr rename noir/noir-repo/noir_stdlib/src/{array.nr => array/mod.nr} (57%) create mode 100644 noir/noir-repo/noir_stdlib/src/array/quicksort.nr create mode 100644 noir/noir-repo/test_programs/compile_success_empty/arithmetic_generics_move_constant_terms/Nargo.toml create mode 100644 noir/noir-repo/test_programs/compile_success_empty/arithmetic_generics_move_constant_terms/src/main.nr create mode 100644 noir/noir-repo/test_programs/compile_success_empty/comptime_globals_regression/Nargo.toml create mode 100644 noir/noir-repo/test_programs/compile_success_empty/comptime_globals_regression/src/main.nr delete mode 100644 noir/noir-repo/test_programs/execution_success/verify_honk_proof/Nargo.toml delete mode 100644 noir/noir-repo/test_programs/execution_success/verify_honk_proof/Prover.toml delete mode 100644 noir/noir-repo/test_programs/execution_success/verify_honk_proof/src/main.nr create mode 100644 noir/noir-repo/tooling/lsp/src/requests/code_action/implement_missing_members.rs diff --git a/.noir-sync-commit b/.noir-sync-commit index f2fa0b3c445..c9c0a69394e 100644 --- a/.noir-sync-commit +++ b/.noir-sync-commit @@ -1 +1 @@ -3c3ed1e3d28946a02071c524dd128afe131bc3da +9bf2dcbf166f9ffd97c369c0de3d95329c850d47 diff --git a/noir/noir-repo/.github/scripts/cargo-binstall-install.sh b/noir/noir-repo/.github/scripts/cargo-binstall-install.sh index 55d90904ca3..5cbf2cda221 100755 --- a/noir/noir-repo/.github/scripts/cargo-binstall-install.sh +++ b/noir/noir-repo/.github/scripts/cargo-binstall-install.sh @@ -1,4 +1,9 @@ #!/usr/bin/env bash set -eu -curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash +cd $(dirname "$0") + +CARGO_BINSTALL_CHECK=$(./command-check.sh cargo-binstall) +if [ $CARGO_BINSTALL_CHECK != "true" ]; then + curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash +fi diff --git a/noir/noir-repo/.github/scripts/command-check.sh b/noir/noir-repo/.github/scripts/command-check.sh new file mode 100755 index 00000000000..ebe2fa52bde --- /dev/null +++ b/noir/noir-repo/.github/scripts/command-check.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -eu + +command -v $1 >/dev/null 2>&1 && echo "true" || { echo >&2 "$1 is not installed" && echo "false"; } diff --git a/noir/noir-repo/acvm-repo/acir/src/circuit/opcodes.rs b/noir/noir-repo/acvm-repo/acir/src/circuit/opcodes.rs index d7f0f5f6f1f..848d7bda84b 100644 --- a/noir/noir-repo/acvm-repo/acir/src/circuit/opcodes.rs +++ b/noir/noir-repo/acvm-repo/acir/src/circuit/opcodes.rs @@ -13,7 +13,9 @@ use serde::{Deserialize, Serialize}; mod black_box_function_call; mod memory_operation; -pub use black_box_function_call::{BlackBoxFuncCall, ConstantOrWitnessEnum, FunctionInput}; +pub use black_box_function_call::{ + BlackBoxFuncCall, ConstantOrWitnessEnum, FunctionInput, InvalidInputBitSize, +}; pub use memory_operation::{BlockId, MemOp}; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -40,7 +42,7 @@ pub enum Opcode { /// values which define the opcode. /// /// A general expression of assert-zero opcode is the following: - /// ``` + /// ```text /// \sum_{i,j} {q_M}_{i,j}w_iw_j + \sum_i q_iw_i +q_c = 0 /// ``` /// diff --git a/noir/noir-repo/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs b/noir/noir-repo/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs index 333bab419c8..f527522cceb 100644 --- a/noir/noir-repo/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs +++ b/noir/noir-repo/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs @@ -1,6 +1,8 @@ use crate::native_types::Witness; -use crate::BlackBoxFunc; +use crate::{AcirField, BlackBoxFunc}; + use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use thiserror::Error; // Note: Some functions will not use all of the witness // So we need to supply how many bits of the witness is needed @@ -13,8 +15,8 @@ pub enum ConstantOrWitnessEnum { #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct FunctionInput { - pub input: ConstantOrWitnessEnum, - pub num_bits: u32, + input: ConstantOrWitnessEnum, + num_bits: u32, } impl FunctionInput { @@ -25,6 +27,14 @@ impl FunctionInput { } } + pub fn input(self) -> ConstantOrWitnessEnum { + self.input + } + + pub fn input_ref(&self) -> &ConstantOrWitnessEnum { + &self.input + } + pub fn num_bits(&self) -> u32 { self.num_bits } @@ -32,9 +42,25 @@ impl FunctionInput { pub fn witness(witness: Witness, num_bits: u32) -> FunctionInput { FunctionInput { input: ConstantOrWitnessEnum::Witness(witness), num_bits } } +} + +#[derive(Clone, PartialEq, Eq, Debug, Error)] +#[error("FunctionInput value has too many bits: value: {value}, {value_num_bits} >= {max_bits}")] +pub struct InvalidInputBitSize { + pub value: String, + pub value_num_bits: u32, + pub max_bits: u32, +} - pub fn constant(value: F, num_bits: u32) -> FunctionInput { - FunctionInput { input: ConstantOrWitnessEnum::Constant(value), num_bits } +impl FunctionInput { + pub fn constant(value: F, max_bits: u32) -> Result, InvalidInputBitSize> { + if value.num_bits() <= max_bits { + Ok(FunctionInput { input: ConstantOrWitnessEnum::Constant(value), num_bits: max_bits }) + } else { + let value_num_bits = value.num_bits(); + let value = format!("{}", value); + Err(InvalidInputBitSize { value, value_num_bits, max_bits }) + } } } diff --git a/noir/noir-repo/acvm-repo/acir/src/lib.rs b/noir/noir-repo/acvm-repo/acir/src/lib.rs index 845a1d6ad5a..36331427b9f 100644 --- a/noir/noir-repo/acvm-repo/acir/src/lib.rs +++ b/noir/noir-repo/acvm-repo/acir/src/lib.rs @@ -12,6 +12,7 @@ pub use acir_field; pub use acir_field::{AcirField, FieldElement}; pub use brillig; pub use circuit::black_box_functions::BlackBoxFunc; +pub use circuit::opcodes::InvalidInputBitSize; #[cfg(test)] mod reflection { diff --git a/noir/noir-repo/acvm-repo/acir/tests/test_program_serialization.rs b/noir/noir-repo/acvm-repo/acir/tests/test_program_serialization.rs index 838886a03ce..6dd99f2c289 100644 --- a/noir/noir-repo/acvm-repo/acir/tests/test_program_serialization.rs +++ b/noir/noir-repo/acvm-repo/acir/tests/test_program_serialization.rs @@ -62,13 +62,13 @@ fn multi_scalar_mul_circuit() { let multi_scalar_mul: Opcode = Opcode::BlackBoxFuncCall(BlackBoxFuncCall::MultiScalarMul { points: vec![ - FunctionInput::witness(Witness(1), 128), - FunctionInput::witness(Witness(2), 128), + FunctionInput::witness(Witness(1), FieldElement::max_num_bits()), + FunctionInput::witness(Witness(2), FieldElement::max_num_bits()), FunctionInput::witness(Witness(3), 1), ], scalars: vec![ - FunctionInput::witness(Witness(4), 128), - FunctionInput::witness(Witness(5), 128), + FunctionInput::witness(Witness(4), FieldElement::max_num_bits()), + FunctionInput::witness(Witness(5), FieldElement::max_num_bits()), ], outputs: (Witness(6), Witness(7), Witness(8)), }); @@ -91,10 +91,10 @@ fn multi_scalar_mul_circuit() { let bytes = Program::serialize_program(&program); let expected_serialization: Vec = vec![ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 141, 11, 10, 0, 32, 8, 67, 43, 181, 15, 116, 232, - 142, 158, 210, 130, 149, 240, 112, 234, 212, 156, 78, 12, 39, 67, 71, 158, 142, 80, 29, 44, - 228, 66, 90, 168, 119, 189, 74, 115, 131, 174, 78, 115, 58, 124, 70, 254, 130, 59, 74, 253, - 68, 255, 255, 221, 39, 54, 221, 93, 91, 132, 193, 0, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 141, 11, 10, 0, 32, 8, 67, 43, 181, 15, 116, 255, + 227, 70, 74, 11, 86, 194, 195, 169, 83, 115, 58, 49, 156, 12, 29, 121, 58, 66, 117, 176, + 144, 11, 105, 161, 222, 245, 42, 205, 13, 186, 58, 205, 233, 240, 25, 249, 11, 238, 40, + 245, 19, 253, 255, 119, 159, 216, 103, 157, 249, 169, 193, 0, 0, 0, ]; assert_eq!(bytes, expected_serialization) diff --git a/noir/noir-repo/acvm-repo/acvm/src/compiler/optimizers/redundant_range.rs b/noir/noir-repo/acvm-repo/acvm/src/compiler/optimizers/redundant_range.rs index b03b6715abe..3570a36a7e7 100644 --- a/noir/noir-repo/acvm-repo/acvm/src/compiler/optimizers/redundant_range.rs +++ b/noir/noir-repo/acvm-repo/acvm/src/compiler/optimizers/redundant_range.rs @@ -1,6 +1,6 @@ use acir::{ circuit::{ - opcodes::{BlackBoxFuncCall, ConstantOrWitnessEnum, FunctionInput}, + opcodes::{BlackBoxFuncCall, ConstantOrWitnessEnum}, Circuit, Opcode, }, native_types::Witness, @@ -73,10 +73,13 @@ impl RangeOptimizer { } } - Opcode::BlackBoxFuncCall(BlackBoxFuncCall::RANGE { - input: - FunctionInput { input: ConstantOrWitnessEnum::Witness(witness), num_bits }, - }) => Some((*witness, *num_bits)), + Opcode::BlackBoxFuncCall(BlackBoxFuncCall::RANGE { input }) => { + if let ConstantOrWitnessEnum::Witness(witness) = input.input() { + Some((witness, input.num_bits())) + } else { + None + } + } _ => None, }) else { @@ -106,17 +109,28 @@ impl RangeOptimizer { let mut new_order_list = Vec::with_capacity(order_list.len()); let mut optimized_opcodes = Vec::with_capacity(self.circuit.opcodes.len()); for (idx, opcode) in self.circuit.opcodes.into_iter().enumerate() { - let (witness, num_bits) = match opcode { - Opcode::BlackBoxFuncCall(BlackBoxFuncCall::RANGE { - input: - FunctionInput { input: ConstantOrWitnessEnum::Witness(w), num_bits: bits }, - }) => (w, bits), - _ => { - // If its not the range opcode, add it to the opcode - // list and continue; + let (witness, num_bits) = { + // If its not the range opcode, add it to the opcode + // list and continue; + let mut push_non_range_opcode = || { optimized_opcodes.push(opcode.clone()); new_order_list.push(order_list[idx]); - continue; + }; + + match opcode { + Opcode::BlackBoxFuncCall(BlackBoxFuncCall::RANGE { input }) => { + match input.input() { + ConstantOrWitnessEnum::Witness(witness) => (witness, input.num_bits()), + _ => { + push_non_range_opcode(); + continue; + } + } + } + _ => { + push_non_range_opcode(); + continue; + } } }; // If we've already applied the range constraint for this witness then skip this opcode. diff --git a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/bigint.rs b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/bigint.rs index 1bce4aa6c5e..ccad3510682 100644 --- a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/bigint.rs +++ b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/bigint.rs @@ -27,7 +27,7 @@ impl AcvmBigIntSolver { ) -> Result<(), OpcodeResolutionError> { let bytes = inputs .iter() - .map(|input| input_to_value(initial_witness, *input).unwrap().to_u128() as u8) + .map(|input| input_to_value(initial_witness, *input, false).unwrap().to_u128() as u8) .collect::>(); self.bigint_solver.bigint_from_bytes(&bytes, modulus, output)?; Ok(()) diff --git a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/embedded_curve_ops.rs b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/embedded_curve_ops.rs index c290faeaa4a..9e511571275 100644 --- a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/embedded_curve_ops.rs +++ b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/embedded_curve_ops.rs @@ -15,11 +15,11 @@ pub(super) fn multi_scalar_mul( outputs: (Witness, Witness, Witness), ) -> Result<(), OpcodeResolutionError> { let points: Result, _> = - points.iter().map(|input| input_to_value(initial_witness, *input)).collect(); + points.iter().map(|input| input_to_value(initial_witness, *input, false)).collect(); let points: Vec<_> = points?.into_iter().collect(); let scalars: Result, _> = - scalars.iter().map(|input| input_to_value(initial_witness, *input)).collect(); + scalars.iter().map(|input| input_to_value(initial_witness, *input, false)).collect(); let mut scalars_lo = Vec::new(); let mut scalars_hi = Vec::new(); for (i, scalar) in scalars?.into_iter().enumerate() { @@ -47,12 +47,12 @@ pub(super) fn embedded_curve_add( input2: [FunctionInput; 3], outputs: (Witness, Witness, Witness), ) -> Result<(), OpcodeResolutionError> { - let input1_x = input_to_value(initial_witness, input1[0])?; - let input1_y = input_to_value(initial_witness, input1[1])?; - let input1_infinite = input_to_value(initial_witness, input1[2])?; - let input2_x = input_to_value(initial_witness, input2[0])?; - let input2_y = input_to_value(initial_witness, input2[1])?; - let input2_infinite = input_to_value(initial_witness, input2[2])?; + let input1_x = input_to_value(initial_witness, input1[0], false)?; + let input1_y = input_to_value(initial_witness, input1[1], false)?; + let input1_infinite = input_to_value(initial_witness, input1[2], false)?; + let input2_x = input_to_value(initial_witness, input2[0], false)?; + let input2_y = input_to_value(initial_witness, input2[1], false)?; + let input2_infinite = input_to_value(initial_witness, input2[2], false)?; let (res_x, res_y, res_infinite) = backend.ec_add( &input1_x, &input1_y, diff --git a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/hash.rs b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/hash.rs index b51139f76b7..234ab6162ca 100644 --- a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/hash.rs +++ b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/hash.rs @@ -34,7 +34,7 @@ fn get_hash_input( for input in inputs.iter() { let num_bits = input.num_bits() as usize; - let witness_assignment = input_to_value(initial_witness, *input)?; + let witness_assignment = input_to_value(initial_witness, *input, false)?; let bytes = witness_assignment.fetch_nearest_bytes(num_bits); message_input.extend(bytes); } @@ -42,7 +42,8 @@ fn get_hash_input( // Truncate the message if there is a `message_size` parameter given match message_size { Some(input) => { - let num_bytes_to_take = input_to_value(initial_witness, *input)?.to_u128() as usize; + let num_bytes_to_take = + input_to_value(initial_witness, *input, false)?.to_u128() as usize; // If the number of bytes to take is more than the amount of bytes available // in the message, then we error. @@ -78,7 +79,7 @@ fn to_u32_array( ) -> Result<[u32; N], OpcodeResolutionError> { let mut result = [0; N]; for (it, input) in result.iter_mut().zip(inputs) { - let witness_value = input_to_value(initial_witness, *input)?; + let witness_value = input_to_value(initial_witness, *input, false)?; *it = witness_value.to_u128() as u32; } Ok(result) @@ -133,7 +134,7 @@ pub(crate) fn solve_poseidon2_permutation_opcode( // Read witness assignments let mut state = Vec::new(); for input in inputs.iter() { - let witness_assignment = input_to_value(initial_witness, *input)?; + let witness_assignment = input_to_value(initial_witness, *input, false)?; state.push(witness_assignment); } diff --git a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/logic.rs b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/logic.rs index 7ce0827d932..8468b0ca27a 100644 --- a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/logic.rs +++ b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/logic.rs @@ -51,8 +51,11 @@ fn solve_logic_opcode( result: Witness, logic_op: impl Fn(F, F) -> F, ) -> Result<(), OpcodeResolutionError> { - let w_l_value = input_to_value(initial_witness, *a)?; - let w_r_value = input_to_value(initial_witness, *b)?; + // TODO(https://github.com/noir-lang/noir/issues/5985): re-enable these once we figure out how to combine these with existing + // noirc_frontend/noirc_evaluator overflow error messages + let skip_bitsize_checks = true; + let w_l_value = input_to_value(initial_witness, *a, skip_bitsize_checks)?; + let w_r_value = input_to_value(initial_witness, *b, skip_bitsize_checks)?; let assignment = logic_op(w_l_value, w_r_value); insert_value(&result, assignment, initial_witness) diff --git a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/mod.rs b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/mod.rs index def4216fe15..8b8bfc5cfc5 100644 --- a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/mod.rs +++ b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/mod.rs @@ -42,11 +42,11 @@ fn first_missing_assignment( inputs: &[FunctionInput], ) -> Option { inputs.iter().find_map(|input| { - if let ConstantOrWitnessEnum::Witness(witness) = input.input { - if witness_assignments.contains_key(&witness) { + if let ConstantOrWitnessEnum::Witness(ref witness) = input.input_ref() { + if witness_assignments.contains_key(witness) { None } else { - Some(witness) + Some(*witness) } } else { None @@ -108,7 +108,7 @@ pub(crate) fn solve( for (it, input) in state.iter_mut().zip(inputs.as_ref()) { let num_bits = input.num_bits() as usize; assert_eq!(num_bits, 64); - let witness_assignment = input_to_value(initial_witness, *input)?; + let witness_assignment = input_to_value(initial_witness, *input, false)?; let lane = witness_assignment.try_to_u64(); *it = lane.unwrap(); } diff --git a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/pedersen.rs b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/pedersen.rs index b1b95393b19..654814bf92d 100644 --- a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/pedersen.rs +++ b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/pedersen.rs @@ -17,7 +17,7 @@ pub(super) fn pedersen( outputs: (Witness, Witness), ) -> Result<(), OpcodeResolutionError> { let scalars: Result, _> = - inputs.iter().map(|input| input_to_value(initial_witness, *input)).collect(); + inputs.iter().map(|input| input_to_value(initial_witness, *input, false)).collect(); let scalars: Vec<_> = scalars?.into_iter().collect(); let (res_x, res_y) = backend.pedersen_commitment(&scalars, domain_separator)?; @@ -36,7 +36,7 @@ pub(super) fn pedersen_hash( output: Witness, ) -> Result<(), OpcodeResolutionError> { let scalars: Result, _> = - inputs.iter().map(|input| input_to_value(initial_witness, *input)).collect(); + inputs.iter().map(|input| input_to_value(initial_witness, *input, false)).collect(); let scalars: Vec<_> = scalars?.into_iter().collect(); let res = backend.pedersen_hash(&scalars, domain_separator)?; diff --git a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/range.rs b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/range.rs index 054730bb6c0..4f9be14360e 100644 --- a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/range.rs +++ b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/range.rs @@ -8,7 +8,10 @@ pub(crate) fn solve_range_opcode( initial_witness: &WitnessMap, input: &FunctionInput, ) -> Result<(), OpcodeResolutionError> { - let w_value = input_to_value(initial_witness, *input)?; + // TODO(https://github.com/noir-lang/noir/issues/5985): + // re-enable bitsize checks + let skip_bitsize_checks = true; + let w_value = input_to_value(initial_witness, *input, skip_bitsize_checks)?; if w_value.num_bits() > input.num_bits() { return Err(OpcodeResolutionError::UnsatisfiedConstrain { opcode_location: ErrorLocation::Unresolved, diff --git a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/signature/schnorr.rs b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/signature/schnorr.rs index 4f8e88373ba..a856303d065 100644 --- a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/signature/schnorr.rs +++ b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/signature/schnorr.rs @@ -21,8 +21,8 @@ pub(crate) fn schnorr_verify( message: &[FunctionInput], output: Witness, ) -> Result<(), OpcodeResolutionError> { - let public_key_x: &F = &input_to_value(initial_witness, public_key_x)?; - let public_key_y: &F = &input_to_value(initial_witness, public_key_y)?; + let public_key_x: &F = &input_to_value(initial_witness, public_key_x, false)?; + let public_key_y: &F = &input_to_value(initial_witness, public_key_y, false)?; let signature = to_u8_array(initial_witness, signature)?; let message = to_u8_vec(initial_witness, message)?; diff --git a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/utils.rs b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/utils.rs index 9b9157421e5..b966cb0cc5d 100644 --- a/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/utils.rs +++ b/noir/noir-repo/acvm-repo/acvm/src/pwg/blackbox/utils.rs @@ -8,7 +8,7 @@ pub(crate) fn to_u8_array( ) -> Result<[u8; N], OpcodeResolutionError> { let mut result = [0; N]; for (it, input) in result.iter_mut().zip(inputs) { - let witness_value_bytes = input_to_value(initial_witness, *input)?.to_be_bytes(); + let witness_value_bytes = input_to_value(initial_witness, *input, false)?.to_be_bytes(); let byte = witness_value_bytes .last() .expect("Field element must be represented by non-zero amount of bytes"); @@ -23,7 +23,7 @@ pub(crate) fn to_u8_vec( ) -> Result, OpcodeResolutionError> { let mut result = Vec::with_capacity(inputs.len()); for input in inputs { - let witness_value_bytes = input_to_value(initial_witness, *input)?.to_be_bytes(); + let witness_value_bytes = input_to_value(initial_witness, *input, false)?.to_be_bytes(); let byte = witness_value_bytes .last() .expect("Field element must be represented by non-zero amount of bytes"); diff --git a/noir/noir-repo/acvm-repo/acvm/src/pwg/mod.rs b/noir/noir-repo/acvm-repo/acvm/src/pwg/mod.rs index 647c11bd3c3..c73893ceea6 100644 --- a/noir/noir-repo/acvm-repo/acvm/src/pwg/mod.rs +++ b/noir/noir-repo/acvm-repo/acvm/src/pwg/mod.rs @@ -6,7 +6,9 @@ use acir::{ brillig::ForeignCallResult, circuit::{ brillig::{BrilligBytecode, BrilligFunctionId}, - opcodes::{AcirFunctionId, BlockId, ConstantOrWitnessEnum, FunctionInput}, + opcodes::{ + AcirFunctionId, BlockId, ConstantOrWitnessEnum, FunctionInput, InvalidInputBitSize, + }, AssertionPayload, ErrorSelector, ExpressionOrMemory, Opcode, OpcodeLocation, RawAssertionPayload, ResolvedAssertionPayload, STRING_ERROR_SELECTOR, }, @@ -128,6 +130,11 @@ pub enum OpcodeResolutionError { }, #[error("Index out of bounds, array has size {array_size:?}, but index was {index:?}")] IndexOutOfBounds { opcode_location: ErrorLocation, index: u32, array_size: u32 }, + #[error("Cannot solve opcode: {invalid_input_bit_size}")] + InvalidInputBitSize { + opcode_location: ErrorLocation, + invalid_input_bit_size: InvalidInputBitSize, + }, #[error("Failed to solve blackbox function: {0}, reason: {1}")] BlackBoxFunctionFailed(BlackBoxFunc, String), #[error("Failed to solve brillig function")] @@ -152,6 +159,15 @@ impl From for OpcodeResolutionError { } } +impl From for OpcodeResolutionError { + fn from(invalid_input_bit_size: InvalidInputBitSize) -> Self { + Self::InvalidInputBitSize { + opcode_location: ErrorLocation::Unresolved, + invalid_input_bit_size, + } + } +} + pub struct ACVM<'a, F, B: BlackBoxFunctionSolver> { status: ACVMStatus, @@ -387,6 +403,13 @@ impl<'a, F: AcirField, B: BlackBoxFunctionSolver> ACVM<'a, F, B> { *opcode_index = ErrorLocation::Resolved(location); *assertion_payload = self.extract_assertion_payload(location); } + OpcodeResolutionError::InvalidInputBitSize { + opcode_location: opcode_index, + .. + } => { + let location = OpcodeLocation::Acir(self.instruction_pointer()); + *opcode_index = ErrorLocation::Resolved(location); + } // All other errors are thrown normally. _ => (), }; @@ -633,12 +656,31 @@ pub fn witness_to_value( } } +// TODO(https://github.com/noir-lang/noir/issues/5985): +// remove skip_bitsize_checks pub fn input_to_value( initial_witness: &WitnessMap, input: FunctionInput, + skip_bitsize_checks: bool, ) -> Result> { - match input.input { - ConstantOrWitnessEnum::Witness(witness) => Ok(*witness_to_value(initial_witness, witness)?), + match input.input() { + ConstantOrWitnessEnum::Witness(witness) => { + let initial_value = *witness_to_value(initial_witness, witness)?; + if skip_bitsize_checks || initial_value.num_bits() <= input.num_bits() { + Ok(initial_value) + } else { + let value_num_bits = initial_value.num_bits(); + let value = initial_value.to_string(); + Err(OpcodeResolutionError::InvalidInputBitSize { + opcode_location: ErrorLocation::Unresolved, + invalid_input_bit_size: InvalidInputBitSize { + value, + value_num_bits, + max_bits: input.num_bits(), + }, + }) + } + } ConstantOrWitnessEnum::Constant(value) => Ok(value), } } diff --git a/noir/noir-repo/acvm-repo/acvm/tests/solver.rs b/noir/noir-repo/acvm-repo/acvm/tests/solver.rs index 41e28882993..766d374c43c 100644 --- a/noir/noir-repo/acvm-repo/acvm/tests/solver.rs +++ b/noir/noir-repo/acvm-repo/acvm/tests/solver.rs @@ -19,6 +19,7 @@ use acvm_blackbox_solver::StubbedBlackBoxSolver; use bn254_blackbox_solver::{field_from_hex, Bn254BlackBoxSolver, POSEIDON2_CONFIG}; use brillig_vm::brillig::HeapValueType; +use num_bigint::BigUint; use proptest::arbitrary::any; use proptest::prelude::*; use proptest::result::maybe_ok; @@ -835,15 +836,15 @@ fn constant_or_witness_to_function_inputs( xs: Vec, offset: usize, num_bits: Option, -) -> Vec> { +) -> Result>, OpcodeResolutionError> { let num_bits = num_bits.unwrap_or(FieldElement::max_num_bits()); xs.into_iter() .enumerate() .map(|(i, (x, use_constant))| { if use_constant { - FunctionInput::constant(x, num_bits) + FunctionInput::constant(x, num_bits).map_err(From::from) } else { - FunctionInput::witness(Witness((i + offset) as u32), num_bits) + Ok(FunctionInput::witness(Witness((i + offset) as u32), num_bits)) } }) .collect() @@ -869,9 +870,11 @@ fn solve_array_input_blackbox_call( num_outputs: usize, num_bits: Option, f: F, -) -> Vec +) -> Result, OpcodeResolutionError> where - F: FnOnce((Vec>, Vec)) -> BlackBoxFuncCall, + F: FnOnce( + (Vec>, Vec), + ) -> Result, OpcodeResolutionError>, { let initial_witness_vec: Vec<_> = inputs.iter().enumerate().map(|(i, (x, _))| (Witness(i as u32), *x)).collect(); @@ -880,8 +883,8 @@ where .collect(); let initial_witness = WitnessMap::from(BTreeMap::from_iter(initial_witness_vec)); - let inputs = constant_or_witness_to_function_inputs(inputs, 0, num_bits); - let op = Opcode::BlackBoxFuncCall(f((inputs.clone(), outputs.clone()))); + let inputs = constant_or_witness_to_function_inputs(inputs, 0, num_bits)?; + let op = Opcode::BlackBoxFuncCall(f((inputs.clone(), outputs.clone()))?); let opcodes = vec![op]; let unconstrained_functions = vec![]; let mut acvm = @@ -890,10 +893,10 @@ where assert_eq!(solver_status, ACVMStatus::Solved); let witness_map = acvm.finalize(); - outputs + Ok(outputs .iter() .map(|witness| *witness_map.get(witness).expect("all witnesses to be set")) - .collect() + .collect()) } prop_compose! { @@ -978,7 +981,7 @@ fn bigint_solve_binary_op_opt( modulus: Vec, lhs: Vec, rhs: Vec, -) -> Vec { +) -> Result, OpcodeResolutionError> { let initial_witness_vec: Vec<_> = lhs .iter() .chain(rhs.iter()) @@ -993,8 +996,8 @@ fn bigint_solve_binary_op_opt( .collect(); let initial_witness = WitnessMap::from(BTreeMap::from_iter(initial_witness_vec)); - let lhs = constant_or_witness_to_function_inputs(lhs, 0, None); - let rhs = constant_or_witness_to_function_inputs(rhs, lhs.len(), None); + let lhs = constant_or_witness_to_function_inputs(lhs, 0, None)?; + let rhs = constant_or_witness_to_function_inputs(rhs, lhs.len(), None)?; let to_op_input = if middle_op.is_some() { 2 } else { 0 }; @@ -1025,10 +1028,10 @@ fn bigint_solve_binary_op_opt( let solver_status = acvm.solve(); assert_eq!(solver_status, ACVMStatus::Solved); let witness_map = acvm.finalize(); - output_witnesses + Ok(output_witnesses .iter() .map(|witness| *witness_map.get(witness).expect("all witnesses to be set")) - .collect() + .collect()) } // Solve the given BlackBoxFuncCall with witnesses: 1, 2 as x, y, resp. @@ -1037,10 +1040,13 @@ fn solve_blackbox_func_call( blackbox_func_call: impl Fn( Option, Option, - ) -> BlackBoxFuncCall, + ) -> Result< + BlackBoxFuncCall, + OpcodeResolutionError, + >, lhs: (FieldElement, bool), // if false, use a Witness rhs: (FieldElement, bool), // if false, use a Witness -) -> FieldElement { +) -> Result> { let (lhs, lhs_constant) = lhs; let (rhs, rhs_constant) = rhs; @@ -1057,7 +1063,7 @@ fn solve_blackbox_func_call( rhs_opt = Some(rhs); } - let op = Opcode::BlackBoxFuncCall(blackbox_func_call(lhs_opt, rhs_opt)); + let op = Opcode::BlackBoxFuncCall(blackbox_func_call(lhs_opt, rhs_opt)?); let opcodes = vec![op]; let unconstrained_functions = vec![]; let mut acvm = @@ -1066,60 +1072,60 @@ fn solve_blackbox_func_call( assert_eq!(solver_status, ACVMStatus::Solved); let witness_map = acvm.finalize(); - witness_map[&Witness(3)] + Ok(witness_map[&Witness(3)]) } // N inputs // 32 outputs fn sha256_op( function_inputs_and_outputs: (Vec>, Vec), -) -> BlackBoxFuncCall { +) -> Result, OpcodeResolutionError> { let (function_inputs, outputs) = function_inputs_and_outputs; - BlackBoxFuncCall::SHA256 { + Ok(BlackBoxFuncCall::SHA256 { inputs: function_inputs, outputs: outputs.try_into().expect("SHA256 returns 32 outputs"), - } + }) } // N inputs // 32 outputs fn blake2s_op( function_inputs_and_outputs: (Vec>, Vec), -) -> BlackBoxFuncCall { +) -> Result, OpcodeResolutionError> { let (function_inputs, outputs) = function_inputs_and_outputs; - BlackBoxFuncCall::Blake2s { + Ok(BlackBoxFuncCall::Blake2s { inputs: function_inputs, outputs: outputs.try_into().expect("Blake2s returns 32 outputs"), - } + }) } // N inputs // 32 outputs fn blake3_op( function_inputs_and_outputs: (Vec>, Vec), -) -> BlackBoxFuncCall { +) -> Result, OpcodeResolutionError> { let (function_inputs, outputs) = function_inputs_and_outputs; - BlackBoxFuncCall::Blake3 { + Ok(BlackBoxFuncCall::Blake3 { inputs: function_inputs, outputs: outputs.try_into().expect("Blake3 returns 32 outputs"), - } + }) } // variable inputs // 32 outputs fn keccak256_op( function_inputs_and_outputs: (Vec>, Vec), -) -> BlackBoxFuncCall { +) -> Result, OpcodeResolutionError> { let (function_inputs, outputs) = function_inputs_and_outputs; let function_inputs_len = function_inputs.len(); - BlackBoxFuncCall::Keccak256 { + Ok(BlackBoxFuncCall::Keccak256 { inputs: function_inputs, var_message_size: FunctionInput::constant( function_inputs_len.into(), FieldElement::max_num_bits(), - ), + )?, outputs: outputs.try_into().expect("Keccak256 returns 32 outputs"), - } + }) } // var_message_size is the number of bytes to take @@ -1131,65 +1137,65 @@ fn keccak256_op( // 32 outputs fn keccak256_invalid_message_size_op( function_inputs_and_outputs: (Vec>, Vec), -) -> BlackBoxFuncCall { +) -> Result, OpcodeResolutionError> { let (function_inputs, outputs) = function_inputs_and_outputs; let function_inputs_len = function_inputs.len(); - BlackBoxFuncCall::Keccak256 { + Ok(BlackBoxFuncCall::Keccak256 { inputs: function_inputs, var_message_size: FunctionInput::constant( (function_inputs_len - 1).into(), FieldElement::max_num_bits(), - ), + )?, outputs: outputs.try_into().expect("Keccak256 returns 32 outputs"), - } + }) } // 25 inputs // 25 outputs fn keccakf1600_op( function_inputs_and_outputs: (Vec>, Vec), -) -> BlackBoxFuncCall { +) -> Result, OpcodeResolutionError> { let (function_inputs, outputs) = function_inputs_and_outputs; - BlackBoxFuncCall::Keccakf1600 { + Ok(BlackBoxFuncCall::Keccakf1600 { inputs: function_inputs.try_into().expect("Keccakf1600 expects 25 inputs"), outputs: outputs.try_into().expect("Keccakf1600 returns 25 outputs"), - } + }) } // N inputs // N outputs fn poseidon2_permutation_op( function_inputs_and_outputs: (Vec>, Vec), -) -> BlackBoxFuncCall { +) -> Result, OpcodeResolutionError> { let (inputs, outputs) = function_inputs_and_outputs; let len = inputs.len() as u32; - BlackBoxFuncCall::Poseidon2Permutation { inputs, outputs, len } + Ok(BlackBoxFuncCall::Poseidon2Permutation { inputs, outputs, len }) } // N inputs // N outputs fn poseidon2_permutation_invalid_len_op( function_inputs_and_outputs: (Vec>, Vec), -) -> BlackBoxFuncCall { +) -> Result, OpcodeResolutionError> { let (inputs, outputs) = function_inputs_and_outputs; let len = (inputs.len() as u32) + 1; - BlackBoxFuncCall::Poseidon2Permutation { inputs, outputs, len } + Ok(BlackBoxFuncCall::Poseidon2Permutation { inputs, outputs, len }) } // 24 inputs (16 + 8) // 8 outputs fn sha256_compression_op( function_inputs_and_outputs: (Vec>, Vec), -) -> BlackBoxFuncCall { +) -> Result, OpcodeResolutionError> { let (function_inputs, outputs) = function_inputs_and_outputs; let mut function_inputs = function_inputs.into_iter(); let inputs = core::array::from_fn(|_| function_inputs.next().unwrap()); let hash_values = core::array::from_fn(|_| function_inputs.next().unwrap()); - BlackBoxFuncCall::Sha256Compression { + Ok(BlackBoxFuncCall::Sha256Compression { inputs: Box::new(inputs), hash_values: Box::new(hash_values), outputs: outputs.try_into().unwrap(), - } + }) } fn into_repr_vec(fields: T) -> Vec @@ -1209,13 +1215,13 @@ where fn run_both_poseidon2_permutations( inputs: Vec, -) -> (Vec, Vec) { +) -> Result<(Vec, Vec), OpcodeResolutionError> { let result = solve_array_input_blackbox_call( inputs.clone(), inputs.len(), None, poseidon2_permutation_op, - ); + )?; let poseidon2_t = POSEIDON2_CONFIG.t as usize; let poseidon2_d = 5; @@ -1238,7 +1244,7 @@ fn run_both_poseidon2_permutations( let expected_result = external_poseidon2.permutation(&into_repr_vec(drop_use_constant(&inputs))); - (into_repr_vec(result), expected_result) + Ok((into_repr_vec(result), expected_result)) } // Using the given BigInt modulus, solve the following circuit: @@ -1254,7 +1260,7 @@ fn bigint_solve_binary_op( lhs: Vec, rhs: Vec, ) -> Vec { - bigint_solve_binary_op_opt(Some(middle_op), modulus, lhs, rhs) + bigint_solve_binary_op_opt(Some(middle_op), modulus, lhs, rhs).unwrap() } // Using the given BigInt modulus, solve the following circuit: @@ -1265,69 +1271,89 @@ fn bigint_solve_from_to_le_bytes( modulus: Vec, inputs: Vec, ) -> Vec { - bigint_solve_binary_op_opt(None, modulus, inputs, vec![]) + bigint_solve_binary_op_opt(None, modulus, inputs, vec![]).unwrap() } fn function_input_from_option( witness: Witness, opt_constant: Option, -) -> FunctionInput { +) -> Result, OpcodeResolutionError> { opt_constant - .map(|constant| FunctionInput::constant(constant, FieldElement::max_num_bits())) - .unwrap_or(FunctionInput::witness(witness, FieldElement::max_num_bits())) + .map(|constant| { + FunctionInput::constant(constant, FieldElement::max_num_bits()).map_err(From::from) + }) + .unwrap_or(Ok(FunctionInput::witness(witness, FieldElement::max_num_bits()))) } -fn and_op(x: Option, y: Option) -> BlackBoxFuncCall { - let lhs = function_input_from_option(Witness(1), x); - let rhs = function_input_from_option(Witness(2), y); - BlackBoxFuncCall::AND { lhs, rhs, output: Witness(3) } +fn and_op( + x: Option, + y: Option, +) -> Result, OpcodeResolutionError> { + let lhs = function_input_from_option(Witness(1), x)?; + let rhs = function_input_from_option(Witness(2), y)?; + Ok(BlackBoxFuncCall::AND { lhs, rhs, output: Witness(3) }) } -fn xor_op(x: Option, y: Option) -> BlackBoxFuncCall { - let lhs = function_input_from_option(Witness(1), x); - let rhs = function_input_from_option(Witness(2), y); - BlackBoxFuncCall::XOR { lhs, rhs, output: Witness(3) } +fn xor_op( + x: Option, + y: Option, +) -> Result, OpcodeResolutionError> { + let lhs = function_input_from_option(Witness(1), x)?; + let rhs = function_input_from_option(Witness(2), y)?; + Ok(BlackBoxFuncCall::XOR { lhs, rhs, output: Witness(3) }) } fn prop_assert_commutative( - op: impl Fn(Option, Option) -> BlackBoxFuncCall, + op: impl Fn( + Option, + Option, + ) -> Result, OpcodeResolutionError>, x: (FieldElement, bool), y: (FieldElement, bool), ) -> (FieldElement, FieldElement) { - (solve_blackbox_func_call(&op, x, y), solve_blackbox_func_call(&op, y, x)) + (solve_blackbox_func_call(&op, x, y).unwrap(), solve_blackbox_func_call(&op, y, x).unwrap()) } fn prop_assert_associative( - op: impl Fn(Option, Option) -> BlackBoxFuncCall, + op: impl Fn( + Option, + Option, + ) -> Result, OpcodeResolutionError>, x: (FieldElement, bool), y: (FieldElement, bool), z: (FieldElement, bool), use_constant_xy: bool, use_constant_yz: bool, ) -> (FieldElement, FieldElement) { - let f_xy = (solve_blackbox_func_call(&op, x, y), use_constant_xy); - let f_f_xy_z = solve_blackbox_func_call(&op, f_xy, z); + let f_xy = (solve_blackbox_func_call(&op, x, y).unwrap(), use_constant_xy); + let f_f_xy_z = solve_blackbox_func_call(&op, f_xy, z).unwrap(); - let f_yz = (solve_blackbox_func_call(&op, y, z), use_constant_yz); - let f_x_f_yz = solve_blackbox_func_call(&op, x, f_yz); + let f_yz = (solve_blackbox_func_call(&op, y, z).unwrap(), use_constant_yz); + let f_x_f_yz = solve_blackbox_func_call(&op, x, f_yz).unwrap(); (f_f_xy_z, f_x_f_yz) } fn prop_assert_identity_l( - op: impl Fn(Option, Option) -> BlackBoxFuncCall, + op: impl Fn( + Option, + Option, + ) -> Result, OpcodeResolutionError>, op_identity: (FieldElement, bool), x: (FieldElement, bool), ) -> (FieldElement, FieldElement) { - (solve_blackbox_func_call(op, op_identity, x), x.0) + (solve_blackbox_func_call(op, op_identity, x).unwrap(), x.0) } fn prop_assert_zero_l( - op: impl Fn(Option, Option) -> BlackBoxFuncCall, + op: impl Fn( + Option, + Option, + ) -> Result, OpcodeResolutionError>, op_zero: (FieldElement, bool), x: (FieldElement, bool), ) -> (FieldElement, FieldElement) { - (solve_blackbox_func_call(op, op_zero, x), FieldElement::zero()) + (solve_blackbox_func_call(op, op_zero, x).unwrap(), FieldElement::zero()) } // Test that varying one of the inputs produces a different result @@ -1341,14 +1367,19 @@ fn prop_assert_injective( op: F, ) -> (bool, String) where - F: FnOnce((Vec>, Vec)) -> BlackBoxFuncCall + F: FnOnce( + (Vec>, Vec), + ) + -> Result, OpcodeResolutionError> + Clone, { let equal_inputs = drop_use_constant_eq(&inputs, &distinct_inputs); let message = format!("not injective:\n{:?}\n{:?}", &inputs, &distinct_inputs); let outputs_not_equal = solve_array_input_blackbox_call(inputs, num_outputs, num_bits, op.clone()) - != solve_array_input_blackbox_call(distinct_inputs, num_outputs, num_bits, op); + .expect("injectivity test operations to have valid input") + != solve_array_input_blackbox_call(distinct_inputs, num_outputs, num_bits, op) + .expect("injectivity test operations to have valid input"); (equal_inputs || outputs_not_equal, message) } @@ -1381,12 +1412,12 @@ prop_compose! { -> (Vec, Vec) { let (_size, patch_location, patch_value) = size_and_patch; let (inputs, distinct_inputs) = inputs_distinct_inputs; + let modulus = if let Some(max_input_bits) = max_input_bits { + 1u128 << max_input_bits + } else { + 1 + }; let to_input = |(x, use_constant)| { - let modulus = if let Some(max_input_bits) = max_input_bits { - 2u128 << max_input_bits - } else { - 1 - }; (FieldElement::from(x % modulus), use_constant) }; let inputs: Vec<_> = inputs.into_iter().map(to_input).collect(); @@ -1397,9 +1428,11 @@ prop_compose! { let distinct_inputs_len = distinct_inputs.len(); let positive_patch_value = std::cmp::max(patch_value, 1); if distinct_inputs_len != 0 { - distinct_inputs[patch_location % distinct_inputs_len].0 += FieldElement::from(positive_patch_value) + let previous_input = &mut distinct_inputs[patch_location % distinct_inputs_len].0; + let patched_input: BigUint = (*previous_input + FieldElement::from(positive_patch_value)).into_repr().into(); + *previous_input = FieldElement::from_be_bytes_reduce(&(patched_input % BigUint::from(modulus)).to_bytes_be()); } else { - distinct_inputs.push((FieldElement::zero(), true)) + distinct_inputs.push((FieldElement::zero(), true)); } } @@ -1411,17 +1444,17 @@ prop_compose! { fn poseidon2_permutation_zeroes() { let use_constants: [bool; 4] = [false; 4]; let inputs: Vec<_> = [FieldElement::zero(); 4].into_iter().zip(use_constants).collect(); - let (result, expected_result) = run_both_poseidon2_permutations(inputs); + let (results, expected_results) = run_both_poseidon2_permutations(inputs).unwrap(); - let internal_expected_result = vec![ + let internal_expected_results = vec![ field_from_hex("18DFB8DC9B82229CFF974EFEFC8DF78B1CE96D9D844236B496785C698BC6732E"), field_from_hex("095C230D1D37A246E8D2D5A63B165FE0FADE040D442F61E25F0590E5FB76F839"), field_from_hex("0BB9545846E1AFA4FA3C97414A60A20FC4949F537A68CCECA34C5CE71E28AA59"), field_from_hex("18A4F34C9C6F99335FF7638B82AEED9018026618358873C982BBDDE265B2ED6D"), ]; - assert_eq!(expected_result, into_repr_vec(internal_expected_result)); - assert_eq!(result, expected_result); + assert_eq!(expected_results, into_repr_vec(internal_expected_results)); + assert_eq!(results, expected_results); } #[test] @@ -1434,7 +1467,7 @@ fn sha256_zeros() { .into_iter() .map(|x: u128| FieldElement::from(x)) .collect(); - assert_eq!(results, expected_results); + assert_eq!(results, Ok(expected_results)); } #[test] @@ -1452,7 +1485,7 @@ fn sha256_compression_zeros() { .into_iter() .map(|x: u128| FieldElement::from(x)) .collect(); - assert_eq!(results, expected_results); + assert_eq!(results, Ok(expected_results)); } #[test] @@ -1465,7 +1498,7 @@ fn blake2s_zeros() { .into_iter() .map(|x: u128| FieldElement::from(x)) .collect(); - assert_eq!(results, expected_results); + assert_eq!(results, Ok(expected_results)); } #[test] @@ -1478,7 +1511,7 @@ fn blake3_zeros() { .into_iter() .map(|x: u128| FieldElement::from(x)) .collect(); - assert_eq!(results, expected_results); + assert_eq!(results, Ok(expected_results)); } #[test] @@ -1491,7 +1524,7 @@ fn keccak256_zeros() { .into_iter() .map(|x: u128| FieldElement::from(x)) .collect(); - assert_eq!(results, expected_results); + assert_eq!(results, Ok(expected_results)); } #[test] @@ -1533,7 +1566,7 @@ fn keccakf1600_zeros() { .map(|x: u128| FieldElement::from(x)) .collect(); - assert_eq!(results, expected_results); + assert_eq!(results, Ok(expected_results)); } // NOTE: an "average" bigint is large, so consider increasing the number of proptest shrinking @@ -1570,13 +1603,13 @@ proptest! { // test that AND(x, x) == x #[test] fn and_self_identity(x in field_element()) { - prop_assert_eq!(solve_blackbox_func_call(and_op, x, x), x.0); + prop_assert_eq!(solve_blackbox_func_call(and_op, x, x).unwrap(), x.0); } // test that XOR(x, x) == 0 #[test] fn xor_self_zero(x in field_element()) { - prop_assert_eq!(solve_blackbox_func_call(xor_op, x, x), FieldElement::zero()); + prop_assert_eq!(solve_blackbox_func_call(xor_op, x, x).unwrap(), FieldElement::zero()); } #[test] @@ -1606,7 +1639,7 @@ proptest! { #[test] fn poseidon2_permutation_matches_external_impl(inputs in proptest::collection::vec(field_element(), 4)) { - let (result, expected_result) = run_both_poseidon2_permutations(inputs); + let (result, expected_result) = run_both_poseidon2_permutations(inputs).unwrap(); prop_assert_eq!(result, expected_result) } diff --git a/noir/noir-repo/acvm-repo/acvm_js/build.sh b/noir/noir-repo/acvm-repo/acvm_js/build.sh index c07d2d8a4c1..16fb26e55db 100755 --- a/noir/noir-repo/acvm-repo/acvm_js/build.sh +++ b/noir/noir-repo/acvm-repo/acvm_js/build.sh @@ -25,7 +25,7 @@ function run_if_available { require_command jq require_command cargo require_command wasm-bindgen -#require_command wasm-opt +require_command wasm-opt self_path=$(dirname "$(readlink -f "$0")") pname=$(cargo read-manifest | jq -r '.name') diff --git a/noir/noir-repo/acvm-repo/acvm_js/src/execute.rs b/noir/noir-repo/acvm-repo/acvm_js/src/execute.rs index 98a0c4c3abe..c3627d0eff5 100644 --- a/noir/noir-repo/acvm-repo/acvm_js/src/execute.rs +++ b/noir/noir-repo/acvm-repo/acvm_js/src/execute.rs @@ -201,6 +201,10 @@ impl<'a, B: BlackBoxFunctionSolver> ProgramExecutor<'a, B> { opcode_location: ErrorLocation::Resolved(opcode_location), .. } => Some(vec![*opcode_location]), + OpcodeResolutionError::InvalidInputBitSize { + opcode_location: ErrorLocation::Resolved(opcode_location), + .. + } => Some(vec![*opcode_location]), OpcodeResolutionError::BrilligFunctionFailed { call_stack, .. } => { Some(call_stack.clone()) } diff --git a/noir/noir-repo/acvm-repo/acvm_js/test/shared/multi_scalar_mul.ts b/noir/noir-repo/acvm-repo/acvm_js/test/shared/multi_scalar_mul.ts index 80fbf14e8f1..ffb9952b136 100644 --- a/noir/noir-repo/acvm-repo/acvm_js/test/shared/multi_scalar_mul.ts +++ b/noir/noir-repo/acvm-repo/acvm_js/test/shared/multi_scalar_mul.ts @@ -1,8 +1,8 @@ // See `multi_scalar_mul_circuit` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 141, 11, 10, 0, 32, 8, 67, 43, 181, 15, 116, 232, 142, 158, 210, 130, 149, 240, - 112, 234, 212, 156, 78, 12, 39, 67, 71, 158, 142, 80, 29, 44, 228, 66, 90, 168, 119, 189, 74, 115, 131, 174, 78, 115, - 58, 124, 70, 254, 130, 59, 74, 253, 68, 255, 255, 221, 39, 54, 221, 93, 91, 132, 193, 0, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 141, 11, 10, 0, 32, 8, 67, 43, 181, 15, 116, 255, 227, 70, 74, 11, 86, 194, + 195, 169, 83, 115, 58, 49, 156, 12, 29, 121, 58, 66, 117, 176, 144, 11, 105, 161, 222, 245, 42, 205, 13, 186, 58, 205, + 233, 240, 25, 249, 11, 238, 40, 245, 19, 253, 255, 119, 159, 216, 103, 157, 249, 169, 193, 0, 0, 0, ]); export const initialWitnessMap = new Map([ [1, '0x0000000000000000000000000000000000000000000000000000000000000001'], diff --git a/noir/noir-repo/aztec_macros/src/transforms/events.rs b/noir/noir-repo/aztec_macros/src/transforms/events.rs index d753bb43471..878bc37393a 100644 --- a/noir/noir-repo/aztec_macros/src/transforms/events.rs +++ b/noir/noir-repo/aztec_macros/src/transforms/events.rs @@ -1,4 +1,7 @@ -use noirc_frontend::ast::{Documented, ItemVisibility, NoirFunction, NoirTraitImpl, TraitImplItem}; +use noirc_errors::Span; +use noirc_frontend::ast::{ + Documented, ItemVisibility, NoirFunction, NoirTraitImpl, TraitImplItem, TraitImplItemKind, +}; use noirc_frontend::macros_api::{NodeInterner, StructId}; use noirc_frontend::token::SecondaryAttribute; use noirc_frontend::{ @@ -67,30 +70,37 @@ pub fn generate_event_impls( event_byte_len, empty_spans, )?; - event_interface_trait_impl.items.push(Documented::not_documented( - TraitImplItem::Function(generate_fn_get_event_type_id( + event_interface_trait_impl.items.push(Documented::not_documented(TraitImplItem { + kind: TraitImplItemKind::Function(generate_fn_get_event_type_id( event_type.as_str(), event_len, empty_spans, )?), - )); - event_interface_trait_impl.items.push(Documented::not_documented( - TraitImplItem::Function(generate_fn_private_to_be_bytes( + span: Span::default(), + })); + event_interface_trait_impl.items.push(Documented::not_documented(TraitImplItem { + kind: TraitImplItemKind::Function(generate_fn_private_to_be_bytes( event_type.as_str(), event_byte_len, empty_spans, )?), - )); - event_interface_trait_impl.items.push(Documented::not_documented( - TraitImplItem::Function(generate_fn_to_be_bytes( + span: Span::default(), + })); + event_interface_trait_impl.items.push(Documented::not_documented(TraitImplItem { + kind: TraitImplItemKind::Function(generate_fn_to_be_bytes( event_type.as_str(), event_byte_len, empty_spans, )?), - )); - event_interface_trait_impl.items.push(Documented::not_documented( - TraitImplItem::Function(generate_fn_emit(event_type.as_str(), empty_spans)?), - )); + span: Span::default(), + })); + event_interface_trait_impl.items.push(Documented::not_documented(TraitImplItem { + kind: TraitImplItemKind::Function(generate_fn_emit( + event_type.as_str(), + empty_spans, + )?), + span: Span::default(), + })); submodule.contents.trait_impls.push(event_interface_trait_impl); let serialize_trait_impl = generate_trait_impl_serialize( diff --git a/noir/noir-repo/aztec_macros/src/transforms/note_interface.rs b/noir/noir-repo/aztec_macros/src/transforms/note_interface.rs index 6e95efa637c..d9c4a594fc6 100644 --- a/noir/noir-repo/aztec_macros/src/transforms/note_interface.rs +++ b/noir/noir-repo/aztec_macros/src/transforms/note_interface.rs @@ -1,7 +1,7 @@ use noirc_errors::Span; use noirc_frontend::ast::{ Documented, ItemVisibility, LetStatement, NoirFunction, NoirStruct, PathKind, StructField, - TraitImplItem, TypeImpl, UnresolvedTypeData, UnresolvedTypeExpression, + TraitImplItem, TraitImplItemKind, TypeImpl, UnresolvedTypeData, UnresolvedTypeExpression, }; use noirc_frontend::{ graph::CrateId, @@ -153,9 +153,10 @@ pub fn generate_note_interface_impl( note_interface_impl_span, empty_spans, )?; - trait_impl.items.push(Documented::not_documented(TraitImplItem::Function( - note_serialize_content_fn, - ))); + trait_impl.items.push(Documented::not_documented(TraitImplItem { + kind: TraitImplItemKind::Function(note_serialize_content_fn), + span: note_interface_impl_span, + })); let note_deserialize_content_fn = generate_note_deserialize_content( ¬e_type, @@ -165,9 +166,10 @@ pub fn generate_note_interface_impl( note_interface_impl_span, empty_spans, )?; - trait_impl.items.push(Documented::not_documented(TraitImplItem::Function( - note_deserialize_content_fn, - ))); + trait_impl.items.push(Documented::not_documented(TraitImplItem { + kind: TraitImplItemKind::Function(note_deserialize_content_fn), + span: note_interface_impl_span, + })); let note_properties_struct = generate_note_properties_struct( ¬e_type, @@ -196,9 +198,10 @@ pub fn generate_note_interface_impl( note_interface_impl_span, empty_spans, )?; - trait_impl - .items - .push(Documented::not_documented(TraitImplItem::Function(get_header_fn))); + trait_impl.items.push(Documented::not_documented(TraitImplItem { + kind: TraitImplItemKind::Function(get_header_fn), + span: note_interface_impl_span, + })); } if !check_trait_method_implemented(trait_impl, "set_header") { let set_header_fn = generate_note_set_header( @@ -207,18 +210,20 @@ pub fn generate_note_interface_impl( note_interface_impl_span, empty_spans, )?; - trait_impl - .items - .push(Documented::not_documented(TraitImplItem::Function(set_header_fn))); + trait_impl.items.push(Documented::not_documented(TraitImplItem { + kind: TraitImplItemKind::Function(set_header_fn), + span: note_interface_impl_span, + })); } if !check_trait_method_implemented(trait_impl, "get_note_type_id") { let note_type_id = compute_note_type_id(¬e_type); let get_note_type_id_fn = generate_get_note_type_id(note_type_id, note_interface_impl_span, empty_spans)?; - trait_impl - .items - .push(Documented::not_documented(TraitImplItem::Function(get_note_type_id_fn))); + trait_impl.items.push(Documented::not_documented(TraitImplItem { + kind: TraitImplItemKind::Function(get_note_type_id_fn), + span: note_interface_impl_span, + })); } if !check_trait_method_implemented(trait_impl, "compute_note_hiding_point") { @@ -227,9 +232,10 @@ pub fn generate_note_interface_impl( note_interface_impl_span, empty_spans, )?; - trait_impl.items.push(Documented::not_documented(TraitImplItem::Function( - compute_note_hiding_point_fn, - ))); + trait_impl.items.push(Documented::not_documented(TraitImplItem { + kind: TraitImplItemKind::Function(compute_note_hiding_point_fn), + span: note_interface_impl_span, + })); } if !check_trait_method_implemented(trait_impl, "to_be_bytes") { @@ -240,9 +246,10 @@ pub fn generate_note_interface_impl( note_interface_impl_span, empty_spans, )?; - trait_impl - .items - .push(Documented::not_documented(TraitImplItem::Function(to_be_bytes_fn))); + trait_impl.items.push(Documented::not_documented(TraitImplItem { + kind: TraitImplItemKind::Function(to_be_bytes_fn), + span: note_interface_impl_span, + })); } } diff --git a/noir/noir-repo/aztec_macros/src/utils/ast_utils.rs b/noir/noir-repo/aztec_macros/src/utils/ast_utils.rs index b68946ec020..eeb8e1f7d78 100644 --- a/noir/noir-repo/aztec_macros/src/utils/ast_utils.rs +++ b/noir/noir-repo/aztec_macros/src/utils/ast_utils.rs @@ -3,7 +3,7 @@ use noirc_frontend::ast::{ BinaryOpKind, CallExpression, CastExpression, Expression, ExpressionKind, FunctionReturnType, Ident, IndexExpression, InfixExpression, Lambda, MemberAccessExpression, MethodCallExpression, NoirTraitImpl, Path, PathSegment, Pattern, PrefixExpression, Statement, StatementKind, - TraitImplItem, UnaryOp, UnresolvedType, UnresolvedTypeData, + TraitImplItemKind, UnaryOp, UnresolvedType, UnresolvedTypeData, }; use noirc_frontend::token::SecondaryAttribute; @@ -179,8 +179,8 @@ pub fn index_array(array: Ident, index: &str) -> Expression { } pub fn check_trait_method_implemented(trait_impl: &NoirTraitImpl, method_name: &str) -> bool { - trait_impl.items.iter().any(|item| match &item.item { - TraitImplItem::Function(func) => func.def.name.0.contents == method_name, + trait_impl.items.iter().any(|item| match &item.item.kind { + TraitImplItemKind::Function(func) => func.def.name.0.contents == method_name, _ => false, }) } diff --git a/noir/noir-repo/aztec_macros/src/utils/errors.rs b/noir/noir-repo/aztec_macros/src/utils/errors.rs index 557d065cb25..c0b4310de96 100644 --- a/noir/noir-repo/aztec_macros/src/utils/errors.rs +++ b/noir/noir-repo/aztec_macros/src/utils/errors.rs @@ -29,7 +29,7 @@ impl From for MacroError { fn from(err: AztecMacroError) -> Self { match err { AztecMacroError::AztecDepNotFound {} => MacroError { - primary_message: "Aztec dependency not found. Please add aztec as a dependency in your Nargo.toml. For more information go to https://docs.aztec.network/developers/debugging/aztecnr-errors#aztec-dependency-not-found-please-add-aztec-as-a-dependency-in-your-nargotoml".to_owned(), + primary_message: "Aztec dependency not found. Please add aztec as a dependency in your Nargo.toml. For more information go to https://docs.aztec.network/reference/developer_references/common_errors/aztecnr-errors#aztec-dependency-not-found-please-add-aztec-as-a-dependency-in-your-nargotoml".to_owned(), secondary_message: None, span: None, }, diff --git a/noir/noir-repo/aztec_macros/src/utils/parse_utils.rs b/noir/noir-repo/aztec_macros/src/utils/parse_utils.rs index dce3af1402b..712afbc248b 100644 --- a/noir/noir-repo/aztec_macros/src/utils/parse_utils.rs +++ b/noir/noir-repo/aztec_macros/src/utils/parse_utils.rs @@ -6,9 +6,9 @@ use noirc_frontend::{ InfixExpression, LValue, Lambda, LetStatement, Literal, MemberAccessExpression, MethodCallExpression, ModuleDeclaration, NoirFunction, NoirStruct, NoirTrait, NoirTraitImpl, NoirTypeAlias, Path, PathSegment, Pattern, PrefixExpression, Statement, - StatementKind, TraitImplItem, TraitItem, TypeImpl, UnresolvedGeneric, UnresolvedGenerics, - UnresolvedTraitConstraint, UnresolvedType, UnresolvedTypeData, UnresolvedTypeExpression, - UseTree, UseTreeKind, + StatementKind, TraitImplItem, TraitImplItemKind, TraitItem, TypeImpl, UnresolvedGeneric, + UnresolvedGenerics, UnresolvedTraitConstraint, UnresolvedType, UnresolvedTypeData, + UnresolvedTypeExpression, UseTree, UseTreeKind, }, parser::{Item, ItemKind, ParsedSubModule, ParserError}, ParsedModule, @@ -137,14 +137,20 @@ fn empty_trait_item(trait_item: &mut TraitItem) { } fn empty_trait_impl_item(trait_impl_item: &mut TraitImplItem) { + trait_impl_item.span = Default::default(); + + empty_trait_impl_item_kind(&mut trait_impl_item.kind); +} + +fn empty_trait_impl_item_kind(trait_impl_item: &mut TraitImplItemKind) { match trait_impl_item { - TraitImplItem::Function(noir_function) => empty_noir_function(noir_function), - TraitImplItem::Constant(name, typ, default_value) => { + TraitImplItemKind::Function(noir_function) => empty_noir_function(noir_function), + TraitImplItemKind::Constant(name, typ, default_value) => { empty_ident(name); empty_unresolved_type(typ); empty_expression(default_value); } - TraitImplItem::Type { name, alias } => { + TraitImplItemKind::Type { name, alias } => { empty_ident(name); empty_unresolved_type(alias); } diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_slice_ops.rs b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_slice_ops.rs index 36a3b34aeb0..85db1bd8b96 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_slice_ops.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_slice_ops.rs @@ -1,3 +1,5 @@ +use acvm::acir::brillig::MemoryAddress; + use crate::brillig::brillig_ir::{ brillig_variable::{BrilligVariable, BrilligVector, SingleAddrVariable}, BrilligBinaryOp, @@ -6,57 +8,37 @@ use crate::brillig::brillig_ir::{ use super::brillig_block::BrilligBlock; impl<'block> BrilligBlock<'block> { + fn write_variables(&mut self, write_pointer: MemoryAddress, variables: &[BrilligVariable]) { + for (index, variable) in variables.iter().enumerate() { + self.brillig_context.store_instruction(write_pointer, variable.extract_register()); + if index != variables.len() - 1 { + self.brillig_context.codegen_usize_op_in_place( + write_pointer, + BrilligBinaryOp::Add, + 1, + ); + } + } + } + pub(crate) fn slice_push_back_operation( &mut self, target_vector: BrilligVector, source_vector: BrilligVector, variables_to_insert: &[BrilligVariable], ) { - // First we need to allocate the target vector incrementing the size by variables_to_insert.len() - let source_size = self.brillig_context.codegen_make_vector_length(source_vector); - - let target_size = SingleAddrVariable::new_usize(self.brillig_context.allocate_register()); - self.brillig_context.codegen_usize_op( - source_size.address, - target_size.address, - BrilligBinaryOp::Add, + let write_pointer = self.brillig_context.allocate_register(); + self.brillig_context.call_prepare_vector_push_procedure( + source_vector, + target_vector, + write_pointer, variables_to_insert.len(), + true, ); - self.brillig_context.codegen_initialize_vector(target_vector, target_size); + self.write_variables(write_pointer, variables_to_insert); - // Now we copy the source vector into the target vector - let source_vector_items_pointer = - self.brillig_context.codegen_make_vector_items_pointer(source_vector); - let target_vector_items_pointer = - self.brillig_context.codegen_make_vector_items_pointer(target_vector); - - self.brillig_context.codegen_mem_copy( - source_vector_items_pointer, - target_vector_items_pointer, - source_size, - ); - - for (index, variable) in variables_to_insert.iter().enumerate() { - let target_index = self.brillig_context.make_usize_constant_instruction(index.into()); - self.brillig_context.memory_op_instruction( - target_index.address, - source_size.address, - target_index.address, - BrilligBinaryOp::Add, - ); - self.brillig_context.codegen_store_with_offset( - target_vector_items_pointer, - target_index, - variable.extract_register(), - ); - self.brillig_context.deallocate_single_addr(target_index); - } - - self.brillig_context.deallocate_single_addr(source_size); - self.brillig_context.deallocate_single_addr(target_size); - self.brillig_context.deallocate_register(source_vector_items_pointer); - self.brillig_context.deallocate_register(target_vector_items_pointer); + self.brillig_context.deallocate_register(write_pointer); } pub(crate) fn slice_push_front_operation( @@ -65,56 +47,30 @@ impl<'block> BrilligBlock<'block> { source_vector: BrilligVector, variables_to_insert: &[BrilligVariable], ) { - // First we need to allocate the target vector incrementing the size by variables_to_insert.len() - let source_size = self.brillig_context.codegen_make_vector_length(source_vector); - - let target_size = SingleAddrVariable::new_usize(self.brillig_context.allocate_register()); - self.brillig_context.codegen_usize_op( - source_size.address, - target_size.address, - BrilligBinaryOp::Add, - variables_to_insert.len(), - ); - - self.brillig_context.codegen_initialize_vector(target_vector, target_size); - - // Now we offset the target pointer by variables_to_insert.len() - let source_vector_items_pointer = - self.brillig_context.codegen_make_vector_items_pointer(source_vector); - let target_vector_items_pointer = - self.brillig_context.codegen_make_vector_items_pointer(target_vector); - - let destination_copy_pointer = self.brillig_context.allocate_register(); - self.brillig_context.codegen_usize_op( - target_vector_items_pointer, - destination_copy_pointer, - BrilligBinaryOp::Add, + let write_pointer = self.brillig_context.allocate_register(); + self.brillig_context.call_prepare_vector_push_procedure( + source_vector, + target_vector, + write_pointer, variables_to_insert.len(), + false, ); - // Now we copy the source vector into the target vector starting at index variables_to_insert.len() - self.brillig_context.codegen_mem_copy( - source_vector_items_pointer, - destination_copy_pointer, - source_size, - ); + self.write_variables(write_pointer, variables_to_insert); + self.brillig_context.deallocate_register(write_pointer); + } - // Then we write the items to insert at the start - for (index, variable) in variables_to_insert.iter().enumerate() { - let target_index = self.brillig_context.make_usize_constant_instruction(index.into()); - self.brillig_context.codegen_store_with_offset( - target_vector_items_pointer, - target_index, - variable.extract_register(), - ); - self.brillig_context.deallocate_single_addr(target_index); + fn read_variables(&mut self, read_pointer: MemoryAddress, variables: &[BrilligVariable]) { + for (index, variable) in variables.iter().enumerate() { + self.brillig_context.load_instruction(variable.extract_register(), read_pointer); + if index != variables.len() - 1 { + self.brillig_context.codegen_usize_op_in_place( + read_pointer, + BrilligBinaryOp::Add, + 1, + ); + } } - - self.brillig_context.deallocate_register(destination_copy_pointer); - self.brillig_context.deallocate_single_addr(source_size); - self.brillig_context.deallocate_single_addr(target_size); - self.brillig_context.deallocate_register(source_vector_items_pointer); - self.brillig_context.deallocate_register(target_vector_items_pointer); } pub(crate) fn slice_pop_front_operation( @@ -123,55 +79,17 @@ impl<'block> BrilligBlock<'block> { source_vector: BrilligVector, removed_items: &[BrilligVariable], ) { - // First we need to allocate the target vector decrementing the size by removed_items.len() - let source_size = self.brillig_context.codegen_make_vector_length(source_vector); - - let target_size = SingleAddrVariable::new_usize(self.brillig_context.allocate_register()); - self.brillig_context.codegen_usize_op( - source_size.address, - target_size.address, - BrilligBinaryOp::Sub, + let read_pointer = self.brillig_context.allocate_register(); + self.brillig_context.call_vector_pop_procedure( + source_vector, + target_vector, + read_pointer, removed_items.len(), + false, ); - self.brillig_context.codegen_initialize_vector(target_vector, target_size); - - // Now we offset the source pointer by removed_items.len() - let source_vector_items_pointer = - self.brillig_context.codegen_make_vector_items_pointer(source_vector); - let target_vector_items_pointer = - self.brillig_context.codegen_make_vector_items_pointer(target_vector); - - let source_copy_pointer = self.brillig_context.allocate_register(); - self.brillig_context.codegen_usize_op( - source_vector_items_pointer, - source_copy_pointer, - BrilligBinaryOp::Add, - removed_items.len(), - ); - - // Now we copy the source vector starting at index removed_items.len() into the target vector - self.brillig_context.codegen_mem_copy( - source_copy_pointer, - target_vector_items_pointer, - target_size, - ); - - for (index, variable) in removed_items.iter().enumerate() { - let target_index = self.brillig_context.make_usize_constant_instruction(index.into()); - self.brillig_context.codegen_load_with_offset( - source_vector_items_pointer, - target_index, - variable.extract_register(), - ); - self.brillig_context.deallocate_single_addr(target_index); - } - - self.brillig_context.deallocate_register(source_copy_pointer); - self.brillig_context.deallocate_single_addr(source_size); - self.brillig_context.deallocate_single_addr(target_size); - self.brillig_context.deallocate_register(source_vector_items_pointer); - self.brillig_context.deallocate_register(target_vector_items_pointer); + self.read_variables(read_pointer, removed_items); + self.brillig_context.deallocate_register(read_pointer); } pub(crate) fn slice_pop_back_operation( @@ -180,50 +98,17 @@ impl<'block> BrilligBlock<'block> { source_vector: BrilligVector, removed_items: &[BrilligVariable], ) { - // First we need to allocate the target vector decrementing the size by removed_items.len() - let source_size = self.brillig_context.codegen_make_vector_length(source_vector); - - let target_size = SingleAddrVariable::new_usize(self.brillig_context.allocate_register()); - self.brillig_context.codegen_usize_op( - source_size.address, - target_size.address, - BrilligBinaryOp::Sub, + let read_pointer = self.brillig_context.allocate_register(); + self.brillig_context.call_vector_pop_procedure( + source_vector, + target_vector, + read_pointer, removed_items.len(), + true, ); - self.brillig_context.codegen_initialize_vector(target_vector, target_size); - - // Now we copy all elements except the last items into the target vector - let source_vector_items_pointer = - self.brillig_context.codegen_make_vector_items_pointer(source_vector); - let target_vector_items_pointer = - self.brillig_context.codegen_make_vector_items_pointer(target_vector); - - self.brillig_context.codegen_mem_copy( - source_vector_items_pointer, - target_vector_items_pointer, - target_size, - ); - - for (index, variable) in removed_items.iter().enumerate() { - let target_index = self.brillig_context.make_usize_constant_instruction(index.into()); - self.brillig_context.memory_op_instruction( - target_index.address, - target_size.address, - target_index.address, - BrilligBinaryOp::Add, - ); - self.brillig_context.codegen_load_with_offset( - source_vector_items_pointer, - target_index, - variable.extract_register(), - ); - self.brillig_context.deallocate_single_addr(target_index); - } - self.brillig_context.deallocate_single_addr(source_size); - self.brillig_context.deallocate_single_addr(target_size); - self.brillig_context.deallocate_register(source_vector_items_pointer); - self.brillig_context.deallocate_register(target_vector_items_pointer); + self.read_variables(read_pointer, removed_items); + self.brillig_context.deallocate_register(read_pointer); } pub(crate) fn slice_insert_operation( @@ -233,95 +118,18 @@ impl<'block> BrilligBlock<'block> { index: SingleAddrVariable, items: &[BrilligVariable], ) { - // First we need to allocate the target vector incrementing the size by items.len() - let source_size = self.brillig_context.codegen_make_vector_length(source_vector); - - let target_size = SingleAddrVariable::new_usize(self.brillig_context.allocate_register()); - self.brillig_context.codegen_usize_op( - source_size.address, - target_size.address, - BrilligBinaryOp::Add, - items.len(), - ); - - self.brillig_context.codegen_initialize_vector(target_vector, target_size); - - // Copy the elements to the left of the index - let source_vector_items_pointer = - self.brillig_context.codegen_make_vector_items_pointer(source_vector); - let target_vector_items_pointer = - self.brillig_context.codegen_make_vector_items_pointer(target_vector); + let write_pointer = self.brillig_context.allocate_register(); - self.brillig_context.codegen_mem_copy( - source_vector_items_pointer, - target_vector_items_pointer, + self.brillig_context.call_prepare_vector_insert_procedure( + source_vector, + target_vector, index, - ); - - // Compute the source pointer just at the index - let source_pointer_at_index = self.brillig_context.allocate_register(); - self.brillig_context.memory_op_instruction( - source_vector_items_pointer, - index.address, - source_pointer_at_index, - BrilligBinaryOp::Add, - ); - - // Compute the target pointer after the inserted elements - let target_pointer_after_index = self.brillig_context.allocate_register(); - self.brillig_context.memory_op_instruction( - target_vector_items_pointer, - index.address, - target_pointer_after_index, - BrilligBinaryOp::Add, - ); - self.brillig_context.codegen_usize_op_in_place( - target_pointer_after_index, - BrilligBinaryOp::Add, + write_pointer, items.len(), ); - // Compute the number of elements to the right of the index - let item_count = self.brillig_context.allocate_register(); - self.brillig_context.memory_op_instruction( - source_size.address, - index.address, - item_count, - BrilligBinaryOp::Sub, - ); - - // Copy the elements to the right of the index - self.brillig_context.codegen_mem_copy( - source_pointer_at_index, - target_pointer_after_index, - SingleAddrVariable::new_usize(item_count), - ); - - // Write the items to insert starting at the index - for (subitem_index, variable) in items.iter().enumerate() { - let target_index = - self.brillig_context.make_usize_constant_instruction(subitem_index.into()); - self.brillig_context.memory_op_instruction( - target_index.address, - index.address, - target_index.address, - BrilligBinaryOp::Add, - ); - self.brillig_context.codegen_store_with_offset( - target_vector_items_pointer, - target_index, - variable.extract_register(), - ); - self.brillig_context.deallocate_single_addr(target_index); - } - - self.brillig_context.deallocate_register(source_pointer_at_index); - self.brillig_context.deallocate_register(target_pointer_after_index); - self.brillig_context.deallocate_register(item_count); - self.brillig_context.deallocate_single_addr(source_size); - self.brillig_context.deallocate_single_addr(target_size); - self.brillig_context.deallocate_register(source_vector_items_pointer); - self.brillig_context.deallocate_register(target_vector_items_pointer); + self.write_variables(write_pointer, items); + self.brillig_context.deallocate_register(write_pointer); } pub(crate) fn slice_remove_operation( @@ -331,100 +139,21 @@ impl<'block> BrilligBlock<'block> { index: SingleAddrVariable, removed_items: &[BrilligVariable], ) { - // First we need to allocate the target vector decrementing the size by removed_items.len() - let source_size = self.brillig_context.codegen_make_vector_length(source_vector); - - let target_size = SingleAddrVariable::new_usize(self.brillig_context.allocate_register()); - self.brillig_context.codegen_usize_op( - source_size.address, - target_size.address, - BrilligBinaryOp::Sub, - removed_items.len(), - ); - - self.brillig_context.codegen_initialize_vector(target_vector, target_size); - - // Copy the elements to the left of the index - let source_vector_items_pointer = - self.brillig_context.codegen_make_vector_items_pointer(source_vector); - let target_vector_items_pointer = - self.brillig_context.codegen_make_vector_items_pointer(target_vector); - - self.brillig_context.codegen_mem_copy( - source_vector_items_pointer, - target_vector_items_pointer, - index, - ); - - // Compute the source pointer after the removed items - let source_pointer_after_index = self.brillig_context.allocate_register(); - self.brillig_context.memory_op_instruction( - source_vector_items_pointer, - index.address, - source_pointer_after_index, - BrilligBinaryOp::Add, - ); - self.brillig_context.codegen_usize_op_in_place( - source_pointer_after_index, - BrilligBinaryOp::Add, - removed_items.len(), - ); - - // Compute the target pointer at the index - let target_pointer_at_index = self.brillig_context.allocate_register(); + let read_pointer = self.brillig_context.codegen_make_vector_items_pointer(source_vector); self.brillig_context.memory_op_instruction( - target_vector_items_pointer, + read_pointer, index.address, - target_pointer_at_index, + read_pointer, BrilligBinaryOp::Add, ); + self.read_variables(read_pointer, removed_items); - // Compute the number of elements to the right of the index - let item_count = self.brillig_context.allocate_register(); - self.brillig_context.memory_op_instruction( - source_size.address, - index.address, - item_count, - BrilligBinaryOp::Sub, - ); - self.brillig_context.codegen_usize_op_in_place( - item_count, - BrilligBinaryOp::Sub, + self.brillig_context.call_vector_remove_procedure( + source_vector, + target_vector, + index, removed_items.len(), ); - - // Copy the elements to the right of the index - self.brillig_context.codegen_mem_copy( - source_pointer_after_index, - target_pointer_at_index, - SingleAddrVariable::new_usize(item_count), - ); - - // Get the removed items - for (subitem_index, variable) in removed_items.iter().enumerate() { - let target_index = - self.brillig_context.make_usize_constant_instruction(subitem_index.into()); - self.brillig_context.memory_op_instruction( - target_index.address, - index.address, - target_index.address, - BrilligBinaryOp::Add, - ); - self.brillig_context.codegen_load_with_offset( - source_vector_items_pointer, - target_index, - variable.extract_register(), - ); - self.brillig_context.deallocate_single_addr(target_index); - } - - self.brillig_context.deallocate_register(source_pointer_after_index); - self.brillig_context.deallocate_register(target_pointer_at_index); - self.brillig_context.deallocate_register(item_count); - self.brillig_context.deallocate_single_addr(source_size); - self.brillig_context.deallocate_single_addr(target_size); - self.brillig_context.deallocate_register(source_vector_items_pointer); - self.brillig_context.deallocate_register(target_vector_items_pointer); } } @@ -458,7 +187,6 @@ mod tests { let ssa = builder.finish(); let mut brillig_context = create_context(ssa.main_id); brillig_context.enter_context(Label::block(ssa.main_id, Id::test_new(0))); - brillig_context.disable_procedures(); let function_context = FunctionContext::new(ssa.main()); (ssa, function_context, brillig_context) diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir.rs b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir.rs index b52b239e6b9..d8065294b0c 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir.rs @@ -112,10 +112,6 @@ impl BrilligContext { can_call_procedures: true, } } - /// Allows disabling procedures so tests don't need a linking pass - pub(crate) fn disable_procedures(&mut self) { - self.can_call_procedures = false; - } } /// Special brillig context to codegen compiler intrinsic shared procedures @@ -165,7 +161,8 @@ pub(crate) mod tests { use crate::brillig::brillig_ir::{BrilligBinaryOp, BrilligContext}; use crate::ssa::ir::function::FunctionId; - use super::artifact::{BrilligParameter, GeneratedBrillig, Label}; + use super::artifact::{BrilligParameter, GeneratedBrillig, Label, LabelType}; + use super::procedures::compile_procedure; use super::registers::Stack; use super::{BrilligOpcode, ReservedRegisters}; @@ -237,13 +234,17 @@ pub(crate) mod tests { returns: Vec, ) -> GeneratedBrillig { let artifact = context.artifact(); - let mut entry_point_artifact = BrilligContext::new_entry_point_artifact( - arguments, - returns, - FunctionId::test_new(0), - true, - ); + let mut entry_point_artifact = + BrilligContext::new_entry_point_artifact(arguments, returns, FunctionId::test_new(0)); entry_point_artifact.link_with(&artifact); + while let Some(unresolved_fn_label) = entry_point_artifact.first_unresolved_function_call() + { + let LabelType::Procedure(procedure_id) = unresolved_fn_label.label_type else { + panic!("Test functions cannot be linked with other functions"); + }; + let procedure_artifact = compile_procedure(procedure_id); + entry_point_artifact.link_with(&procedure_artifact); + } entry_point_artifact.finish() } diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/entry_point.rs b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/entry_point.rs index bde128d0b6b..ff9b5ea67eb 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/entry_point.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/entry_point.rs @@ -18,12 +18,9 @@ impl BrilligContext { arguments: Vec, return_parameters: Vec, target_function: FunctionId, - disable_procedures: bool, ) -> BrilligArtifact { let mut context = BrilligContext::new(false); - if disable_procedures { - context.disable_procedures(); - } + context.codegen_entry_point(&arguments, &return_parameters); context.add_external_call_instruction(target_function); diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/mod.rs b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/mod.rs index d2a011f8aa5..32fe6725e56 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/mod.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/mod.rs @@ -1,12 +1,20 @@ mod array_copy; mod array_reverse; mod mem_copy; +mod prepare_vector_insert; +mod prepare_vector_push; mod vector_copy; +mod vector_pop; +mod vector_remove; use array_copy::compile_array_copy_procedure; use array_reverse::compile_array_reverse_procedure; use mem_copy::compile_mem_copy_procedure; +use prepare_vector_insert::compile_prepare_vector_insert_procedure; +use prepare_vector_push::compile_prepare_vector_push_procedure; use vector_copy::compile_vector_copy_procedure; +use vector_pop::compile_vector_pop_procedure; +use vector_remove::compile_vector_remove_procedure; use crate::brillig::brillig_ir::AcirField; @@ -25,6 +33,10 @@ pub(crate) enum ProcedureId { ArrayReverse, VectorCopy, MemCopy, + PrepareVectorPush(bool), + VectorPop(bool), + PrepareVectorInsert, + VectorRemove, } pub(crate) fn compile_procedure( @@ -38,6 +50,16 @@ pub(crate) fn compile_procedure( ProcedureId::ArrayCopy => compile_array_copy_procedure(&mut brillig_context), ProcedureId::ArrayReverse => compile_array_reverse_procedure(&mut brillig_context), ProcedureId::VectorCopy => compile_vector_copy_procedure(&mut brillig_context), + ProcedureId::PrepareVectorPush(push_back) => { + compile_prepare_vector_push_procedure(&mut brillig_context, push_back); + } + ProcedureId::VectorPop(pop_back) => { + compile_vector_pop_procedure(&mut brillig_context, pop_back); + } + ProcedureId::PrepareVectorInsert => { + compile_prepare_vector_insert_procedure(&mut brillig_context); + } + ProcedureId::VectorRemove => compile_vector_remove_procedure(&mut brillig_context), }; brillig_context.stop_instruction(); diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/prepare_vector_insert.rs b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/prepare_vector_insert.rs new file mode 100644 index 00000000000..d3a6855fa0f --- /dev/null +++ b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/prepare_vector_insert.rs @@ -0,0 +1,134 @@ +use std::vec; + +use acvm::{acir::brillig::MemoryAddress, AcirField}; + +use super::ProcedureId; +use crate::brillig::brillig_ir::{ + brillig_variable::{BrilligVector, SingleAddrVariable}, + debug_show::DebugToString, + registers::{RegisterAllocator, ScratchSpace}, + BrilligBinaryOp, BrilligContext, +}; + +impl BrilligContext { + /// It prepares a vector for a insert operation, leaving a hole at the index position which is returned as the write_pointer. + pub(crate) fn call_prepare_vector_insert_procedure( + &mut self, + source_vector: BrilligVector, + destination_vector: BrilligVector, + index: SingleAddrVariable, + write_pointer: MemoryAddress, + item_count: usize, + ) { + let source_vector_pointer_arg = MemoryAddress::from(ScratchSpace::start()); + let index_arg = MemoryAddress::from(ScratchSpace::start() + 1); + let item_count_arg = MemoryAddress::from(ScratchSpace::start() + 2); + let new_vector_pointer_return = MemoryAddress::from(ScratchSpace::start() + 3); + let write_pointer_return = MemoryAddress::from(ScratchSpace::start() + 4); + + self.mov_instruction(source_vector_pointer_arg, source_vector.pointer); + self.mov_instruction(index_arg, index.address); + self.usize_const_instruction(item_count_arg, item_count.into()); + + self.add_procedure_call_instruction(ProcedureId::PrepareVectorInsert); + + self.mov_instruction(destination_vector.pointer, new_vector_pointer_return); + self.mov_instruction(write_pointer, write_pointer_return); + } +} + +pub(super) fn compile_prepare_vector_insert_procedure( + brillig_context: &mut BrilligContext, +) { + let source_vector_pointer_arg = MemoryAddress::from(ScratchSpace::start()); + let index_arg = MemoryAddress::from(ScratchSpace::start() + 1); + let item_count_arg = MemoryAddress::from(ScratchSpace::start() + 2); + let new_vector_pointer_return = MemoryAddress::from(ScratchSpace::start() + 3); + let write_pointer_return = MemoryAddress::from(ScratchSpace::start() + 4); + + brillig_context.set_allocated_registers(vec![ + source_vector_pointer_arg, + index_arg, + item_count_arg, + new_vector_pointer_return, + write_pointer_return, + ]); + + let source_vector = BrilligVector { pointer: source_vector_pointer_arg }; + let target_vector = BrilligVector { pointer: new_vector_pointer_return }; + let index = SingleAddrVariable::new_usize(index_arg); + + // First we need to allocate the target vector incrementing the size by items.len() + let source_size = brillig_context.codegen_make_vector_length(source_vector); + + let target_size = SingleAddrVariable::new_usize(brillig_context.allocate_register()); + brillig_context.memory_op_instruction( + source_size.address, + item_count_arg, + target_size.address, + BrilligBinaryOp::Add, + ); + + brillig_context.codegen_initialize_vector(target_vector, target_size); + + // Copy the elements to the left of the index + let source_vector_items_pointer = + brillig_context.codegen_make_vector_items_pointer(source_vector); + let target_vector_items_pointer = + brillig_context.codegen_make_vector_items_pointer(target_vector); + + brillig_context.codegen_mem_copy( + source_vector_items_pointer, + target_vector_items_pointer, + index, + ); + + // Compute the source pointer just at the index + let source_pointer_at_index = brillig_context.allocate_register(); + brillig_context.memory_op_instruction( + source_vector_items_pointer, + index_arg, + source_pointer_at_index, + BrilligBinaryOp::Add, + ); + + // Compute the target pointer after the inserted elements + brillig_context.memory_op_instruction( + target_vector_items_pointer, + index.address, + write_pointer_return, + BrilligBinaryOp::Add, + ); + let target_pointer_after_index = brillig_context.allocate_register(); + + brillig_context.memory_op_instruction( + write_pointer_return, + item_count_arg, + target_pointer_after_index, + BrilligBinaryOp::Add, + ); + + // Compute the number of elements to the right of the index + let item_count = brillig_context.allocate_register(); + brillig_context.memory_op_instruction( + source_size.address, + index.address, + item_count, + BrilligBinaryOp::Sub, + ); + + // Copy the elements to the right of the index + brillig_context.codegen_mem_copy( + source_pointer_at_index, + target_pointer_after_index, + SingleAddrVariable::new_usize(item_count), + ); + + brillig_context.deallocate_register(source_pointer_at_index); + brillig_context.deallocate_register(target_pointer_after_index); + brillig_context.deallocate_register(item_count); + brillig_context.deallocate_single_addr(source_size); + brillig_context.deallocate_single_addr(target_size); + brillig_context.deallocate_register(source_vector_items_pointer); + brillig_context.deallocate_register(target_vector_items_pointer); +} diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/prepare_vector_push.rs b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/prepare_vector_push.rs new file mode 100644 index 00000000000..8af75712374 --- /dev/null +++ b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/prepare_vector_push.rs @@ -0,0 +1,111 @@ +use std::vec; + +use acvm::{acir::brillig::MemoryAddress, AcirField}; + +use super::ProcedureId; +use crate::brillig::brillig_ir::{ + brillig_variable::{BrilligVector, SingleAddrVariable}, + debug_show::DebugToString, + registers::{RegisterAllocator, ScratchSpace}, + BrilligBinaryOp, BrilligContext, +}; + +impl BrilligContext { + /// Prepares a vector for a push operation, allocating a larger vector and copying the source vector into the destination vector. + /// It returns the write pointer to where to put the new items. + pub(crate) fn call_prepare_vector_push_procedure( + &mut self, + source_vector: BrilligVector, + destination_vector: BrilligVector, + write_pointer: MemoryAddress, + item_push_count: usize, + back: bool, + ) { + let source_vector_pointer_arg = MemoryAddress::from(ScratchSpace::start()); + let item_push_count_arg = MemoryAddress::from(ScratchSpace::start() + 1); + let new_vector_pointer_return = MemoryAddress::from(ScratchSpace::start() + 2); + let write_pointer_return = MemoryAddress::from(ScratchSpace::start() + 3); + + self.mov_instruction(source_vector_pointer_arg, source_vector.pointer); + self.usize_const_instruction(item_push_count_arg, item_push_count.into()); + + self.add_procedure_call_instruction(ProcedureId::PrepareVectorPush(back)); + + self.mov_instruction(destination_vector.pointer, new_vector_pointer_return); + self.mov_instruction(write_pointer, write_pointer_return); + } +} + +pub(super) fn compile_prepare_vector_push_procedure( + brillig_context: &mut BrilligContext, + push_back: bool, +) { + let source_vector_pointer_arg = MemoryAddress::from(ScratchSpace::start()); + let item_push_count_arg = MemoryAddress::from(ScratchSpace::start() + 1); + let new_vector_pointer_return = MemoryAddress::from(ScratchSpace::start() + 2); + let write_pointer_return = MemoryAddress::from(ScratchSpace::start() + 3); + + brillig_context.set_allocated_registers(vec![ + source_vector_pointer_arg, + item_push_count_arg, + new_vector_pointer_return, + write_pointer_return, + ]); + + let source_vector = BrilligVector { pointer: source_vector_pointer_arg }; + let target_vector = BrilligVector { pointer: new_vector_pointer_return }; + + // First we need to allocate the target vector incrementing the size by item_push_count_arg + let source_size = brillig_context.codegen_make_vector_length(source_vector); + + let target_size = SingleAddrVariable::new_usize(brillig_context.allocate_register()); + brillig_context.memory_op_instruction( + source_size.address, + item_push_count_arg, + target_size.address, + BrilligBinaryOp::Add, + ); + + brillig_context.codegen_initialize_vector(target_vector, target_size); + + // Now we copy the source vector into the target vector + let source_vector_items_pointer = + brillig_context.codegen_make_vector_items_pointer(source_vector); + let target_vector_items_pointer = + brillig_context.codegen_make_vector_items_pointer(target_vector); + + if push_back { + brillig_context.codegen_mem_copy( + source_vector_items_pointer, + target_vector_items_pointer, + source_size, + ); + + brillig_context.memory_op_instruction( + target_vector_items_pointer, + source_size.address, + write_pointer_return, + BrilligBinaryOp::Add, + ); + } else { + brillig_context.mov_instruction(write_pointer_return, target_vector_items_pointer); + + brillig_context.memory_op_instruction( + target_vector_items_pointer, + item_push_count_arg, + target_vector_items_pointer, + BrilligBinaryOp::Add, + ); + + brillig_context.codegen_mem_copy( + source_vector_items_pointer, + target_vector_items_pointer, + source_size, + ); + } + + brillig_context.deallocate_single_addr(source_size); + brillig_context.deallocate_single_addr(target_size); + brillig_context.deallocate_register(source_vector_items_pointer); + brillig_context.deallocate_register(target_vector_items_pointer); +} diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/vector_pop.rs b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/vector_pop.rs new file mode 100644 index 00000000000..bb14ffac6be --- /dev/null +++ b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/vector_pop.rs @@ -0,0 +1,113 @@ +use std::vec; + +use acvm::{acir::brillig::MemoryAddress, AcirField}; + +use super::ProcedureId; +use crate::brillig::brillig_ir::{ + brillig_variable::{BrilligVector, SingleAddrVariable}, + debug_show::DebugToString, + registers::{RegisterAllocator, ScratchSpace}, + BrilligBinaryOp, BrilligContext, +}; + +impl BrilligContext { + /// Pops items from the vector, returning the new vector and the pointer to the popped items in read_pointer. + pub(crate) fn call_vector_pop_procedure( + &mut self, + source_vector: BrilligVector, + destination_vector: BrilligVector, + read_pointer: MemoryAddress, + item_pop_count: usize, + back: bool, + ) { + let source_vector_pointer_arg = MemoryAddress::from(ScratchSpace::start()); + let item_pop_count_arg = MemoryAddress::from(ScratchSpace::start() + 1); + let new_vector_pointer_return = MemoryAddress::from(ScratchSpace::start() + 2); + let read_pointer_return = MemoryAddress::from(ScratchSpace::start() + 3); + + self.mov_instruction(source_vector_pointer_arg, source_vector.pointer); + self.usize_const_instruction(item_pop_count_arg, item_pop_count.into()); + + self.add_procedure_call_instruction(ProcedureId::VectorPop(back)); + + self.mov_instruction(destination_vector.pointer, new_vector_pointer_return); + self.mov_instruction(read_pointer, read_pointer_return); + } +} + +pub(super) fn compile_vector_pop_procedure( + brillig_context: &mut BrilligContext, + pop_back: bool, +) { + let source_vector_pointer_arg = MemoryAddress::from(ScratchSpace::start()); + let item_pop_count_arg = MemoryAddress::from(ScratchSpace::start() + 1); + let new_vector_pointer_return = MemoryAddress::from(ScratchSpace::start() + 2); + let read_pointer_return = MemoryAddress::from(ScratchSpace::start() + 3); + + brillig_context.set_allocated_registers(vec![ + source_vector_pointer_arg, + item_pop_count_arg, + new_vector_pointer_return, + read_pointer_return, + ]); + + let source_vector = BrilligVector { pointer: source_vector_pointer_arg }; + let target_vector = BrilligVector { pointer: new_vector_pointer_return }; + + // First we need to allocate the target vector decrementing the size by removed_items.len() + let source_size = brillig_context.codegen_make_vector_length(source_vector); + + let target_size = SingleAddrVariable::new_usize(brillig_context.allocate_register()); + brillig_context.memory_op_instruction( + source_size.address, + item_pop_count_arg, + target_size.address, + BrilligBinaryOp::Sub, + ); + + brillig_context.codegen_initialize_vector(target_vector, target_size); + + // Now we offset the source pointer by removed_items.len() + let source_vector_items_pointer = + brillig_context.codegen_make_vector_items_pointer(source_vector); + let target_vector_items_pointer = + brillig_context.codegen_make_vector_items_pointer(target_vector); + + if pop_back { + // Now we copy the source vector starting at index 0 into the target vector + brillig_context.codegen_mem_copy( + source_vector_items_pointer, + target_vector_items_pointer, + target_size, + ); + brillig_context.memory_op_instruction( + source_vector_items_pointer, + target_size.address, + read_pointer_return, + BrilligBinaryOp::Add, + ); + } else { + let source_copy_pointer = brillig_context.allocate_register(); + brillig_context.memory_op_instruction( + source_vector_items_pointer, + item_pop_count_arg, + source_copy_pointer, + BrilligBinaryOp::Add, + ); + + // Now we copy the source vector starting at index removed_items.len() into the target vector + brillig_context.codegen_mem_copy( + source_copy_pointer, + target_vector_items_pointer, + target_size, + ); + brillig_context.mov_instruction(read_pointer_return, source_vector_items_pointer); + + brillig_context.deallocate_register(source_copy_pointer); + } + + brillig_context.deallocate_single_addr(source_size); + brillig_context.deallocate_single_addr(target_size); + brillig_context.deallocate_register(source_vector_items_pointer); + brillig_context.deallocate_register(target_vector_items_pointer); +} diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/vector_remove.rs b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/vector_remove.rs new file mode 100644 index 00000000000..d4a7217677f --- /dev/null +++ b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/procedures/vector_remove.rs @@ -0,0 +1,134 @@ +use std::vec; + +use acvm::{acir::brillig::MemoryAddress, AcirField}; + +use super::ProcedureId; +use crate::brillig::brillig_ir::{ + brillig_variable::{BrilligVector, SingleAddrVariable}, + debug_show::DebugToString, + registers::{RegisterAllocator, ScratchSpace}, + BrilligBinaryOp, BrilligContext, +}; + +impl BrilligContext { + /// Removes items from the vector, returning the new vector. + pub(crate) fn call_vector_remove_procedure( + &mut self, + source_vector: BrilligVector, + destination_vector: BrilligVector, + index: SingleAddrVariable, + item_count: usize, + ) { + let source_vector_pointer_arg = MemoryAddress::from(ScratchSpace::start()); + let index_arg = MemoryAddress::from(ScratchSpace::start() + 1); + let item_count_arg = MemoryAddress::from(ScratchSpace::start() + 2); + let new_vector_pointer_return = MemoryAddress::from(ScratchSpace::start() + 3); + + self.mov_instruction(source_vector_pointer_arg, source_vector.pointer); + self.mov_instruction(index_arg, index.address); + self.usize_const_instruction(item_count_arg, item_count.into()); + + self.add_procedure_call_instruction(ProcedureId::VectorRemove); + + self.mov_instruction(destination_vector.pointer, new_vector_pointer_return); + } +} + +pub(super) fn compile_vector_remove_procedure( + brillig_context: &mut BrilligContext, +) { + let source_vector_pointer_arg = MemoryAddress::from(ScratchSpace::start()); + let index_arg = MemoryAddress::from(ScratchSpace::start() + 1); + let item_count_arg = MemoryAddress::from(ScratchSpace::start() + 2); + let new_vector_pointer_return = MemoryAddress::from(ScratchSpace::start() + 3); + + brillig_context.set_allocated_registers(vec![ + source_vector_pointer_arg, + index_arg, + item_count_arg, + new_vector_pointer_return, + ]); + + let source_vector = BrilligVector { pointer: source_vector_pointer_arg }; + let target_vector = BrilligVector { pointer: new_vector_pointer_return }; + let index = SingleAddrVariable::new_usize(index_arg); + + // First we need to allocate the target vector decrementing the size by removed_items.len() + let source_size = brillig_context.codegen_make_vector_length(source_vector); + + let target_size = SingleAddrVariable::new_usize(brillig_context.allocate_register()); + brillig_context.memory_op_instruction( + source_size.address, + item_count_arg, + target_size.address, + BrilligBinaryOp::Sub, + ); + + brillig_context.codegen_initialize_vector(target_vector, target_size); + + // Copy the elements to the left of the index + let source_vector_items_pointer = + brillig_context.codegen_make_vector_items_pointer(source_vector); + let target_vector_items_pointer = + brillig_context.codegen_make_vector_items_pointer(target_vector); + + brillig_context.codegen_mem_copy( + source_vector_items_pointer, + target_vector_items_pointer, + index, + ); + + // Compute the source pointer after the removed items + let source_pointer_after_index = brillig_context.allocate_register(); + brillig_context.memory_op_instruction( + source_vector_items_pointer, + index.address, + source_pointer_after_index, + BrilligBinaryOp::Add, + ); + brillig_context.memory_op_instruction( + source_pointer_after_index, + item_count_arg, + source_pointer_after_index, + BrilligBinaryOp::Add, + ); + + // Compute the target pointer at the index + let target_pointer_at_index = brillig_context.allocate_register(); + brillig_context.memory_op_instruction( + target_vector_items_pointer, + index.address, + target_pointer_at_index, + BrilligBinaryOp::Add, + ); + + // Compute the number of elements to the right of the index + let item_count = brillig_context.allocate_register(); + brillig_context.memory_op_instruction( + source_size.address, + index.address, + item_count, + BrilligBinaryOp::Sub, + ); + brillig_context.memory_op_instruction( + item_count, + item_count_arg, + item_count, + BrilligBinaryOp::Sub, + ); + + // Copy the elements to the right of the index + brillig_context.codegen_mem_copy( + source_pointer_after_index, + target_pointer_at_index, + SingleAddrVariable::new_usize(item_count), + ); + + brillig_context.deallocate_register(source_pointer_after_index); + brillig_context.deallocate_register(target_pointer_at_index); + brillig_context.deallocate_register(item_count); + brillig_context.deallocate_single_addr(source_size); + brillig_context.deallocate_single_addr(target_size); + brillig_context.deallocate_register(source_vector_items_pointer); + brillig_context.deallocate_register(target_vector_items_pointer); +} diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/errors.rs b/noir/noir-repo/compiler/noirc_evaluator/src/errors.rs index bcd6865b721..c4ba08f9acd 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/errors.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/errors.rs @@ -34,6 +34,13 @@ pub enum RuntimeError { UnInitialized { name: String, call_stack: CallStack }, #[error("Integer sized {num_bits:?} is over the max supported size of {max_num_bits:?}")] UnsupportedIntegerSize { num_bits: u32, max_num_bits: u32, call_stack: CallStack }, + #[error("Integer {value}, sized {num_bits:?}, is over the max supported size of {max_num_bits:?} for the blackbox function's inputs")] + InvalidBlackBoxInputBitSize { + value: String, + num_bits: u32, + max_num_bits: u32, + call_stack: CallStack, + }, #[error("Could not determine loop bound at compile-time")] UnknownLoopBound { call_stack: CallStack }, #[error("Argument is not constant")] @@ -156,6 +163,7 @@ impl RuntimeError { | RuntimeError::StaticAssertFailed { call_stack } | RuntimeError::IntegerOutOfBounds { call_stack, .. } | RuntimeError::UnsupportedIntegerSize { call_stack, .. } + | RuntimeError::InvalidBlackBoxInputBitSize { call_stack, .. } | RuntimeError::NestedSlice { call_stack, .. } | RuntimeError::BigIntModulus { call_stack, .. } | RuntimeError::UnconstrainedSliceReturnToConstrained { call_stack } diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index d12d49784ec..9586d08e10c 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -1420,7 +1420,7 @@ impl AcirContext { } BlackBoxFunc::AES128Encrypt => { let invalid_input = "aes128_encrypt - operation requires a plaintext to encrypt"; - let input_size = match inputs.first().expect(invalid_input) { + let input_size: usize = match inputs.first().expect(invalid_input) { AcirValue::Array(values) => Ok::(values.len()), AcirValue::DynamicArray(dyn_array) => Ok::(dyn_array.len), _ => { @@ -1510,7 +1510,18 @@ impl AcirContext { let num_bits = typ.bit_size::(); match self.vars[&input].as_constant() { Some(constant) if allow_constant_inputs => { - single_val_witnesses.push(FunctionInput::constant(*constant, num_bits)); + single_val_witnesses.push( + FunctionInput::constant(*constant, num_bits).map_err( + |invalid_input_bit_size| { + RuntimeError::InvalidBlackBoxInputBitSize { + value: invalid_input_bit_size.value, + num_bits: invalid_input_bit_size.value_num_bits, + max_num_bits: invalid_input_bit_size.max_bits, + call_stack: self.get_call_stack(), + } + }, + )?, + ); } _ => { let witness_var = self.get_or_create_witness_var(input)?; diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs index 5091854a2ed..15b44fde65d 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs @@ -960,7 +960,6 @@ impl<'a> Context<'a> { arguments, BrilligFunctionContext::return_values(func), func.id(), - false, ); entry_point.name = func.name().to_string(); diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs index 8c128c452d0..13e1e181dec 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs @@ -117,10 +117,6 @@ struct PerFunctionContext<'f> { /// Track a value's last load across all blocks. /// If a value is not used in anymore loads we can remove the last store to that value. last_loads: HashMap, - - /// Track whether the last instruction is an inc_rc/dec_rc instruction. - /// If it is we should not remove any known store values. - inside_rc_reload: bool, } impl<'f> PerFunctionContext<'f> { @@ -135,7 +131,6 @@ impl<'f> PerFunctionContext<'f> { blocks: BTreeMap::new(), instructions_to_remove: BTreeSet::new(), last_loads: HashMap::default(), - inside_rc_reload: false, } } @@ -324,7 +319,7 @@ impl<'f> PerFunctionContext<'f> { let known_value = references.get_known_value(value); if let Some(known_value) = known_value { let known_value_is_address = known_value == address; - if known_value_is_address && !self.inside_rc_reload { + if known_value_is_address { self.instructions_to_remove.insert(instruction); } } @@ -383,18 +378,6 @@ impl<'f> PerFunctionContext<'f> { Instruction::Call { arguments, .. } => self.mark_all_unknown(arguments, references), _ => (), } - - self.track_rc_reload_state(instruction); - } - - fn track_rc_reload_state(&mut self, instruction: InstructionId) { - match &self.inserter.function.dfg[instruction] { - // We just had an increment or decrement to an array's reference counter - Instruction::IncrementRc { .. } | Instruction::DecrementRc { .. } => { - self.inside_rc_reload = true; - } - _ => self.inside_rc_reload = false, - } } fn check_array_aliasing(&self, references: &mut Block, array: ValueId) { diff --git a/noir/noir-repo/compiler/noirc_frontend/src/ast/traits.rs b/noir/noir-repo/compiler/noirc_frontend/src/ast/traits.rs index 0463a5b8392..0de1dbaa021 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/ast/traits.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/ast/traits.rs @@ -95,7 +95,13 @@ pub struct TraitBound { } #[derive(Clone, Debug)] -pub enum TraitImplItem { +pub struct TraitImplItem { + pub kind: TraitImplItemKind, + pub span: Span, +} + +#[derive(Clone, Debug)] +pub enum TraitImplItemKind { Function(NoirFunction), Constant(Ident, UnresolvedType, Expression), Type { name: Ident, alias: UnresolvedType }, @@ -202,11 +208,17 @@ impl Display for NoirTraitImpl { } impl Display for TraitImplItem { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.kind.fmt(f) + } +} + +impl Display for TraitImplItemKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - TraitImplItem::Function(function) => function.fmt(f), - TraitImplItem::Type { name, alias } => write!(f, "type {name} = {alias};"), - TraitImplItem::Constant(name, typ, value) => { + TraitImplItemKind::Function(function) => function.fmt(f), + TraitImplItemKind::Type { name, alias } => write!(f, "type {name} = {alias};"), + TraitImplItemKind::Constant(name, typ, value) => { write!(f, "let {name}: {typ} = {value};") } } diff --git a/noir/noir-repo/compiler/noirc_frontend/src/ast/visitor.rs b/noir/noir-repo/compiler/noirc_frontend/src/ast/visitor.rs index fcb4e4c5dd1..47083a5043b 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/ast/visitor.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/ast/visitor.rs @@ -22,8 +22,8 @@ use crate::{ use super::{ FunctionReturnType, GenericTypeArgs, IntegerBitSize, ItemVisibility, Pattern, Signedness, - UnresolvedGenerics, UnresolvedTraitConstraint, UnresolvedType, UnresolvedTypeData, - UnresolvedTypeExpression, + TraitImplItemKind, UnresolvedGenerics, UnresolvedTraitConstraint, UnresolvedType, + UnresolvedTypeData, UnresolvedTypeExpression, }; #[derive(Debug, Copy, Clone, PartialEq, Eq)] @@ -69,6 +69,10 @@ pub trait Visitor { true } + fn visit_trait_impl_item_kind(&mut self, _: &TraitImplItemKind, _span: Span) -> bool { + true + } + fn visit_trait_impl_item_function(&mut self, _: &NoirFunction, _span: Span) -> bool { true } @@ -78,11 +82,17 @@ pub trait Visitor { _name: &Ident, _typ: &UnresolvedType, _expression: &Expression, + _span: Span, ) -> bool { true } - fn visit_trait_impl_item_type(&mut self, _name: &Ident, _alias: &UnresolvedType) -> bool { + fn visit_trait_impl_item_type( + &mut self, + _name: &Ident, + _alias: &UnresolvedType, + _span: Span, + ) -> bool { true } @@ -569,24 +579,32 @@ impl TraitImplItem { } pub fn accept_children(&self, visitor: &mut impl Visitor) { - match self { - TraitImplItem::Function(noir_function) => { - let span = Span::from( - noir_function.name_ident().span().start()..noir_function.span().end(), - ); + self.kind.accept(self.span, visitor); + } +} + +impl TraitImplItemKind { + pub fn accept(&self, span: Span, visitor: &mut impl Visitor) { + if visitor.visit_trait_impl_item_kind(self, span) { + self.accept_children(span, visitor); + } + } + pub fn accept_children(&self, span: Span, visitor: &mut impl Visitor) { + match self { + TraitImplItemKind::Function(noir_function) => { if visitor.visit_trait_impl_item_function(noir_function, span) { noir_function.accept(span, visitor); } } - TraitImplItem::Constant(name, unresolved_type, expression) => { - if visitor.visit_trait_impl_item_constant(name, unresolved_type, expression) { + TraitImplItemKind::Constant(name, unresolved_type, expression) => { + if visitor.visit_trait_impl_item_constant(name, unresolved_type, expression, span) { unresolved_type.accept(visitor); expression.accept(visitor); } } - TraitImplItem::Type { name, alias } => { - if visitor.visit_trait_impl_item_type(name, alias) { + TraitImplItemKind::Type { name, alias } => { + if visitor.visit_trait_impl_item_type(name, alias, span) { alias.accept(visitor); } } diff --git a/noir/noir-repo/compiler/noirc_frontend/src/elaborator/patterns.rs b/noir/noir-repo/compiler/noirc_frontend/src/elaborator/patterns.rs index f738657fd23..09357e77c0b 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/elaborator/patterns.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/elaborator/patterns.rs @@ -513,15 +513,6 @@ impl<'context> Elaborator<'context> { let typ = self.type_check_variable(expr, id, generics); self.interner.push_expr_type(id, typ.clone()); - // Comptime variables must be replaced with their values - if let Some(definition) = self.interner.try_definition(definition_id) { - if definition.comptime && !self.in_comptime_context() { - let mut interpreter = self.setup_interpreter(); - let value = interpreter.evaluate(id); - return self.inline_comptime_value(value, span); - } - } - (id, typ) } diff --git a/noir/noir-repo/compiler/noirc_frontend/src/elaborator/statements.rs b/noir/noir-repo/compiler/noirc_frontend/src/elaborator/statements.rs index 9e29978a9d5..543cf20b647 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/elaborator/statements.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/elaborator/statements.rs @@ -249,6 +249,13 @@ impl<'context> Elaborator<'context> { } else { if let Some(definition) = self.interner.try_definition(ident.id) { mutable = definition.mutable; + + if definition.comptime && !self.in_comptime_context() { + self.push_err(ResolverError::MutatingComptimeInNonComptimeContext { + name: definition.name.clone(), + span: ident.location.span, + }); + } } let typ = self.interner.definition_type(ident.id).instantiate(self.interner).0; diff --git a/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter.rs b/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter.rs index 5f58c18d66e..281318c5b7e 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter.rs @@ -434,7 +434,14 @@ impl<'local, 'interner> Interpreter<'local, 'interner> { for scope in self.elaborator.interner.comptime_scopes.iter_mut().rev() { if let Entry::Occupied(mut entry) = scope.entry(id) { - entry.insert(argument); + match entry.get() { + Value::Pointer(reference, true) => { + *reference.borrow_mut() = argument; + } + _ => { + entry.insert(argument); + } + } return Ok(()); } } @@ -527,12 +534,13 @@ impl<'local, 'interner> Interpreter<'local, 'interner> { DefinitionKind::Local(_) => self.lookup(&ident), DefinitionKind::Global(global_id) => { // Avoid resetting the value if it is already known - if let Ok(value) = self.lookup(&ident) { - Ok(value) + if let Some(value) = &self.elaborator.interner.get_global(*global_id).value { + Ok(value.clone()) } else { - let crate_of_global = self.elaborator.interner.get_global(*global_id).crate_id; + let global_id = *global_id; + let crate_of_global = self.elaborator.interner.get_global(global_id).crate_id; let let_ = - self.elaborator.interner.get_global_let_statement(*global_id).ok_or_else( + self.elaborator.interner.get_global_let_statement(global_id).ok_or_else( || { let location = self.elaborator.interner.expr_location(&id); InterpreterError::VariableNotInScope { location } @@ -542,7 +550,10 @@ impl<'local, 'interner> Interpreter<'local, 'interner> { if let_.comptime || crate_of_global != self.crate_id { self.evaluate_let(let_.clone())?; } - self.lookup(&ident) + + let value = self.lookup(&ident)?; + self.elaborator.interner.get_global_mut(global_id).value = Some(value.clone()); + Ok(value) } } DefinitionKind::GenericType(type_variable) => { diff --git a/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin.rs b/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin.rs index 166c6479b15..9d1349b5209 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin.rs @@ -1,7 +1,4 @@ -use std::{ - hash::{Hash, Hasher}, - rc::Rc, -}; +use std::rc::Rc; use acvm::{AcirField, FieldElement}; use builtin_helpers::{ @@ -43,7 +40,7 @@ use crate::{ Kind, QuotedType, ResolvedGeneric, Shared, Type, TypeVariable, }; -use self::builtin_helpers::{get_array, get_str, get_u8}; +use self::builtin_helpers::{eq_item, get_array, get_str, get_u8, hash_item}; use super::Interpreter; pub(crate) mod builtin_helpers; @@ -104,9 +101,11 @@ impl<'local, 'context> Interpreter<'local, 'context> { "fresh_type_variable" => fresh_type_variable(interner), "function_def_add_attribute" => function_def_add_attribute(self, arguments, location), "function_def_body" => function_def_body(interner, arguments, location), + "function_def_eq" => function_def_eq(arguments, location), "function_def_has_named_attribute" => { function_def_has_named_attribute(interner, arguments, location) } + "function_def_hash" => function_def_hash(arguments, location), "function_def_is_unconstrained" => { function_def_is_unconstrained(interner, arguments, location) } @@ -126,20 +125,24 @@ impl<'local, 'context> Interpreter<'local, 'context> { function_def_set_unconstrained(self, arguments, location) } "module_add_item" => module_add_item(self, arguments, location), + "module_eq" => module_eq(arguments, location), "module_functions" => module_functions(self, arguments, location), "module_has_named_attribute" => module_has_named_attribute(self, arguments, location), + "module_hash" => module_hash(arguments, location), "module_is_contract" => module_is_contract(self, arguments, location), "module_name" => module_name(interner, arguments, location), - "modulus_be_bits" => modulus_be_bits(interner, arguments, location), - "modulus_be_bytes" => modulus_be_bytes(interner, arguments, location), - "modulus_le_bits" => modulus_le_bits(interner, arguments, location), - "modulus_le_bytes" => modulus_le_bytes(interner, arguments, location), - "modulus_num_bits" => modulus_num_bits(interner, arguments, location), + "module_structs" => module_structs(self, arguments, location), + "modulus_be_bits" => modulus_be_bits(arguments, location), + "modulus_be_bytes" => modulus_be_bytes(arguments, location), + "modulus_le_bits" => modulus_le_bits(arguments, location), + "modulus_le_bytes" => modulus_le_bytes(arguments, location), + "modulus_num_bits" => modulus_num_bits(arguments, location), "quoted_as_expr" => quoted_as_expr(arguments, return_type, location), "quoted_as_module" => quoted_as_module(self, arguments, return_type, location), "quoted_as_trait_constraint" => quoted_as_trait_constraint(self, arguments, location), "quoted_as_type" => quoted_as_type(self, arguments, location), "quoted_eq" => quoted_eq(arguments, location), + "quoted_hash" => quoted_hash(arguments, location), "quoted_tokens" => quoted_tokens(arguments, location), "slice_insert" => slice_insert(interner, arguments, location), "slice_pop_back" => slice_pop_back(interner, arguments, location, call_stack), @@ -151,22 +154,24 @@ impl<'local, 'context> Interpreter<'local, 'context> { "struct_def_add_attribute" => struct_def_add_attribute(interner, arguments, location), "struct_def_add_generic" => struct_def_add_generic(interner, arguments, location), "struct_def_as_type" => struct_def_as_type(interner, arguments, location), + "struct_def_eq" => struct_def_eq(arguments, location), "struct_def_fields" => struct_def_fields(interner, arguments, location), "struct_def_generics" => struct_def_generics(interner, arguments, location), "struct_def_has_named_attribute" => { struct_def_has_named_attribute(interner, arguments, location) } + "struct_def_hash" => struct_def_hash(arguments, location), "struct_def_module" => struct_def_module(self, arguments, location), "struct_def_name" => struct_def_name(interner, arguments, location), "struct_def_set_fields" => struct_def_set_fields(interner, arguments, location), "to_le_radix" => to_le_radix(arguments, return_type, location), - "trait_constraint_eq" => trait_constraint_eq(interner, arguments, location), - "trait_constraint_hash" => trait_constraint_hash(interner, arguments, location), + "trait_constraint_eq" => trait_constraint_eq(arguments, location), + "trait_constraint_hash" => trait_constraint_hash(arguments, location), "trait_def_as_trait_constraint" => { trait_def_as_trait_constraint(interner, arguments, location) } - "trait_def_eq" => trait_def_eq(interner, arguments, location), - "trait_def_hash" => trait_def_hash(interner, arguments, location), + "trait_def_eq" => trait_def_eq(arguments, location), + "trait_def_hash" => trait_def_hash(arguments, location), "trait_impl_methods" => trait_impl_methods(interner, arguments, location), "trait_impl_trait_generic_args" => { trait_impl_trait_generic_args(interner, arguments, location) @@ -182,6 +187,7 @@ impl<'local, 'context> Interpreter<'local, 'context> { "type_get_trait_impl" => { type_get_trait_impl(interner, arguments, return_type, location) } + "type_hash" => type_hash(arguments, location), "type_implements" => type_implements(interner, arguments, location), "type_is_bool" => type_is_bool(arguments, location), "type_is_field" => type_is_field(arguments, location), @@ -427,7 +433,15 @@ fn struct_def_generics( Ok(Value::Slice(generics.collect(), typ)) } -// fn has_named_attribute(self, name: Quoted) -> bool +fn struct_def_hash(arguments: Vec<(Value, Location)>, location: Location) -> IResult { + hash_item(arguments, location, get_struct) +} + +fn struct_def_eq(arguments: Vec<(Value, Location)>, location: Location) -> IResult { + eq_item(arguments, location, get_struct) +} + +// fn has_named_attribute(self, name: str) -> bool {} fn struct_def_has_named_attribute( interner: &NodeInterner, arguments: Vec<(Value, Location)>, @@ -436,14 +450,9 @@ fn struct_def_has_named_attribute( let (self_argument, name) = check_two_arguments(arguments, location)?; let struct_id = get_struct(self_argument)?; - let name = get_quoted(name)?; - let name = name.iter().map(|token| token.to_string()).collect::>().join(""); + let name = get_str(interner, name)?; - let attributes = interner.struct_attributes(&struct_id); - let attributes = attributes.iter().filter_map(|attribute| attribute.as_custom()); - let attributes = attributes.map(|attribute| &attribute.contents); - - Ok(Value::Bool(has_named_attribute(&name, attributes, location))) + Ok(Value::Bool(has_named_attribute(&name, interner.struct_attributes(&struct_id)))) } /// fn fields(self) -> [(Quoted, Type)] @@ -903,12 +912,12 @@ where // fn type_eq(_first: Type, _second: Type) -> bool fn type_eq(arguments: Vec<(Value, Location)>, location: Location) -> IResult { - let (self_type, other_type) = check_two_arguments(arguments, location)?; - - let self_type = get_type(self_type)?; - let other_type = get_type(other_type)?; + eq_item(arguments, location, get_type) +} - Ok(Value::Bool(self_type == other_type)) +// fn type_hash(_t: Type) -> Field +fn type_hash(arguments: Vec<(Value, Location)>, location: Location) -> IResult { + hash_item(arguments, location, get_type) } // fn get_trait_impl(self, constraint: TraitConstraint) -> Option @@ -977,65 +986,23 @@ fn type_of(arguments: Vec<(Value, Location)>, location: Location) -> IResult Field -fn trait_constraint_hash( - _interner: &mut NodeInterner, - arguments: Vec<(Value, Location)>, - location: Location, -) -> IResult { - let argument = check_one_argument(arguments, location)?; - - let bound = get_trait_constraint(argument)?; - - let mut hasher = std::collections::hash_map::DefaultHasher::new(); - bound.hash(&mut hasher); - let hash = hasher.finish(); - - Ok(Value::Field((hash as u128).into())) +fn trait_constraint_hash(arguments: Vec<(Value, Location)>, location: Location) -> IResult { + hash_item(arguments, location, get_trait_constraint) } // fn constraint_eq(constraint_a: TraitConstraint, constraint_b: TraitConstraint) -> bool -fn trait_constraint_eq( - _interner: &mut NodeInterner, - arguments: Vec<(Value, Location)>, - location: Location, -) -> IResult { - let (value_a, value_b) = check_two_arguments(arguments, location)?; - - let constraint_a = get_trait_constraint(value_a)?; - let constraint_b = get_trait_constraint(value_b)?; - - Ok(Value::Bool(constraint_a == constraint_b)) +fn trait_constraint_eq(arguments: Vec<(Value, Location)>, location: Location) -> IResult { + eq_item(arguments, location, get_trait_constraint) } // fn trait_def_hash(def: TraitDefinition) -> Field -fn trait_def_hash( - _interner: &mut NodeInterner, - arguments: Vec<(Value, Location)>, - location: Location, -) -> IResult { - let argument = check_one_argument(arguments, location)?; - - let id = get_trait_def(argument)?; - - let mut hasher = std::collections::hash_map::DefaultHasher::new(); - id.hash(&mut hasher); - let hash = hasher.finish(); - - Ok(Value::Field((hash as u128).into())) +fn trait_def_hash(arguments: Vec<(Value, Location)>, location: Location) -> IResult { + hash_item(arguments, location, get_trait_def) } // fn trait_def_eq(def_a: TraitDefinition, def_b: TraitDefinition) -> bool -fn trait_def_eq( - _interner: &mut NodeInterner, - arguments: Vec<(Value, Location)>, - location: Location, -) -> IResult { - let (id_a, id_b) = check_two_arguments(arguments, location)?; - - let id_a = get_trait_def(id_a)?; - let id_b = get_trait_def(id_b)?; - - Ok(Value::Bool(id_a == id_b)) +fn trait_def_eq(arguments: Vec<(Value, Location)>, location: Location) -> IResult { + eq_item(arguments, location, get_trait_def) } // fn methods(self) -> [FunctionDefinition] @@ -1985,7 +1952,7 @@ fn function_def_body( } } -// fn has_named_attribute(self, name: Quoted) -> bool +// fn has_named_attribute(self, name: str) -> bool {} fn function_def_has_named_attribute( interner: &NodeInterner, arguments: Vec<(Value, Location)>, @@ -1993,15 +1960,25 @@ fn function_def_has_named_attribute( ) -> IResult { let (self_argument, name) = check_two_arguments(arguments, location)?; let func_id = get_function_def(self_argument)?; - let func_meta = interner.function_meta(&func_id); - let name = get_quoted(name)?; - let name = name.iter().map(|token| token.to_string()).collect::>().join(""); + let name = &*get_str(interner, name)?; + + let modifiers = interner.function_modifiers(&func_id); + if let Some(attribute) = &modifiers.attributes.function { + if name == attribute.name() { + return Ok(Value::Bool(true)); + } + } + + Ok(Value::Bool(has_named_attribute(name, &modifiers.attributes.secondary))) +} - let attributes = &func_meta.custom_attributes; - let attributes = attributes.iter().map(|attribute| &attribute.contents); +fn function_def_hash(arguments: Vec<(Value, Location)>, location: Location) -> IResult { + hash_item(arguments, location, get_function_def) +} - Ok(Value::Bool(has_named_attribute(&name, attributes, location))) +fn function_def_eq(arguments: Vec<(Value, Location)>, location: Location) -> IResult { + eq_item(arguments, location, get_function_def) } // fn is_unconstrained(self) -> bool @@ -2270,6 +2247,14 @@ fn module_add_item( Ok(Value::Unit) } +fn module_hash(arguments: Vec<(Value, Location)>, location: Location) -> IResult { + hash_item(arguments, location, get_module) +} + +fn module_eq(arguments: Vec<(Value, Location)>, location: Location) -> IResult { + eq_item(arguments, location, get_module) +} + // fn functions(self) -> [FunctionDefinition] fn module_functions( interpreter: &Interpreter, @@ -2294,7 +2279,31 @@ fn module_functions( Ok(Value::Slice(func_ids, slice_type)) } -// fn has_named_attribute(self, name: Quoted) -> bool +// fn structs(self) -> [StructDefinition] +fn module_structs( + interpreter: &Interpreter, + arguments: Vec<(Value, Location)>, + location: Location, +) -> IResult { + let self_argument = check_one_argument(arguments, location)?; + let module_id = get_module(self_argument)?; + let module_data = interpreter.elaborator.get_module(module_id); + let struct_ids = module_data + .type_definitions() + .filter_map(|module_def_id| { + if let ModuleDefId::TypeId(id) = module_def_id { + Some(Value::StructDefinition(id)) + } else { + None + } + }) + .collect(); + + let slice_type = Type::Slice(Box::new(Type::Quoted(QuotedType::StructDefinition))); + Ok(Value::Slice(struct_ids, slice_type)) +} + +// fn has_named_attribute(self, name: str) -> bool {} fn module_has_named_attribute( interpreter: &Interpreter, arguments: Vec<(Value, Location)>, @@ -2304,12 +2313,9 @@ fn module_has_named_attribute( let module_id = get_module(self_argument)?; let module_data = interpreter.elaborator.get_module(module_id); - let name = get_quoted(name)?; - let name = name.iter().map(|token| token.to_string()).collect::>().join(""); - - let attributes = module_data.outer_attributes.iter().chain(&module_data.inner_attributes); + let name = get_str(interpreter.elaborator.interner, name)?; - Ok(Value::Bool(has_named_attribute(&name, attributes, location))) + Ok(Value::Bool(has_named_attribute(&name, &module_data.attributes))) } // fn is_contract(self) -> bool @@ -2336,11 +2342,7 @@ fn module_name( Ok(Value::Quoted(tokens)) } -fn modulus_be_bits( - _interner: &mut NodeInterner, - arguments: Vec<(Value, Location)>, - location: Location, -) -> IResult { +fn modulus_be_bits(arguments: Vec<(Value, Location)>, location: Location) -> IResult { check_argument_count(0, &arguments, location)?; let bits = FieldElement::modulus().to_radix_be(2); @@ -2351,11 +2353,7 @@ fn modulus_be_bits( Ok(Value::Slice(bits_vector, typ)) } -fn modulus_be_bytes( - _interner: &mut NodeInterner, - arguments: Vec<(Value, Location)>, - location: Location, -) -> IResult { +fn modulus_be_bytes(arguments: Vec<(Value, Location)>, location: Location) -> IResult { check_argument_count(0, &arguments, location)?; let bytes = FieldElement::modulus().to_bytes_be(); @@ -2366,35 +2364,23 @@ fn modulus_be_bytes( Ok(Value::Slice(bytes_vector, typ)) } -fn modulus_le_bits( - interner: &mut NodeInterner, - arguments: Vec<(Value, Location)>, - location: Location, -) -> IResult { - let Value::Slice(bits, typ) = modulus_be_bits(interner, arguments, location)? else { +fn modulus_le_bits(arguments: Vec<(Value, Location)>, location: Location) -> IResult { + let Value::Slice(bits, typ) = modulus_be_bits(arguments, location)? else { unreachable!("modulus_be_bits must return slice") }; let reversed_bits = bits.into_iter().rev().collect(); Ok(Value::Slice(reversed_bits, typ)) } -fn modulus_le_bytes( - interner: &mut NodeInterner, - arguments: Vec<(Value, Location)>, - location: Location, -) -> IResult { - let Value::Slice(bytes, typ) = modulus_be_bytes(interner, arguments, location)? else { +fn modulus_le_bytes(arguments: Vec<(Value, Location)>, location: Location) -> IResult { + let Value::Slice(bytes, typ) = modulus_be_bytes(arguments, location)? else { unreachable!("modulus_be_bytes must return slice") }; let reversed_bytes = bytes.into_iter().rev().collect(); Ok(Value::Slice(reversed_bytes, typ)) } -fn modulus_num_bits( - _interner: &mut NodeInterner, - arguments: Vec<(Value, Location)>, - location: Location, -) -> IResult { +fn modulus_num_bits(arguments: Vec<(Value, Location)>, location: Location) -> IResult { check_argument_count(0, &arguments, location)?; let bits = FieldElement::max_num_bits().into(); Ok(Value::U64(bits)) @@ -2402,19 +2388,18 @@ fn modulus_num_bits( // fn quoted_eq(_first: Quoted, _second: Quoted) -> bool fn quoted_eq(arguments: Vec<(Value, Location)>, location: Location) -> IResult { - let (self_value, other_value) = check_two_arguments(arguments, location)?; - - let self_quoted = get_quoted(self_value)?; - let other_quoted = get_quoted(other_value)?; + eq_item(arguments, location, get_quoted) +} - Ok(Value::Bool(self_quoted == other_quoted)) +fn quoted_hash(arguments: Vec<(Value, Location)>, location: Location) -> IResult { + hash_item(arguments, location, get_quoted) } fn trait_def_as_trait_constraint( interner: &mut NodeInterner, arguments: Vec<(Value, Location)>, location: Location, -) -> Result { +) -> IResult { let argument = check_one_argument(arguments, location)?; let trait_id = get_trait_def(argument)?; diff --git a/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin/builtin_helpers.rs b/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin/builtin_helpers.rs index 6e72866bec0..911e89a52ec 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin/builtin_helpers.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin/builtin_helpers.rs @@ -1,4 +1,5 @@ -use std::rc::Rc; +use std::hash::Hash; +use std::{hash::Hasher, rc::Rc}; use acvm::FieldElement; use noirc_errors::Location; @@ -8,7 +9,6 @@ use crate::{ BlockExpression, ExpressionKind, IntegerBitSize, LValue, Pattern, Signedness, StatementKind, UnresolvedTypeData, }, - elaborator::Elaborator, hir::{ comptime::{ errors::IResult, @@ -25,7 +25,7 @@ use crate::{ macros_api::{NodeInterner, StructId}, node_interner::{FuncId, TraitId, TraitImplId}, parser::NoirParser, - token::{Token, Tokens}, + token::{SecondaryAttribute, Token, Tokens}, QuotedType, Type, }; @@ -449,25 +449,39 @@ pub(super) fn block_expression_to_value(block_expr: BlockExpression) -> Value { Value::Slice(statements, typ) } -pub(super) fn has_named_attribute<'a>( - name: &'a str, - attributes: impl Iterator, - location: Location, -) -> bool { +pub(super) fn has_named_attribute(name: &str, attributes: &[SecondaryAttribute]) -> bool { for attribute in attributes { - let parse_result = Elaborator::parse_attribute(attribute, location); - let Ok(Some((function, _arguments))) = parse_result else { - continue; - }; - - let ExpressionKind::Variable(path) = function.kind else { - continue; - }; - - if path.last_name() == name { - return true; + if let Some(attribute_name) = attribute.name() { + if name == attribute_name { + return true; + } } } false } + +pub(super) fn hash_item( + arguments: Vec<(Value, Location)>, + location: Location, + get_item: impl FnOnce((Value, Location)) -> IResult, +) -> IResult { + let argument = check_one_argument(arguments, location)?; + let item = get_item(argument)?; + + let mut hasher = std::collections::hash_map::DefaultHasher::new(); + item.hash(&mut hasher); + let hash = hasher.finish(); + Ok(Value::Field((hash as u128).into())) +} + +pub(super) fn eq_item( + arguments: Vec<(Value, Location)>, + location: Location, + mut get_item: impl FnMut((Value, Location)) -> IResult, +) -> IResult { + let (self_arg, other_arg) = check_two_arguments(arguments, location)?; + let self_arg = get_item(self_arg)?; + let other_arg = get_item(other_arg)?; + Ok(Value::Bool(self_arg == other_arg)) +} diff --git a/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/value.rs b/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/value.rs index f6450175955..4eee59489a9 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/value.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/hir/comptime/value.rs @@ -405,6 +405,11 @@ impl Value { } Value::Quoted(tokens) => HirExpression::Unquote(add_token_spans(tokens, location.span)), Value::TypedExpr(TypedExpr::ExprId(expr_id)) => interner.expression(&expr_id), + // Only convert pointers with auto_deref = true. These are mutable variables + // and we don't need to wrap them in `&mut`. + Value::Pointer(element, true) => { + return element.unwrap_or_clone().into_hir_expression(interner, location); + } Value::TypedExpr(TypedExpr::StmtId(..)) | Value::Expr(..) | Value::Pointer(..) diff --git a/noir/noir-repo/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs b/noir/noir-repo/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs index d93b708c91d..57c7fdd9cdb 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs @@ -12,7 +12,7 @@ use rustc_hash::FxHashMap as HashMap; use crate::ast::{ Documented, FunctionDefinition, Ident, ItemVisibility, LetStatement, ModuleDeclaration, - NoirFunction, NoirStruct, NoirTrait, NoirTraitImpl, NoirTypeAlias, Pattern, TraitImplItem, + NoirFunction, NoirStruct, NoirTrait, NoirTraitImpl, NoirTypeAlias, Pattern, TraitImplItemKind, TraitItem, TypeImpl, }; use crate::hir::resolution::errors::ResolverError; @@ -1124,18 +1124,18 @@ pub(crate) fn collect_trait_impl_items( let module = ModuleId { krate, local_id }; for item in std::mem::take(&mut trait_impl.items) { - match item.item { - TraitImplItem::Function(impl_method) => { + match item.item.kind { + TraitImplItemKind::Function(impl_method) => { let func_id = interner.push_empty_fn(); let location = Location::new(impl_method.span(), file_id); interner.push_function(func_id, &impl_method.def, module, location); interner.set_doc_comments(ReferenceId::Function(func_id), item.doc_comments); unresolved_functions.push_fn(local_id, func_id, impl_method); } - TraitImplItem::Constant(name, typ, expr) => { + TraitImplItemKind::Constant(name, typ, expr) => { associated_constants.push((name, typ, expr)); } - TraitImplItem::Type { name, alias } => { + TraitImplItemKind::Type { name, alias } => { associated_types.push((name, alias)); } } diff --git a/noir/noir-repo/compiler/noirc_frontend/src/hir/def_map/module_data.rs b/noir/noir-repo/compiler/noirc_frontend/src/hir/def_map/module_data.rs index e829df3572c..6a0f472ef75 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/hir/def_map/module_data.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/hir/def_map/module_data.rs @@ -26,8 +26,7 @@ pub struct ModuleData { /// True if this module is a `contract Foo { ... }` module containing contract functions pub is_contract: bool, - pub outer_attributes: Vec, - pub inner_attributes: Vec, + pub attributes: Vec, } impl ModuleData { @@ -38,11 +37,8 @@ impl ModuleData { inner_attributes: Vec, is_contract: bool, ) -> ModuleData { - let outer_attributes = outer_attributes.iter().filter_map(|attr| attr.as_custom()); - let outer_attributes = outer_attributes.map(|attr| attr.contents.to_string()).collect(); - - let inner_attributes = inner_attributes.iter().filter_map(|attr| attr.as_custom()); - let inner_attributes = inner_attributes.map(|attr| attr.contents.to_string()).collect(); + let mut attributes = outer_attributes; + attributes.extend(inner_attributes); ModuleData { parent, @@ -51,8 +47,7 @@ impl ModuleData { definitions: ItemScope::default(), location, is_contract, - outer_attributes, - inner_attributes, + attributes, } } diff --git a/noir/noir-repo/compiler/noirc_frontend/src/hir/resolution/errors.rs b/noir/noir-repo/compiler/noirc_frontend/src/hir/resolution/errors.rs index ec22c8f1986..cb726a01dec 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/hir/resolution/errors.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/hir/resolution/errors.rs @@ -128,6 +128,8 @@ pub enum ResolverError { QuoteInRuntimeCode { span: Span }, #[error("Comptime-only type `{typ}` cannot be used in runtime code")] ComptimeTypeInRuntimeCode { typ: String, span: Span }, + #[error("Comptime variable `{name}` cannot be mutated in a non-comptime context")] + MutatingComptimeInNonComptimeContext { name: String, span: Span }, } impl ResolverError { @@ -522,6 +524,13 @@ impl<'a> From<&'a ResolverError> for Diagnostic { *span, ) }, + ResolverError::MutatingComptimeInNonComptimeContext { name, span } => { + Diagnostic::simple_error( + format!("Comptime variable `{name}` cannot be mutated in a non-comptime context"), + format!("`{name}` mutated here"), + *span, + ) + }, } } } diff --git a/noir/noir-repo/compiler/noirc_frontend/src/hir_def/types.rs b/noir/noir-repo/compiler/noirc_frontend/src/hir_def/types.rs index d47e6522756..bcbcc8ad789 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/hir_def/types.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/hir_def/types.rs @@ -471,6 +471,16 @@ impl Shared { pub fn borrow_mut(&self) -> std::cell::RefMut { self.0.borrow_mut() } + + pub fn unwrap_or_clone(self) -> T + where + T: Clone, + { + match Rc::try_unwrap(self.0) { + Ok(elem) => elem.into_inner(), + Err(rc) => rc.as_ref().clone().into_inner(), + } + } } /// A restricted subset of binary operators useable on @@ -1620,8 +1630,18 @@ impl Type { (InfixExpr(lhs_a, op_a, rhs_a), InfixExpr(lhs_b, op_b, rhs_b)) => { if op_a == op_b { - lhs_a.try_unify(lhs_b, bindings)?; - rhs_a.try_unify(rhs_b, bindings) + // We need to preserve the original bindings since if syntactic equality + // fails we fall back to other equality strategies. + let mut new_bindings = bindings.clone(); + let lhs_result = lhs_a.try_unify(lhs_b, &mut new_bindings); + let rhs_result = rhs_a.try_unify(rhs_b, &mut new_bindings); + + if lhs_result.is_ok() && rhs_result.is_ok() { + *bindings = new_bindings; + Ok(()) + } else { + lhs.try_unify_by_moving_constant_terms(&rhs, bindings) + } } else { Err(UnificationError) } diff --git a/noir/noir-repo/compiler/noirc_frontend/src/hir_def/types/arithmetic.rs b/noir/noir-repo/compiler/noirc_frontend/src/hir_def/types/arithmetic.rs index ad07185dff1..44a7526c894 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/hir_def/types/arithmetic.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/hir_def/types/arithmetic.rs @@ -1,6 +1,6 @@ use std::collections::BTreeSet; -use crate::{BinaryTypeOperator, Type}; +use crate::{BinaryTypeOperator, Type, TypeBindings, UnificationError}; impl Type { /// Try to canonicalize the representation of this type. @@ -212,4 +212,44 @@ impl Type { _ => None, } } + + /// Try to unify equations like `(..) + 3 = (..) + 1` + /// by transforming them to `(..) + 2 = (..)` + pub(super) fn try_unify_by_moving_constant_terms( + &self, + other: &Type, + bindings: &mut TypeBindings, + ) -> Result<(), UnificationError> { + if let Type::InfixExpr(lhs_a, op_a, rhs_a) = self { + if let Some(inverse) = op_a.inverse() { + if let Some(rhs_a) = rhs_a.evaluate_to_u32() { + let rhs_a = Box::new(Type::Constant(rhs_a)); + let new_other = Type::InfixExpr(Box::new(other.clone()), inverse, rhs_a); + + let mut tmp_bindings = bindings.clone(); + if lhs_a.try_unify(&new_other, &mut tmp_bindings).is_ok() { + *bindings = tmp_bindings; + return Ok(()); + } + } + } + } + + if let Type::InfixExpr(lhs_b, op_b, rhs_b) = other { + if let Some(inverse) = op_b.inverse() { + if let Some(rhs_b) = rhs_b.evaluate_to_u32() { + let rhs_b = Box::new(Type::Constant(rhs_b)); + let new_self = Type::InfixExpr(Box::new(self.clone()), inverse, rhs_b); + + let mut tmp_bindings = bindings.clone(); + if new_self.try_unify(lhs_b, &mut tmp_bindings).is_ok() { + *bindings = tmp_bindings; + return Ok(()); + } + } + } + } + + Err(UnificationError) + } } diff --git a/noir/noir-repo/compiler/noirc_frontend/src/lexer/token.rs b/noir/noir-repo/compiler/noirc_frontend/src/lexer/token.rs index f5f7f0458d7..012b21a8904 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/lexer/token.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/lexer/token.rs @@ -10,6 +10,8 @@ use crate::{ }, }; +use super::Lexer; + /// Represents a token in noir's grammar - a word, number, /// or symbol that can be used in noir's syntax. This is the /// smallest unit of grammar. A parser may (will) decide to parse @@ -362,11 +364,11 @@ impl fmt::Display for Token { Token::Ident(ref s) => write!(f, "{s}"), Token::Int(n) => write!(f, "{}", n.to_u128()), Token::Bool(b) => write!(f, "{b}"), - Token::Str(ref b) => write!(f, "{b}"), - Token::FmtStr(ref b) => write!(f, "f{b}"), + Token::Str(ref b) => write!(f, "{b:?}"), + Token::FmtStr(ref b) => write!(f, "f{b:?}"), Token::RawStr(ref b, hashes) => { let h: String = std::iter::once('#').cycle().take(hashes as usize).collect(); - write!(f, "r{h}\"{b}\"{h}") + write!(f, "r{h}{b:?}{h}") } Token::Keyword(k) => write!(f, "{k}"), Token::Attribute(ref a) => write!(f, "{a}"), @@ -868,6 +870,18 @@ impl FunctionAttribute { pub fn is_no_predicates(&self) -> bool { matches!(self, FunctionAttribute::NoPredicates) } + + pub fn name(&self) -> &'static str { + match self { + FunctionAttribute::Foreign(_) => "foreign", + FunctionAttribute::Builtin(_) => "builtin", + FunctionAttribute::Oracle(_) => "oracle", + FunctionAttribute::Test(_) => "test", + FunctionAttribute::Recursive => "recursive", + FunctionAttribute::Fold => "fold", + FunctionAttribute::NoPredicates => "no_predicates", + } + } } impl fmt::Display for FunctionAttribute { @@ -903,15 +917,6 @@ pub enum SecondaryAttribute { Varargs, } -#[derive(PartialEq, Eq, Hash, Debug, Clone, PartialOrd, Ord)] -pub struct CustomAtrribute { - pub contents: String, - // The span of the entire attribute, including leading `#[` and trailing `]` - pub span: Span, - // The span for the attribute contents (what's inside `#[...]`) - pub contents_span: Span, -} - impl SecondaryAttribute { pub(crate) fn as_custom(&self) -> Option<&CustomAtrribute> { if let Self::Custom(attribute) = self { @@ -920,6 +925,20 @@ impl SecondaryAttribute { None } } + + pub(crate) fn name(&self) -> Option { + match self { + SecondaryAttribute::Deprecated(_) => Some("deprecated".to_string()), + SecondaryAttribute::ContractLibraryMethod => { + Some("contract_library_method".to_string()) + } + SecondaryAttribute::Export => Some("export".to_string()), + SecondaryAttribute::Field(_) => Some("field".to_string()), + SecondaryAttribute::Custom(custom) => custom.name(), + SecondaryAttribute::Abi(_) => Some("abi".to_string()), + SecondaryAttribute::Varargs => Some("varargs".to_string()), + } + } } impl fmt::Display for SecondaryAttribute { @@ -939,6 +958,27 @@ impl fmt::Display for SecondaryAttribute { } } +#[derive(PartialEq, Eq, Hash, Debug, Clone, PartialOrd, Ord)] +pub struct CustomAtrribute { + pub contents: String, + // The span of the entire attribute, including leading `#[` and trailing `]` + pub span: Span, + // The span for the attribute contents (what's inside `#[...]`) + pub contents_span: Span, +} + +impl CustomAtrribute { + fn name(&self) -> Option { + let mut lexer = Lexer::new(&self.contents); + let token = lexer.next()?.ok()?; + if let Token::Ident(ident) = token.into_token() { + Some(ident) + } else { + None + } + } +} + impl AsRef for FunctionAttribute { fn as_ref(&self) -> &str { match self { diff --git a/noir/noir-repo/compiler/noirc_frontend/src/parser/parser/traits.rs b/noir/noir-repo/compiler/noirc_frontend/src/parser/parser/traits.rs index cb17bf2caf7..58db2465f22 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/parser/parser/traits.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/parser/parser/traits.rs @@ -10,9 +10,10 @@ use super::{ use crate::ast::{ Documented, Expression, ItemVisibility, NoirTrait, NoirTraitImpl, TraitBound, TraitImplItem, - TraitItem, UnresolvedTraitConstraint, UnresolvedType, + TraitImplItemKind, TraitItem, UnresolvedTraitConstraint, UnresolvedType, }; use crate::macros_api::Pattern; +use crate::parser::spanned; use crate::{ parser::{ ignore_then_commit, parenthesized, parser::primitives::keyword, NoirParser, ParserError, @@ -173,7 +174,7 @@ fn trait_implementation_body() -> impl NoirParser> } // Trait impl functions are always public f.def_mut().visibility = ItemVisibility::Public; - TraitImplItem::Function(f) + TraitImplItemKind::Function(f) }); let alias = keyword(Keyword::Type) @@ -181,11 +182,11 @@ fn trait_implementation_body() -> impl NoirParser> .then_ignore(just(Token::Assign)) .then(parse_type()) .then_ignore(just(Token::Semicolon)) - .map(|(name, alias)| TraitImplItem::Type { name, alias }); + .map(|(name, alias)| TraitImplItemKind::Type { name, alias }); let let_statement = let_statement(expression()).then_ignore(just(Token::Semicolon)).try_map( |((pattern, typ), expr), span| match pattern { - Pattern::Identifier(ident) => Ok(TraitImplItem::Constant(ident, typ, expr)), + Pattern::Identifier(ident) => Ok(TraitImplItemKind::Constant(ident, typ, expr)), _ => Err(ParserError::with_reason( ParserErrorReason::PatternInTraitFunctionParameter, span, @@ -195,7 +196,7 @@ fn trait_implementation_body() -> impl NoirParser> let item = choice((function, alias, let_statement)); outer_doc_comments() - .then(item) + .then(spanned(item).map(|(kind, span)| TraitImplItem { kind, span })) .map(|(doc_comments, item)| Documented::new(item, doc_comments)) .repeated() } diff --git a/noir/noir-repo/compiler/wasm/scripts/install_wasm-pack.sh b/noir/noir-repo/compiler/wasm/scripts/install_wasm-pack.sh index b0fdffe0458..8936dd86fb7 100755 --- a/noir/noir-repo/compiler/wasm/scripts/install_wasm-pack.sh +++ b/noir/noir-repo/compiler/wasm/scripts/install_wasm-pack.sh @@ -3,10 +3,7 @@ set -eu cd $(dirname "$0")/.. -# Install wasm-pack -CARGO_BINSTALL_CHECK=$(./scripts/command-check.sh cargo-binstall) -if [ $CARGO_BINSTALL_CHECK != "true" ]; then - curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash -fi +../../.github/scripts/cargo-binstall-install.sh +# Install wasm-pack cargo-binstall wasm-pack@0.12.1 -y --force diff --git a/noir/noir-repo/cspell.json b/noir/noir-repo/cspell.json index 293523d7c15..4d83c535e7d 100644 --- a/noir/noir-repo/cspell.json +++ b/noir/noir-repo/cspell.json @@ -25,6 +25,7 @@ "bindgen", "bitand", "bitmask", + "bitsize", "blackbox", "boilerplate", "boilerplates", diff --git a/noir/noir-repo/docs/docs/noir/concepts/data_types/arrays.md b/noir/noir-repo/docs/docs/noir/concepts/data_types/arrays.md index e5e9f5a1d3b..d0d8eb70aa6 100644 --- a/noir/noir-repo/docs/docs/noir/concepts/data_types/arrays.md +++ b/noir/noir-repo/docs/docs/noir/concepts/data_types/arrays.md @@ -128,7 +128,9 @@ fn main() { ### sort_via -Sorts the array with a custom comparison function +Sorts the array with a custom comparison function. The ordering function must return true if the first argument should be sorted to be before the second argument or is equal to the second argument. + +Using this method with an operator like `<` that does not return `true` for equal values will result in an assertion failure for arrays with equal elements. ```rust fn sort_via(self, ordering: fn(T, T) -> bool) -> [T; N] @@ -139,10 +141,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/docs/noir/concepts/generics.md b/noir/noir-repo/docs/docs/noir/concepts/generics.md index f05540f9f55..6dbde4ed53b 100644 --- a/noir/noir-repo/docs/docs/noir/concepts/generics.md +++ b/noir/noir-repo/docs/docs/noir/concepts/generics.md @@ -197,7 +197,7 @@ impl Serialize for (T, U) fn main() { let data = (1, [2, 3, 4]); - assert(data.serialize().len(), 4); + assert_eq(data.serialize().len(), 4); } ``` diff --git a/noir/noir-repo/docs/docs/noir/standard_library/meta/function_def.md b/noir/noir-repo/docs/docs/noir/standard_library/meta/function_def.md index c9fa3b345f0..583771aeb73 100644 --- a/noir/noir-repo/docs/docs/noir/standard_library/meta/function_def.md +++ b/noir/noir-repo/docs/docs/noir/standard_library/meta/function_def.md @@ -101,3 +101,14 @@ This means any functions called at compile-time are invalid targets for this met Mutates the function to be unconstrained (if `true` is given) or not (if `false` is given). This is only valid on functions in the current crate which have not yet been resolved. This means any functions called at compile-time are invalid targets for this method. + +## Trait Implementations + +```rust +impl Eq for FunctionDefinition +impl Hash for FunctionDefinition +``` + +Note that each function is assigned a unique ID internally and this is what is used for +equality and hashing. So even functions with identical signatures and bodies may not +be equal in this sense if they were originally different items in the source program. diff --git a/noir/noir-repo/docs/docs/noir/standard_library/meta/module.md b/noir/noir-repo/docs/docs/noir/standard_library/meta/module.md index de042760d51..2765718dd7b 100644 --- a/noir/noir-repo/docs/docs/noir/standard_library/meta/module.md +++ b/noir/noir-repo/docs/docs/noir/standard_library/meta/module.md @@ -16,17 +16,11 @@ Adds a top-level item (a function, a struct, a global, etc.) to the module. Adding multiple items in one go is also valid if the `Quoted` value has multiple items in it. Note that the items are type-checked as if they are inside the module they are being added to. -### name - -#include_code name noir_stdlib/src/meta/module.nr rust - -Returns the name of the module. - ### functions #include_code functions noir_stdlib/src/meta/module.nr rust -Returns each function in the module. +Returns each function defined in the module. ### has_named_attribute @@ -39,3 +33,26 @@ Returns true if this module has a custom attribute with the given name. #include_code is_contract noir_stdlib/src/meta/module.nr rust `true` if this module is a contract module (was declared via `contract foo { ... }`). + +### name + +#include_code name noir_stdlib/src/meta/module.nr rust + +Returns the name of the module. + +### structs + +#include_code structs noir_stdlib/src/meta/module.nr rust + +Returns each struct defined in the module. + +## Trait Implementations + +```rust +impl Eq for Module +impl Hash for Module +``` + +Note that each module is assigned a unique ID internally and this is what is used for +equality and hashing. So even modules with identical names and contents may not +be equal in this sense if they were originally different items in the source program. diff --git a/noir/noir-repo/docs/docs/noir/standard_library/meta/op.md b/noir/noir-repo/docs/docs/noir/standard_library/meta/op.md index d8b154edc02..55d2d244344 100644 --- a/noir/noir-repo/docs/docs/noir/standard_library/meta/op.md +++ b/noir/noir-repo/docs/docs/noir/standard_library/meta/op.md @@ -43,6 +43,13 @@ Returns `true` if this operator is `-`. Returns this operator as a `Quoted` value. +### Trait Implementations + +```rust +impl Eq for UnaryOp +impl Hash for UnaryOp +``` + ### BinaryOp Represents a binary operator. One of `+`, `-`, `*`, `/`, `%`, `==`, `!=`, `<`, `<=`, `>`, `>=`, `&`, `|`, `^`, `>>`, or `<<`. @@ -143,4 +150,11 @@ Represents a binary operator. One of `+`, `-`, `*`, `/`, `%`, `==`, `!=`, `<`, ` #include_code binary_quoted noir_stdlib/src/meta/op.nr rust -Returns this operator as a `Quoted` value. \ No newline at end of file +Returns this operator as a `Quoted` value. + +### Trait Implementations + +```rust +impl Eq for BinaryOp +impl Hash for BinaryOp +``` diff --git a/noir/noir-repo/docs/docs/noir/standard_library/meta/quoted.md b/noir/noir-repo/docs/docs/noir/standard_library/meta/quoted.md index ac075d96648..11dacd51fcb 100644 --- a/noir/noir-repo/docs/docs/noir/standard_library/meta/quoted.md +++ b/noir/noir-repo/docs/docs/noir/standard_library/meta/quoted.md @@ -60,4 +60,5 @@ Returns a slice of the individual tokens that form this token stream. ```rust impl Eq for Quoted +impl Hash for Quoted ``` diff --git a/noir/noir-repo/docs/docs/noir/standard_library/meta/struct_def.md b/noir/noir-repo/docs/docs/noir/standard_library/meta/struct_def.md index c088e538fc9..535708e0353 100644 --- a/noir/noir-repo/docs/docs/noir/standard_library/meta/struct_def.md +++ b/noir/noir-repo/docs/docs/noir/standard_library/meta/struct_def.md @@ -117,3 +117,14 @@ comptime fn mangle_fields(s: StructDefinition) { ]); } ``` + +## Trait Implementations + +```rust +impl Eq for StructDefinition +impl Hash for StructDefinition +``` + +Note that each struct is assigned a unique ID internally and this is what is used for +equality and hashing. So even structs with identical generics and fields may not +be equal in this sense if they were originally different items in the source program. diff --git a/noir/noir-repo/docs/docs/noir/standard_library/meta/typ.md b/noir/noir-repo/docs/docs/noir/standard_library/meta/typ.md index 1334092a9fa..5a8b43b1dfa 100644 --- a/noir/noir-repo/docs/docs/noir/standard_library/meta/typ.md +++ b/noir/noir-repo/docs/docs/noir/standard_library/meta/typ.md @@ -150,7 +150,8 @@ fn foo() where T: Default { ```rust impl Eq for Type +impl Hash for Type ``` Note that this is syntactic equality, this is not the same as whether two types will type check to be the same type. Unless type inference or generics are being used however, users should not -typically have to worry about this distinction. +typically have to worry about this distinction unless `std::meta::typ::fresh_type_variable` is used. diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.17.0/language_concepts/data_types/04_arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.17.0/language_concepts/data_types/04_arrays.md index 1424ca2df14..3c84da3f8ad 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.17.0/language_concepts/data_types/04_arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.17.0/language_concepts/data_types/04_arrays.md @@ -130,10 +130,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.19.0/language_concepts/data_types/04_arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.19.0/language_concepts/data_types/04_arrays.md index 1424ca2df14..3c84da3f8ad 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.19.0/language_concepts/data_types/04_arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.19.0/language_concepts/data_types/04_arrays.md @@ -130,10 +130,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.19.1/language_concepts/data_types/04_arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.19.1/language_concepts/data_types/04_arrays.md index 1424ca2df14..3c84da3f8ad 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.19.1/language_concepts/data_types/04_arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.19.1/language_concepts/data_types/04_arrays.md @@ -130,10 +130,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.19.2/language_concepts/data_types/04_arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.19.2/language_concepts/data_types/04_arrays.md index 1424ca2df14..3c84da3f8ad 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.19.2/language_concepts/data_types/04_arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.19.2/language_concepts/data_types/04_arrays.md @@ -130,10 +130,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.19.3/language_concepts/data_types/04_arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.19.3/language_concepts/data_types/04_arrays.md index 1424ca2df14..3c84da3f8ad 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.19.3/language_concepts/data_types/04_arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.19.3/language_concepts/data_types/04_arrays.md @@ -130,10 +130,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.19.4/language_concepts/data_types/04_arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.19.4/language_concepts/data_types/04_arrays.md index 5b4a544cf37..36410468ec1 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.19.4/language_concepts/data_types/04_arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.19.4/language_concepts/data_types/04_arrays.md @@ -130,10 +130,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.22.0/noir/syntax/data_types/arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.22.0/noir/syntax/data_types/arrays.md index 4c80d50ed01..addda1da8bc 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.22.0/noir/syntax/data_types/arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.22.0/noir/syntax/data_types/arrays.md @@ -131,10 +131,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.23.0/noir/concepts/data_types/arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.23.0/noir/concepts/data_types/arrays.md index d95346454a9..fb81dcc3970 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.23.0/noir/concepts/data_types/arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.23.0/noir/concepts/data_types/arrays.md @@ -137,10 +137,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.24.0/noir/concepts/data_types/arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.24.0/noir/concepts/data_types/arrays.md index ca54d82b26b..9a4c485feb1 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.24.0/noir/concepts/data_types/arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.24.0/noir/concepts/data_types/arrays.md @@ -139,10 +139,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/arrays.md index ca54d82b26b..9a4c485feb1 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/arrays.md @@ -139,10 +139,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.26.0/noir/concepts/data_types/arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.26.0/noir/concepts/data_types/arrays.md index 95d749053e2..9b02d52e8a8 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.26.0/noir/concepts/data_types/arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.26.0/noir/concepts/data_types/arrays.md @@ -139,10 +139,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.27.0/noir/concepts/data_types/arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.27.0/noir/concepts/data_types/arrays.md index 95d749053e2..9b02d52e8a8 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.27.0/noir/concepts/data_types/arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.27.0/noir/concepts/data_types/arrays.md @@ -139,10 +139,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.28.0/noir/concepts/data_types/arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.28.0/noir/concepts/data_types/arrays.md index 95d749053e2..9b02d52e8a8 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.28.0/noir/concepts/data_types/arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.28.0/noir/concepts/data_types/arrays.md @@ -139,10 +139,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.29.0/noir/concepts/data_types/arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.29.0/noir/concepts/data_types/arrays.md index 95d749053e2..9b02d52e8a8 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.29.0/noir/concepts/data_types/arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.29.0/noir/concepts/data_types/arrays.md @@ -139,10 +139,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.30.0/noir/concepts/data_types/arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.30.0/noir/concepts/data_types/arrays.md index 95d749053e2..9b02d52e8a8 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.30.0/noir/concepts/data_types/arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.30.0/noir/concepts/data_types/arrays.md @@ -139,10 +139,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.31.0/noir/concepts/data_types/arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.31.0/noir/concepts/data_types/arrays.md index 95d749053e2..9b02d52e8a8 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.31.0/noir/concepts/data_types/arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.31.0/noir/concepts/data_types/arrays.md @@ -139,10 +139,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.32.0/noir/concepts/data_types/arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.32.0/noir/concepts/data_types/arrays.md index 9a4ab5d3c1f..d26f6dff070 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.32.0/noir/concepts/data_types/arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.32.0/noir/concepts/data_types/arrays.md @@ -139,10 +139,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/docs/versioned_docs/version-v0.33.0/noir/concepts/data_types/arrays.md b/noir/noir-repo/docs/versioned_docs/version-v0.33.0/noir/concepts/data_types/arrays.md index 9a4ab5d3c1f..d26f6dff070 100644 --- a/noir/noir-repo/docs/versioned_docs/version-v0.33.0/noir/concepts/data_types/arrays.md +++ b/noir/noir-repo/docs/versioned_docs/version-v0.33.0/noir/concepts/data_types/arrays.md @@ -139,10 +139,10 @@ example ```rust fn main() { let arr = [42, 32] - let sorted_ascending = arr.sort_via(|a, b| a < b); + let sorted_ascending = arr.sort_via(|a, b| a <= b); assert(sorted_ascending == [32, 42]); // verifies - let sorted_descending = arr.sort_via(|a, b| a > b); + let sorted_descending = arr.sort_via(|a, b| a >= b); assert(sorted_descending == [32, 42]); // does not verify } ``` diff --git a/noir/noir-repo/noir_stdlib/src/array/check_shuffle.nr b/noir/noir-repo/noir_stdlib/src/array/check_shuffle.nr new file mode 100644 index 00000000000..26f5ced3467 --- /dev/null +++ b/noir/noir-repo/noir_stdlib/src/array/check_shuffle.nr @@ -0,0 +1,116 @@ +use crate::cmp::Eq; + +unconstrained fn __get_shuffle_indices(lhs: [T; N], rhs: [T; N]) -> [Field; N] where T: Eq { + let mut shuffle_indices: [Field;N ] = [0; N]; + + let mut shuffle_mask: [bool; N] = [false; N]; + for i in 0..N { + let mut found = false; + for j in 0..N { + if ((shuffle_mask[j] == false) & (!found)) { + if (lhs[i] == rhs[j]) { + found = true; + shuffle_indices[i] = j as Field; + shuffle_mask[j] = true; + } + } + if (found) { + continue; + } + } + assert(found == true, "check_shuffle, lhs and rhs arrays do not contain equivalent values"); + } + + shuffle_indices +} + +unconstrained fn __get_index(indices: [Field; N], idx: Field) -> Field { + let mut result = 0; + for i in 0..N { + if (indices[i] == idx) { + result = i as Field; + break; + } + } + result +} + +pub(crate) fn check_shuffle(lhs: [T; N], rhs: [T; N]) where T: Eq { + unsafe { + let shuffle_indices = __get_shuffle_indices(lhs, rhs); + + for i in 0..N { + let idx = __get_index(shuffle_indices, i as Field); + assert_eq(shuffle_indices[idx], i as Field); + } + for i in 0..N { + let idx = shuffle_indices[i]; + let expected = rhs[idx]; + let result = lhs[i]; + assert_eq(expected, result); + } + } +} + +mod test { + use super::check_shuffle; + use crate::cmp::Eq; + + struct CompoundStruct { + a: bool, + b: Field, + c: u64 + } + impl Eq for CompoundStruct { + fn eq(self, other: Self) -> bool { + (self.a == other.a) & (self.b == other.b) & (self.c == other.c) + } + } + + #[test] + fn test_shuffle() { + let lhs: [Field; 5] = [0, 1, 2, 3, 4]; + let rhs: [Field; 5] = [2, 0, 3, 1, 4]; + check_shuffle(lhs, rhs); + } + + #[test] + fn test_shuffle_identity() { + let lhs: [Field; 5] = [0, 1, 2, 3, 4]; + let rhs: [Field; 5] = [0, 1, 2, 3, 4]; + check_shuffle(lhs, rhs); + } + + #[test(should_fail_with = "check_shuffle, lhs and rhs arrays do not contain equivalent values")] + fn test_shuffle_fail() { + let lhs: [Field; 5] = [0, 1, 2, 3, 4]; + let rhs: [Field; 5] = [0, 1, 2, 3, 5]; + check_shuffle(lhs, rhs); + } + + #[test(should_fail_with = "check_shuffle, lhs and rhs arrays do not contain equivalent values")] + fn test_shuffle_duplicates() { + let lhs: [Field; 5] = [0, 1, 2, 3, 4]; + let rhs: [Field; 5] = [0, 1, 2, 3, 3]; + check_shuffle(lhs, rhs); + } + + #[test] + fn test_shuffle_compound_struct() { + let lhs: [CompoundStruct; 5] = [ + CompoundStruct { a: false, b: 0, c: 12345 }, + CompoundStruct { a: false, b: -100, c: 54321 }, + CompoundStruct { a: true, b: 5, c: 0xffffffffffffffff }, + CompoundStruct { a: true, b: 9814, c: 0xeeffee0011001133 }, + CompoundStruct { a: false, b: 0x155, c: 0 } + ]; + let rhs: [CompoundStruct; 5] = [ + CompoundStruct { a: false, b: 0x155, c: 0 }, + CompoundStruct { a: false, b: 0, c: 12345 }, + CompoundStruct { a: false, b: -100, c: 54321 }, + CompoundStruct { a: true, b: 9814, c: 0xeeffee0011001133 }, + CompoundStruct { a: true, b: 5, c: 0xffffffffffffffff } + ]; + check_shuffle(lhs, rhs); + } +} diff --git a/noir/noir-repo/noir_stdlib/src/array.nr b/noir/noir-repo/noir_stdlib/src/array/mod.nr similarity index 57% rename from noir/noir-repo/noir_stdlib/src/array.nr rename to noir/noir-repo/noir_stdlib/src/array/mod.nr index 68e134b56fa..f3cf6b78081 100644 --- a/noir/noir-repo/noir_stdlib/src/array.nr +++ b/noir/noir-repo/noir_stdlib/src/array/mod.nr @@ -1,63 +1,15 @@ -use crate::cmp::Ord; +use crate::cmp::{Eq, Ord}; use crate::convert::From; +use crate::runtime::is_unconstrained; + +mod check_shuffle; +mod quicksort; impl [T; N] { /// Returns the length of the slice. #[builtin(array_len)] pub fn len(self) -> u32 {} - pub fn sort(self) -> Self where T: Ord { - self.sort_via(|a: T, b: T| a <= b) - } - - pub fn sort_via(self, ordering: fn[Env](T, T) -> bool) -> Self { - let sorted_index = unsafe { - // Safety: These indices are asserted to be the sorted element indices via `find_index` - let sorted_index: [u32; N] = self.get_sorting_index(ordering); - - for i in 0..N { - let pos = find_index(sorted_index, i); - assert(sorted_index[pos] == i); - } - - sorted_index - }; - - // Sort the array using the indexes - let mut result = self; - for i in 0..N { - result[i] = self[sorted_index[i]]; - } - // Ensure the array is sorted - for i in 0..N - 1 { - assert(ordering(result[i], result[i + 1])); - } - - result - } - - /// Returns the index of the elements in the array that would sort it, using the provided custom sorting function. - unconstrained fn get_sorting_index(self, ordering: fn[Env](T, T) -> bool) -> [u32; N] { - let mut result = [0; N]; - let mut a = self; - for i in 0..N { - result[i] = i; - } - for i in 1..N { - for j in 0..i { - if ordering(a[i], a[j]) { - let old_a_j = a[j]; - a[j] = a[i]; - a[i] = old_a_j; - let old_j = result[j]; - result[j] = result[i]; - result[i] = old_j; - } - } - } - result - } - #[builtin(as_slice)] pub fn as_slice(self) -> [T] {} @@ -114,6 +66,38 @@ impl [T; N] { } } +impl [T; N] where T: Ord + Eq { + pub fn sort(self) -> Self { + self.sort_via(|a: T, b: T| a <= b) + } +} + +impl [T; N] where T: Eq { + + /// Sorts the array using a custom predicate function `ordering`. + /// + /// The `ordering` function must be designed to return `true` for equal valued inputs + /// If this is not done, `sort_via` will fail to sort inputs with duplicated elements. + pub fn sort_via(self, ordering: fn[Env](T, T) -> bool) -> Self { + unsafe { + // Safety: `sorted` array is checked to be: + // a. a permutation of `input`'s elements + // b. satisfying the predicate `ordering` + let sorted = quicksort::quicksort(self, ordering); + + if !is_unconstrained() { + for i in 0..N - 1 { + assert( + ordering(sorted[i], sorted[i + 1]), "Array has not been sorted correctly according to `ordering`." + ); + } + check_shuffle::check_shuffle(self, sorted); + } + sorted + } + } +} + impl [u8; N] { /// Convert a sequence of bytes as-is into a string. /// This function performs no UTF-8 validation or similar. @@ -121,18 +105,6 @@ impl [u8; N] { pub fn as_str_unchecked(self) -> str {} } -// helper function used to look up the position of a value in an array of Field -// Note that function returns 0 if the value is not found -unconstrained fn find_index(a: [u32; N], find: u32) -> u32 { - let mut result = 0; - for i in 0..a.len() { - if a[i] == find { - result = i; - } - } - result -} - impl From> for [u8; N] { fn from(s: str) -> Self { s.as_bytes() diff --git a/noir/noir-repo/noir_stdlib/src/array/quicksort.nr b/noir/noir-repo/noir_stdlib/src/array/quicksort.nr new file mode 100644 index 00000000000..6a54ed246f5 --- /dev/null +++ b/noir/noir-repo/noir_stdlib/src/array/quicksort.nr @@ -0,0 +1,39 @@ +unconstrained fn partition( + arr: &mut [T; N], + low: u32, + high: u32, + sortfn: fn[Env](T, T) -> bool +) -> u32 { + let pivot = high; + let mut i = low; + for j in low..high { + if (sortfn(arr[j], arr[pivot])) { + let temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + i += 1; + } + } + let temp = arr[i]; + arr[i] = arr[pivot]; + arr[pivot] = temp; + i +} + +unconstrained fn quicksort_recursive(arr: &mut [T; N], low: u32, high: u32, sortfn: fn[Env](T, T) -> bool) { + if low < high { + let pivot_index = partition(arr, low, high, sortfn); + if pivot_index > 0 { + quicksort_recursive(arr, low, pivot_index - 1, sortfn); + } + quicksort_recursive(arr, pivot_index + 1, high, sortfn); + } +} + +unconstrained pub(crate) fn quicksort(_arr: [T; N], sortfn: fn[Env](T, T) -> bool) -> [T; N] { + let mut arr: [T; N] = _arr; + if arr.len() <= 1 {} else { + quicksort_recursive(&mut arr, 0, arr.len() - 1, sortfn); + } + arr +} diff --git a/noir/noir-repo/noir_stdlib/src/bigint.nr b/noir/noir-repo/noir_stdlib/src/bigint.nr index 81dad968bf7..34eca47046d 100644 --- a/noir/noir-repo/noir_stdlib/src/bigint.nr +++ b/noir/noir-repo/noir_stdlib/src/bigint.nr @@ -56,19 +56,15 @@ struct Secpk1Fq { impl BigField for Secpk1Fq { fn from_le_bytes(bytes: [u8]) -> Secpk1Fq { assert(bytes.len() <= 32); - let mut array = [0;32]; + let mut array = [0; 32]; for i in 0..bytes.len() { array[i] = bytes[i]; } - Secpk1Fq { - array: array, - } + Secpk1Fq { array } } - fn from_le_bytes_32(bytes: [u8;32]) -> Secpk1Fq { - Secpk1Fq { - array: bytes, - } + fn from_le_bytes_32(bytes: [u8; 32]) -> Secpk1Fq { + Secpk1Fq { array: bytes } } fn to_le_bytes(self) -> [u8] { @@ -76,40 +72,32 @@ impl BigField for Secpk1Fq { } } -impl Add for Secpk1Fq { +impl Add for Secpk1Fq { fn add(self: Self, other: Secpk1Fq) -> Secpk1Fq { let a = BigInt::from_le_bytes(self.array.as_slice(), secpk1_fq); let b = BigInt::from_le_bytes(other.array.as_slice(), secpk1_fq); - Secpk1Fq { - array: a.bigint_add(b).to_le_bytes() - } + Secpk1Fq { array: a.bigint_add(b).to_le_bytes() } } } -impl Sub for Secpk1Fq { +impl Sub for Secpk1Fq { fn sub(self: Self, other: Secpk1Fq) -> Secpk1Fq { let a = BigInt::from_le_bytes(self.array.as_slice(), secpk1_fq); let b = BigInt::from_le_bytes(other.array.as_slice(), secpk1_fq); - Secpk1Fq { - array: a.bigint_sub(b).to_le_bytes() - } + Secpk1Fq { array: a.bigint_sub(b).to_le_bytes() } } } -impl Mul for Secpk1Fq { +impl Mul for Secpk1Fq { fn mul(self: Self, other: Secpk1Fq) -> Secpk1Fq { let a = BigInt::from_le_bytes(self.array.as_slice(), secpk1_fq); let b = BigInt::from_le_bytes(other.array.as_slice(), secpk1_fq); - Secpk1Fq { - array: a.bigint_mul(b).to_le_bytes() - } + Secpk1Fq { array: a.bigint_mul(b).to_le_bytes() } } } -impl Div for Secpk1Fq { +impl Div for Secpk1Fq { fn div(self: Self, other: Secpk1Fq) -> Secpk1Fq { let a = BigInt::from_le_bytes(self.array.as_slice(), secpk1_fq); let b = BigInt::from_le_bytes(other.array.as_slice(), secpk1_fq); - Secpk1Fq { - array: a.bigint_div(b).to_le_bytes() - } + Secpk1Fq { array: a.bigint_div(b).to_le_bytes() } } } impl Eq for Secpk1Fq { @@ -125,60 +113,48 @@ struct Secpk1Fr { impl BigField for Secpk1Fr { fn from_le_bytes(bytes: [u8]) -> Secpk1Fr { assert(bytes.len() <= 32); - let mut array = [0;32]; + let mut array = [0; 32]; for i in 0..bytes.len() { array[i] = bytes[i]; } - Secpk1Fr { - array: array, - } + Secpk1Fr { array } } - fn from_le_bytes_32(bytes: [u8;32]) -> Secpk1Fr { - Secpk1Fr { - array: bytes, - } + fn from_le_bytes_32(bytes: [u8; 32]) -> Secpk1Fr { + Secpk1Fr { array: bytes } } - + fn to_le_bytes(self) -> [u8] { self.array } } -impl Add for Secpk1Fr { +impl Add for Secpk1Fr { fn add(self: Self, other: Secpk1Fr) -> Secpk1Fr { let a = BigInt::from_le_bytes(self.array.as_slice(), secpk1_fr); let b = BigInt::from_le_bytes(other.array.as_slice(), secpk1_fr); - Secpk1Fr { - array: a.bigint_add(b).to_le_bytes() - } + Secpk1Fr { array: a.bigint_add(b).to_le_bytes() } } } -impl Sub for Secpk1Fr { +impl Sub for Secpk1Fr { fn sub(self: Self, other: Secpk1Fr) -> Secpk1Fr { let a = BigInt::from_le_bytes(self.array.as_slice(), secpk1_fr); let b = BigInt::from_le_bytes(other.array.as_slice(), secpk1_fr); - Secpk1Fr { - array: a.bigint_sub(b).to_le_bytes() - } + Secpk1Fr { array: a.bigint_sub(b).to_le_bytes() } } } -impl Mul for Secpk1Fr { +impl Mul for Secpk1Fr { fn mul(self: Self, other: Secpk1Fr) -> Secpk1Fr { let a = BigInt::from_le_bytes(self.array.as_slice(), secpk1_fr); let b = BigInt::from_le_bytes(other.array.as_slice(), secpk1_fr); - Secpk1Fr { - array: a.bigint_mul(b).to_le_bytes() - } + Secpk1Fr { array: a.bigint_mul(b).to_le_bytes() } } } -impl Div for Secpk1Fr { +impl Div for Secpk1Fr { fn div(self: Self, other: Secpk1Fr) -> Secpk1Fr { let a = BigInt::from_le_bytes(self.array.as_slice(), secpk1_fr); let b = BigInt::from_le_bytes(other.array.as_slice(), secpk1_fr); - Secpk1Fr { - array: a.bigint_div(b).to_le_bytes() - } + Secpk1Fr { array: a.bigint_div(b).to_le_bytes() } } } impl Eq for Secpk1Fr { @@ -194,19 +170,15 @@ struct Bn254Fr { impl BigField for Bn254Fr { fn from_le_bytes(bytes: [u8]) -> Bn254Fr { assert(bytes.len() <= 32); - let mut array = [0;32]; + let mut array = [0; 32]; for i in 0..bytes.len() { array[i] = bytes[i]; } - Bn254Fr { - array: array, - } + Bn254Fr { array } } - fn from_le_bytes_32(bytes: [u8;32]) -> Bn254Fr { - Bn254Fr { - array: bytes, - } + fn from_le_bytes_32(bytes: [u8; 32]) -> Bn254Fr { + Bn254Fr { array: bytes } } fn to_le_bytes(self) -> [u8] { @@ -214,40 +186,32 @@ impl BigField for Bn254Fr { } } -impl Add for Bn254Fr { +impl Add for Bn254Fr { fn add(self: Self, other: Bn254Fr) -> Bn254Fr { let a = BigInt::from_le_bytes(self.array.as_slice(), bn254_fr); let b = BigInt::from_le_bytes(other.array.as_slice(), bn254_fr); - Bn254Fr { - array: a.bigint_add(b).to_le_bytes() - } + Bn254Fr { array: a.bigint_add(b).to_le_bytes() } } } -impl Sub for Bn254Fr { +impl Sub for Bn254Fr { fn sub(self: Self, other: Bn254Fr) -> Bn254Fr { let a = BigInt::from_le_bytes(self.array.as_slice(), bn254_fr); let b = BigInt::from_le_bytes(other.array.as_slice(), bn254_fr); - Bn254Fr { - array: a.bigint_sub(b).to_le_bytes() - } + Bn254Fr { array: a.bigint_sub(b).to_le_bytes() } } } -impl Mul for Bn254Fr { +impl Mul for Bn254Fr { fn mul(self: Self, other: Bn254Fr) -> Bn254Fr { let a = BigInt::from_le_bytes(self.array.as_slice(), bn254_fr); let b = BigInt::from_le_bytes(other.array.as_slice(), bn254_fr); - Bn254Fr { - array: a.bigint_mul(b).to_le_bytes() - } + Bn254Fr { array: a.bigint_mul(b).to_le_bytes() } } } -impl Div for Bn254Fr { +impl Div for Bn254Fr { fn div(self: Self, other: Bn254Fr) -> Bn254Fr { let a = BigInt::from_le_bytes(self.array.as_slice(), bn254_fr); let b = BigInt::from_le_bytes(other.array.as_slice(), bn254_fr); - Bn254Fr { - array: a.bigint_div(b).to_le_bytes() - } + Bn254Fr { array: a.bigint_div(b).to_le_bytes() } } } impl Eq for Bn254Fr { @@ -263,19 +227,15 @@ struct Bn254Fq { impl BigField for Bn254Fq { fn from_le_bytes(bytes: [u8]) -> Bn254Fq { assert(bytes.len() <= 32); - let mut array = [0;32]; + let mut array = [0; 32]; for i in 0..bytes.len() { array[i] = bytes[i]; } - Bn254Fq { - array: array, - } + Bn254Fq { array } } - fn from_le_bytes_32(bytes: [u8;32]) -> Bn254Fq { - Bn254Fq { - array: bytes, - } + fn from_le_bytes_32(bytes: [u8; 32]) -> Bn254Fq { + Bn254Fq { array: bytes } } fn to_le_bytes(self) -> [u8] { @@ -283,40 +243,32 @@ impl BigField for Bn254Fq { } } -impl Add for Bn254Fq { +impl Add for Bn254Fq { fn add(self: Self, other: Bn254Fq) -> Bn254Fq { let a = BigInt::from_le_bytes(self.array.as_slice(), bn254_fq); let b = BigInt::from_le_bytes(other.array.as_slice(), bn254_fq); - Bn254Fq { - array: a.bigint_add(b).to_le_bytes() - } + Bn254Fq { array: a.bigint_add(b).to_le_bytes() } } } -impl Sub for Bn254Fq { +impl Sub for Bn254Fq { fn sub(self: Self, other: Bn254Fq) -> Bn254Fq { let a = BigInt::from_le_bytes(self.array.as_slice(), bn254_fq); let b = BigInt::from_le_bytes(other.array.as_slice(), bn254_fq); - Bn254Fq { - array: a.bigint_sub(b).to_le_bytes() - } + Bn254Fq { array: a.bigint_sub(b).to_le_bytes() } } } -impl Mul for Bn254Fq { +impl Mul for Bn254Fq { fn mul(self: Self, other: Bn254Fq) -> Bn254Fq { let a = BigInt::from_le_bytes(self.array.as_slice(), bn254_fq); let b = BigInt::from_le_bytes(other.array.as_slice(), bn254_fq); - Bn254Fq { - array: a.bigint_mul(b).to_le_bytes() - } + Bn254Fq { array: a.bigint_mul(b).to_le_bytes() } } } -impl Div for Bn254Fq { +impl Div for Bn254Fq { fn div(self: Self, other: Bn254Fq) -> Bn254Fq { let a = BigInt::from_le_bytes(self.array.as_slice(), bn254_fq); let b = BigInt::from_le_bytes(other.array.as_slice(), bn254_fq); - Bn254Fq { - array: a.bigint_div(b).to_le_bytes() - } + Bn254Fq { array: a.bigint_div(b).to_le_bytes() } } } impl Eq for Bn254Fq { @@ -332,19 +284,15 @@ struct Secpr1Fq { impl BigField for Secpr1Fq { fn from_le_bytes(bytes: [u8]) -> Secpr1Fq { assert(bytes.len() <= 32); - let mut array = [0;32]; + let mut array = [0; 32]; for i in 0..bytes.len() { array[i] = bytes[i]; } - Secpr1Fq { - array: array, - } + Secpr1Fq { array } } - fn from_le_bytes_32(bytes: [u8;32]) -> Secpr1Fq { - Secpr1Fq { - array: bytes, - } + fn from_le_bytes_32(bytes: [u8; 32]) -> Secpr1Fq { + Secpr1Fq { array: bytes } } fn to_le_bytes(self) -> [u8] { @@ -352,40 +300,32 @@ impl BigField for Secpr1Fq { } } -impl Add for Secpr1Fq { +impl Add for Secpr1Fq { fn add(self: Self, other: Secpr1Fq) -> Secpr1Fq { let a = BigInt::from_le_bytes(self.array.as_slice(), secpr1_fq); let b = BigInt::from_le_bytes(other.array.as_slice(), secpr1_fq); - Secpr1Fq { - array: a.bigint_add(b).to_le_bytes() - } + Secpr1Fq { array: a.bigint_add(b).to_le_bytes() } } } -impl Sub for Secpr1Fq { +impl Sub for Secpr1Fq { fn sub(self: Self, other: Secpr1Fq) -> Secpr1Fq { let a = BigInt::from_le_bytes(self.array.as_slice(), secpr1_fq); let b = BigInt::from_le_bytes(other.array.as_slice(), secpr1_fq); - Secpr1Fq { - array: a.bigint_sub(b).to_le_bytes() - } + Secpr1Fq { array: a.bigint_sub(b).to_le_bytes() } } } -impl Mul for Secpr1Fq { +impl Mul for Secpr1Fq { fn mul(self: Self, other: Secpr1Fq) -> Secpr1Fq { let a = BigInt::from_le_bytes(self.array.as_slice(), secpr1_fq); let b = BigInt::from_le_bytes(other.array.as_slice(), secpr1_fq); - Secpr1Fq { - array: a.bigint_mul(b).to_le_bytes() - } + Secpr1Fq { array: a.bigint_mul(b).to_le_bytes() } } } -impl Div for Secpr1Fq { +impl Div for Secpr1Fq { fn div(self: Self, other: Secpr1Fq) -> Secpr1Fq { let a = BigInt::from_le_bytes(self.array.as_slice(), secpr1_fq); let b = BigInt::from_le_bytes(other.array.as_slice(), secpr1_fq); - Secpr1Fq { - array: a.bigint_div(b).to_le_bytes() - } + Secpr1Fq { array: a.bigint_div(b).to_le_bytes() } } } impl Eq for Secpr1Fq { @@ -401,19 +341,15 @@ struct Secpr1Fr { impl BigField for Secpr1Fr { fn from_le_bytes(bytes: [u8]) -> Secpr1Fr { assert(bytes.len() <= 32); - let mut array = [0;32]; + let mut array = [0; 32]; for i in 0..bytes.len() { array[i] = bytes[i]; } - Secpr1Fr { - array: array, - } + Secpr1Fr { array } } - fn from_le_bytes_32(bytes: [u8;32]) -> Secpr1Fr { - Secpr1Fr { - array: bytes, - } + fn from_le_bytes_32(bytes: [u8; 32]) -> Secpr1Fr { + Secpr1Fr { array: bytes } } fn to_le_bytes(self) -> [u8] { @@ -421,40 +357,32 @@ impl BigField for Secpr1Fr { } } -impl Add for Secpr1Fr { +impl Add for Secpr1Fr { fn add(self: Self, other: Secpr1Fr) -> Secpr1Fr { let a = BigInt::from_le_bytes(self.array.as_slice(), secpr1_fr); let b = BigInt::from_le_bytes(other.array.as_slice(), secpr1_fr); - Secpr1Fr { - array: a.bigint_add(b).to_le_bytes() - } + Secpr1Fr { array: a.bigint_add(b).to_le_bytes() } } } -impl Sub for Secpr1Fr { +impl Sub for Secpr1Fr { fn sub(self: Self, other: Secpr1Fr) -> Secpr1Fr { let a = BigInt::from_le_bytes(self.array.as_slice(), secpr1_fr); let b = BigInt::from_le_bytes(other.array.as_slice(), secpr1_fr); - Secpr1Fr { - array: a.bigint_sub(b).to_le_bytes() - } + Secpr1Fr { array: a.bigint_sub(b).to_le_bytes() } } } -impl Mul for Secpr1Fr { +impl Mul for Secpr1Fr { fn mul(self: Self, other: Secpr1Fr) -> Secpr1Fr { let a = BigInt::from_le_bytes(self.array.as_slice(), secpr1_fr); let b = BigInt::from_le_bytes(other.array.as_slice(), secpr1_fr); - Secpr1Fr { - array: a.bigint_mul(b).to_le_bytes() - } + Secpr1Fr { array: a.bigint_mul(b).to_le_bytes() } } } -impl Div for Secpr1Fr { +impl Div for Secpr1Fr { fn div(self: Self, other: Secpr1Fr) -> Secpr1Fr { let a = BigInt::from_le_bytes(self.array.as_slice(), secpr1_fr); let b = BigInt::from_le_bytes(other.array.as_slice(), secpr1_fr); - Secpr1Fr { - array: a.bigint_div(b).to_le_bytes() - } + Secpr1Fr { array: a.bigint_div(b).to_le_bytes() } } } impl Eq for Secpr1Fr { diff --git a/noir/noir-repo/noir_stdlib/src/cmp.nr b/noir/noir-repo/noir_stdlib/src/cmp.nr index 521604a4e20..e76116951c5 100644 --- a/noir/noir-repo/noir_stdlib/src/cmp.nr +++ b/noir/noir-repo/noir_stdlib/src/cmp.nr @@ -22,26 +22,74 @@ comptime fn derive_eq(s: StructDefinition) -> Quoted { } // docs:end:derive_eq -impl Eq for Field { fn eq(self, other: Field) -> bool { self == other } } +impl Eq for Field { + fn eq(self, other: Field) -> bool { + self == other + } +} -impl Eq for u64 { fn eq(self, other: u64) -> bool { self == other } } -impl Eq for u32 { fn eq(self, other: u32) -> bool { self == other } } -impl Eq for u16 { fn eq(self, other: u16) -> bool { self == other } } -impl Eq for u8 { fn eq(self, other: u8) -> bool { self == other } } -impl Eq for u1 { fn eq(self, other: u1) -> bool { self == other } } +impl Eq for u64 { + fn eq(self, other: u64) -> bool { + self == other + } +} +impl Eq for u32 { + fn eq(self, other: u32) -> bool { + self == other + } +} +impl Eq for u16 { + fn eq(self, other: u16) -> bool { + self == other + } +} +impl Eq for u8 { + fn eq(self, other: u8) -> bool { + self == other + } +} +impl Eq for u1 { + fn eq(self, other: u1) -> bool { + self == other + } +} -impl Eq for i8 { fn eq(self, other: i8) -> bool { self == other } } -impl Eq for i16 { fn eq(self, other: i16) -> bool { self == other } } -impl Eq for i32 { fn eq(self, other: i32) -> bool { self == other } } -impl Eq for i64 { fn eq(self, other: i64) -> bool { self == other } } +impl Eq for i8 { + fn eq(self, other: i8) -> bool { + self == other + } +} +impl Eq for i16 { + fn eq(self, other: i16) -> bool { + self == other + } +} +impl Eq for i32 { + fn eq(self, other: i32) -> bool { + self == other + } +} +impl Eq for i64 { + fn eq(self, other: i64) -> bool { + self == other + } +} -impl Eq for () { fn eq(_self: Self, _other: ()) -> bool { true } } -impl Eq for bool { fn eq(self, other: bool) -> bool { self == other } } +impl Eq for () { + fn eq(_self: Self, _other: ()) -> bool { + true + } +} +impl Eq for bool { + fn eq(self, other: bool) -> bool { + self == other + } +} impl Eq for [T; N] where T: Eq { fn eq(self, other: [T; N]) -> bool { let mut result = true; - for i in 0 .. self.len() { + for i in 0..self.len() { result &= self[i].eq(other[i]); } result @@ -51,7 +99,7 @@ impl Eq for [T; N] where T: Eq { impl Eq for [T] where T: Eq { fn eq(self, other: [T]) -> bool { let mut result = self.len() == other.len(); - for i in 0 .. self.len() { + for i in 0..self.len() { result &= self[i].eq(other[i]); } result @@ -86,7 +134,11 @@ impl Eq for (A, B, C, D) where A: Eq, B: Eq, C: Eq, D: Eq { impl Eq for (A, B, C, D, E) where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq { fn eq(self, other: (A, B, C, D, E)) -> bool { - self.0.eq(other.0) & self.1.eq(other.1) & self.2.eq(other.2) & self.3.eq(other.3) & self.4.eq(other.4) + self.0.eq(other.0) + & self.1.eq(other.1) + & self.2.eq(other.2) + & self.3.eq(other.3) + & self.4.eq(other.4) } } @@ -255,12 +307,10 @@ impl Ord for bool { } else { Ordering::greater() } + } else if other { + Ordering::less() } else { - if other { - Ordering::less() - } else { - Ordering::equal() - } + Ordering::equal() } } } @@ -270,7 +320,7 @@ impl Ord for [T; N] where T: Ord { // the ordering for the whole array. fn cmp(self, other: [T; N]) -> Ordering { let mut result = Ordering::equal(); - for i in 0 .. self.len() { + for i in 0..self.len() { if result == Ordering::equal() { let result_i = self[i].cmp(other[i]); @@ -290,7 +340,7 @@ impl Ord for [T] where T: Ord { // the ordering for the whole array. fn cmp(self, other: [T]) -> Ordering { let mut result = self.len().cmp(other.len()); - for i in 0 .. self.len() { + for i in 0..self.len() { if result == Ordering::equal() { let result_i = self[i].cmp(other[i]); diff --git a/noir/noir-repo/noir_stdlib/src/collections/bounded_vec.nr b/noir/noir-repo/noir_stdlib/src/collections/bounded_vec.nr index fede1b17c07..315e398f097 100644 --- a/noir/noir-repo/noir_stdlib/src/collections/bounded_vec.nr +++ b/noir/noir-repo/noir_stdlib/src/collections/bounded_vec.nr @@ -428,13 +428,13 @@ impl Eq for BoundedVec where T: Eq { // // We make the assumption that the user has used the proper interface for working with `BoundedVec`s // rather than directly manipulating the internal fields as this can result in an inconsistent internal state. - + (self.len == other.len) & (self.storage == other.storage) } } impl From<[T; Len]> for BoundedVec { - fn from(array: [T; Len]) -> BoundedVec { + fn from(array: [T; Len]) -> BoundedVec { BoundedVec::from_array(array) } } diff --git a/noir/noir-repo/noir_stdlib/src/collections/map.nr b/noir/noir-repo/noir_stdlib/src/collections/map.nr index e84103aafc5..def15f718ca 100644 --- a/noir/noir-repo/noir_stdlib/src/collections/map.nr +++ b/noir/noir-repo/noir_stdlib/src/collections/map.nr @@ -50,12 +50,9 @@ struct Slot { _is_deleted: bool, } -impl Default for Slot{ - fn default() -> Self{ - Slot{ - _key_value: Option::none(), - _is_deleted: false - } +impl Default for Slot { + fn default() -> Self { + Slot { _key_value: Option::none(), _is_deleted: false } } } @@ -649,8 +646,7 @@ where K: Eq + Hash, V: Eq, B: BuildHasher, - H: Hasher -{ + H: Hasher { /// Checks if two HashMaps are equal. /// /// Example: @@ -668,22 +664,22 @@ where /// assert(map1 == map2); /// ``` fn eq(self, other: HashMap) -> bool { -// docs:end:eq + // docs:end:eq let mut equal = false; - if self.len() == other.len(){ + if self.len() == other.len() { equal = true; - for slot in self._table{ + for slot in self._table { // Not marked as deleted and has key-value. - if equal & slot.is_valid(){ + if equal & slot.is_valid() { let (key, value) = slot.key_value_unchecked(); let other_value = other.get(key); - if other_value.is_none(){ + if other_value.is_none() { equal = false; - }else{ + } else { let other_value = other_value.unwrap_unchecked(); - if value != other_value{ + if value != other_value { equal = false; } } @@ -699,8 +695,7 @@ where impl Default for HashMap where B: BuildHasher + Default, - H: Hasher + Default -{ + H: Hasher + Default { /// Constructs an empty HashMap. /// /// Example: diff --git a/noir/noir-repo/noir_stdlib/src/collections/umap.nr b/noir/noir-repo/noir_stdlib/src/collections/umap.nr index c71905e63b3..aa944404751 100644 --- a/noir/noir-repo/noir_stdlib/src/collections/umap.nr +++ b/noir/noir-repo/noir_stdlib/src/collections/umap.nr @@ -31,12 +31,9 @@ struct Slot { _is_deleted: bool, } -impl Default for Slot{ - fn default() -> Self{ - Slot{ - _key_value: Option::none(), - _is_deleted: false - } +impl Default for Slot { + fn default() -> Self { + Slot { _key_value: Option::none(), _is_deleted: false } } } @@ -425,25 +422,26 @@ where K: Eq + Hash, V: Eq, B: BuildHasher, - H: Hasher -{ + H: Hasher { fn eq(self, other: UHashMap) -> bool { -// docs:end:eq + // docs:end:eq let mut equal = false; - if self.len() == other.len(){ + if self.len() == other.len() { equal = true; - for slot in self._table{ + for slot in self._table { // Not marked as deleted and has key-value. - if equal & slot.is_valid(){ + if equal & slot.is_valid() { let (key, value) = slot.key_value_unchecked(); - let other_value = unsafe { other.get(key) }; + let other_value = unsafe { + other.get(key) + }; - if other_value.is_none(){ + if other_value.is_none() { equal = false; - }else{ + } else { let other_value = other_value.unwrap_unchecked(); - if value != other_value{ + if value != other_value { equal = false; } } @@ -459,10 +457,9 @@ where impl Default for UHashMap where B: BuildHasher + Default, - H: Hasher + Default -{ + H: Hasher + Default { fn default() -> Self { -// docs:end:default + // docs:end:default UHashMap::with_hasher(B::default()) } } diff --git a/noir/noir-repo/noir_stdlib/src/convert.nr b/noir/noir-repo/noir_stdlib/src/convert.nr index d3537df3c5e..0b2bd4f2eb7 100644 --- a/noir/noir-repo/noir_stdlib/src/convert.nr +++ b/noir/noir-repo/noir_stdlib/src/convert.nr @@ -5,9 +5,9 @@ trait From { // docs:end:from-trait impl From for T { - fn from(input: T) -> T { - input - } + fn from(input: T) -> T { + input + } } // docs:start:into-trait @@ -16,37 +16,101 @@ trait Into { } impl Into for U where T: From { - fn into(self) -> T { - T::from(self) - } + fn into(self) -> T { + T::from(self) + } } // docs:end:into-trait // docs:start:from-impls // Unsigned integers -impl From for u32 { fn from(value: u8) -> u32 { value as u32 } } +impl From for u32 { + fn from(value: u8) -> u32 { + value as u32 + } +} -impl From for u64 { fn from(value: u8) -> u64 { value as u64 } } -impl From for u64 { fn from(value: u32) -> u64 { value as u64 } } +impl From for u64 { + fn from(value: u8) -> u64 { + value as u64 + } +} +impl From for u64 { + fn from(value: u32) -> u64 { + value as u64 + } +} -impl From for Field { fn from(value: u8) -> Field { value as Field } } -impl From for Field { fn from(value: u32) -> Field { value as Field } } -impl From for Field { fn from(value: u64) -> Field { value as Field } } +impl From for Field { + fn from(value: u8) -> Field { + value as Field + } +} +impl From for Field { + fn from(value: u32) -> Field { + value as Field + } +} +impl From for Field { + fn from(value: u64) -> Field { + value as Field + } +} // Signed integers -impl From for i32 { fn from(value: i8) -> i32 { value as i32 } } +impl From for i32 { + fn from(value: i8) -> i32 { + value as i32 + } +} -impl From for i64 { fn from(value: i8) -> i64 { value as i64 } } -impl From for i64 { fn from(value: i32) -> i64 { value as i64 } } +impl From for i64 { + fn from(value: i8) -> i64 { + value as i64 + } +} +impl From for i64 { + fn from(value: i32) -> i64 { + value as i64 + } +} // Booleans -impl From for u8 { fn from(value: bool) -> u8 { value as u8 } } -impl From for u32 { fn from(value: bool) -> u32 { value as u32 } } -impl From for u64 { fn from(value: bool) -> u64 { value as u64 } } -impl From for i8 { fn from(value: bool) -> i8 { value as i8 } } -impl From for i32 { fn from(value: bool) -> i32 { value as i32 } } -impl From for i64 { fn from(value: bool) -> i64 { value as i64 } } -impl From for Field { fn from(value: bool) -> Field { value as Field } } +impl From for u8 { + fn from(value: bool) -> u8 { + value as u8 + } +} +impl From for u32 { + fn from(value: bool) -> u32 { + value as u32 + } +} +impl From for u64 { + fn from(value: bool) -> u64 { + value as u64 + } +} +impl From for i8 { + fn from(value: bool) -> i8 { + value as i8 + } +} +impl From for i32 { + fn from(value: bool) -> i32 { + value as i32 + } +} +impl From for i64 { + fn from(value: bool) -> i64 { + value as i64 + } +} +impl From for Field { + fn from(value: bool) -> Field { + value as Field + } +} // docs:end:from-impls diff --git a/noir/noir-repo/noir_stdlib/src/default.nr b/noir/noir-repo/noir_stdlib/src/default.nr index 3ac5fbb394e..3dcc04c7d0c 100644 --- a/noir/noir-repo/noir_stdlib/src/default.nr +++ b/noir/noir-repo/noir_stdlib/src/default.nr @@ -15,21 +15,69 @@ comptime fn derive_default(s: StructDefinition) -> Quoted { crate::meta::make_trait_impl(s, name, signature, for_each_field, quote { , }, body) } -impl Default for Field { fn default() -> Field { 0 } } +impl Default for Field { + fn default() -> Field { + 0 + } +} -impl Default for u1 { fn default() -> u1 { 0 } } -impl Default for u8 { fn default() -> u8 { 0 } } -impl Default for u16 { fn default() -> u16 { 0 } } -impl Default for u32 { fn default() -> u32 { 0 } } -impl Default for u64 { fn default() -> u64 { 0 } } +impl Default for u1 { + fn default() -> u1 { + 0 + } +} +impl Default for u8 { + fn default() -> u8 { + 0 + } +} +impl Default for u16 { + fn default() -> u16 { + 0 + } +} +impl Default for u32 { + fn default() -> u32 { + 0 + } +} +impl Default for u64 { + fn default() -> u64 { + 0 + } +} -impl Default for i8 { fn default() -> i8 { 0 } } -impl Default for i16 { fn default() -> i16 { 0 } } -impl Default for i32 { fn default() -> i32 { 0 } } -impl Default for i64 { fn default() -> i64 { 0 } } +impl Default for i8 { + fn default() -> i8 { + 0 + } +} +impl Default for i16 { + fn default() -> i16 { + 0 + } +} +impl Default for i32 { + fn default() -> i32 { + 0 + } +} +impl Default for i64 { + fn default() -> i64 { + 0 + } +} -impl Default for () { fn default() -> () { () } } -impl Default for bool { fn default() -> bool { false } } +impl Default for () { + fn default() -> () { + () + } +} +impl Default for bool { + fn default() -> bool { + false + } +} impl Default for [T; N] where T: Default { fn default() -> [T; N] { diff --git a/noir/noir-repo/noir_stdlib/src/ec/montcurve.nr b/noir/noir-repo/noir_stdlib/src/ec/montcurve.nr index 12b48d66b9d..676b1cd81a7 100644 --- a/noir/noir-repo/noir_stdlib/src/ec/montcurve.nr +++ b/noir/noir-repo/noir_stdlib/src/ec/montcurve.nr @@ -276,7 +276,8 @@ mod curvegroup { impl Eq for Point { fn eq(self, p: Self) -> bool { - (self.z == p.z) | (((self.x * self.z) == (p.x * p.z)) & ((self.y * self.z) == (p.y * p.z))) + (self.z == p.z) + | (((self.x * self.z) == (p.x * p.z)) & ((self.y * self.z) == (p.y * p.z))) } } diff --git a/noir/noir-repo/noir_stdlib/src/ec/swcurve.nr b/noir/noir-repo/noir_stdlib/src/ec/swcurve.nr index 4139492af63..9620b23948d 100644 --- a/noir/noir-repo/noir_stdlib/src/ec/swcurve.nr +++ b/noir/noir-repo/noir_stdlib/src/ec/swcurve.nr @@ -60,11 +60,10 @@ mod affine { impl Eq for Point { fn eq(self, p: Self) -> bool { - let Self {x: x1, y: y1, infty: inf1} = self; + let Self {x: x1, y: y1, infty: inf1} = self; let Self {x: x2, y: y2, infty: inf2} = p; - (inf1 & inf2) - | (!inf1 & !inf2 & (x1 == x2) & (y1 == y2)) + (inf1 & inf2) | (!inf1 & !inf2 & (x1 == x2) & (y1 == y2)) } } @@ -245,10 +244,13 @@ mod curvegroup { impl Eq for Point { fn eq(self, p: Self) -> bool { - let Self {x: x1, y: y1, z: z1} = self; + let Self {x: x1, y: y1, z: z1} = self; let Self {x: x2, y: y2, z: z2} = p; - ((z1 == 0) & (z2 == 0)) | ((z1 != 0) & (z2 != 0) & (x1*z2*z2 == x2*z1*z1) & (y1*z2*z2*z2 == y2*z1*z1*z1)) + ((z1 == 0) & (z2 == 0)) | ((z1 != 0) + & (z2 != 0) + & (x1 * z2 * z2 == x2 * z1 * z1) + & (y1 * z2 * z2 * z2 == y2 * z1 * z1 * z1)) } } diff --git a/noir/noir-repo/noir_stdlib/src/ec/tecurve.nr b/noir/noir-repo/noir_stdlib/src/ec/tecurve.nr index 2ba3fd4401c..9973678a048 100644 --- a/noir/noir-repo/noir_stdlib/src/ec/tecurve.nr +++ b/noir/noir-repo/noir_stdlib/src/ec/tecurve.nr @@ -70,7 +70,7 @@ mod affine { impl Eq for Point { fn eq(self, p: Self) -> bool { - let Self {x: x1, y: y1} = self; + let Self {x: x1, y: y1} = self; let Self {x: x2, y: y2} = p; (x1 == x2) & (y1 == y2) @@ -261,7 +261,7 @@ mod curvegroup { let Self {x: x1, y: y1, t: _t1, z: z1} = self; let Self {x: x2, y: y2, t: _t2, z:z2} = p; - (x1*z2 == x2*z1) & (y1*z2 == y2*z1) + (x1 * z2 == x2 * z1) & (y1 * z2 == y2 * z1) } } diff --git a/noir/noir-repo/noir_stdlib/src/embedded_curve_ops.nr b/noir/noir-repo/noir_stdlib/src/embedded_curve_ops.nr index 6b70b6ddef0..094ad5204c3 100644 --- a/noir/noir-repo/noir_stdlib/src/embedded_curve_ops.nr +++ b/noir/noir-repo/noir_stdlib/src/embedded_curve_ops.nr @@ -25,14 +25,14 @@ impl EmbeddedCurvePoint { impl Add for EmbeddedCurvePoint { /// Adds two points P+Q, using the curve addition formula, and also handles point at infinity - fn add(self, other: EmbeddedCurvePoint) -> EmbeddedCurvePoint { + fn add(self, other: EmbeddedCurvePoint) -> EmbeddedCurvePoint { embedded_curve_add(self, other) } } impl Sub for EmbeddedCurvePoint { /// Points subtraction operation, using addition and negation - fn sub(self, other: EmbeddedCurvePoint) -> EmbeddedCurvePoint { + fn sub(self, other: EmbeddedCurvePoint) -> EmbeddedCurvePoint { self + other.neg() } } @@ -40,19 +40,16 @@ impl Sub for EmbeddedCurvePoint { impl Neg for EmbeddedCurvePoint { /// Negates a point P, i.e returns -P, by negating the y coordinate. /// If the point is at infinity, then the result is also at infinity. - fn neg(self) -> EmbeddedCurvePoint { - EmbeddedCurvePoint { - x: self.x, - y: -self.y, - is_infinite: self.is_infinite - } + fn neg(self) -> EmbeddedCurvePoint { + EmbeddedCurvePoint { x: self.x, y: -self.y, is_infinite: self.is_infinite } } } impl Eq for EmbeddedCurvePoint { /// Checks whether two points are equal fn eq(self: Self, b: EmbeddedCurvePoint) -> bool { - (self.is_infinite & b.is_infinite) | ((self.is_infinite == b.is_infinite) & (self.x == b.x) & (self.y == b.y)) + (self.is_infinite & b.is_infinite) + | ((self.is_infinite == b.is_infinite) & (self.x == b.x) & (self.y == b.y)) } } diff --git a/noir/noir-repo/noir_stdlib/src/hash/mimc.nr b/noir/noir-repo/noir_stdlib/src/hash/mimc.nr index a16a73c5bc5..6145a387f26 100644 --- a/noir/noir-repo/noir_stdlib/src/hash/mimc.nr +++ b/noir/noir-repo/noir_stdlib/src/hash/mimc.nr @@ -142,15 +142,13 @@ impl Hasher for MimcHasher { r } - fn write(&mut self, input: Field){ + fn write(&mut self, input: Field) { self._state = self._state.push_back(input); } } -impl Default for MimcHasher{ - fn default() -> Self{ - MimcHasher { - _state: &[], - } +impl Default for MimcHasher { + fn default() -> Self { + MimcHasher { _state: &[] } } } diff --git a/noir/noir-repo/noir_stdlib/src/hash/mod.nr b/noir/noir-repo/noir_stdlib/src/hash/mod.nr index 0e15595ff40..4c67a0cfa8b 100644 --- a/noir/noir-repo/noir_stdlib/src/hash/mod.nr +++ b/noir/noir-repo/noir_stdlib/src/hash/mod.nr @@ -170,84 +170,82 @@ struct BuildHasherDefault; impl BuildHasher for BuildHasherDefault where - H: Hasher + Default -{ - fn build_hasher(_self: Self) -> H{ + H: Hasher + Default { + fn build_hasher(_self: Self) -> H { H::default() } } impl Default for BuildHasherDefault where - H: Hasher + Default -{ - fn default() -> Self{ - BuildHasherDefault{} - } + H: Hasher + Default { + fn default() -> Self { + BuildHasherDefault {} + } } impl Hash for Field { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { H::write(state, self); } } impl Hash for u1 { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { H::write(state, self as Field); } } impl Hash for u8 { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { H::write(state, self as Field); } } impl Hash for u16 { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { H::write(state, self as Field); } } impl Hash for u32 { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { H::write(state, self as Field); } } impl Hash for u64 { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { H::write(state, self as Field); } } impl Hash for i8 { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { H::write(state, self as Field); } } impl Hash for i16 { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { H::write(state, self as Field); } } impl Hash for i32 { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { H::write(state, self as Field); } } impl Hash for i64 { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { H::write(state, self as Field); } } impl Hash for bool { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { H::write(state, self as Field); } } @@ -257,14 +255,14 @@ impl Hash for () { } impl Hash for U128 { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { H::write(state, self.lo as Field); H::write(state, self.hi as Field); } } impl Hash for [T; N] where T: Hash { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { for elem in self { elem.hash(state); } @@ -272,7 +270,7 @@ impl Hash for [T; N] where T: Hash { } impl Hash for [T] where T: Hash { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { self.len().hash(state); for elem in self { elem.hash(state); @@ -281,14 +279,14 @@ impl Hash for [T] where T: Hash { } impl Hash for (A, B) where A: Hash, B: Hash { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { self.0.hash(state); self.1.hash(state); } } impl Hash for (A, B, C) where A: Hash, B: Hash, C: Hash { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { self.0.hash(state); self.1.hash(state); self.2.hash(state); @@ -296,7 +294,7 @@ impl Hash for (A, B, C) where A: Hash, B: Hash, C: Hash { } impl Hash for (A, B, C, D) where A: Hash, B: Hash, C: Hash, D: Hash { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { self.0.hash(state); self.1.hash(state); self.2.hash(state); @@ -305,7 +303,7 @@ impl Hash for (A, B, C, D) where A: Hash, B: Hash, C: Hash, D: Hash } impl Hash for (A, B, C, D, E) where A: Hash, B: Hash, C: Hash, D: Hash, E: Hash { - fn hash(self, state: &mut H) where H: Hasher{ + fn hash(self, state: &mut H) where H: Hasher { self.0.hash(state); self.1.hash(state); self.2.hash(state); diff --git a/noir/noir-repo/noir_stdlib/src/hash/poseidon/mod.nr b/noir/noir-repo/noir_stdlib/src/hash/poseidon/mod.nr index cf9b6187c02..47403e0c1d3 100644 --- a/noir/noir-repo/noir_stdlib/src/hash/poseidon/mod.nr +++ b/noir/noir-repo/noir_stdlib/src/hash/poseidon/mod.nr @@ -177,16 +177,16 @@ impl Hasher for PoseidonHasher { assert(len < 16); if len == 1 { result = bn254::hash_1([self._state[0]]); - } + } if len == 2 { result = bn254::hash_2([self._state[0],self._state[1]]); - } + } if len == 3 { result = bn254::hash_3([self._state[0],self._state[1],self._state[2]]); - } + } if len == 4 { result = bn254::hash_4([self._state[0],self._state[1],self._state[2],self._state[3]]); - } + } if len == 5 { result = bn254::hash_5([self._state[0],self._state[1],self._state[2],self._state[3],self._state[4]]); } @@ -220,20 +220,18 @@ impl Hasher for PoseidonHasher { if len == 15 { result = bn254::hash_15([self._state[0],self._state[1],self._state[2],self._state[3],self._state[4], self._state[5], self._state[6], self._state[7], self._state[8], self._state[9], self._state[10], self._state[11], self._state[12], self._state[13], self._state[14]]); } - + result } - fn write(&mut self, input: Field){ + fn write(&mut self, input: Field) { self._state = self._state.push_back(input); } } -impl Default for PoseidonHasher{ - fn default() -> Self{ - PoseidonHasher{ - _state: &[], - } +impl Default for PoseidonHasher { + fn default() -> Self { + PoseidonHasher { _state: &[] } } } diff --git a/noir/noir-repo/noir_stdlib/src/hash/poseidon2.nr b/noir/noir-repo/noir_stdlib/src/hash/poseidon2.nr index 902d3cc8104..9f28cf3e904 100644 --- a/noir/noir-repo/noir_stdlib/src/hash/poseidon2.nr +++ b/noir/noir-repo/noir_stdlib/src/hash/poseidon2.nr @@ -88,7 +88,7 @@ struct Poseidon2Hasher{ impl Hasher for Poseidon2Hasher { fn finish(self) -> Field { - let iv : Field = (self._state.len() as Field)*18446744073709551616; // iv = (self._state.len() << 64) + let iv : Field = (self._state.len() as Field) * 18446744073709551616; // iv = (self._state.len() << 64) let mut sponge = Poseidon2::new(iv); for i in 0..self._state.len() { sponge.absorb(self._state[i]); @@ -96,15 +96,13 @@ impl Hasher for Poseidon2Hasher { sponge.squeeze() } - fn write(&mut self, input: Field){ + fn write(&mut self, input: Field) { self._state = self._state.push_back(input); } } impl Default for Poseidon2Hasher { fn default() -> Self { - Poseidon2Hasher { - _state: &[], - } + Poseidon2Hasher { _state: &[] } } } diff --git a/noir/noir-repo/noir_stdlib/src/meta/function_def.nr b/noir/noir-repo/noir_stdlib/src/meta/function_def.nr index 5d536d60ae1..cd5f9cc79fb 100644 --- a/noir/noir-repo/noir_stdlib/src/meta/function_def.nr +++ b/noir/noir-repo/noir_stdlib/src/meta/function_def.nr @@ -11,7 +11,7 @@ impl FunctionDefinition { #[builtin(function_def_has_named_attribute)] // docs:start:has_named_attribute - comptime fn has_named_attribute(self, name: Quoted) -> bool {} + comptime fn has_named_attribute(self, name: str) -> bool {} // docs:end:has_named_attribute #[builtin(function_def_is_unconstrained)] @@ -64,3 +64,21 @@ impl FunctionDefinition { comptime fn set_unconstrained(self, value: bool) {} // docs:end:set_unconstrained } + +impl crate::hash::Hash for FunctionDefinition { + comptime fn hash(self, state: &mut H) where H: crate::hash::Hasher { + state.write(function_def_hash(self)) + } +} + +impl crate::cmp::Eq for FunctionDefinition { + comptime fn eq(self, other: Self) -> bool { + function_def_eq(self, other) + } +} + +#[builtin(function_def_eq)] +comptime fn function_def_eq(_first: FunctionDefinition, _second: FunctionDefinition) -> bool {} + +#[builtin(function_def_hash)] +comptime fn function_def_hash(_function: FunctionDefinition) -> Field {} diff --git a/noir/noir-repo/noir_stdlib/src/meta/module.nr b/noir/noir-repo/noir_stdlib/src/meta/module.nr index 6f936bf4c57..1b29301c4ef 100644 --- a/noir/noir-repo/noir_stdlib/src/meta/module.nr +++ b/noir/noir-repo/noir_stdlib/src/meta/module.nr @@ -6,21 +6,44 @@ impl Module { #[builtin(module_has_named_attribute)] // docs:start:has_named_attribute - comptime fn has_named_attribute(self, name: Quoted) -> bool {} + comptime fn has_named_attribute(self, name: str) -> bool {} // docs:end:has_named_attribute #[builtin(module_is_contract)] -// docs:start:is_contract + // docs:start:is_contract comptime fn is_contract(self) -> bool {} // docs:end:is_contract #[builtin(module_functions)] -// docs:start:functions + // docs:start:functions comptime fn functions(self) -> [FunctionDefinition] {} // docs:end:functions + #[builtin(module_structs)] + // docs:start:structs + comptime fn structs(self) -> [StructDefinition] {} + // docs:end:structs + #[builtin(module_name)] -// docs:start:name + // docs:start:name comptime fn name(self) -> Quoted {} // docs:end:name } + +impl crate::hash::Hash for Module { + comptime fn hash(self, state: &mut H) where H: crate::hash::Hasher { + state.write(module_hash(self)) + } +} + +impl crate::cmp::Eq for Module { + comptime fn eq(self, other: Self) -> bool { + module_eq(self, other) + } +} + +#[builtin(module_eq)] +comptime fn module_eq(_first: Module, _second: Module) -> bool {} + +#[builtin(module_hash)] +comptime fn module_hash(_module: Module) -> Field {} diff --git a/noir/noir-repo/noir_stdlib/src/meta/op.nr b/noir/noir-repo/noir_stdlib/src/meta/op.nr index 4b104486201..31a815f07ba 100644 --- a/noir/noir-repo/noir_stdlib/src/meta/op.nr +++ b/noir/noir-repo/noir_stdlib/src/meta/op.nr @@ -1,3 +1,4 @@ +#[derive(Eq, Hash)] struct UnaryOp { op: Field } @@ -45,6 +46,7 @@ impl UnaryOp { } } +#[derive(Eq, Hash)] struct BinaryOp { op: Field } diff --git a/noir/noir-repo/noir_stdlib/src/meta/quoted.nr b/noir/noir-repo/noir_stdlib/src/meta/quoted.nr index ff74580ce20..6e8d001c57c 100644 --- a/noir/noir-repo/noir_stdlib/src/meta/quoted.nr +++ b/noir/noir-repo/noir_stdlib/src/meta/quoted.nr @@ -34,6 +34,14 @@ impl Eq for Quoted { } } +impl crate::hash::Hash for Quoted { + comptime fn hash(self, state: &mut H) where H: crate::hash::Hasher { + state.write(quoted_hash(self)) + } +} + #[builtin(quoted_eq)] comptime fn quoted_eq(_first: Quoted, _second: Quoted) -> bool {} +#[builtin(quoted_hash)] +comptime fn quoted_hash(_quoted: Quoted) -> Field {} diff --git a/noir/noir-repo/noir_stdlib/src/meta/struct_def.nr b/noir/noir-repo/noir_stdlib/src/meta/struct_def.nr index e3621b3482e..b17c0d37613 100644 --- a/noir/noir-repo/noir_stdlib/src/meta/struct_def.nr +++ b/noir/noir-repo/noir_stdlib/src/meta/struct_def.nr @@ -18,7 +18,7 @@ impl StructDefinition { #[builtin(struct_def_has_named_attribute)] // docs:start:has_named_attribute - comptime fn has_named_attribute(self, name: Quoted) -> bool {} + comptime fn has_named_attribute(self, name: str) -> bool {} // docs:end:has_named_attribute /// Return each generic on this struct. @@ -53,3 +53,21 @@ impl StructDefinition { comptime fn set_fields(self, new_fields: [(Quoted, Type)]) {} // docs:end:set_fields } + +impl crate::hash::Hash for StructDefinition { + comptime fn hash(self, state: &mut H) where H: crate::hash::Hasher { + state.write(struct_def_hash(self)) + } +} + +impl crate::cmp::Eq for StructDefinition { + comptime fn eq(self, other: Self) -> bool { + struct_def_eq(self, other) + } +} + +#[builtin(struct_def_eq)] +comptime fn struct_def_eq(_first: StructDefinition, _second: StructDefinition) -> bool {} + +#[builtin(struct_def_hash)] +comptime fn struct_def_hash(_struct: StructDefinition) -> Field {} diff --git a/noir/noir-repo/noir_stdlib/src/meta/typ.nr b/noir/noir-repo/noir_stdlib/src/meta/typ.nr index d692f6e5a7e..5a748c2c823 100644 --- a/noir/noir-repo/noir_stdlib/src/meta/typ.nr +++ b/noir/noir-repo/noir_stdlib/src/meta/typ.nr @@ -69,5 +69,14 @@ impl Eq for Type { } } +impl crate::hash::Hash for Type { + comptime fn hash(self, state: &mut H) where H: crate::hash::Hasher { + state.write(type_hash(self)) + } +} + #[builtin(type_eq)] comptime fn type_eq(_first: Type, _second: Type) -> bool {} + +#[builtin(type_hash)] +comptime fn type_hash(_typ: Type) -> Field {} diff --git a/noir/noir-repo/noir_stdlib/src/ops/arith.nr b/noir/noir-repo/noir_stdlib/src/ops/arith.nr index 918c8e9bc28..653dfd59978 100644 --- a/noir/noir-repo/noir_stdlib/src/ops/arith.nr +++ b/noir/noir-repo/noir_stdlib/src/ops/arith.nr @@ -4,18 +4,58 @@ trait Add { } // docs:end:add-trait -impl Add for Field { fn add(self, other: Field) -> Field { self + other } } +impl Add for Field { + fn add(self, other: Field) -> Field { + self + other + } +} -impl Add for u64 { fn add(self, other: u64) -> u64 { self + other } } -impl Add for u32 { fn add(self, other: u32) -> u32 { self + other } } -impl Add for u16 { fn add(self, other: u16) -> u16 { self + other } } -impl Add for u8 { fn add(self, other: u8) -> u8 { self + other } } -impl Add for u1 { fn add(self, other: u1) -> u1 { self + other } } +impl Add for u64 { + fn add(self, other: u64) -> u64 { + self + other + } +} +impl Add for u32 { + fn add(self, other: u32) -> u32 { + self + other + } +} +impl Add for u16 { + fn add(self, other: u16) -> u16 { + self + other + } +} +impl Add for u8 { + fn add(self, other: u8) -> u8 { + self + other + } +} +impl Add for u1 { + fn add(self, other: u1) -> u1 { + self + other + } +} -impl Add for i8 { fn add(self, other: i8) -> i8 { self + other } } -impl Add for i16 { fn add(self, other: i16) -> i16 { self + other } } -impl Add for i32 { fn add(self, other: i32) -> i32 { self + other } } -impl Add for i64 { fn add(self, other: i64) -> i64 { self + other } } +impl Add for i8 { + fn add(self, other: i8) -> i8 { + self + other + } +} +impl Add for i16 { + fn add(self, other: i16) -> i16 { + self + other + } +} +impl Add for i32 { + fn add(self, other: i32) -> i32 { + self + other + } +} +impl Add for i64 { + fn add(self, other: i64) -> i64 { + self + other + } +} // docs:start:sub-trait trait Sub { @@ -23,18 +63,58 @@ trait Sub { } // docs:end:sub-trait -impl Sub for Field { fn sub(self, other: Field) -> Field { self - other } } +impl Sub for Field { + fn sub(self, other: Field) -> Field { + self - other + } +} -impl Sub for u64 { fn sub(self, other: u64) -> u64 { self - other } } -impl Sub for u32 { fn sub(self, other: u32) -> u32 { self - other } } -impl Sub for u16 { fn sub(self, other: u16) -> u16 { self - other } } -impl Sub for u8 { fn sub(self, other: u8) -> u8 { self - other } } -impl Sub for u1 { fn sub(self, other: u1) -> u1 { self - other } } +impl Sub for u64 { + fn sub(self, other: u64) -> u64 { + self - other + } +} +impl Sub for u32 { + fn sub(self, other: u32) -> u32 { + self - other + } +} +impl Sub for u16 { + fn sub(self, other: u16) -> u16 { + self - other + } +} +impl Sub for u8 { + fn sub(self, other: u8) -> u8 { + self - other + } +} +impl Sub for u1 { + fn sub(self, other: u1) -> u1 { + self - other + } +} -impl Sub for i8 { fn sub(self, other: i8) -> i8 { self - other } } -impl Sub for i16 { fn sub(self, other: i16) -> i16 { self - other } } -impl Sub for i32 { fn sub(self, other: i32) -> i32 { self - other } } -impl Sub for i64 { fn sub(self, other: i64) -> i64 { self - other } } +impl Sub for i8 { + fn sub(self, other: i8) -> i8 { + self - other + } +} +impl Sub for i16 { + fn sub(self, other: i16) -> i16 { + self - other + } +} +impl Sub for i32 { + fn sub(self, other: i32) -> i32 { + self - other + } +} +impl Sub for i64 { + fn sub(self, other: i64) -> i64 { + self - other + } +} // docs:start:mul-trait trait Mul { @@ -42,18 +122,58 @@ trait Mul { } // docs:end:mul-trait -impl Mul for Field { fn mul(self, other: Field) -> Field { self * other } } +impl Mul for Field { + fn mul(self, other: Field) -> Field { + self * other + } +} -impl Mul for u64 { fn mul(self, other: u64) -> u64 { self * other } } -impl Mul for u32 { fn mul(self, other: u32) -> u32 { self * other } } -impl Mul for u16 { fn mul(self, other: u16) -> u16 { self * other } } -impl Mul for u8 { fn mul(self, other: u8) -> u8 { self * other } } -impl Mul for u1 { fn mul(self, other: u1) -> u1 { self * other } } +impl Mul for u64 { + fn mul(self, other: u64) -> u64 { + self * other + } +} +impl Mul for u32 { + fn mul(self, other: u32) -> u32 { + self * other + } +} +impl Mul for u16 { + fn mul(self, other: u16) -> u16 { + self * other + } +} +impl Mul for u8 { + fn mul(self, other: u8) -> u8 { + self * other + } +} +impl Mul for u1 { + fn mul(self, other: u1) -> u1 { + self * other + } +} -impl Mul for i8 { fn mul(self, other: i8) -> i8 { self * other } } -impl Mul for i16 { fn mul(self, other: i16) -> i16 { self * other } } -impl Mul for i32 { fn mul(self, other: i32) -> i32 { self * other } } -impl Mul for i64 { fn mul(self, other: i64) -> i64 { self * other } } +impl Mul for i8 { + fn mul(self, other: i8) -> i8 { + self * other + } +} +impl Mul for i16 { + fn mul(self, other: i16) -> i16 { + self * other + } +} +impl Mul for i32 { + fn mul(self, other: i32) -> i32 { + self * other + } +} +impl Mul for i64 { + fn mul(self, other: i64) -> i64 { + self * other + } +} // docs:start:div-trait trait Div { @@ -61,18 +181,58 @@ trait Div { } // docs:end:div-trait -impl Div for Field { fn div(self, other: Field) -> Field { self / other } } +impl Div for Field { + fn div(self, other: Field) -> Field { + self / other + } +} -impl Div for u64 { fn div(self, other: u64) -> u64 { self / other } } -impl Div for u32 { fn div(self, other: u32) -> u32 { self / other } } -impl Div for u16 { fn div(self, other: u16) -> u16 { self / other } } -impl Div for u8 { fn div(self, other: u8) -> u8 { self / other } } -impl Div for u1 { fn div(self, other: u1) -> u1 { self / other } } +impl Div for u64 { + fn div(self, other: u64) -> u64 { + self / other + } +} +impl Div for u32 { + fn div(self, other: u32) -> u32 { + self / other + } +} +impl Div for u16 { + fn div(self, other: u16) -> u16 { + self / other + } +} +impl Div for u8 { + fn div(self, other: u8) -> u8 { + self / other + } +} +impl Div for u1 { + fn div(self, other: u1) -> u1 { + self / other + } +} -impl Div for i8 { fn div(self, other: i8) -> i8 { self / other } } -impl Div for i16 { fn div(self, other: i16) -> i16 { self / other } } -impl Div for i32 { fn div(self, other: i32) -> i32 { self / other } } -impl Div for i64 { fn div(self, other: i64) -> i64 { self / other } } +impl Div for i8 { + fn div(self, other: i8) -> i8 { + self / other + } +} +impl Div for i16 { + fn div(self, other: i16) -> i16 { + self / other + } +} +impl Div for i32 { + fn div(self, other: i32) -> i32 { + self / other + } +} +impl Div for i64 { + fn div(self, other: i64) -> i64 { + self / other + } +} // docs:start:rem-trait trait Rem{ @@ -80,16 +240,52 @@ trait Rem{ } // docs:end:rem-trait -impl Rem for u64 { fn rem(self, other: u64) -> u64 { self % other } } -impl Rem for u32 { fn rem(self, other: u32) -> u32 { self % other } } -impl Rem for u16 { fn rem(self, other: u16) -> u16 { self % other } } -impl Rem for u8 { fn rem(self, other: u8) -> u8 { self % other } } -impl Rem for u1 { fn rem(self, other: u1) -> u1 { self % other } } +impl Rem for u64 { + fn rem(self, other: u64) -> u64 { + self % other + } +} +impl Rem for u32 { + fn rem(self, other: u32) -> u32 { + self % other + } +} +impl Rem for u16 { + fn rem(self, other: u16) -> u16 { + self % other + } +} +impl Rem for u8 { + fn rem(self, other: u8) -> u8 { + self % other + } +} +impl Rem for u1 { + fn rem(self, other: u1) -> u1 { + self % other + } +} -impl Rem for i8 { fn rem(self, other: i8) -> i8 { self % other } } -impl Rem for i16 { fn rem(self, other: i16) -> i16 { self % other } } -impl Rem for i32 { fn rem(self, other: i32) -> i32 { self % other } } -impl Rem for i64 { fn rem(self, other: i64) -> i64 { self % other } } +impl Rem for i8 { + fn rem(self, other: i8) -> i8 { + self % other + } +} +impl Rem for i16 { + fn rem(self, other: i16) -> i16 { + self % other + } +} +impl Rem for i32 { + fn rem(self, other: i32) -> i32 { + self % other + } +} +impl Rem for i64 { + fn rem(self, other: i64) -> i64 { + self % other + } +} // docs:start:neg-trait trait Neg { @@ -98,11 +294,31 @@ trait Neg { // docs:end:neg-trait // docs:start:neg-trait-impls -impl Neg for Field { fn neg(self) -> Field { -self } } +impl Neg for Field { + fn neg(self) -> Field { + -self + } +} -impl Neg for i8 { fn neg(self) -> i8 { -self } } -impl Neg for i16 { fn neg(self) -> i16 { -self } } -impl Neg for i32 { fn neg(self) -> i32 { -self } } -impl Neg for i64 { fn neg(self) -> i64 { -self } } +impl Neg for i8 { + fn neg(self) -> i8 { + -self + } +} +impl Neg for i16 { + fn neg(self) -> i16 { + -self + } +} +impl Neg for i32 { + fn neg(self) -> i32 { + -self + } +} +impl Neg for i64 { + fn neg(self) -> i64 { + -self + } +} // docs:end:neg-trait-impls diff --git a/noir/noir-repo/noir_stdlib/src/ops/bit.nr b/noir/noir-repo/noir_stdlib/src/ops/bit.nr index 015d0008e7a..0c0329efe4c 100644 --- a/noir/noir-repo/noir_stdlib/src/ops/bit.nr +++ b/noir/noir-repo/noir_stdlib/src/ops/bit.nr @@ -5,18 +5,58 @@ trait Not { // docs:end:not-trait // docs:start:not-trait-impls -impl Not for bool { fn not(self) -> bool { !self } } - -impl Not for u64 { fn not(self) -> u64 { !self } } -impl Not for u32 { fn not(self) -> u32 { !self } } -impl Not for u16 { fn not(self) -> u16 { !self } } -impl Not for u8 { fn not(self) -> u8 { !self } } -impl Not for u1 { fn not(self) -> u1 { !self } } - -impl Not for i8 { fn not(self) -> i8 { !self } } -impl Not for i16 { fn not(self) -> i16 { !self } } -impl Not for i32 { fn not(self) -> i32 { !self } } -impl Not for i64 { fn not(self) -> i64 { !self } } +impl Not for bool { + fn not(self) -> bool { + !self + } +} + +impl Not for u64 { + fn not(self) -> u64 { + !self + } +} +impl Not for u32 { + fn not(self) -> u32 { + !self + } +} +impl Not for u16 { + fn not(self) -> u16 { + !self + } +} +impl Not for u8 { + fn not(self) -> u8 { + !self + } +} +impl Not for u1 { + fn not(self) -> u1 { + !self + } +} + +impl Not for i8 { + fn not(self) -> i8 { + !self + } +} +impl Not for i16 { + fn not(self) -> i16 { + !self + } +} +impl Not for i32 { + fn not(self) -> i32 { + !self + } +} +impl Not for i64 { + fn not(self) -> i64 { + !self + } +} // docs:end:not-trait-impls // docs:start:bitor-trait @@ -25,18 +65,58 @@ trait BitOr { } // docs:end:bitor-trait -impl BitOr for bool { fn bitor(self, other: bool) -> bool { self | other } } +impl BitOr for bool { + fn bitor(self, other: bool) -> bool { + self | other + } +} -impl BitOr for u64 { fn bitor(self, other: u64) -> u64 { self | other } } -impl BitOr for u32 { fn bitor(self, other: u32) -> u32 { self | other } } -impl BitOr for u16 { fn bitor(self, other: u16) -> u16 { self | other } } -impl BitOr for u8 { fn bitor(self, other: u8) -> u8 { self | other } } -impl BitOr for u1 { fn bitor(self, other: u1) -> u1 { self | other } } +impl BitOr for u64 { + fn bitor(self, other: u64) -> u64 { + self | other + } +} +impl BitOr for u32 { + fn bitor(self, other: u32) -> u32 { + self | other + } +} +impl BitOr for u16 { + fn bitor(self, other: u16) -> u16 { + self | other + } +} +impl BitOr for u8 { + fn bitor(self, other: u8) -> u8 { + self | other + } +} +impl BitOr for u1 { + fn bitor(self, other: u1) -> u1 { + self | other + } +} -impl BitOr for i8 { fn bitor(self, other: i8) -> i8 { self | other } } -impl BitOr for i16 { fn bitor(self, other: i16) -> i16 { self | other } } -impl BitOr for i32 { fn bitor(self, other: i32) -> i32 { self | other } } -impl BitOr for i64 { fn bitor(self, other: i64) -> i64 { self | other } } +impl BitOr for i8 { + fn bitor(self, other: i8) -> i8 { + self | other + } +} +impl BitOr for i16 { + fn bitor(self, other: i16) -> i16 { + self | other + } +} +impl BitOr for i32 { + fn bitor(self, other: i32) -> i32 { + self | other + } +} +impl BitOr for i64 { + fn bitor(self, other: i64) -> i64 { + self | other + } +} // docs:start:bitand-trait trait BitAnd { @@ -44,18 +124,58 @@ trait BitAnd { } // docs:end:bitand-trait -impl BitAnd for bool { fn bitand(self, other: bool) -> bool { self & other } } +impl BitAnd for bool { + fn bitand(self, other: bool) -> bool { + self & other + } +} -impl BitAnd for u64 { fn bitand(self, other: u64) -> u64 { self & other } } -impl BitAnd for u32 { fn bitand(self, other: u32) -> u32 { self & other } } -impl BitAnd for u16 { fn bitand(self, other: u16) -> u16 { self & other } } -impl BitAnd for u8 { fn bitand(self, other: u8) -> u8 { self & other } } -impl BitAnd for u1 { fn bitand(self, other: u1) -> u1 { self & other } } +impl BitAnd for u64 { + fn bitand(self, other: u64) -> u64 { + self & other + } +} +impl BitAnd for u32 { + fn bitand(self, other: u32) -> u32 { + self & other + } +} +impl BitAnd for u16 { + fn bitand(self, other: u16) -> u16 { + self & other + } +} +impl BitAnd for u8 { + fn bitand(self, other: u8) -> u8 { + self & other + } +} +impl BitAnd for u1 { + fn bitand(self, other: u1) -> u1 { + self & other + } +} -impl BitAnd for i8 { fn bitand(self, other: i8) -> i8 { self & other } } -impl BitAnd for i16 { fn bitand(self, other: i16) -> i16 { self & other } } -impl BitAnd for i32 { fn bitand(self, other: i32) -> i32 { self & other } } -impl BitAnd for i64 { fn bitand(self, other: i64) -> i64 { self & other } } +impl BitAnd for i8 { + fn bitand(self, other: i8) -> i8 { + self & other + } +} +impl BitAnd for i16 { + fn bitand(self, other: i16) -> i16 { + self & other + } +} +impl BitAnd for i32 { + fn bitand(self, other: i32) -> i32 { + self & other + } +} +impl BitAnd for i64 { + fn bitand(self, other: i64) -> i64 { + self & other + } +} // docs:start:bitxor-trait trait BitXor { @@ -63,18 +183,58 @@ trait BitXor { } // docs:end:bitxor-trait -impl BitXor for bool { fn bitxor(self, other: bool) -> bool { self ^ other } } +impl BitXor for bool { + fn bitxor(self, other: bool) -> bool { + self ^ other + } +} -impl BitXor for u64 { fn bitxor(self, other: u64) -> u64 { self ^ other } } -impl BitXor for u32 { fn bitxor(self, other: u32) -> u32 { self ^ other } } -impl BitXor for u16 { fn bitxor(self, other: u16) -> u16 { self ^ other } } -impl BitXor for u8 { fn bitxor(self, other: u8) -> u8 { self ^ other } } -impl BitXor for u1 { fn bitxor(self, other: u1) -> u1 { self ^ other } } +impl BitXor for u64 { + fn bitxor(self, other: u64) -> u64 { + self ^ other + } +} +impl BitXor for u32 { + fn bitxor(self, other: u32) -> u32 { + self ^ other + } +} +impl BitXor for u16 { + fn bitxor(self, other: u16) -> u16 { + self ^ other + } +} +impl BitXor for u8 { + fn bitxor(self, other: u8) -> u8 { + self ^ other + } +} +impl BitXor for u1 { + fn bitxor(self, other: u1) -> u1 { + self ^ other + } +} -impl BitXor for i8 { fn bitxor(self, other: i8) -> i8 { self ^ other } } -impl BitXor for i16 { fn bitxor(self, other: i16) -> i16 { self ^ other } } -impl BitXor for i32 { fn bitxor(self, other: i32) -> i32 { self ^ other } } -impl BitXor for i64 { fn bitxor(self, other: i64) -> i64 { self ^ other } } +impl BitXor for i8 { + fn bitxor(self, other: i8) -> i8 { + self ^ other + } +} +impl BitXor for i16 { + fn bitxor(self, other: i16) -> i16 { + self ^ other + } +} +impl BitXor for i32 { + fn bitxor(self, other: i32) -> i32 { + self ^ other + } +} +impl BitXor for i64 { + fn bitxor(self, other: i64) -> i64 { + self ^ other + } +} // docs:start:shl-trait trait Shl { @@ -82,16 +242,52 @@ trait Shl { } // docs:end:shl-trait -impl Shl for u32 { fn shl(self, other: u8) -> u32 { self << other } } -impl Shl for u64 { fn shl(self, other: u8) -> u64 { self << other } } -impl Shl for u16 { fn shl(self, other: u8) -> u16 { self << other } } -impl Shl for u8 { fn shl(self, other: u8) -> u8 { self << other } } -impl Shl for u1 { fn shl(self, other: u8) -> u1 { self << other } } +impl Shl for u32 { + fn shl(self, other: u8) -> u32 { + self << other + } +} +impl Shl for u64 { + fn shl(self, other: u8) -> u64 { + self << other + } +} +impl Shl for u16 { + fn shl(self, other: u8) -> u16 { + self << other + } +} +impl Shl for u8 { + fn shl(self, other: u8) -> u8 { + self << other + } +} +impl Shl for u1 { + fn shl(self, other: u8) -> u1 { + self << other + } +} -impl Shl for i8 { fn shl(self, other: u8) -> i8 { self << other } } -impl Shl for i16 { fn shl(self, other: u8) -> i16 { self << other } } -impl Shl for i32 { fn shl(self, other: u8) -> i32 { self << other } } -impl Shl for i64 { fn shl(self, other: u8) -> i64 { self << other } } +impl Shl for i8 { + fn shl(self, other: u8) -> i8 { + self << other + } +} +impl Shl for i16 { + fn shl(self, other: u8) -> i16 { + self << other + } +} +impl Shl for i32 { + fn shl(self, other: u8) -> i32 { + self << other + } +} +impl Shl for i64 { + fn shl(self, other: u8) -> i64 { + self << other + } +} // docs:start:shr-trait trait Shr { @@ -99,14 +295,50 @@ trait Shr { } // docs:end:shr-trait -impl Shr for u64 { fn shr(self, other: u8) -> u64 { self >> other } } -impl Shr for u32 { fn shr(self, other: u8) -> u32 { self >> other } } -impl Shr for u16 { fn shr(self, other: u8) -> u16 { self >> other } } -impl Shr for u8 { fn shr(self, other: u8) -> u8 { self >> other } } -impl Shr for u1 { fn shr(self, other: u8) -> u1 { self >> other } } +impl Shr for u64 { + fn shr(self, other: u8) -> u64 { + self >> other + } +} +impl Shr for u32 { + fn shr(self, other: u8) -> u32 { + self >> other + } +} +impl Shr for u16 { + fn shr(self, other: u8) -> u16 { + self >> other + } +} +impl Shr for u8 { + fn shr(self, other: u8) -> u8 { + self >> other + } +} +impl Shr for u1 { + fn shr(self, other: u8) -> u1 { + self >> other + } +} -impl Shr for i8 { fn shr(self, other: u8) -> i8 { self >> other } } -impl Shr for i16 { fn shr(self, other: u8) -> i16 { self >> other } } -impl Shr for i32 { fn shr(self, other: u8) -> i32 { self >> other } } -impl Shr for i64 { fn shr(self, other: u8) -> i64 { self >> other } } +impl Shr for i8 { + fn shr(self, other: u8) -> i8 { + self >> other + } +} +impl Shr for i16 { + fn shr(self, other: u8) -> i16 { + self >> other + } +} +impl Shr for i32 { + fn shr(self, other: u8) -> i32 { + self >> other + } +} +impl Shr for i64 { + fn shr(self, other: u8) -> i64 { + self >> other + } +} diff --git a/noir/noir-repo/noir_stdlib/src/option.nr b/noir/noir-repo/noir_stdlib/src/option.nr index 5b6b36679f8..2823ba8af1b 100644 --- a/noir/noir-repo/noir_stdlib/src/option.nr +++ b/noir/noir-repo/noir_stdlib/src/option.nr @@ -195,12 +195,10 @@ impl Ord for Option where T: Ord { } else { Ordering::greater() } + } else if other._is_some { + Ordering::less() } else { - if other._is_some { - Ordering::less() - } else { - Ordering::equal() - } + Ordering::equal() } } } diff --git a/noir/noir-repo/noir_stdlib/src/uint128.nr b/noir/noir-repo/noir_stdlib/src/uint128.nr index ac7f744cb3b..91c3369f889 100644 --- a/noir/noir-repo/noir_stdlib/src/uint128.nr +++ b/noir/noir-repo/noir_stdlib/src/uint128.nr @@ -165,14 +165,11 @@ impl Add for U128 { fn add(self: Self, b: U128) -> U128 { let low = self.lo + b.lo; let lo = low as u64 as Field; - let carry = (low - lo) / pow64; + let carry = (low - lo) / pow64; let high = self.hi + b.hi + carry; let hi = high as u64 as Field; assert(hi == high, "attempt to add with overflow"); - U128 { - lo, - hi, - } + U128 { lo, hi } } } @@ -184,30 +181,24 @@ impl Sub for U128 { let high = self.hi - b.hi - borrow; let hi = high as u64 as Field; assert(hi == high, "attempt to subtract with underflow"); - U128 { - lo, - hi, - } + U128 { lo, hi } } } impl Mul for U128 { fn mul(self: Self, b: U128) -> U128 { - assert(self.hi*b.hi == 0, "attempt to multiply with overflow"); - let low = self.lo*b.lo; + assert(self.hi * b.hi == 0, "attempt to multiply with overflow"); + let low = self.lo * b.lo; let lo = low as u64 as Field; let carry = (low - lo) / pow64; let high = if crate::field::modulus_num_bits() as u32 > 196 { - (self.lo+self.hi)*(b.lo+b.hi) - low + carry + (self.lo + self.hi) * (b.lo + b.hi) - low + carry } else { - self.lo*b.hi + self.hi*b.lo + carry + self.lo * b.hi + self.hi * b.lo + carry }; let hi = high as u64 as Field; assert(hi == high, "attempt to multiply with overflow"); - U128 { - lo, - hi, - } + U128 { lo, hi } } } @@ -230,7 +221,7 @@ impl Rem for U128 { let a = b * q + r; assert_eq(self, a); assert(r < b); - + r } } @@ -246,7 +237,7 @@ impl Ord for U128 { fn cmp(self, other: Self) -> Ordering { let hi_ordering = (self.hi as u64).cmp((other.hi as u64)); let lo_ordering = (self.lo as u64).cmp((other.lo as u64)); - + if hi_ordering == Ordering::equal() { lo_ordering } else { @@ -255,16 +246,13 @@ impl Ord for U128 { } } -impl Not for U128 { +impl Not for U128 { fn not(self) -> U128 { - U128 { - lo: (!(self.lo as u64)) as Field, - hi: (!(self.hi as u64)) as Field - } + U128 { lo: (!(self.lo as u64)) as Field, hi: (!(self.hi as u64)) as Field } } } -impl BitOr for U128 { +impl BitOr for U128 { fn bitor(self, other: U128) -> U128 { U128 { lo: ((self.lo as u64) | (other.lo as u64)) as Field, @@ -274,7 +262,7 @@ impl BitOr for U128 { } impl BitAnd for U128 { - fn bitand(self, other: U128) -> U128 { + fn bitand(self, other: U128) -> U128 { U128 { lo: ((self.lo as u64) & (other.lo as u64)) as Field, hi: ((self.hi as u64) & (other.hi as u64)) as Field @@ -283,7 +271,7 @@ impl BitAnd for U128 { } impl BitXor for U128 { - fn bitxor(self, other: U128) -> U128 { + fn bitxor(self, other: U128) -> U128 { U128 { lo: ((self.lo as u64) ^ (other.lo as u64)) as Field, hi: ((self.hi as u64) ^ (other.hi as u64)) as Field @@ -291,36 +279,36 @@ impl BitXor for U128 { } } -impl Shl for U128 { - fn shl(self, other: u8) -> U128 { +impl Shl for U128 { + fn shl(self, other: u8) -> U128 { assert(other < 128, "attempt to shift left with overflow"); let exp_bits: [u1; 7] = (other as Field).to_be_bits(); let mut r: Field = 2; let mut y: Field = 1; for i in 1..8 { - let bit = exp_bits[7-i] as Field; + let bit = exp_bits[7 - i] as Field; y = bit * (r * y) + (1 - bit) * y; r *= r; } self.wrapping_mul(U128::from_integer(y)) - } + } } -impl Shr for U128 { - fn shr(self, other: u8) -> U128 { +impl Shr for U128 { + fn shr(self, other: u8) -> U128 { assert(other < 128, "attempt to shift right with overflow"); let exp_bits: [u1; 7] = (other as Field).to_be_bits(); let mut r: Field = 2; let mut y: Field = 1; for i in 1..8 { - let bit = exp_bits[7-i] as Field; + let bit = exp_bits[7 - i] as Field; y = bit * (r * y) + (1 - bit) * y; r *= r; } self / U128::from_integer(y) - } + } } mod tests { diff --git a/noir/noir-repo/test_programs/compile_failure/arithmetic_generics_intermediate_underflow/src/main.nr b/noir/noir-repo/test_programs/compile_failure/arithmetic_generics_intermediate_underflow/src/main.nr index 58cf2f648e5..df778468397 100644 --- a/noir/noir-repo/test_programs/compile_failure/arithmetic_generics_intermediate_underflow/src/main.nr +++ b/noir/noir-repo/test_programs/compile_failure/arithmetic_generics_intermediate_underflow/src/main.nr @@ -15,7 +15,7 @@ fn seems_fine(array: [Field; N]) -> [Field; N] { fn pop(array: [Field; N]) -> [Field; N - 1] { let mut result: [Field; N - 1] = std::mem::zeroed(); - for i in 0..N { + for i in 0..N - 1 { result[i] = array[i]; } result diff --git a/noir/noir-repo/test_programs/compile_failure/arithmetic_generics_underflow/src/main.nr b/noir/noir-repo/test_programs/compile_failure/arithmetic_generics_underflow/src/main.nr index 4df83ac56e0..bc670a75a76 100644 --- a/noir/noir-repo/test_programs/compile_failure/arithmetic_generics_underflow/src/main.nr +++ b/noir/noir-repo/test_programs/compile_failure/arithmetic_generics_underflow/src/main.nr @@ -1,7 +1,7 @@ // docs:start:underflow-example fn pop(array: [Field; N]) -> [Field; N - 1] { let mut result: [Field; N - 1] = std::mem::zeroed(); - for i in 0..N { + for i in 0..N - 1 { result[i] = array[i]; } result diff --git a/noir/noir-repo/test_programs/compile_success_empty/arithmetic_generics_move_constant_terms/Nargo.toml b/noir/noir-repo/test_programs/compile_success_empty/arithmetic_generics_move_constant_terms/Nargo.toml new file mode 100644 index 00000000000..8d057a77814 --- /dev/null +++ b/noir/noir-repo/test_programs/compile_success_empty/arithmetic_generics_move_constant_terms/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "arithmetic_generics_move_constant_terms" +type = "bin" +authors = [""] +compiler_version = ">=0.33.0" + +[dependencies] diff --git a/noir/noir-repo/test_programs/compile_success_empty/arithmetic_generics_move_constant_terms/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/arithmetic_generics_move_constant_terms/src/main.nr new file mode 100644 index 00000000000..e27d4baf1f4 --- /dev/null +++ b/noir/noir-repo/test_programs/compile_success_empty/arithmetic_generics_move_constant_terms/src/main.nr @@ -0,0 +1,26 @@ +trait FromCallData { + fn from_calldata(calldata: [Field; N]) -> (Self, [Field; M]); +} + +struct Point { x: Field, y: Field } + +impl FromCallData for Field { + fn from_calldata(calldata: [Field; N]) -> (Self, [Field; N - 1]) { + let slice = calldata.as_slice(); + let (value, slice) = slice.pop_front(); + (value, slice.as_array()) + } +} + +impl FromCallData for Point { + fn from_calldata(calldata: [Field; N]) -> (Self, [Field; N - 2]) { + let (x, calldata) = FromCallData::from_calldata(calldata); + let (y, calldata) = FromCallData::from_calldata(calldata); + (Self { x, y }, calldata) + } +} + +fn main() { + let calldata = [1, 2]; + let _: (Point, _) = FromCallData::from_calldata(calldata); +} diff --git a/noir/noir-repo/test_programs/compile_success_empty/attributes_struct/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/attributes_struct/src/main.nr index 79bf3e29533..669cfc32927 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/attributes_struct/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/attributes_struct/src/main.nr @@ -9,13 +9,16 @@ fn main() {} // Check that add_attribute and has_named_attribute work well +#[abi(something)] #[add_attribute] struct Foo { } comptime fn add_attribute(s: StructDefinition) { - assert(!s.has_named_attribute(quote { foo })); + assert(!s.has_named_attribute("foo")); s.add_attribute("foo"); - assert(s.has_named_attribute(quote { foo })); + assert(s.has_named_attribute("foo")); + + assert(s.has_named_attribute("abi")); } diff --git a/noir/noir-repo/test_programs/compile_success_empty/comptime_function_definition/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/comptime_function_definition/src/main.nr index e01ff4a71f1..4266d3734f9 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/comptime_function_definition/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/comptime_function_definition/src/main.nr @@ -8,6 +8,11 @@ pub fn foo(w: i32, y: Field, Foo { x, field: some_field }: Foo, mut a: bool, (b, 1 } +#[test] +#[deprecated] +#[check_named_attribute] +fn some_test() {} + comptime fn function_attr(f: FunctionDefinition) { // Check FunctionDefinition::parameters let parameters = f.parameters(); @@ -33,7 +38,12 @@ comptime fn function_attr(f: FunctionDefinition) { // Check FunctionDefinition::name assert_eq(f.name(), quote { foo }); - assert(f.has_named_attribute(quote { function_attr })); + assert(f.has_named_attribute("function_attr")); +} + +comptime fn check_named_attribute(f: FunctionDefinition) { + assert(f.has_named_attribute("test")); + assert(f.has_named_attribute("deprecated")); } #[mutate_add_one] diff --git a/noir/noir-repo/test_programs/compile_success_empty/comptime_globals_regression/Nargo.toml b/noir/noir-repo/test_programs/compile_success_empty/comptime_globals_regression/Nargo.toml new file mode 100644 index 00000000000..5c5b64c712a --- /dev/null +++ b/noir/noir-repo/test_programs/compile_success_empty/comptime_globals_regression/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "comptime_globals_regression" +type = "bin" +authors = [""] +compiler_version = ">=0.33.0" + +[dependencies] diff --git a/noir/noir-repo/test_programs/compile_success_empty/comptime_globals_regression/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/comptime_globals_regression/src/main.nr new file mode 100644 index 00000000000..54dbc0413f0 --- /dev/null +++ b/noir/noir-repo/test_programs/compile_success_empty/comptime_globals_regression/src/main.nr @@ -0,0 +1,23 @@ +comptime mut global COUNTER = 0; + +fn main() { + comptime + { + increment() + }; + comptime + { + increment() + }; + + assert_eq(get_counter(), 2); +} + +fn get_counter() -> Field { + COUNTER +} + +comptime fn increment() { + COUNTER += 1; + assert_eq(get_counter(), COUNTER); +} diff --git a/noir/noir-repo/test_programs/compile_success_empty/comptime_module/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/comptime_module/src/main.nr index c3ba7ba4643..9443b59fb0a 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/comptime_module/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/comptime_module/src/main.nr @@ -3,6 +3,8 @@ mod foo { #![some_attribute] pub fn x() {} pub fn y() {} + + struct Struct1 {} } contract bar {} @@ -74,15 +76,19 @@ fn main() { assert_eq(foo.functions().len(), 2); assert_eq(bar.functions().len(), 0); + // Check Module::structs + assert_eq(foo.structs().len(), 1); + assert_eq(bar.structs().len(), 0); + // Check Module::name assert_eq(foo.name(), quote { foo }); assert_eq(bar.name(), quote { bar }); // Check Module::has_named_attribute - assert(foo.has_named_attribute(quote { some_attribute })); - assert(foo.has_named_attribute(quote { outer_attribute })); - assert(!bar.has_named_attribute(quote { some_attribute })); - assert(another_module.has_named_attribute(quote { some_attribute })); + assert(foo.has_named_attribute("some_attribute")); + assert(foo.has_named_attribute("outer_attribute")); + assert(!bar.has_named_attribute("some_attribute")); + assert(another_module.has_named_attribute("some_attribute")); } assert_eq(counter, 4); diff --git a/noir/noir-repo/test_programs/compile_success_empty/comptime_trait_constraint/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/comptime_trait_constraint/src/main.nr index 2f2ca89cfb5..448da96a460 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/comptime_trait_constraint/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/comptime_trait_constraint/src/main.nr @@ -32,7 +32,7 @@ impl Hasher for TestHasher { fn finish(self) -> Field { self.result } - + fn write(&mut self, input: Field) { self.result += input; } diff --git a/noir/noir-repo/test_programs/compile_success_empty/comptime_type/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/comptime_type/src/main.nr index c9307570c87..c7b3d0b9400 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/comptime_type/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/comptime_type/src/main.nr @@ -11,9 +11,7 @@ struct StructImplementsSomeTrait { } -impl SomeTrait for StructImplementsSomeTrait { - -} +impl SomeTrait for StructImplementsSomeTrait {} struct StructDoesNotImplementSomeTrait { diff --git a/noir/noir-repo/test_programs/compile_success_empty/inject_context_attribute/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/inject_context_attribute/src/main.nr index 9dc8cf1ed47..156579ce0b2 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/inject_context_attribute/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/inject_context_attribute/src/main.nr @@ -45,7 +45,7 @@ comptime fn mapping_function(expr: Expr, f: FunctionDefinition) -> Option let (name, arguments) = func_call; name.resolve(Option::some(f)).as_function_definition().and_then( |function_definition: FunctionDefinition| { - if function_definition.has_named_attribute(quote { inject_context }) { + if function_definition.has_named_attribute("inject_context") { let arguments = arguments.push_front(quote { _context }.as_expr().unwrap()); let arguments = arguments.map(|arg: Expr| arg.quoted()).join(quote { , }); Option::some(quote { $name($arguments) }.as_expr().unwrap()) diff --git a/noir/noir-repo/test_programs/compile_success_empty/no_duplicate_methods/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/no_duplicate_methods/src/main.nr index 2be1d3fa11e..3ca9c841a8c 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/no_duplicate_methods/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/no_duplicate_methods/src/main.nr @@ -10,11 +10,15 @@ trait ToField2 { struct Foo { x: Field } impl ToField for Foo { - fn to_field(self) -> Field { self.x } + fn to_field(self) -> Field { + self.x + } } impl ToField2 for Foo { - fn to_field(self) -> Field { self.x } + fn to_field(self) -> Field { + self.x + } } impl Foo { diff --git a/noir/noir-repo/test_programs/compile_success_empty/regression_4635/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/regression_4635/src/main.nr index 75188f797dd..6709a421470 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/regression_4635/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/regression_4635/src/main.nr @@ -44,7 +44,7 @@ struct MyStruct { impl Deserialize<1> for MyStruct where T: FromField { fn deserialize(fields: [Field; 1]) -> Self { - Self{ a: FromField::from_field(fields[0]) } + Self { a: FromField::from_field(fields[0]) } } } diff --git a/noir/noir-repo/test_programs/compile_success_empty/serialize/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/serialize/src/main.nr index 79114c5b567..6fee6fb72a6 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/serialize/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/serialize/src/main.nr @@ -14,10 +14,10 @@ impl Serialize for (A, B) where A: Serialize Serialize for [T; N] where T: Serialize Self { - Self { bar: x, array: [x,y] } + fn my_default(x: Field, y: Field) -> Self { + Self { bar: x, array: [x, y] } } } diff --git a/noir/noir-repo/test_programs/compile_success_empty/trait_function_calls/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/trait_function_calls/src/main.nr index 39d28a5a3b3..62af0e756cd 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/trait_function_calls/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/trait_function_calls/src/main.nr @@ -30,7 +30,7 @@ trait Trait1a { } } struct Struct1a { vl: Field } -impl Trait1a for Struct1a { } +impl Trait1a for Struct1a {} // 1b) trait default method -> trait overriden method trait Trait1b { fn trait_method1(self) -> Field { @@ -162,7 +162,7 @@ trait Trait2a { } } struct Struct2a { vl: Field } -impl Trait2a for Struct2a { } +impl Trait2a for Struct2a {} // 2b) trait default method -> trait overriden function trait Trait2b { fn trait_method1(self) -> Field { @@ -294,7 +294,7 @@ trait Trait3a { } } struct Struct3a { vl: Field } -impl Trait3a for Struct3a { } +impl Trait3a for Struct3a {} // 3b) trait default function -> trait overriden method trait Trait3b { fn trait_function1(a: Field, b: Self) -> Field { @@ -426,7 +426,7 @@ trait Trait4a { } } struct Struct4a { vl: Field } -impl Trait4a for Struct4a { } +impl Trait4a for Struct4a {} // 4b) trait default function -> trait overriden function trait Trait4b { fn trait_function1() -> Field { diff --git a/noir/noir-repo/test_programs/compile_success_empty/trait_impl_generics/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/trait_impl_generics/src/main.nr index c46c41cbdd7..bae4d62f9e4 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/trait_impl_generics/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/trait_impl_generics/src/main.nr @@ -5,11 +5,15 @@ trait Foo { } impl Foo for Empty { - fn foo(_self: Self) -> u32 { 32 } + fn foo(_self: Self) -> u32 { + 32 + } } impl Foo for Empty { - fn foo(_self: Self) -> u32 { 64 } + fn foo(_self: Self) -> u32 { + 64 + } } fn main() { @@ -43,7 +47,9 @@ trait T2 { struct S2 { x: T } impl T2 for S2 { - fn t2(self) -> Self { self } + fn t2(self) -> Self { + self + } } fn call_impl_with_generic_function() { @@ -55,5 +61,7 @@ trait T3 { } impl T3 for u32 { - fn t3(_self: Self, y: U) -> U { y } + fn t3(_self: Self, y: U) -> U { + y + } } diff --git a/noir/noir-repo/test_programs/compile_success_empty/trait_impl_with_where_clause/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/trait_impl_with_where_clause/src/main.nr index 780512f04dc..6da2c86fa2f 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/trait_impl_with_where_clause/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/trait_impl_with_where_clause/src/main.nr @@ -13,7 +13,7 @@ trait MyEq { impl MyEq for [T; 3] where T: MyEq { fn my_eq(self, other: Self) -> bool { let mut ret = true; - for i in 0 .. self.len() { + for i in 0..self.len() { ret &= self[i].my_eq(other[i]); } ret diff --git a/noir/noir-repo/test_programs/compile_success_empty/trait_multi_module_test/src/module6.nr b/noir/noir-repo/test_programs/compile_success_empty/trait_multi_module_test/src/module6.nr index 35f5ce3a183..cb4eb3a2956 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/trait_multi_module_test/src/module6.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/trait_multi_module_test/src/module6.nr @@ -1,2 +1,2 @@ // ensure we can implement traits using the Path syntax -impl crate::module4::MyTrait4 for crate::module5::MyStruct5 { } +impl crate::module4::MyTrait4 for crate::module5::MyStruct5 {} diff --git a/noir/noir-repo/test_programs/compile_success_empty/trait_override_implementation/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/trait_override_implementation/src/main.nr index 21d89b1b261..68a928c0c52 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/trait_override_implementation/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/trait_override_implementation/src/main.nr @@ -12,8 +12,8 @@ struct Foo { } impl MyDefault for Foo { - fn my_default(x: Field,y: Field) -> Self { - Self { bar: x, array: [x,y] } + fn my_default(x: Field, y: Field) -> Self { + Self { bar: x, array: [x, y] } } fn method2(x: Field) -> Field { @@ -32,9 +32,15 @@ trait F { struct Bar {} impl F for Bar { - fn f5(_self: Self) -> Field { 50 } - fn f1(_self: Self) -> Field { 10 } - fn f3(_self: Self) -> Field { 30 } + fn f5(_self: Self) -> Field { + 50 + } + fn f1(_self: Self) -> Field { + 10 + } + fn f3(_self: Self) -> Field { + 30 + } } // Impls on mutable references are temporarily disabled // impl F for &mut Bar { diff --git a/noir/noir-repo/test_programs/compile_success_empty/trait_static_methods/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/trait_static_methods/src/main.nr index 838e47ee82e..976d0ab762c 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/trait_static_methods/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/trait_static_methods/src/main.nr @@ -16,7 +16,7 @@ struct Foo { impl ATrait for Foo { fn asd() -> Self { // This should pass as Self should be bound to Foo while typechecking this - Foo{x: 100} + Foo { x: 100 } } } @@ -27,7 +27,7 @@ impl ATrait for Bar { // The trait method is declared as returning `Self` // but explicitly specifying the type in the impl should work fn asd() -> Bar { - Bar{x: 100} + Bar { x: 100 } } fn static_method_2() -> Field { diff --git a/noir/noir-repo/test_programs/compile_success_empty/trait_where_clause/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/trait_where_clause/src/main.nr index 5fd7e78abf4..655450d05ac 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/trait_where_clause/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/trait_where_clause/src/main.nr @@ -12,9 +12,21 @@ struct Add20 { x: Field, } struct Add30 { x: Field, } struct AddXY { x: Field, y: Field, } -impl Asd for Add10 { fn asd(self) -> Field { self.x + 10 } } -impl Asd for Add20 { fn asd(self) -> Field { self.x + 20 } } -impl Asd for Add30 { fn asd(self) -> Field { self.x + 30 } } +impl Asd for Add10 { + fn asd(self) -> Field { + self.x + 10 + } +} +impl Asd for Add20 { + fn asd(self) -> Field { + self.x + 20 + } +} +impl Asd for Add30 { + fn asd(self) -> Field { + self.x + 30 + } +} impl Asd for AddXY { fn asd(self) -> Field { @@ -29,7 +41,9 @@ impl StaticTrait for Static100 { struct Static200 {} impl StaticTrait for Static200 { - fn static_function(slf: Self) -> Field { 200 } + fn static_function(slf: Self) -> Field { + 200 + } } fn assert_asd_eq_100(t: T) where T: crate::the_trait::Asd { diff --git a/noir/noir-repo/test_programs/compile_success_empty/traits/src/main.nr b/noir/noir-repo/test_programs/compile_success_empty/traits/src/main.nr index 0a5644e7530..9ef0ec6aba9 100644 --- a/noir/noir-repo/test_programs/compile_success_empty/traits/src/main.nr +++ b/noir/noir-repo/test_programs/compile_success_empty/traits/src/main.nr @@ -8,8 +8,8 @@ struct Foo { } impl MyDefault for Foo { - fn my_default(x: Field,y: Field) -> Self { - Self { bar: x, array: [x,y] } + fn my_default(x: Field, y: Field) -> Self { + Self { bar: x, array: [x, y] } } } diff --git a/noir/noir-repo/test_programs/execution_success/derive/src/main.nr b/noir/noir-repo/test_programs/execution_success/derive/src/main.nr index b32612831d7..f2f467eb761 100644 --- a/noir/noir-repo/test_programs/execution_success/derive/src/main.nr +++ b/noir/noir-repo/test_programs/execution_success/derive/src/main.nr @@ -69,7 +69,7 @@ impl std::hash::Hasher for TestHasher { fn finish(self) -> Field { self.result } - + fn write(&mut self, input: Field) { self.result += input; } diff --git a/noir/noir-repo/test_programs/execution_success/higher_order_functions/src/main.nr b/noir/noir-repo/test_programs/execution_success/higher_order_functions/src/main.nr index 6583f961d58..0a498e74ad1 100644 --- a/noir/noir-repo/test_programs/execution_success/higher_order_functions/src/main.nr +++ b/noir/noir-repo/test_programs/execution_success/higher_order_functions/src/main.nr @@ -63,7 +63,7 @@ fn test_array_functions() { // // opened #2121 for it // https://github.com/noir-lang/noir/issues/2121 - // let descending = myarray.sort_via(|a, b| a > b); + // let descending = myarray.sort_via(|a, b| a >= b); // assert(descending == [3, 2, 1]); assert(evens.map(|n| n / 2) == myarray); assert(evens.map(|n| n / two) == myarray); diff --git a/noir/noir-repo/test_programs/execution_success/slice_regex/src/main.nr b/noir/noir-repo/test_programs/execution_success/slice_regex/src/main.nr index 2382f5b0f2f..15768248473 100644 --- a/noir/noir-repo/test_programs/execution_success/slice_regex/src/main.nr +++ b/noir/noir-repo/test_programs/execution_success/slice_regex/src/main.nr @@ -12,9 +12,8 @@ impl Match { impl Eq for Match { fn eq(self, other: Self) -> bool { - (self.succeeded == other.succeeded) & - (self.match_ends == other.match_ends) - // (self.leftover == other.leftover) + (self.succeeded == other.succeeded) & (self.match_ends == other.match_ends) + // (self.leftover == other.leftover) } } @@ -48,17 +47,9 @@ impl Regex for str { } } if matches_input { - Match { - succeeded: true, - match_ends: self_as_bytes.len(), - leftover, - } + Match { succeeded: true, match_ends: self_as_bytes.len(), leftover } } else { - Match { - succeeded: false, - match_ends: 0, - leftover: input, - } + Match { succeeded: false, match_ends: 0, leftover: input } } } } @@ -73,21 +64,13 @@ impl Regex for (T, U) where T: Regex, U: Regex { Match { succeeded: true, match_ends: lhs_result.match_ends + rhs_result.match_ends, - leftover: rhs_result.leftover, + leftover: rhs_result.leftover } } else { - Match { - succeeded: false, - match_ends: 0, - leftover: input, - } + Match { succeeded: false, match_ends: 0, leftover: input } } } else { - Match { - succeeded: false, - match_ends: 0, - leftover: input, - } + Match { succeeded: false, match_ends: 0, leftover: input } } } } @@ -136,10 +119,7 @@ struct Question { impl Regex for Question where T: Regex { fn match(self, input: [u8]) -> Match { - Or { - lhs: self.inner, - rhs: (), - }.match(input) + Or { lhs: self.inner, rhs: () }.match(input) } } @@ -150,9 +130,7 @@ struct Star { impl Regex for Star where T: Regex { fn match(self, input: [u8]) -> Match { - let regex: Repeated<_, N> = Repeated { - inner: Question { inner: self.inner }, - }; + let regex: Repeated<_, N> = Repeated { inner: Question { inner: self.inner } }; regex.match(input) } } @@ -166,10 +144,7 @@ impl Regex for Plus where T: Regex fn match(self, input: [u8]) -> Match { std::static_assert(N_PRED + 1 == N, "N - 1 != N_PRED"); let star: Star = Star { inner: self.inner }; - ( - self.inner, - star - ).match(input) + (self.inner, star).match(input) } } diff --git a/noir/noir-repo/test_programs/execution_success/trait_impl_base_type/src/main.nr b/noir/noir-repo/test_programs/execution_success/trait_impl_base_type/src/main.nr index bb11dcab73a..e12cf019e0b 100644 --- a/noir/noir-repo/test_programs/execution_success/trait_impl_base_type/src/main.nr +++ b/noir/noir-repo/test_programs/execution_success/trait_impl_base_type/src/main.nr @@ -5,7 +5,7 @@ trait Fieldable { impl Fieldable for u32 { fn to_field(self) -> Field { let res = self as Field; - res * 3 + res * 3 } } @@ -18,21 +18,13 @@ impl Fieldable for [u32; 3] { impl Fieldable for bool { fn to_field(self) -> Field { - if self { - 14 - } else { - 3 - } + if self { 14 } else { 3 } } } impl Fieldable for (u32, bool) { fn to_field(self) -> Field { - if self.1 { - self.0 as Field - } else { - 32 - } + if self.1 { self.0 as Field } else { 32 } } } diff --git a/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Nargo.toml b/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Nargo.toml deleted file mode 100644 index 8fce1bf44b6..00000000000 --- a/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Nargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "verify_honk_proof" -type = "bin" -authors = [""] - -[dependencies] diff --git a/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Prover.toml b/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Prover.toml deleted file mode 100644 index 3f6bf0b427a..00000000000 --- a/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Prover.toml +++ /dev/null @@ -1,4 +0,0 @@ -key_hash = "0x0000000000000000000000000000000000000000000000000000000000000000" -proof = ["0x0000000000000000000000000000000000000000000000000000000000000040", "0x0000000000000000000000000000000000000000000000000000000000000011", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000042ab5d6d1986846cf", "0x00000000000000000000000000000000000000000000000b75c020998797da78", "0x0000000000000000000000000000000000000000000000005a107acb64952eca", "0x000000000000000000000000000000000000000000000000000031e97a575e9d", "0x00000000000000000000000000000000000000000000000b5666547acf8bd5a4", "0x00000000000000000000000000000000000000000000000c410db10a01750aeb", "0x00000000000000000000000000000000000000000000000d722669117f9758a4", "0x000000000000000000000000000000000000000000000000000178cbf4206471", "0x000000000000000000000000000000000000000000000000e91b8a11e7842c38", "0x000000000000000000000000000000000000000000000007fd51009034b3357f", "0x000000000000000000000000000000000000000000000009889939f81e9c7402", "0x0000000000000000000000000000000000000000000000000000f94656a2ca48", "0x000000000000000000000000000000000000000000000006fb128b46c1ddb67f", "0x0000000000000000000000000000000000000000000000093fe27776f50224bd", "0x000000000000000000000000000000000000000000000004a0c80c0da527a081", "0x0000000000000000000000000000000000000000000000000001b52c2020d746", "0x0000000000000000000000000000005a9bae947e1e91af9e4033d8d6aa6ed632", "0x000000000000000000000000000000000025e485e013446d4ac7981c88ba6ecc", "0x000000000000000000000000000000ff1e0496e30ab24a63b32b2d1120b76e62", "0x00000000000000000000000000000000001afe0a8a685d7cd85d1010e55d9d7c", "0x000000000000000000000000000000b0804efd6573805f991458295f510a2004", "0x00000000000000000000000000000000000c81a178016e2fe18605022d5a8b0e", "0x000000000000000000000000000000eba51e76eb1cfff60a53a0092a3c3dea47", "0x000000000000000000000000000000000022e7466247b533282f5936ac4e6c15", "0x00000000000000000000000000000071b1d76edf770edff98f00ff4deec264cd", "0x00000000000000000000000000000000001e48128e68794d8861fcbb2986a383", "0x000000000000000000000000000000d3a2af4915ae6d86b097adc377fafda2d4", "0x000000000000000000000000000000000006359de9ca452dab3a4f1f8d9c9d98", "0x0000000000000000000000000000006cf7dd96d7636fda5953191b1ad776d491", "0x00000000000000000000000000000000001633d881a08d136e834cb13a28fcc6", "0x00000000000000000000000000000001254956cff6908b069fca0e6cf1c47eb1", "0x000000000000000000000000000000000006f4d4dd3890e997e75e75886bf8f7", "0x0000000000000000000000000000006cf7dd96d7636fda5953191b1ad776d491", "0x00000000000000000000000000000000001633d881a08d136e834cb13a28fcc6", "0x00000000000000000000000000000001254956cff6908b069fca0e6cf1c47eb1", "0x000000000000000000000000000000000006f4d4dd3890e997e75e75886bf8f7", "0x000000000000000000000000000000f968b227a358a305607f3efc933823d288", "0x00000000000000000000000000000000000eaf8adb390375a76d95e918b65e08", "0x000000000000000000000000000000bb34b4b447aae56f5e24f81c3acd6d547f", "0x00000000000000000000000000000000002175d012746260ebcfe339a91a81e1", "0x00000000000000000000000000000052eebbd1f6f7554e837f60c44000ed14b6", "0x00000000000000000000000000000000001c1c045a3ec94b8801f2272cc0b3f4", "0x0000000000000000000000000000004d2ef74134578f6b431a9df071ffca4292", "0x0000000000000000000000000000000000291326ade7aa6f0dfc8900eab5580b", "0x0000000000000000000000000000002433eec6418a6dba820c9527e2581fc8bc", "0x00000000000000000000000000000000000e88b7daad19af2ac2f9bdf9e50ee2", "0x000000000000000000000000000000dcfce2c427155cc3e4d035735d3dd5ece8", "0x00000000000000000000000000000000002d7d473cac1a15d0fee8b22c1a7b3e", "0x23fb9503f571d567261006e2ca8b4326d325820140b488bb71617583602f4e3e", "0x0c68b96eebbfcac292403ed3b6f61536550e66473904e7d5d28080108fd0b1c3", "0x08d3bdbefd6d437c50fb9e3e3861913433e76577a18d81aa0ea4b8843e55f9ae", "0x08f6173fe87b72da6d821a496eb99b0cfe0ccadcffd25e5a3b718d83ff9adb1a", "0x1e6bd0a24c2cc58c93cf255cc68dd0c57299c99fd934267906b34facb0145cf4", "0x1175996557630bc376d38636f72b277cb8d54a969a39988a7e78f464c03eaeda", "0x03c3bd1f43baf44de0d9bf0f474c5df04b182214d57a196a717aef8868f9948c", "0x27306ffc7a96c8c27c9812d9dfa649ab6897b69125939aabe814e07d105daa32", "0x0c7f0b70aa08158e55bb39471609782656793ac76a03f2b64dcd135e6542592c", "0x03885b9eff8dac38a64779e3aba31f18c74166892cef9c5081ab57f6daf59865", "0x18dd8385333838c514fd11f36469c88e7ea5f6440aee17fa93c0f03c765d4ced", "0x08ad5bc6c05ecc9ae0d8f0b3196f229a53dbe753f41c12c52045c40e7d8220cc", "0x2f308380f90378084075f2bafa73228b17cbdfc2d693f9aaa1e5089557d0f32e", "0x2d3407e6de05e5935a31037c3db88069d0c41ec86cc8dda815048d6ce76f7a5f", "0x108c231f660e75f209201507a2dba6fccf99734ad91db8ecea675275afdf3ce1", "0x0e68df40e8c467a617229ab0f1dc0d4a04254492e709333d623c0963518dd6b4", "0x290650614292eec7c4f26fd402a047298f1a618dc8ff7de615752f737df7d515", "0x0de290891aaf146fd890a3cd5c25025113df2ec4d0a134513a2f397eaf4e3ea9", "0x25521f6f658bd20d9aaa8041164509b7b8d96fc5ef385f6eb6582375d1a86168", "0x0e9ab2f2f06220644c41fb09456d91751c522b015622f30568e66457f647a2bc", "0x28364f88f1e9c7d8e7767a3b954c5daa29223d646279930b34da51351dc01992", "0x0560c214728aacc262eeee0037be142d81aec26a1f5a9cf0606c4236ed344aa8", "0x1faea1662601fa01ad93d160277a1c81f2c60a761b74660f24a596ec8cb783e7", "0x0e703bb7bbf3a8bb8211715d86a1becb7aa3271f51d6001d5d3042faa7465df9", "0x0cc5b499ea9d9cbae4a0e33a5b601a7f7b686d6980dc0dd5bae4382a8ab1c7c7", "0x27fae143a80a37af95a47d5953096eef9b1127b5475480b8a6ecebdb00a65e23", "0x02cdf7c51d9182fbe07e7768ed0fcfe452ef70fc2ac87dc38fc0d4137bdf4aec", "0x14838df5a54d57d0a28b0375107bb7e7e7259c576a08ea39db6af8b0341d2911", "0x1b1fb0b1242e17beebb218c4ec88c830accea9bc93deec6d087d36d4d8de31fd", "0x1a8c0bdf35e674aa37118f5ad7fe6b62c65d8502e9697b3a92dfda8a1923d110", "0x2819aaa537cf012ceb48a8c8036b6fee492eeeef6698dcf8e3bc825d71efa3f8", "0x1ceedf534535a0d2a427b2ceeb3c8878a658b80eaf5210dbc0d32888fe3d05a7", "0x25c96dba803387eb5f3562785bc3bccddb7c9eb019bd4b07dd4563f77965c00c", "0x0353f3ff0f4f3da362b11eac12167dcbc9b3c76fb555f7e5534c14bb4c3f8037", "0x2904e33424ad29d38bda66a50b54a67acdf09be06a068ddc09d5eabdf9c2a9e5", "0x0b28534bf4b58e7f46c4a7514f3b521dd47bbac2a3adf09387baf19ec8df39c5", "0x1628b67c5d7b8c4cb5d8cdd2d0fd1d92bea3bfcf490fba7f16447cb686d7a388", "0x151bde642447aaf993e737329a3b81c6e243eecbe6a7bb43cdb8ffe74b2c0484", "0x07b319f585e9a9a3883deaddd9b0f43c844cbc7477636034f1543ce9f98821bf", "0x2c8738d76925012cc029f5b888be3cae165daa6beb22b5d73f017c918d891c34", "0x118fff7a26b04a6476c21267a3a4e96247640f6eabd05a05f1a94f881c6ee32b", "0x081d82e0808b6d444b03e1d722375adef2659d5914faa3d9ca4cb12c912be257", "0x18426c5ff5a3140f19bdc05e247cc05e1f70e1ea482b2a2b21f4930a494d7a61", "0x296babb7c6a72783d92bc3dee7f90a97302d64a518faeec0f42af4f599ccc0d1", "0x03337dd83835a2e9fe02c97056360eec725d55b01f039663108939f0333dba11", "0x11a796e7e6f1081be5aad42b475dc224f9547769bc6b358af63207fe0d324a4a", "0x2419618a28070cb7af904460207371f5ff9fa0939f6a0148add60ede530b0f14", "0x004d323457b070f3f41a4ce1ad5a867b3dea1a592bccb40c4d69c8521d9682b6", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x2d6ba30a2a23364900cf52019e2d19574813fe4922763a4e281c58c400ffce14", "0x06a0c085375f88283bedf3a1fc76ef35490655f372e2a985842a9375383b69d7", "0x219b78e5cf2ab2e35edfc8e40362062081a24ff4e9c9d15afa254c2a02d6d4e2", "0x182f29b047e6167c338c36d31685a825c66f327336545c623e7a6bd18e4fa97f", "0x1686460e2586e702724b9daf02315a33ddf5cbd275cfadbc3858f9ef3fe97133", "0x2183aaf585ac708b4000a5b88cf5a767356677087133bd90fff1c3e030b91f1e", "0x27dfa9c69d03c7776fecac8e0f56162caa95f44692cdae91f5b52dfc97eb9006", "0x10a9959de8c6d238c6c6dd68274cc9fc5b6d66759938638072d71659a2fe210d", "0x0e179d6215630fdd7d50362ade21893456d4b9a693e96152d9a6bac6518d4605", "0x0175b579d4e3b24eb0a319a6c79756c8a68ce2c1e0d0d8d1593d685125fbfb66", "0x1132bd3d531944f5024f2705d39b13e00ae90c246f6550c745234fd3d080712b", "0x1f2326f3955b431f2a17e937128b890aa366b107b69c61b8b45832fd06ce9e4e", "0x13576e6c03c3f2042c56113991821ec1f9dec46b6b0ff2748e037c94e6656c40", "0x00bb713034ce9d247110149e2a1754dc76f3ad700d420508148060091037477a", "0x25fb93286a48dc64c67ffac9e3f4a96b6c70bb87744e10e44a782117f8f537a0", "0x191227cd5e49d8a6b5aca93888b3286b41069df547e4bd91ffe65e48ab45b2a8", "0x120d4ac764ca4db67357140c8a8dd1523c013f747250a03a6130416669b087e1", "0x131cc1285b242d73eee36b79ccb3024525ae3caf0f91981cb89ec8d81b16a198", "0x0cacfa5aa1bc4624d5d476aced4d4c8026fb881679172dbc482d18772bc28c9f", "0x0e138279e8a4fe06018e9b9e649921500766e7a7afcc971f41732aa51ec31a43", "0x000000000000000000000000000000332f935a88cd2cc8a138d5ff2efe4cdec8", "0x0e1c2af7515e65c7ebced1a37faf4dbeef5c414f5601219d00d3844658b05a61", "0x12aff8e8eed2d2946c91652d448240590690672893b4759cdd31e1ec9ea45138", "0x1e89f396af25e81f9c4b3af2b0a15fd961789f3a8aa60edbdc4e8f2dfb610375", "0x29c05199f808bf38009ee7fa3c82b6aa5e3d65f180f49d4564c4bf6918399461", "0x019ce7ac46f4e5f1d4ce2d3866321506cea78ff5e5fe400d83b0395341cfe5d5", "0x20b40d1a69e62e7eecbf490915e2791975d3bca30859f237c56c4486e1fbb441", "0x243f7e62233a1f80ee17978814d7ab095bcc416d6bcee4583ce1167c7206b7b4", "0x0b6067a921e8d87bc8fd1af67382fbe2a27bcc833effa13fd7d85b5458d71e28", "0x30307a6766be04f3c50378d1b83f2e147e2ceef344d0c60e1abf939d29c26e27", "0x004c0ec19588b920084d00c6bfe0af4dbf83ca101eac5d833cb8191fe1c298b4", "0x00da79a40286bd8d3993b331a72f8195c7ba04bd863d1afd469bb094e29cc7d9", "0x115b70a2c50ee9abc28472ba8e820cfba158113a5a39c8e31817c84182d0503a", "0x09341d5c4b6d85bde38834a418a8ca375592c320c669bdd540c7ccee760f2ea1", "0x09341d5c4b6d85bde38834a418a8ca375592c320c669bdd540c7ccee760f2ea1", "0x0e63e927a9562ce0914fcd8892dff9a94ac722365ce21b8f5c75cc560b364e57", "0x05cf84989894e741a3e1cd815a8f84febfb08e61ee7b424c902fb02ca7d12e95", "0x1f958ad88d5e4a270f35e534154e7a519c5bbfab36d5084202d5b78baf63e09e", "0x21f0a33450db8821c2f8d042aae7e70bf05c9814b063e73c5e95f8ddba515a81", "0x2767a30fa0351c7deb2c8f542ecace4c41c1d136dd460dfad50b372f2a5f4b71", "0x137ee4ebfbc7227bf57ffc35d3368dd4f96c62911db9380aafa220d061c3b59d", "0x111515d3566611192f64e1e0848635ca6d7f73d8039d8b3522da1e2359e6d1b2", "0x2f6284e905c491b8defe4c467b2e664e2fbf144b5ca45e05c4a9d1aa8d41e149", "0x1e688ca09721459cd96d6af042716567a8f5fdb479f08ff9eff248c6013315a4", "0x00000000000000000000000000000015207c89ecabf752a46c0d5b8dbd296d86", "0x0000000000000000000000000000000000286c2b4d49249737816da8fd9f2753", "0x0000000000000000000000000000002492e649af820ca5d83e59823126c03bfb", "0x00000000000000000000000000000000001cdf1b636e33bf02a813687147476e", "0x000000000000000000000000000000b49023689f96212b8166d0c9b105e6df9a", "0x00000000000000000000000000000000000d9d27730e57d86079464ecd8d9edd", "0x0000000000000000000000000000005292b5583bd716a723bae47d344d655528", "0x000000000000000000000000000000000026651dba1a1074382c734163ab3614", "0x0000000000000000000000000000008984f01bc1f237c72fd6d2bb10cc21eb85", "0x00000000000000000000000000000000001029818de60ae9bb21ac2b5d5a4c97", "0x0000000000000000000000000000003aca28da52679f34e33756dfe00f1d8072", "0x0000000000000000000000000000000000124ecac53af720c02d18f54fd29100", "0x000000000000000000000000000000d09ed1c104d0397f046d89b8476f47e641", "0x00000000000000000000000000000000002c5094b27ad41c8a203b16dc74ee54", "0x000000000000000000000000000000bf8609068d29793771eb3f64e7dc3db96d", "0x0000000000000000000000000000000000225e220e16aedaecf2c10de6e41042", "0x0000000000000000000000000000006ae4f0d8baca7866ad4632141f90770cd7", "0x0000000000000000000000000000000000256cb979ab5bbe98be3a413ae8f246", "0x000000000000000000000000000000891f30bd3ac8e7e63e00db4951d518822f", "0x000000000000000000000000000000000014dffca5d842acfcd23fa491a7dae2", "0x000000000000000000000000000000af99905ea5b7a25f2172f044a59b90e67d", "0x00000000000000000000000000000000001e35bb78e382a5b98ad04b846df528", "0x0000000000000000000000000000003cfb75469b791ea188b8dfdff0f269e7b5", "0x00000000000000000000000000000000000e4fb9eb44a3d44d808794066f8811", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x000000000000000000000000000000c42f38f2993af03e18e76996c49f945c6a", "0x00000000000000000000000000000000002aefe820f0e4700abedd9fb6f046c1", "0x0000000000000000000000000000007a878e53414bf22854877c5066eaf916b8", "0x00000000000000000000000000000000001410a75247434da28c1ba6b64703bb", "0x000000000000000000000000000000bca902c1e2af8b47771e7eb42c3870f46b", "0x0000000000000000000000000000000000276eb602c3c232b51668d229d602b8", "0x000000000000000000000000000000dac1254c0753ee39d49d795bc6b3550ba7", "0x000000000000000000000000000000000007d60be9174146bd83f202aa062b92"] -public_inputs = ["0x0000000000000000000000000000000000000000000000000000000000000003"] -verification_key = ["0x0000000000000000000000000000000000000000000000000000000000000040", "0x0000000000000000000000000000000000000000000000000000000000000011", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000003", "0x0000000000000000000000000000000000000000000000000000000000000004", "0x0000000000000000000000000000000000000000000000000000000000000005", "0x0000000000000000000000000000000000000000000000000000000000000006", "0x0000000000000000000000000000000000000000000000000000000000000007", "0x0000000000000000000000000000000000000000000000000000000000000008", "0x0000000000000000000000000000000000000000000000000000000000000009", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000000000000000000000000000000000000000000b", "0x000000000000000000000000000000000000000000000000000000000000000c", "0x000000000000000000000000000000000000000000000000000000000000000d", "0x000000000000000000000000000000000000000000000000000000000000000e", "0x000000000000000000000000000000000000000000000000000000000000000f", "0x0000000000000000000000000000000000000000000000000000000000000010", "0x00000000000000000000000000000060e430ad1c23bfcf3514323aae3f206e84", "0x00000000000000000000000000000000001b5c3ff4c2458d8f481b1c068f27ae", "0x000000000000000000000000000000bb510ab2112def34980e4fc6998ad9dd16", "0x00000000000000000000000000000000000576e7c105b43e061e13cb877fefe1", "0x000000000000000000000000000000ced074785d11857b065d8199e6669a601c", "0x00000000000000000000000000000000000053b48a4098c1c0ae268f273952f7", "0x000000000000000000000000000000d1d4b26e941db8168cee8f6de548ae0fd8", "0x00000000000000000000000000000000001a9adf5a6dadc3d948bb61dfd63f4c", "0x0000000000000000000000000000009ce1faac6f8de6ebb18f1db17372c82ad5", "0x00000000000000000000000000000000002002681bb417184b2df070a16a3858", "0x000000000000000000000000000000161baa651a8092e0e84725594de5aba511", "0x00000000000000000000000000000000000be0064399c2a1efff9eb0cdcb2223", "0x0000000000000000000000000000008673be6fd1bdbe980a29d8c1ded54381e7", "0x000000000000000000000000000000000008a5158a7d9648cf1d234524c9fa0c", "0x0000000000000000000000000000002b4fce6e4b1c72062b296d49bca2aa4130", "0x00000000000000000000000000000000002e45a9eff4b6769e55fb710cded44f", "0x00000000000000000000000000000072b85bf733758b76bcf97333efb85a23e3", "0x000000000000000000000000000000000017da0ea508994fc82862715e4b5592", "0x00000000000000000000000000000094fa74695cf058dba8ff35aec95456c6c3", "0x0000000000000000000000000000000000211acddb851061c24b8f159e832bd1", "0x000000000000000000000000000000303b5e5c531384b9a792e11702ad3bcab0", "0x00000000000000000000000000000000000d336dff51a60b8833d5d7f6d4314c", "0x0000000000000000000000000000009f825dde88092070747180d581c342444a", "0x0000000000000000000000000000000000237fbd6511a03cca8cac01b555fe01", "0x0000000000000000000000000000007c313205159495df6d8de292079a4844ff", "0x000000000000000000000000000000000018facdfc468530dd45e8f7a1d38ce9", "0x0000000000000000000000000000000d1ce33446fc3dc4ab40ca38d92dac74e1", "0x00000000000000000000000000000000000852d8e3e0e8f4435af3e94222688b", "0x0000000000000000000000000000006c04ee19ec1dfec87ed47d6d04aa158de2", "0x000000000000000000000000000000000013240f97a584b45184c8ec31319b5f", "0x000000000000000000000000000000cefb5d240b07ceb4be26ea429b6dc9d9e0", "0x00000000000000000000000000000000002dad22022121d689f57fb38ca21349", "0x000000000000000000000000000000c9f189f2a91aeb664ce376d8b157ba98f8", "0x00000000000000000000000000000000002531a51ad54f124d58094b219818d2", "0x000000000000000000000000000000ef1e6db71809307f677677e62b4163f556", "0x0000000000000000000000000000000000272da4396fb2a7ee0638b9140e523d", "0x0000000000000000000000000000002e54c0244a7732c87bc4712a76dd8c83fb", "0x000000000000000000000000000000000007db77b3e04b7eba9643da57cbbe4d", "0x000000000000000000000000000000e0dfe1ddd7f74ae0d636c910c3e85830d8", "0x00000000000000000000000000000000000466fa9b57ec4664abd1505b490862", "0x0000000000000000000000000000009ee55ae8a32fe5384c79907067cc27192e", "0x00000000000000000000000000000000000799d0e465cec07ecb5238c854e830", "0x0000000000000000000000000000001d5910ad361e76e1c241247a823733c39f", "0x00000000000000000000000000000000002b03f2ccf7507564da2e6678bef8fe", "0x000000000000000000000000000000ee40d90bea71fba7a412dd61fcf34e8ceb", "0x0000000000000000000000000000000000140b0936c323fd2471155617b6af56", "0x0000000000000000000000000000002b90071823185c5ff8e440fd3d73b6fefc", "0x00000000000000000000000000000000002b6c10790a5f6631c87d652e059df4", "0x00000000000000000000000000000029a17181c7934fc3fdbd352eac5cb521b9", "0x00000000000000000000000000000000001f497cbf5284ff29a2d336e5991999", "0x000000000000000000000000000000072bd9c0c6beda1fdee6d4ff0432ba9e1b", "0x000000000000000000000000000000000013ea38a0bd2aa751a490a724fac818", "0x000000000000000000000000000000c599f63dcd3edd49f08ae5c3141c1e3493", "0x00000000000000000000000000000000002bdb36be0bea09950dd32a8ccf6fbc", "0x00000000000000000000000000000047f27f29724e7f19eba0340256a0bd4b7d", "0x00000000000000000000000000000000001c1c5ccf87a962129ca785f8f35120", "0x000000000000000000000000000000c5c71efdae00679bbe4a95096e012b1817", "0x000000000000000000000000000000000017a365de041e317817d0135f2b48e0", "0x0000000000000000000000000000008ae711ac402f7848d719c93a89ba8d39f1", "0x00000000000000000000000000000000002b6fb40ed8a1935226f4f9786a0499", "0x0000000000000000000000000000002f03a71501d83de1da5715a4e9462d6198", "0x00000000000000000000000000000000001644064443b8546f48eae693af47b8", "0x00000000000000000000000000000083763ab1b6e8fe269b2fe4c7b9c448c08d", "0x000000000000000000000000000000000021d7cc18c59676a8eeb47c0111c251", "0x000000000000000000000000000000b5f937153073e03ea7d51a996e0ebc2e6b", "0x000000000000000000000000000000000011ddd0e26457373eb06e0493177672", "0x000000000000000000000000000000c5f6eb9f6fc8fa99811a4a88c74a6d018b", "0x000000000000000000000000000000000025bcd07a0732c123567834f5109558", "0x000000000000000000000000000000aeb08a0b1a4442189448b4e97490568146", "0x000000000000000000000000000000000002a1744e4771705536a88f07e0f90f", "0x000000000000000000000000000000b938568293bd0724b0ea76c2ec34c4a829", "0x0000000000000000000000000000000000053296e8f3b9ad3af877dfa9c7c2a7", "0x000000000000000000000000000000f0ca1db6323996eba26bdc86dafef9d10b", "0x00000000000000000000000000000000001441a46c58af03d5645d52721d956a", "0x0000000000000000000000000000008bbf8f884013c66c28ba09c2fbd573b656", "0x0000000000000000000000000000000000206c391ca06fac27d1908e94570243", "0x0000000000000000000000000000002d4f5aaed88ba4f79612d53b804ca8f194", "0x00000000000000000000000000000000001674011c96392df08970fa6b7b4cb8", "0x0000000000000000000000000000009f88297c1729d76c4d9306853598c91325", "0x0000000000000000000000000000000000256f51adfcacc3c1e340be4d32d3e9", "0x0000000000000000000000000000000ab9955eec0d74eb799afed2a802b24d75", "0x00000000000000000000000000000000001fcbe43ea105b30d36ed0b21b03411", "0x000000000000000000000000000000d66b1d5433f1aa5305cd1edce7c22de466", "0x00000000000000000000000000000000002331546a256b8a3b751956806680d4", "0x000000000000000000000000000000e97954ad6cd6f45fb15c91434121db4304", "0x00000000000000000000000000000000002e20a97e09d50f227ced47e7a98250", "0x0000000000000000000000000000001ebbc27eb9ebededefba79522eb58ae89b", "0x0000000000000000000000000000000000090efa4974e566e81d1177b85a30be", "0x0000000000000000000000000000005eafa070b9c9632404052642e3bc14f9fd", "0x00000000000000000000000000000000001489068864102daca6a6b8bc4d448b", "0x0000000000000000000000000000009ebc91aaaac036a6477cadbe54e8556dfd", "0x00000000000000000000000000000000000ef6d835e2ed3343b95c82c8c54037", "0x00000000000000000000000000000033b28b529dff46e93af4e7422530478e4a", "0x000000000000000000000000000000000020a86c2f8591bf190bcddcc03c42fb", "0x000000000000000000000000000000a9679d0acc088f7dc27bf6d866bcd2dda2", "0x00000000000000000000000000000000002fb9d0d2d4099402bed74f738f64cc", "0x00000000000000000000000000000023b09f876a29a061582848a8b9a5870c12", "0x00000000000000000000000000000000001d5bb906f03f0d49e9c4791bc43af9", "0x00000000000000000000000000000017aac9854ea240d8ec97bf760c4d4ba870", "0x00000000000000000000000000000000000b227a556c414ada0dc75bb303e30e", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000009b624fa65d1a24b7f14a8f25f3789622af", "0x000000000000000000000000000000000013d47bff8c630e847b70e2732fd3f0", "0x00000000000000000000000000000061d21663e93132f32921075f4c936a84df", "0x00000000000000000000000000000000001a74ca4e118fb480b9b999902989a3"] diff --git a/noir/noir-repo/test_programs/execution_success/verify_honk_proof/src/main.nr b/noir/noir-repo/test_programs/execution_success/verify_honk_proof/src/main.nr deleted file mode 100644 index b60a47ccc7f..00000000000 --- a/noir/noir-repo/test_programs/execution_success/verify_honk_proof/src/main.nr +++ /dev/null @@ -1,17 +0,0 @@ - -// This circuit aggregates a single Honk proof from `assert_statement_recursive`. -global SIZE_OF_PROOF_IF_LOGN_IS_28 : u32 = 439; -global HONK_IDENTIFIER : u32 = 1; -fn main( - verification_key: [Field; 128], - // This is the proof without public inputs attached. - // - // This means: the size of this does not change with the number of public inputs. - proof: [Field; SIZE_OF_PROOF_IF_LOGN_IS_28], - public_inputs: pub [Field; 1], - // This is currently not public. It is fine given that the vk is a part of the circuit definition. - // I believe we want to eventually make it public too though. - key_hash: Field -) { - std::verify_proof(verification_key, proof, public_inputs, key_hash); -} diff --git a/noir/noir-repo/tooling/fuzzer/src/dictionary/mod.rs b/noir/noir-repo/tooling/fuzzer/src/dictionary/mod.rs index 942462c4f37..e10da8cc54a 100644 --- a/noir/noir-repo/tooling/fuzzer/src/dictionary/mod.rs +++ b/noir/noir-repo/tooling/fuzzer/src/dictionary/mod.rs @@ -10,7 +10,7 @@ use acvm::{ circuit::{ brillig::{BrilligBytecode, BrilligInputs}, directives::Directive, - opcodes::{BlackBoxFuncCall, ConstantOrWitnessEnum, FunctionInput}, + opcodes::{BlackBoxFuncCall, ConstantOrWitnessEnum}, Circuit, Opcode, Program, }, native_types::Expression, @@ -83,21 +83,24 @@ fn build_dictionary_from_circuit(circuit: &Circuit) -> HashSet< } } - Opcode::BlackBoxFuncCall(BlackBoxFuncCall::RANGE { - input: FunctionInput { input: ConstantOrWitnessEnum::Constant(c), num_bits }, - }) => { - let field = 1u128.wrapping_shl(*num_bits); - constants.insert(F::from(field)); - constants.insert(F::from(field - 1)); - constants.insert(*c); - } - Opcode::BlackBoxFuncCall(BlackBoxFuncCall::RANGE { - input: FunctionInput { input: ConstantOrWitnessEnum::Witness(_), num_bits }, - }) => { - let field = 1u128.wrapping_shl(*num_bits); - constants.insert(F::from(field)); - constants.insert(F::from(field - 1)); + Opcode::BlackBoxFuncCall(BlackBoxFuncCall::RANGE { input }) + if matches!(input.input(), ConstantOrWitnessEnum::Constant(..)) => + { + match input.input() { + ConstantOrWitnessEnum::Constant(c) => { + let field = 1u128.wrapping_shl(input.num_bits()); + constants.insert(F::from(field)); + constants.insert(F::from(field - 1)); + constants.insert(c); + } + _ => { + let field = 1u128.wrapping_shl(input.num_bits()); + constants.insert(F::from(field)); + constants.insert(F::from(field - 1)); + } + } } + _ => (), } } diff --git a/noir/noir-repo/tooling/lsp/src/modules.rs b/noir/noir-repo/tooling/lsp/src/modules.rs index cce7f324a2e..c8f7430c997 100644 --- a/noir/noir-repo/tooling/lsp/src/modules.rs +++ b/noir/noir-repo/tooling/lsp/src/modules.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use noirc_frontend::{ ast::ItemVisibility, - graph::CrateId, + graph::{CrateId, Dependency}, hir::def_map::{CrateDefMap, ModuleId}, macros_api::{ModuleDefId, NodeInterner}, node_interner::ReferenceId, @@ -41,7 +41,7 @@ pub(crate) fn module_def_id_to_reference_id(module_def_id: ModuleDefId) -> Refer /// Returns the fully-qualified path of the given `ModuleDefId` relative to `current_module_id`: /// - If `ModuleDefId` is a module, that module's path is returned /// - Otherwise, that item's parent module's path is returned -pub(crate) fn module_full_path( +pub(crate) fn relative_module_full_path( module_def_id: ModuleDefId, visibility: ItemVisibility, current_module_id: ModuleId, @@ -55,8 +55,12 @@ pub(crate) fn module_full_path( return None; } - full_path = - module_id_path(module_id, ¤t_module_id, current_module_parent_id, interner); + full_path = relative_module_id_path( + module_id, + ¤t_module_id, + current_module_parent_id, + interner, + ); } else { let Some(parent_module) = get_parent_module(interner, module_def_id) else { return None; @@ -66,15 +70,19 @@ pub(crate) fn module_full_path( return None; } - full_path = - module_id_path(parent_module, ¤t_module_id, current_module_parent_id, interner); + full_path = relative_module_id_path( + parent_module, + ¤t_module_id, + current_module_parent_id, + interner, + ); } Some(full_path) } /// Returns the path to reach an item inside `target_module_id` from inside `current_module_id`. /// Returns a relative path if possible. -pub(crate) fn module_id_path( +pub(crate) fn relative_module_id_path( target_module_id: ModuleId, current_module_id: &ModuleId, current_module_parent_id: Option, @@ -130,3 +138,52 @@ pub(crate) fn module_id_path( segments.reverse(); segments.join("::") } + +pub(crate) fn module_full_path( + module: &ModuleId, + interner: &NodeInterner, + crate_id: CrateId, + crate_name: &str, + dependencies: &Vec, +) -> String { + let mut segments: Vec = Vec::new(); + + if let Some(module_attributes) = interner.try_module_attributes(module) { + segments.push(module_attributes.name.clone()); + + let mut current_attributes = module_attributes; + loop { + let Some(parent_local_id) = current_attributes.parent else { + break; + }; + + let Some(parent_attributes) = interner.try_module_attributes(&ModuleId { + krate: module.krate, + local_id: parent_local_id, + }) else { + break; + }; + + segments.push(parent_attributes.name.clone()); + current_attributes = parent_attributes; + } + } + + // We don't record module attributes for the root module, + // so we handle that case separately + if module.krate.is_root() { + if module.krate == crate_id { + segments.push(crate_name.to_string()); + } else { + for dep in dependencies { + if dep.crate_id == crate_id { + segments.push(dep.name.to_string()); + break; + } + } + } + }; + + segments.reverse(); + segments.join("::") +} diff --git a/noir/noir-repo/tooling/lsp/src/requests/code_action.rs b/noir/noir-repo/tooling/lsp/src/requests/code_action.rs index 95cdc0b88b4..f5cfabe5141 100644 --- a/noir/noir-repo/tooling/lsp/src/requests/code_action.rs +++ b/noir/noir-repo/tooling/lsp/src/requests/code_action.rs @@ -11,7 +11,7 @@ use lsp_types::{ }; use noirc_errors::Span; use noirc_frontend::{ - ast::{ConstructorExpression, Path, Visitor}, + ast::{ConstructorExpression, NoirTraitImpl, Path, Visitor}, graph::CrateId, hir::def_map::{CrateDefMap, LocalModuleId, ModuleId}, macros_api::NodeInterner, @@ -26,6 +26,7 @@ use crate::{utils, LspState}; use super::{process_request, to_lsp_location}; mod fill_struct_fields; +mod implement_missing_members; mod import_or_qualify; #[cfg(test)] mod tests; @@ -219,4 +220,10 @@ impl<'a> Visitor for CodeActionFinder<'a> { true } + + fn visit_noir_trait_impl(&mut self, noir_trait_impl: &NoirTraitImpl, span: Span) -> bool { + self.implement_missing_members(noir_trait_impl, span); + + true + } } diff --git a/noir/noir-repo/tooling/lsp/src/requests/code_action/implement_missing_members.rs b/noir/noir-repo/tooling/lsp/src/requests/code_action/implement_missing_members.rs new file mode 100644 index 00000000000..eb1a8704131 --- /dev/null +++ b/noir/noir-repo/tooling/lsp/src/requests/code_action/implement_missing_members.rs @@ -0,0 +1,867 @@ +use std::collections::{BTreeMap, HashMap}; + +use lsp_types::TextEdit; +use noirc_errors::{Location, Span}; +use noirc_frontend::{ + ast::{NoirTraitImpl, TraitImplItemKind, UnresolvedTypeData}, + graph::CrateId, + hir::{ + def_map::{CrateDefMap, ModuleId}, + type_check::generics::TraitGenerics, + }, + hir_def::{function::FuncMeta, stmt::HirPattern, traits::Trait}, + macros_api::{ModuleDefId, NodeInterner}, + node_interner::ReferenceId, + Kind, ResolvedGeneric, Type, TypeVariableKind, +}; + +use crate::{byte_span_to_range, modules::relative_module_id_path}; + +use super::CodeActionFinder; + +impl<'a> CodeActionFinder<'a> { + pub(super) fn implement_missing_members( + &mut self, + noir_trait_impl: &NoirTraitImpl, + span: Span, + ) { + if !self.includes_span(span) { + return; + } + + let location = Location::new(noir_trait_impl.trait_name.span(), self.file); + let Some(ReferenceId::Trait(trait_id)) = self.interner.find_referenced(location) else { + return; + }; + + let trait_ = self.interner.get_trait(trait_id); + + // Get all methods + let mut method_ids = trait_.method_ids.clone(); + + // Also get all associated types + let mut associated_types = HashMap::new(); + for associated_type in &trait_.associated_types { + associated_types.insert(associated_type.name.as_ref(), associated_type); + } + + // Remove the ones that already are implemented + for item in &noir_trait_impl.items { + match &item.item.kind { + TraitImplItemKind::Function(noir_function) => { + method_ids.remove(noir_function.name()); + } + TraitImplItemKind::Constant(..) => (), + TraitImplItemKind::Type { name, alias } => { + if let UnresolvedTypeData::Unspecified = alias.typ { + continue; + } + associated_types.remove(&name.0.contents); + } + } + } + + // Also remove default methods + for trait_function in &trait_.methods { + if trait_function.default_impl.is_some() { + method_ids.remove(&trait_function.name.0.contents); + } + } + + if method_ids.is_empty() && associated_types.is_empty() { + return; + } + + let bytes = self.source.as_bytes(); + let right_brace_index = span.end() as usize - 1; + + // Let's find out the indent + let mut cursor = right_brace_index - 1; + while cursor > 0 { + let c = bytes[cursor] as char; + if c == '\n' { + break; + } + if !c.is_whitespace() { + break; + } + cursor -= 1; + } + let cursor_char = bytes[cursor] as char; + + let indent = if cursor_char == '\n' { right_brace_index - cursor - 1 } else { 0 }; + let indent_string = " ".repeat(indent + 4); + + let index = cursor + 1; + + let Some(range) = byte_span_to_range(self.files, self.file, index..index) else { + return; + }; + + let mut method_ids: Vec<_> = method_ids.iter().collect(); + method_ids.sort_by_key(|(name, _)| *name); + + let mut stubs = Vec::new(); + + for (name, _) in associated_types { + stubs.push(format!("{}type {};\n", indent_string, name)); + } + + for (name, func_id) in method_ids { + let func_meta = self.interner.function_meta(func_id); + + let mut generator = MethodStubGenerator::new( + name, + func_meta, + trait_, + noir_trait_impl, + self.interner, + self.def_maps, + self.module_id, + indent + 4, + ); + let stub = generator.generate(); + stubs.push(stub); + } + + let mut new_text = stubs.join("\n"); + if cursor_char != '\n' { + new_text.insert(0, '\n'); + } + + let title = "Implement missing members".to_string(); + let text_edit = TextEdit { range, new_text }; + let code_action = self.new_quick_fix(title, text_edit); + self.code_actions.push(code_action); + } +} + +struct MethodStubGenerator<'a> { + name: &'a str, + func_meta: &'a FuncMeta, + trait_: &'a Trait, + noir_trait_impl: &'a NoirTraitImpl, + interner: &'a NodeInterner, + def_maps: &'a BTreeMap, + module_id: ModuleId, + indent: usize, + string: String, +} + +impl<'a> MethodStubGenerator<'a> { + #[allow(clippy::too_many_arguments)] + fn new( + name: &'a str, + func_meta: &'a FuncMeta, + trait_: &'a Trait, + noir_trait_impl: &'a NoirTraitImpl, + interner: &'a NodeInterner, + def_maps: &'a BTreeMap, + module_id: ModuleId, + indent: usize, + ) -> Self { + Self { + name, + func_meta, + trait_, + noir_trait_impl, + interner, + def_maps, + module_id, + indent, + string: String::new(), + } + } + + fn generate(&mut self) -> String { + let indent_string = " ".repeat(self.indent); + + self.string.push_str(&indent_string); + self.string.push_str("fn "); + self.string.push_str(self.name); + self.append_resolved_generics(&self.func_meta.direct_generics); + self.string.push('('); + for (index, (pattern, typ, _visibility)) in self.func_meta.parameters.iter().enumerate() { + if index > 0 { + self.string.push_str(", "); + } + if self.append_pattern(pattern) { + self.string.push_str(": "); + self.append_type(typ); + } + } + self.string.push(')'); + + let return_type = self.func_meta.return_type(); + if return_type != &Type::Unit { + self.string.push_str(" -> "); + self.append_type(return_type); + } + + if !self.func_meta.trait_constraints.is_empty() { + self.string.push_str(" where "); + for (index, constraint) in self.func_meta.trait_constraints.iter().enumerate() { + if index > 0 { + self.string.push_str(", "); + } + self.append_type(&constraint.typ); + self.string.push_str(": "); + let trait_ = self.interner.get_trait(constraint.trait_id); + self.string.push_str(&trait_.name.0.contents); + self.append_trait_generics(&constraint.trait_generics); + } + } + + self.string.push_str(" {\n"); + + let body_indent_string = " ".repeat(self.indent + 4); + self.string.push_str(&body_indent_string); + self.string.push_str("panic(f\"Implement "); + self.string.push_str(self.name); + self.string.push_str("\")\n"); + self.string.push_str(&indent_string); + self.string.push_str("}\n"); + std::mem::take(&mut self.string) + } + + /// Appends a pattern and returns true if this was not the self type + fn append_pattern(&mut self, pattern: &HirPattern) -> bool { + match pattern { + HirPattern::Identifier(hir_ident) => { + let definition = self.interner.definition(hir_ident.id); + self.string.push_str(&definition.name); + &definition.name != "self" + } + HirPattern::Mutable(pattern, _) => { + self.string.push_str("mut "); + self.append_pattern(pattern) + } + HirPattern::Tuple(patterns, _) => { + self.string.push('('); + for (index, pattern) in patterns.iter().enumerate() { + if index > 0 { + self.string.push_str(", "); + } + self.append_pattern(pattern); + } + self.string.push(')'); + true + } + HirPattern::Struct(typ, patterns, _) => { + self.append_type(typ); + self.string.push_str(" { "); + for (index, (name, _pattern)) in patterns.iter().enumerate() { + if index > 0 { + self.string.push_str(", "); + } + self.string.push_str(&name.0.contents); + } + self.string.push_str(" }"); + true + } + } + } + + fn append_type(&mut self, typ: &Type) { + match typ { + Type::FieldElement => self.string.push_str("Field"), + Type::Array(n, e) => { + self.string.push('['); + self.append_type(e); + self.string.push_str("; "); + self.append_type(n); + self.string.push(']'); + } + Type::Slice(typ) => { + self.string.push('['); + self.append_type(typ); + self.string.push(']'); + } + Type::Tuple(types) => { + self.string.push('('); + for (index, typ) in types.iter().enumerate() { + if index > 0 { + self.string.push_str(", "); + } + self.append_type(typ); + } + self.string.push(')'); + } + Type::Struct(struct_type, generics) => { + let struct_type = struct_type.borrow(); + + let current_module_data = + &self.def_maps[&self.module_id.krate].modules()[self.module_id.local_id.0]; + + // Check if the struct type is already imported/visible in this module + let per_ns = current_module_data.find_name(&struct_type.name); + if let Some((module_def_id, _, _)) = per_ns.types { + if module_def_id == ModuleDefId::TypeId(struct_type.id) { + self.string.push_str(&struct_type.name.0.contents); + self.append_generics(generics); + return; + } + } + + let module_id = struct_type.id.module_id(); + let module_data = &self.def_maps[&module_id.krate].modules()[module_id.local_id.0]; + let parent_module_local_id = module_data.parent.unwrap(); + let parent_module_id = + ModuleId { krate: module_id.krate, local_id: parent_module_local_id }; + + let current_module_parent_id = current_module_data + .parent + .map(|parent| ModuleId { krate: self.module_id.krate, local_id: parent }); + + let relative_path = relative_module_id_path( + parent_module_id, + &self.module_id, + current_module_parent_id, + self.interner, + ); + + if !relative_path.is_empty() { + self.string.push_str(&relative_path); + self.string.push_str("::"); + } + self.string.push_str(&struct_type.name.0.contents); + self.append_generics(generics); + } + Type::Alias(type_alias, generics) => { + let type_alias = type_alias.borrow(); + + let current_module_data = + &self.def_maps[&self.module_id.krate].modules()[self.module_id.local_id.0]; + + // Check if the alias type is already imported/visible in this module + let per_ns = current_module_data.find_name(&type_alias.name); + if let Some((module_def_id, _, _)) = per_ns.types { + if module_def_id == ModuleDefId::TypeAliasId(type_alias.id) { + self.string.push_str(&type_alias.name.0.contents); + self.append_generics(generics); + return; + } + } + + let parent_module_id = + self.interner.reference_module(ReferenceId::Alias(type_alias.id)).unwrap(); + + let current_module_parent_id = current_module_data + .parent + .map(|parent| ModuleId { krate: self.module_id.krate, local_id: parent }); + + let relative_path = relative_module_id_path( + *parent_module_id, + &self.module_id, + current_module_parent_id, + self.interner, + ); + + if !relative_path.is_empty() { + self.string.push_str(&relative_path); + self.string.push_str("::"); + } + self.string.push_str(&type_alias.name.0.contents); + self.append_generics(generics); + } + Type::TraitAsType(trait_id, _, trait_generics) => { + let trait_ = self.interner.get_trait(*trait_id); + + let current_module_data = + &self.def_maps[&self.module_id.krate].modules()[self.module_id.local_id.0]; + + // Check if the trait type is already imported/visible in this module + let per_ns = current_module_data.find_name(&trait_.name); + if let Some((module_def_id, _, _)) = per_ns.types { + if module_def_id == ModuleDefId::TraitId(*trait_id) { + self.string.push_str(&trait_.name.0.contents); + self.append_trait_generics(trait_generics); + return; + } + } + + let parent_module_id = + self.interner.reference_module(ReferenceId::Trait(*trait_id)).unwrap(); + + let current_module_parent_id = current_module_data + .parent + .map(|parent| ModuleId { krate: self.module_id.krate, local_id: parent }); + + let relative_path = relative_module_id_path( + *parent_module_id, + &self.module_id, + current_module_parent_id, + self.interner, + ); + + if !relative_path.is_empty() { + self.string.push_str(&relative_path); + self.string.push_str("::"); + } + self.string.push_str(&trait_.name.0.contents); + self.append_trait_generics(trait_generics); + } + Type::TypeVariable(typevar, _) => { + if typevar.id() == self.trait_.self_type_typevar.id() { + self.string.push_str("Self"); + return; + } + + let generics = &self.trait_.generics; + if let Some(index) = + generics.iter().position(|generic| generic.type_var.id() == typevar.id()) + { + if let Some(typ) = self.noir_trait_impl.trait_generics.ordered_args.get(index) { + self.string.push_str(&typ.to_string()); + return; + } + } + + for associated_type in &self.trait_.associated_types { + if typevar.id() == associated_type.type_var.id() { + self.string.push_str("Self::"); + self.string.push_str(&associated_type.name); + return; + } + } + + for generic in &self.func_meta.direct_generics { + if typevar.id() == generic.type_var.id() { + self.string.push_str(&generic.name); + return; + } + } + + self.string.push_str("error"); + } + Type::NamedGeneric(typevar, _name, _kind) => { + self.append_type(&Type::TypeVariable(typevar.clone(), TypeVariableKind::Normal)); + } + Type::Function(args, ret, env, unconstrained) => { + if *unconstrained { + self.string.push_str("unconstrained "); + } + self.string.push_str("fn"); + + if let Type::Unit = **env { + } else { + self.string.push('['); + self.append_type(env); + self.string.push(']'); + } + + self.string.push('('); + for (index, arg) in args.iter().enumerate() { + if index > 0 { + self.string.push_str(", "); + } + self.append_type(arg); + } + self.string.push(')'); + + if let Type::Unit = **ret { + } else { + self.string.push_str(" -> "); + self.append_type(ret); + } + } + Type::MutableReference(typ) => { + self.string.push_str("&mut "); + self.append_type(typ); + } + Type::Forall(_, _) => { + panic!("Shouldn't get a Type::Forall"); + } + Type::InfixExpr(left, op, right) => { + self.append_type(left); + self.string.push(' '); + self.string.push_str(&op.to_string()); + self.string.push(' '); + self.append_type(right); + } + Type::Constant(_) + | Type::Integer(_, _) + | Type::Bool + | Type::String(_) + | Type::FmtString(_, _) + | Type::Unit + | Type::Quoted(_) + | Type::Error => self.string.push_str(&typ.to_string()), + } + } + + fn append_generics(&mut self, generics: &[Type]) { + if generics.is_empty() { + return; + } + + self.string.push('<'); + for (index, typ) in generics.iter().enumerate() { + if index > 0 { + self.string.push_str(", "); + } + self.append_type(typ); + } + self.string.push('>'); + } + + fn append_trait_generics(&mut self, generics: &TraitGenerics) { + if generics.named.is_empty() && generics.ordered.is_empty() { + return; + } + + let mut index = 0; + + self.string.push('<'); + for generic in &generics.ordered { + if index > 0 { + self.string.push_str(", "); + } + self.append_type(generic); + index += 1; + } + for named_type in &generics.named { + if index > 0 { + self.string.push_str(", "); + } + self.string.push_str(&named_type.name.0.contents); + self.string.push_str(" = "); + self.append_type(&named_type.typ); + index += 1; + } + self.string.push('>'); + } + + fn append_resolved_generics(&mut self, generics: &[ResolvedGeneric]) { + if generics.is_empty() { + return; + } + + self.string.push('<'); + for (index, generic) in self.func_meta.direct_generics.iter().enumerate() { + if index > 0 { + self.string.push_str(", "); + } + self.append_resolved_generic(generic); + } + self.string.push('>'); + } + + fn append_resolved_generic(&mut self, generic: &ResolvedGeneric) { + match &generic.kind { + Kind::Normal => self.string.push_str(&generic.name), + Kind::Numeric(typ) => { + self.string.push_str("let "); + self.string.push_str(&generic.name); + self.string.push_str(": "); + self.append_type(typ); + } + } + } +} + +#[cfg(test)] +mod tests { + use tokio::test; + + use crate::requests::code_action::tests::assert_code_action; + + #[test] + async fn test_add_missing_impl_members_simple() { + let title = "Implement missing members"; + + let src = r#" +trait Trait { + fn foo(x: i32) -> i32; + fn bar() {} +} + +struct Foo {} + +impl Tra>| i32; + fn bar() {} +} + +struct Foo {} + +impl Trait for Foo { + fn foo(x: i32) -> i32 { + panic(f"Implement foo") + } +}"#; + + assert_code_action(title, src, expected).await; + } + + #[test] + async fn test_add_missing_impl_members_multiple_with_self_type() { + let title = "Implement missing members"; + + let src = r#" +trait Trait { + fn bar(self) -> Self; + fn foo(x: i32) -> i32; +} + +struct Foo {} + +impl Tra>| Self; + fn foo(x: i32) -> i32; +} + +struct Foo {} + +impl Trait for Foo { + fn bar(self) -> Self { + panic(f"Implement bar") + } + + fn foo(x: i32) -> i32 { + panic(f"Implement foo") + } +}"#; + + assert_code_action(title, src, expected).await; + } + + #[test] + async fn test_add_missing_impl_members_qualify_type() { + let title = "Implement missing members"; + + let src = r#" +mod moo { + struct Moo {} + + trait Trait { + fn foo(x: Moo); + } +} + +struct Foo {} + +use moo::Trait; + +impl Tra>|| { + fn foo(x: T) -> [T; N] where M: Bar; +} + +struct Foo {} + +impl Tra>| for Foo { +}"#; + + let expected = r#" +trait Bar {} + +trait Trait { + fn foo(x: T) -> [T; N] where M: Bar; +} + +struct Foo {} + +impl Trait<[U]> for Foo { + fn foo(x: [U]) -> [[U]; N] where M: Bar { + panic(f"Implement foo") + } +}"#; + + assert_code_action(title, src, expected).await; + } + + #[test] + async fn test_add_missing_impl_members_associated_types() { + let title = "Implement missing members"; + + let src = r#" +trait Trait { + type Elem; + + fn foo(x: Self::Elem) -> [Self::Elem]; +} + +struct Foo {} + +impl Trait>|< for Foo { +}"#; + + let expected = r#" +trait Trait { + type Elem; + + fn foo(x: Self::Elem) -> [Self::Elem]; +} + +struct Foo {} + +impl Trait for Foo { + type Elem; + + fn foo(x: Self::Elem) -> [Self::Elem] { + panic(f"Implement foo") + } +}"#; + + assert_code_action(title, src, expected).await; + } + + #[test] + async fn test_add_missing_impl_members_nested() { + let title = "Implement missing members"; + + let src = r#" +mod moo { + trait Trait { + fn foo(); + fn bar(); + } + + struct Foo {} + + impl Tra>|| CodeActionFinder<'a> { for (module_def_id, visibility, defining_module) in entries { let module_full_path = if let Some(defining_module) = defining_module { - module_id_path( + relative_module_id_path( *defining_module, &self.module_id, current_module_parent_id, self.interner, ) } else { - let Some(module_full_path) = module_full_path( + let Some(module_full_path) = relative_module_full_path( *module_def_id, *visibility, self.module_id, diff --git a/noir/noir-repo/tooling/lsp/src/requests/code_action/tests.rs b/noir/noir-repo/tooling/lsp/src/requests/code_action/tests.rs index a8c81ced2a7..6be2a1ced1a 100644 --- a/noir/noir-repo/tooling/lsp/src/requests/code_action/tests.rs +++ b/noir/noir-repo/tooling/lsp/src/requests/code_action/tests.rs @@ -71,7 +71,10 @@ pub(crate) async fn assert_code_action(title: &str, src: &str, expected: &str) { assert_eq!(text_edits.len(), 1); let result = apply_text_edit(&src.replace(">|<", ""), &text_edits[0]); - assert_eq!(result, expected); + if result != expected { + println!("Expected:\n```\n{}\n```\n\nGot:\n```\n{}\n```", expected, result); + assert_eq!(result, expected); + } } fn apply_text_edit(src: &str, text_edit: &TextEdit) -> String { diff --git a/noir/noir-repo/tooling/lsp/src/requests/completion.rs b/noir/noir-repo/tooling/lsp/src/requests/completion.rs index de5c36bc59f..d07ad826094 100644 --- a/noir/noir-repo/tooling/lsp/src/requests/completion.rs +++ b/noir/noir-repo/tooling/lsp/src/requests/completion.rs @@ -882,7 +882,7 @@ impl<'a> Visitor for NodeFinder<'a> { false } - fn visit_parsed_submodule(&mut self, parsed_sub_module: &ParsedSubModule, span: Span) -> bool { + fn visit_parsed_submodule(&mut self, parsed_sub_module: &ParsedSubModule, _span: Span) -> bool { // Switch `self.module_id` to the submodule let previous_module_id = self.module_id; @@ -897,7 +897,9 @@ impl<'a> Visitor for NodeFinder<'a> { let old_auto_import_line = self.auto_import_line; self.nesting += 1; - if let Some(lsp_location) = to_lsp_location(self.files, self.file, span) { + if let Some(lsp_location) = + to_lsp_location(self.files, self.file, parsed_sub_module.name.span()) + { self.auto_import_line = (lsp_location.range.start.line + 1) as usize; } diff --git a/noir/noir-repo/tooling/lsp/src/requests/completion/auto_import.rs b/noir/noir-repo/tooling/lsp/src/requests/completion/auto_import.rs index d8823794999..f9c5dab0672 100644 --- a/noir/noir-repo/tooling/lsp/src/requests/completion/auto_import.rs +++ b/noir/noir-repo/tooling/lsp/src/requests/completion/auto_import.rs @@ -1,7 +1,7 @@ use lsp_types::{Position, Range, TextEdit}; use noirc_frontend::macros_api::ModuleDefId; -use crate::modules::{get_parent_module_id, module_full_path, module_id_path}; +use crate::modules::{get_parent_module_id, relative_module_full_path, relative_module_id_path}; use super::{ kinds::{FunctionCompletionKind, FunctionKind, RequestedItems}, @@ -40,14 +40,14 @@ impl<'a> NodeFinder<'a> { }; let module_full_path = if let Some(defining_module) = defining_module { - module_id_path( + relative_module_id_path( *defining_module, &self.module_id, current_module_parent_id, self.interner, ) } else { - let Some(module_full_path) = module_full_path( + let Some(module_full_path) = relative_module_full_path( *module_def_id, *visibility, self.module_id, diff --git a/noir/noir-repo/tooling/lsp/src/requests/completion/tests.rs b/noir/noir-repo/tooling/lsp/src/requests/completion/tests.rs index 7e11e0d9d52..6809e24e645 100644 --- a/noir/noir-repo/tooling/lsp/src/requests/completion/tests.rs +++ b/noir/noir-repo/tooling/lsp/src/requests/completion/tests.rs @@ -1395,6 +1395,7 @@ mod completion_tests { #[test] async fn test_auto_imports_when_in_nested_module_and_item_is_further_nested() { let src = r#" + #[something] mod foo { mod bar { pub fn hello_world() {} @@ -1422,8 +1423,8 @@ mod completion_tests { item.additional_text_edits, Some(vec![TextEdit { range: Range { - start: Position { line: 2, character: 4 }, - end: Position { line: 2, character: 4 }, + start: Position { line: 3, character: 4 }, + end: Position { line: 3, character: 4 }, }, new_text: "use bar::hello_world;\n\n ".to_string(), }]) diff --git a/noir/noir-repo/tooling/lsp/src/requests/document_symbol.rs b/noir/noir-repo/tooling/lsp/src/requests/document_symbol.rs index 7ab0a45ad0a..6c41f4dc2e5 100644 --- a/noir/noir-repo/tooling/lsp/src/requests/document_symbol.rs +++ b/noir/noir-repo/tooling/lsp/src/requests/document_symbol.rs @@ -378,12 +378,18 @@ impl<'a> Visitor for DocumentSymbolCollector<'a> { name: &Ident, typ: &UnresolvedType, default_value: &Expression, + _span: Span, ) -> bool { self.collect_in_constant(name, typ, Some(default_value)); false } - fn visit_trait_impl_item_type(&mut self, name: &Ident, alias: &UnresolvedType) -> bool { + fn visit_trait_impl_item_type( + &mut self, + name: &Ident, + alias: &UnresolvedType, + _span: Span, + ) -> bool { self.collect_in_type(name, Some(alias)); false } @@ -662,7 +668,7 @@ mod document_symbol_tests { tags: None, deprecated: None, range: Range { - start: Position { line: 19, character: 7 }, + start: Position { line: 19, character: 4 }, end: Position { line: 20, character: 5 }, }, selection_range: Range { diff --git a/noir/noir-repo/tooling/lsp/src/requests/hover.rs b/noir/noir-repo/tooling/lsp/src/requests/hover.rs index dab6ddd0fc6..8e9666a624b 100644 --- a/noir/noir-repo/tooling/lsp/src/requests/hover.rs +++ b/noir/noir-repo/tooling/lsp/src/requests/hover.rs @@ -14,7 +14,7 @@ use noirc_frontend::{ Generics, Shared, StructType, Type, TypeAlias, TypeBinding, TypeVariable, }; -use crate::LspState; +use crate::{modules::module_full_path, LspState}; use super::{process_request, to_lsp_location, ProcessRequestCallbackArgs}; @@ -352,43 +352,14 @@ fn format_parent_module_from_module_id( args: &ProcessRequestCallbackArgs, string: &mut String, ) -> bool { - let mut segments: Vec<&str> = Vec::new(); - - if let Some(module_attributes) = args.interner.try_module_attributes(module) { - segments.push(&module_attributes.name); - - let mut current_attributes = module_attributes; - loop { - let Some(parent_local_id) = current_attributes.parent else { - break; - }; - - let Some(parent_attributes) = args.interner.try_module_attributes(&ModuleId { - krate: module.krate, - local_id: parent_local_id, - }) else { - break; - }; - - segments.push(&parent_attributes.name); - current_attributes = parent_attributes; - } - } - - // We don't record module attributes for the root module, - // so we handle that case separately - if module.krate.is_root() { - segments.push(&args.crate_name); - }; - - if segments.is_empty() { + let full_path = + module_full_path(module, args.interner, args.crate_id, &args.crate_name, args.dependencies); + if full_path.is_empty() { return false; } - segments.reverse(); - string.push_str(" "); - string.push_str(&segments.join("::")); + string.push_str(&full_path); true } diff --git a/noir/noir-repo/tooling/nargo/src/errors.rs b/noir/noir-repo/tooling/nargo/src/errors.rs index 0b8378702cb..4a72bb1ec78 100644 --- a/noir/noir-repo/tooling/nargo/src/errors.rs +++ b/noir/noir-repo/tooling/nargo/src/errors.rs @@ -115,6 +115,10 @@ fn extract_locations_from_error( OpcodeResolutionError::IndexOutOfBounds { opcode_location: error_location, .. }, acir_call_stack, ) + | ExecutionError::SolvingError( + OpcodeResolutionError::InvalidInputBitSize { opcode_location: error_location, .. }, + acir_call_stack, + ) | ExecutionError::SolvingError( OpcodeResolutionError::UnsatisfiedConstrain { opcode_location: error_location, .. }, acir_call_stack, diff --git a/noir/noir-repo/tooling/nargo/src/ops/execute.rs b/noir/noir-repo/tooling/nargo/src/ops/execute.rs index 59d554d7ca5..eb03bdf01c1 100644 --- a/noir/noir-repo/tooling/nargo/src/ops/execute.rs +++ b/noir/noir-repo/tooling/nargo/src/ops/execute.rs @@ -89,6 +89,10 @@ impl<'a, F: AcirField, B: BlackBoxFunctionSolver, E: ForeignCallExecutor> | OpcodeResolutionError::IndexOutOfBounds { opcode_location: ErrorLocation::Resolved(opcode_location), .. + } + | OpcodeResolutionError::InvalidInputBitSize { + opcode_location: ErrorLocation::Resolved(opcode_location), + .. } => { let resolved_location = ResolvedOpcodeLocation { acir_function_index: self.current_function_index, diff --git a/noir/noir-repo/tooling/nargo/src/ops/test.rs b/noir/noir-repo/tooling/nargo/src/ops/test.rs index efe648e09b0..370a4235f61 100644 --- a/noir/noir-repo/tooling/nargo/src/ops/test.rs +++ b/noir/noir-repo/tooling/nargo/src/ops/test.rs @@ -191,8 +191,16 @@ fn check_expected_failure_message( None => return TestStatus::Pass, }; - let expected_failure_message_matches = - matches!(&failed_assertion, Some(message) if message.contains(expected_failure_message)); + // Match the failure message that the user will see, i.e. the failed_assertion + // if present or else the error_diagnostic's message, against the + // expected_failure_message + let expected_failure_message_matches = failed_assertion + .as_ref() + .or_else(|| { + error_diagnostic.as_ref().map(|file_diagnostic| &file_diagnostic.diagnostic.message) + }) + .map(|message| message.contains(expected_failure_message)) + .unwrap_or(false); if expected_failure_message_matches { return TestStatus::Pass; } diff --git a/noir/noir-repo/tooling/nargo_fmt/src/visitor/item.rs b/noir/noir-repo/tooling/nargo_fmt/src/visitor/item.rs index ba9a8214702..7d5e1886072 100644 --- a/noir/noir-repo/tooling/nargo_fmt/src/visitor/item.rs +++ b/noir/noir-repo/tooling/nargo_fmt/src/visitor/item.rs @@ -7,7 +7,7 @@ use crate::{ visitor::expr::{format_seq, NewlineMode}, }; use noirc_frontend::{ - ast::{NoirFunction, Visibility}, + ast::{NoirFunction, TraitImplItemKind, Visibility}, macros_api::UnresolvedTypeData, }; use noirc_frontend::{ @@ -226,6 +226,47 @@ impl super::FmtVisitor<'_> { self.last_position = span.end(); } } + ItemKind::TraitImpl(noir_trait_impl) => { + self.format_missing_indent(span.start(), true); + + if std::mem::take(&mut self.ignore_next_node) { + self.push_str(self.slice(span)); + self.last_position = span.end(); + continue; + } + + let before_brace = self.span_before(span, Token::LeftBrace).start(); + let slice = self.slice(self.last_position..before_brace).trim(); + let after_brace = self.span_after(span, Token::LeftBrace).start(); + self.last_position = after_brace; + + self.push_str(&format!("{slice} ")); + + if noir_trait_impl.items.is_empty() { + self.visit_empty_block((after_brace - 1..span.end()).into()); + continue; + } else { + self.push_str("{"); + self.indent.block_indent(self.config); + + for documented_item in noir_trait_impl.items { + let span = documented_item.item.span; + match documented_item.item.kind { + TraitImplItemKind::Function(method) => { + self.visit_function(span, method); + } + TraitImplItemKind::Constant(..) + | TraitImplItemKind::Type { .. } => { + self.push_rewrite(self.slice(span).to_string(), span); + self.last_position = span.end(); + } + } + } + + self.close_block((self.last_position..span.end() - 1).into()); + self.last_position = span.end(); + } + } ItemKind::Import(use_tree, visibility) => { let use_tree = UseTree::from_ast(use_tree); let use_tree = use_tree.rewrite_top_level(self, self.shape(), visibility); @@ -234,7 +275,6 @@ impl super::FmtVisitor<'_> { } ItemKind::Struct(_) | ItemKind::Trait(_) - | ItemKind::TraitImpl(_) | ItemKind::TypeAlias(_) | ItemKind::Global(_) | ItemKind::ModuleDecl(_) diff --git a/noir/noir-repo/tooling/nargo_fmt/tests/input/impl.nr b/noir/noir-repo/tooling/nargo_fmt/tests/input/impl.nr index 21ce6a2e175..e4adb8ebd6a 100644 --- a/noir/noir-repo/tooling/nargo_fmt/tests/input/impl.nr +++ b/noir/noir-repo/tooling/nargo_fmt/tests/input/impl.nr @@ -21,7 +21,7 @@ impl MyType { } impl MyStruct where T: MyEq { - fn my_eq(self, other: Self) -> bool { +fn my_eq(self, other: Self) -> bool { (self.a == other.a) & self.b.my_eq(other.b) } } diff --git a/noir/noir-repo/tooling/noir_js_backend_barretenberg/package.json b/noir/noir-repo/tooling/noir_js_backend_barretenberg/package.json index a5593cc284c..4ec715e27eb 100644 --- a/noir/noir-repo/tooling/noir_js_backend_barretenberg/package.json +++ b/noir/noir-repo/tooling/noir_js_backend_barretenberg/package.json @@ -41,7 +41,7 @@ "lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0" }, "dependencies": { - "@aztec/bb.js": "portal:../../../../barretenberg/ts", + "@aztec/bb.js": "0.51.1", "@noir-lang/types": "workspace:*", "fflate": "^0.8.0" }, diff --git a/noir/noir-repo/tooling/noirc_abi_wasm/build.sh b/noir/noir-repo/tooling/noirc_abi_wasm/build.sh index c07d2d8a4c1..16fb26e55db 100755 --- a/noir/noir-repo/tooling/noirc_abi_wasm/build.sh +++ b/noir/noir-repo/tooling/noirc_abi_wasm/build.sh @@ -25,7 +25,7 @@ function run_if_available { require_command jq require_command cargo require_command wasm-bindgen -#require_command wasm-opt +require_command wasm-opt self_path=$(dirname "$(readlink -f "$0")") pname=$(cargo read-manifest | jq -r '.name') diff --git a/noir/noir-repo/yarn.lock b/noir/noir-repo/yarn.lock index f77e9f7e72e..5d1d41f58fd 100644 --- a/noir/noir-repo/yarn.lock +++ b/noir/noir-repo/yarn.lock @@ -221,18 +221,19 @@ __metadata: languageName: node linkType: hard -"@aztec/bb.js@portal:../../../../barretenberg/ts::locator=%40noir-lang%2Fbackend_barretenberg%40workspace%3Atooling%2Fnoir_js_backend_barretenberg": - version: 0.0.0-use.local - resolution: "@aztec/bb.js@portal:../../../../barretenberg/ts::locator=%40noir-lang%2Fbackend_barretenberg%40workspace%3Atooling%2Fnoir_js_backend_barretenberg" +"@aztec/bb.js@npm:0.51.1": + version: 0.51.1 + resolution: "@aztec/bb.js@npm:0.51.1" dependencies: comlink: ^4.4.1 commander: ^10.0.1 debug: ^4.3.4 tslib: ^2.4.0 bin: - bb.js: ./dest/node/main.js + bb.js: dest/node/main.js + checksum: 246953d4d2becc86001b8e6d49ab8c0b4fa4833a9bf1d2177d0fb4e271e66f9dc65e3b02b69b00fbfcb935a11e2f90b5ac229b8c8938c34604fe54b29b3accfb languageName: node - linkType: soft + linkType: hard "@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.10.4, @babel/code-frame@npm:^7.12.11, @babel/code-frame@npm:^7.16.0, @babel/code-frame@npm:^7.22.13, @babel/code-frame@npm:^7.23.5, @babel/code-frame@npm:^7.8.3": version: 7.23.5 @@ -4160,7 +4161,7 @@ __metadata: version: 0.0.0-use.local resolution: "@noir-lang/backend_barretenberg@workspace:tooling/noir_js_backend_barretenberg" dependencies: - "@aztec/bb.js": "portal:../../../../barretenberg/ts" + "@aztec/bb.js": 0.51.1 "@noir-lang/types": "workspace:*" "@types/node": ^20.6.2 "@types/prettier": ^3 From 8a584cc4fa36b84226a36c3074947f80f13a34c7 Mon Sep 17 00:00:00 2001 From: AztecBot Date: Fri, 13 Sep 2024 08:03:13 +0000 Subject: [PATCH 2/4] chore: apply sync fixes --- noir/noir-repo/acvm-repo/acvm_js/build.sh | 2 +- .../verify_honk_proof/Nargo.toml | 6 ++++++ .../verify_honk_proof/Prover.toml | 4 ++++ .../verify_honk_proof/src/main.nr | 17 +++++++++++++++++ .../noir_js_backend_barretenberg/package.json | 2 +- noir/noir-repo/tooling/noirc_abi_wasm/build.sh | 2 +- noir/noir-repo/yarn.lock | 13 ++++++------- 7 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 noir/noir-repo/test_programs/execution_success/verify_honk_proof/Nargo.toml create mode 100644 noir/noir-repo/test_programs/execution_success/verify_honk_proof/Prover.toml create mode 100644 noir/noir-repo/test_programs/execution_success/verify_honk_proof/src/main.nr diff --git a/noir/noir-repo/acvm-repo/acvm_js/build.sh b/noir/noir-repo/acvm-repo/acvm_js/build.sh index 16fb26e55db..c07d2d8a4c1 100755 --- a/noir/noir-repo/acvm-repo/acvm_js/build.sh +++ b/noir/noir-repo/acvm-repo/acvm_js/build.sh @@ -25,7 +25,7 @@ function run_if_available { require_command jq require_command cargo require_command wasm-bindgen -require_command wasm-opt +#require_command wasm-opt self_path=$(dirname "$(readlink -f "$0")") pname=$(cargo read-manifest | jq -r '.name') diff --git a/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Nargo.toml b/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Nargo.toml new file mode 100644 index 00000000000..8fce1bf44b6 --- /dev/null +++ b/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "verify_honk_proof" +type = "bin" +authors = [""] + +[dependencies] diff --git a/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Prover.toml b/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Prover.toml new file mode 100644 index 00000000000..3f6bf0b427a --- /dev/null +++ b/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Prover.toml @@ -0,0 +1,4 @@ +key_hash = "0x0000000000000000000000000000000000000000000000000000000000000000" +proof = ["0x0000000000000000000000000000000000000000000000000000000000000040", "0x0000000000000000000000000000000000000000000000000000000000000011", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000042ab5d6d1986846cf", "0x00000000000000000000000000000000000000000000000b75c020998797da78", "0x0000000000000000000000000000000000000000000000005a107acb64952eca", "0x000000000000000000000000000000000000000000000000000031e97a575e9d", "0x00000000000000000000000000000000000000000000000b5666547acf8bd5a4", "0x00000000000000000000000000000000000000000000000c410db10a01750aeb", "0x00000000000000000000000000000000000000000000000d722669117f9758a4", "0x000000000000000000000000000000000000000000000000000178cbf4206471", "0x000000000000000000000000000000000000000000000000e91b8a11e7842c38", "0x000000000000000000000000000000000000000000000007fd51009034b3357f", "0x000000000000000000000000000000000000000000000009889939f81e9c7402", "0x0000000000000000000000000000000000000000000000000000f94656a2ca48", "0x000000000000000000000000000000000000000000000006fb128b46c1ddb67f", "0x0000000000000000000000000000000000000000000000093fe27776f50224bd", "0x000000000000000000000000000000000000000000000004a0c80c0da527a081", "0x0000000000000000000000000000000000000000000000000001b52c2020d746", "0x0000000000000000000000000000005a9bae947e1e91af9e4033d8d6aa6ed632", "0x000000000000000000000000000000000025e485e013446d4ac7981c88ba6ecc", "0x000000000000000000000000000000ff1e0496e30ab24a63b32b2d1120b76e62", "0x00000000000000000000000000000000001afe0a8a685d7cd85d1010e55d9d7c", "0x000000000000000000000000000000b0804efd6573805f991458295f510a2004", "0x00000000000000000000000000000000000c81a178016e2fe18605022d5a8b0e", "0x000000000000000000000000000000eba51e76eb1cfff60a53a0092a3c3dea47", "0x000000000000000000000000000000000022e7466247b533282f5936ac4e6c15", "0x00000000000000000000000000000071b1d76edf770edff98f00ff4deec264cd", "0x00000000000000000000000000000000001e48128e68794d8861fcbb2986a383", "0x000000000000000000000000000000d3a2af4915ae6d86b097adc377fafda2d4", "0x000000000000000000000000000000000006359de9ca452dab3a4f1f8d9c9d98", "0x0000000000000000000000000000006cf7dd96d7636fda5953191b1ad776d491", "0x00000000000000000000000000000000001633d881a08d136e834cb13a28fcc6", "0x00000000000000000000000000000001254956cff6908b069fca0e6cf1c47eb1", "0x000000000000000000000000000000000006f4d4dd3890e997e75e75886bf8f7", "0x0000000000000000000000000000006cf7dd96d7636fda5953191b1ad776d491", "0x00000000000000000000000000000000001633d881a08d136e834cb13a28fcc6", "0x00000000000000000000000000000001254956cff6908b069fca0e6cf1c47eb1", "0x000000000000000000000000000000000006f4d4dd3890e997e75e75886bf8f7", "0x000000000000000000000000000000f968b227a358a305607f3efc933823d288", "0x00000000000000000000000000000000000eaf8adb390375a76d95e918b65e08", "0x000000000000000000000000000000bb34b4b447aae56f5e24f81c3acd6d547f", "0x00000000000000000000000000000000002175d012746260ebcfe339a91a81e1", "0x00000000000000000000000000000052eebbd1f6f7554e837f60c44000ed14b6", "0x00000000000000000000000000000000001c1c045a3ec94b8801f2272cc0b3f4", "0x0000000000000000000000000000004d2ef74134578f6b431a9df071ffca4292", "0x0000000000000000000000000000000000291326ade7aa6f0dfc8900eab5580b", "0x0000000000000000000000000000002433eec6418a6dba820c9527e2581fc8bc", "0x00000000000000000000000000000000000e88b7daad19af2ac2f9bdf9e50ee2", "0x000000000000000000000000000000dcfce2c427155cc3e4d035735d3dd5ece8", "0x00000000000000000000000000000000002d7d473cac1a15d0fee8b22c1a7b3e", "0x23fb9503f571d567261006e2ca8b4326d325820140b488bb71617583602f4e3e", "0x0c68b96eebbfcac292403ed3b6f61536550e66473904e7d5d28080108fd0b1c3", "0x08d3bdbefd6d437c50fb9e3e3861913433e76577a18d81aa0ea4b8843e55f9ae", "0x08f6173fe87b72da6d821a496eb99b0cfe0ccadcffd25e5a3b718d83ff9adb1a", "0x1e6bd0a24c2cc58c93cf255cc68dd0c57299c99fd934267906b34facb0145cf4", "0x1175996557630bc376d38636f72b277cb8d54a969a39988a7e78f464c03eaeda", "0x03c3bd1f43baf44de0d9bf0f474c5df04b182214d57a196a717aef8868f9948c", "0x27306ffc7a96c8c27c9812d9dfa649ab6897b69125939aabe814e07d105daa32", "0x0c7f0b70aa08158e55bb39471609782656793ac76a03f2b64dcd135e6542592c", "0x03885b9eff8dac38a64779e3aba31f18c74166892cef9c5081ab57f6daf59865", "0x18dd8385333838c514fd11f36469c88e7ea5f6440aee17fa93c0f03c765d4ced", "0x08ad5bc6c05ecc9ae0d8f0b3196f229a53dbe753f41c12c52045c40e7d8220cc", "0x2f308380f90378084075f2bafa73228b17cbdfc2d693f9aaa1e5089557d0f32e", "0x2d3407e6de05e5935a31037c3db88069d0c41ec86cc8dda815048d6ce76f7a5f", "0x108c231f660e75f209201507a2dba6fccf99734ad91db8ecea675275afdf3ce1", "0x0e68df40e8c467a617229ab0f1dc0d4a04254492e709333d623c0963518dd6b4", "0x290650614292eec7c4f26fd402a047298f1a618dc8ff7de615752f737df7d515", "0x0de290891aaf146fd890a3cd5c25025113df2ec4d0a134513a2f397eaf4e3ea9", "0x25521f6f658bd20d9aaa8041164509b7b8d96fc5ef385f6eb6582375d1a86168", "0x0e9ab2f2f06220644c41fb09456d91751c522b015622f30568e66457f647a2bc", "0x28364f88f1e9c7d8e7767a3b954c5daa29223d646279930b34da51351dc01992", "0x0560c214728aacc262eeee0037be142d81aec26a1f5a9cf0606c4236ed344aa8", "0x1faea1662601fa01ad93d160277a1c81f2c60a761b74660f24a596ec8cb783e7", "0x0e703bb7bbf3a8bb8211715d86a1becb7aa3271f51d6001d5d3042faa7465df9", "0x0cc5b499ea9d9cbae4a0e33a5b601a7f7b686d6980dc0dd5bae4382a8ab1c7c7", "0x27fae143a80a37af95a47d5953096eef9b1127b5475480b8a6ecebdb00a65e23", "0x02cdf7c51d9182fbe07e7768ed0fcfe452ef70fc2ac87dc38fc0d4137bdf4aec", "0x14838df5a54d57d0a28b0375107bb7e7e7259c576a08ea39db6af8b0341d2911", "0x1b1fb0b1242e17beebb218c4ec88c830accea9bc93deec6d087d36d4d8de31fd", "0x1a8c0bdf35e674aa37118f5ad7fe6b62c65d8502e9697b3a92dfda8a1923d110", "0x2819aaa537cf012ceb48a8c8036b6fee492eeeef6698dcf8e3bc825d71efa3f8", "0x1ceedf534535a0d2a427b2ceeb3c8878a658b80eaf5210dbc0d32888fe3d05a7", "0x25c96dba803387eb5f3562785bc3bccddb7c9eb019bd4b07dd4563f77965c00c", "0x0353f3ff0f4f3da362b11eac12167dcbc9b3c76fb555f7e5534c14bb4c3f8037", "0x2904e33424ad29d38bda66a50b54a67acdf09be06a068ddc09d5eabdf9c2a9e5", "0x0b28534bf4b58e7f46c4a7514f3b521dd47bbac2a3adf09387baf19ec8df39c5", "0x1628b67c5d7b8c4cb5d8cdd2d0fd1d92bea3bfcf490fba7f16447cb686d7a388", "0x151bde642447aaf993e737329a3b81c6e243eecbe6a7bb43cdb8ffe74b2c0484", "0x07b319f585e9a9a3883deaddd9b0f43c844cbc7477636034f1543ce9f98821bf", "0x2c8738d76925012cc029f5b888be3cae165daa6beb22b5d73f017c918d891c34", "0x118fff7a26b04a6476c21267a3a4e96247640f6eabd05a05f1a94f881c6ee32b", "0x081d82e0808b6d444b03e1d722375adef2659d5914faa3d9ca4cb12c912be257", "0x18426c5ff5a3140f19bdc05e247cc05e1f70e1ea482b2a2b21f4930a494d7a61", "0x296babb7c6a72783d92bc3dee7f90a97302d64a518faeec0f42af4f599ccc0d1", "0x03337dd83835a2e9fe02c97056360eec725d55b01f039663108939f0333dba11", "0x11a796e7e6f1081be5aad42b475dc224f9547769bc6b358af63207fe0d324a4a", "0x2419618a28070cb7af904460207371f5ff9fa0939f6a0148add60ede530b0f14", "0x004d323457b070f3f41a4ce1ad5a867b3dea1a592bccb40c4d69c8521d9682b6", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x2d6ba30a2a23364900cf52019e2d19574813fe4922763a4e281c58c400ffce14", "0x06a0c085375f88283bedf3a1fc76ef35490655f372e2a985842a9375383b69d7", "0x219b78e5cf2ab2e35edfc8e40362062081a24ff4e9c9d15afa254c2a02d6d4e2", "0x182f29b047e6167c338c36d31685a825c66f327336545c623e7a6bd18e4fa97f", "0x1686460e2586e702724b9daf02315a33ddf5cbd275cfadbc3858f9ef3fe97133", "0x2183aaf585ac708b4000a5b88cf5a767356677087133bd90fff1c3e030b91f1e", "0x27dfa9c69d03c7776fecac8e0f56162caa95f44692cdae91f5b52dfc97eb9006", "0x10a9959de8c6d238c6c6dd68274cc9fc5b6d66759938638072d71659a2fe210d", "0x0e179d6215630fdd7d50362ade21893456d4b9a693e96152d9a6bac6518d4605", "0x0175b579d4e3b24eb0a319a6c79756c8a68ce2c1e0d0d8d1593d685125fbfb66", "0x1132bd3d531944f5024f2705d39b13e00ae90c246f6550c745234fd3d080712b", "0x1f2326f3955b431f2a17e937128b890aa366b107b69c61b8b45832fd06ce9e4e", "0x13576e6c03c3f2042c56113991821ec1f9dec46b6b0ff2748e037c94e6656c40", "0x00bb713034ce9d247110149e2a1754dc76f3ad700d420508148060091037477a", "0x25fb93286a48dc64c67ffac9e3f4a96b6c70bb87744e10e44a782117f8f537a0", "0x191227cd5e49d8a6b5aca93888b3286b41069df547e4bd91ffe65e48ab45b2a8", "0x120d4ac764ca4db67357140c8a8dd1523c013f747250a03a6130416669b087e1", "0x131cc1285b242d73eee36b79ccb3024525ae3caf0f91981cb89ec8d81b16a198", "0x0cacfa5aa1bc4624d5d476aced4d4c8026fb881679172dbc482d18772bc28c9f", "0x0e138279e8a4fe06018e9b9e649921500766e7a7afcc971f41732aa51ec31a43", "0x000000000000000000000000000000332f935a88cd2cc8a138d5ff2efe4cdec8", "0x0e1c2af7515e65c7ebced1a37faf4dbeef5c414f5601219d00d3844658b05a61", "0x12aff8e8eed2d2946c91652d448240590690672893b4759cdd31e1ec9ea45138", "0x1e89f396af25e81f9c4b3af2b0a15fd961789f3a8aa60edbdc4e8f2dfb610375", "0x29c05199f808bf38009ee7fa3c82b6aa5e3d65f180f49d4564c4bf6918399461", "0x019ce7ac46f4e5f1d4ce2d3866321506cea78ff5e5fe400d83b0395341cfe5d5", "0x20b40d1a69e62e7eecbf490915e2791975d3bca30859f237c56c4486e1fbb441", "0x243f7e62233a1f80ee17978814d7ab095bcc416d6bcee4583ce1167c7206b7b4", "0x0b6067a921e8d87bc8fd1af67382fbe2a27bcc833effa13fd7d85b5458d71e28", "0x30307a6766be04f3c50378d1b83f2e147e2ceef344d0c60e1abf939d29c26e27", "0x004c0ec19588b920084d00c6bfe0af4dbf83ca101eac5d833cb8191fe1c298b4", "0x00da79a40286bd8d3993b331a72f8195c7ba04bd863d1afd469bb094e29cc7d9", "0x115b70a2c50ee9abc28472ba8e820cfba158113a5a39c8e31817c84182d0503a", "0x09341d5c4b6d85bde38834a418a8ca375592c320c669bdd540c7ccee760f2ea1", "0x09341d5c4b6d85bde38834a418a8ca375592c320c669bdd540c7ccee760f2ea1", "0x0e63e927a9562ce0914fcd8892dff9a94ac722365ce21b8f5c75cc560b364e57", "0x05cf84989894e741a3e1cd815a8f84febfb08e61ee7b424c902fb02ca7d12e95", "0x1f958ad88d5e4a270f35e534154e7a519c5bbfab36d5084202d5b78baf63e09e", "0x21f0a33450db8821c2f8d042aae7e70bf05c9814b063e73c5e95f8ddba515a81", "0x2767a30fa0351c7deb2c8f542ecace4c41c1d136dd460dfad50b372f2a5f4b71", "0x137ee4ebfbc7227bf57ffc35d3368dd4f96c62911db9380aafa220d061c3b59d", "0x111515d3566611192f64e1e0848635ca6d7f73d8039d8b3522da1e2359e6d1b2", "0x2f6284e905c491b8defe4c467b2e664e2fbf144b5ca45e05c4a9d1aa8d41e149", "0x1e688ca09721459cd96d6af042716567a8f5fdb479f08ff9eff248c6013315a4", "0x00000000000000000000000000000015207c89ecabf752a46c0d5b8dbd296d86", "0x0000000000000000000000000000000000286c2b4d49249737816da8fd9f2753", "0x0000000000000000000000000000002492e649af820ca5d83e59823126c03bfb", "0x00000000000000000000000000000000001cdf1b636e33bf02a813687147476e", "0x000000000000000000000000000000b49023689f96212b8166d0c9b105e6df9a", "0x00000000000000000000000000000000000d9d27730e57d86079464ecd8d9edd", "0x0000000000000000000000000000005292b5583bd716a723bae47d344d655528", "0x000000000000000000000000000000000026651dba1a1074382c734163ab3614", "0x0000000000000000000000000000008984f01bc1f237c72fd6d2bb10cc21eb85", "0x00000000000000000000000000000000001029818de60ae9bb21ac2b5d5a4c97", "0x0000000000000000000000000000003aca28da52679f34e33756dfe00f1d8072", "0x0000000000000000000000000000000000124ecac53af720c02d18f54fd29100", "0x000000000000000000000000000000d09ed1c104d0397f046d89b8476f47e641", "0x00000000000000000000000000000000002c5094b27ad41c8a203b16dc74ee54", "0x000000000000000000000000000000bf8609068d29793771eb3f64e7dc3db96d", "0x0000000000000000000000000000000000225e220e16aedaecf2c10de6e41042", "0x0000000000000000000000000000006ae4f0d8baca7866ad4632141f90770cd7", "0x0000000000000000000000000000000000256cb979ab5bbe98be3a413ae8f246", "0x000000000000000000000000000000891f30bd3ac8e7e63e00db4951d518822f", "0x000000000000000000000000000000000014dffca5d842acfcd23fa491a7dae2", "0x000000000000000000000000000000af99905ea5b7a25f2172f044a59b90e67d", "0x00000000000000000000000000000000001e35bb78e382a5b98ad04b846df528", "0x0000000000000000000000000000003cfb75469b791ea188b8dfdff0f269e7b5", "0x00000000000000000000000000000000000e4fb9eb44a3d44d808794066f8811", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x000000000000000000000000000000c42f38f2993af03e18e76996c49f945c6a", "0x00000000000000000000000000000000002aefe820f0e4700abedd9fb6f046c1", "0x0000000000000000000000000000007a878e53414bf22854877c5066eaf916b8", "0x00000000000000000000000000000000001410a75247434da28c1ba6b64703bb", "0x000000000000000000000000000000bca902c1e2af8b47771e7eb42c3870f46b", "0x0000000000000000000000000000000000276eb602c3c232b51668d229d602b8", "0x000000000000000000000000000000dac1254c0753ee39d49d795bc6b3550ba7", "0x000000000000000000000000000000000007d60be9174146bd83f202aa062b92"] +public_inputs = ["0x0000000000000000000000000000000000000000000000000000000000000003"] +verification_key = ["0x0000000000000000000000000000000000000000000000000000000000000040", "0x0000000000000000000000000000000000000000000000000000000000000011", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000003", "0x0000000000000000000000000000000000000000000000000000000000000004", "0x0000000000000000000000000000000000000000000000000000000000000005", "0x0000000000000000000000000000000000000000000000000000000000000006", "0x0000000000000000000000000000000000000000000000000000000000000007", "0x0000000000000000000000000000000000000000000000000000000000000008", "0x0000000000000000000000000000000000000000000000000000000000000009", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000000000000000000000000000000000000000000b", "0x000000000000000000000000000000000000000000000000000000000000000c", "0x000000000000000000000000000000000000000000000000000000000000000d", "0x000000000000000000000000000000000000000000000000000000000000000e", "0x000000000000000000000000000000000000000000000000000000000000000f", "0x0000000000000000000000000000000000000000000000000000000000000010", "0x00000000000000000000000000000060e430ad1c23bfcf3514323aae3f206e84", "0x00000000000000000000000000000000001b5c3ff4c2458d8f481b1c068f27ae", "0x000000000000000000000000000000bb510ab2112def34980e4fc6998ad9dd16", "0x00000000000000000000000000000000000576e7c105b43e061e13cb877fefe1", "0x000000000000000000000000000000ced074785d11857b065d8199e6669a601c", "0x00000000000000000000000000000000000053b48a4098c1c0ae268f273952f7", "0x000000000000000000000000000000d1d4b26e941db8168cee8f6de548ae0fd8", "0x00000000000000000000000000000000001a9adf5a6dadc3d948bb61dfd63f4c", "0x0000000000000000000000000000009ce1faac6f8de6ebb18f1db17372c82ad5", "0x00000000000000000000000000000000002002681bb417184b2df070a16a3858", "0x000000000000000000000000000000161baa651a8092e0e84725594de5aba511", "0x00000000000000000000000000000000000be0064399c2a1efff9eb0cdcb2223", "0x0000000000000000000000000000008673be6fd1bdbe980a29d8c1ded54381e7", "0x000000000000000000000000000000000008a5158a7d9648cf1d234524c9fa0c", "0x0000000000000000000000000000002b4fce6e4b1c72062b296d49bca2aa4130", "0x00000000000000000000000000000000002e45a9eff4b6769e55fb710cded44f", "0x00000000000000000000000000000072b85bf733758b76bcf97333efb85a23e3", "0x000000000000000000000000000000000017da0ea508994fc82862715e4b5592", "0x00000000000000000000000000000094fa74695cf058dba8ff35aec95456c6c3", "0x0000000000000000000000000000000000211acddb851061c24b8f159e832bd1", "0x000000000000000000000000000000303b5e5c531384b9a792e11702ad3bcab0", "0x00000000000000000000000000000000000d336dff51a60b8833d5d7f6d4314c", "0x0000000000000000000000000000009f825dde88092070747180d581c342444a", "0x0000000000000000000000000000000000237fbd6511a03cca8cac01b555fe01", "0x0000000000000000000000000000007c313205159495df6d8de292079a4844ff", "0x000000000000000000000000000000000018facdfc468530dd45e8f7a1d38ce9", "0x0000000000000000000000000000000d1ce33446fc3dc4ab40ca38d92dac74e1", "0x00000000000000000000000000000000000852d8e3e0e8f4435af3e94222688b", "0x0000000000000000000000000000006c04ee19ec1dfec87ed47d6d04aa158de2", "0x000000000000000000000000000000000013240f97a584b45184c8ec31319b5f", "0x000000000000000000000000000000cefb5d240b07ceb4be26ea429b6dc9d9e0", "0x00000000000000000000000000000000002dad22022121d689f57fb38ca21349", "0x000000000000000000000000000000c9f189f2a91aeb664ce376d8b157ba98f8", "0x00000000000000000000000000000000002531a51ad54f124d58094b219818d2", "0x000000000000000000000000000000ef1e6db71809307f677677e62b4163f556", "0x0000000000000000000000000000000000272da4396fb2a7ee0638b9140e523d", "0x0000000000000000000000000000002e54c0244a7732c87bc4712a76dd8c83fb", "0x000000000000000000000000000000000007db77b3e04b7eba9643da57cbbe4d", "0x000000000000000000000000000000e0dfe1ddd7f74ae0d636c910c3e85830d8", "0x00000000000000000000000000000000000466fa9b57ec4664abd1505b490862", "0x0000000000000000000000000000009ee55ae8a32fe5384c79907067cc27192e", "0x00000000000000000000000000000000000799d0e465cec07ecb5238c854e830", "0x0000000000000000000000000000001d5910ad361e76e1c241247a823733c39f", "0x00000000000000000000000000000000002b03f2ccf7507564da2e6678bef8fe", "0x000000000000000000000000000000ee40d90bea71fba7a412dd61fcf34e8ceb", "0x0000000000000000000000000000000000140b0936c323fd2471155617b6af56", "0x0000000000000000000000000000002b90071823185c5ff8e440fd3d73b6fefc", "0x00000000000000000000000000000000002b6c10790a5f6631c87d652e059df4", "0x00000000000000000000000000000029a17181c7934fc3fdbd352eac5cb521b9", "0x00000000000000000000000000000000001f497cbf5284ff29a2d336e5991999", "0x000000000000000000000000000000072bd9c0c6beda1fdee6d4ff0432ba9e1b", "0x000000000000000000000000000000000013ea38a0bd2aa751a490a724fac818", "0x000000000000000000000000000000c599f63dcd3edd49f08ae5c3141c1e3493", "0x00000000000000000000000000000000002bdb36be0bea09950dd32a8ccf6fbc", "0x00000000000000000000000000000047f27f29724e7f19eba0340256a0bd4b7d", "0x00000000000000000000000000000000001c1c5ccf87a962129ca785f8f35120", "0x000000000000000000000000000000c5c71efdae00679bbe4a95096e012b1817", "0x000000000000000000000000000000000017a365de041e317817d0135f2b48e0", "0x0000000000000000000000000000008ae711ac402f7848d719c93a89ba8d39f1", "0x00000000000000000000000000000000002b6fb40ed8a1935226f4f9786a0499", "0x0000000000000000000000000000002f03a71501d83de1da5715a4e9462d6198", "0x00000000000000000000000000000000001644064443b8546f48eae693af47b8", "0x00000000000000000000000000000083763ab1b6e8fe269b2fe4c7b9c448c08d", "0x000000000000000000000000000000000021d7cc18c59676a8eeb47c0111c251", "0x000000000000000000000000000000b5f937153073e03ea7d51a996e0ebc2e6b", "0x000000000000000000000000000000000011ddd0e26457373eb06e0493177672", "0x000000000000000000000000000000c5f6eb9f6fc8fa99811a4a88c74a6d018b", "0x000000000000000000000000000000000025bcd07a0732c123567834f5109558", "0x000000000000000000000000000000aeb08a0b1a4442189448b4e97490568146", "0x000000000000000000000000000000000002a1744e4771705536a88f07e0f90f", "0x000000000000000000000000000000b938568293bd0724b0ea76c2ec34c4a829", "0x0000000000000000000000000000000000053296e8f3b9ad3af877dfa9c7c2a7", "0x000000000000000000000000000000f0ca1db6323996eba26bdc86dafef9d10b", "0x00000000000000000000000000000000001441a46c58af03d5645d52721d956a", "0x0000000000000000000000000000008bbf8f884013c66c28ba09c2fbd573b656", "0x0000000000000000000000000000000000206c391ca06fac27d1908e94570243", "0x0000000000000000000000000000002d4f5aaed88ba4f79612d53b804ca8f194", "0x00000000000000000000000000000000001674011c96392df08970fa6b7b4cb8", "0x0000000000000000000000000000009f88297c1729d76c4d9306853598c91325", "0x0000000000000000000000000000000000256f51adfcacc3c1e340be4d32d3e9", "0x0000000000000000000000000000000ab9955eec0d74eb799afed2a802b24d75", "0x00000000000000000000000000000000001fcbe43ea105b30d36ed0b21b03411", "0x000000000000000000000000000000d66b1d5433f1aa5305cd1edce7c22de466", "0x00000000000000000000000000000000002331546a256b8a3b751956806680d4", "0x000000000000000000000000000000e97954ad6cd6f45fb15c91434121db4304", "0x00000000000000000000000000000000002e20a97e09d50f227ced47e7a98250", "0x0000000000000000000000000000001ebbc27eb9ebededefba79522eb58ae89b", "0x0000000000000000000000000000000000090efa4974e566e81d1177b85a30be", "0x0000000000000000000000000000005eafa070b9c9632404052642e3bc14f9fd", "0x00000000000000000000000000000000001489068864102daca6a6b8bc4d448b", "0x0000000000000000000000000000009ebc91aaaac036a6477cadbe54e8556dfd", "0x00000000000000000000000000000000000ef6d835e2ed3343b95c82c8c54037", "0x00000000000000000000000000000033b28b529dff46e93af4e7422530478e4a", "0x000000000000000000000000000000000020a86c2f8591bf190bcddcc03c42fb", "0x000000000000000000000000000000a9679d0acc088f7dc27bf6d866bcd2dda2", "0x00000000000000000000000000000000002fb9d0d2d4099402bed74f738f64cc", "0x00000000000000000000000000000023b09f876a29a061582848a8b9a5870c12", "0x00000000000000000000000000000000001d5bb906f03f0d49e9c4791bc43af9", "0x00000000000000000000000000000017aac9854ea240d8ec97bf760c4d4ba870", "0x00000000000000000000000000000000000b227a556c414ada0dc75bb303e30e", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000002", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000009b624fa65d1a24b7f14a8f25f3789622af", "0x000000000000000000000000000000000013d47bff8c630e847b70e2732fd3f0", "0x00000000000000000000000000000061d21663e93132f32921075f4c936a84df", "0x00000000000000000000000000000000001a74ca4e118fb480b9b999902989a3"] diff --git a/noir/noir-repo/test_programs/execution_success/verify_honk_proof/src/main.nr b/noir/noir-repo/test_programs/execution_success/verify_honk_proof/src/main.nr new file mode 100644 index 00000000000..b60a47ccc7f --- /dev/null +++ b/noir/noir-repo/test_programs/execution_success/verify_honk_proof/src/main.nr @@ -0,0 +1,17 @@ + +// This circuit aggregates a single Honk proof from `assert_statement_recursive`. +global SIZE_OF_PROOF_IF_LOGN_IS_28 : u32 = 439; +global HONK_IDENTIFIER : u32 = 1; +fn main( + verification_key: [Field; 128], + // This is the proof without public inputs attached. + // + // This means: the size of this does not change with the number of public inputs. + proof: [Field; SIZE_OF_PROOF_IF_LOGN_IS_28], + public_inputs: pub [Field; 1], + // This is currently not public. It is fine given that the vk is a part of the circuit definition. + // I believe we want to eventually make it public too though. + key_hash: Field +) { + std::verify_proof(verification_key, proof, public_inputs, key_hash); +} diff --git a/noir/noir-repo/tooling/noir_js_backend_barretenberg/package.json b/noir/noir-repo/tooling/noir_js_backend_barretenberg/package.json index 4ec715e27eb..a5593cc284c 100644 --- a/noir/noir-repo/tooling/noir_js_backend_barretenberg/package.json +++ b/noir/noir-repo/tooling/noir_js_backend_barretenberg/package.json @@ -41,7 +41,7 @@ "lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0" }, "dependencies": { - "@aztec/bb.js": "0.51.1", + "@aztec/bb.js": "portal:../../../../barretenberg/ts", "@noir-lang/types": "workspace:*", "fflate": "^0.8.0" }, diff --git a/noir/noir-repo/tooling/noirc_abi_wasm/build.sh b/noir/noir-repo/tooling/noirc_abi_wasm/build.sh index 16fb26e55db..c07d2d8a4c1 100755 --- a/noir/noir-repo/tooling/noirc_abi_wasm/build.sh +++ b/noir/noir-repo/tooling/noirc_abi_wasm/build.sh @@ -25,7 +25,7 @@ function run_if_available { require_command jq require_command cargo require_command wasm-bindgen -require_command wasm-opt +#require_command wasm-opt self_path=$(dirname "$(readlink -f "$0")") pname=$(cargo read-manifest | jq -r '.name') diff --git a/noir/noir-repo/yarn.lock b/noir/noir-repo/yarn.lock index 5d1d41f58fd..f77e9f7e72e 100644 --- a/noir/noir-repo/yarn.lock +++ b/noir/noir-repo/yarn.lock @@ -221,19 +221,18 @@ __metadata: languageName: node linkType: hard -"@aztec/bb.js@npm:0.51.1": - version: 0.51.1 - resolution: "@aztec/bb.js@npm:0.51.1" +"@aztec/bb.js@portal:../../../../barretenberg/ts::locator=%40noir-lang%2Fbackend_barretenberg%40workspace%3Atooling%2Fnoir_js_backend_barretenberg": + version: 0.0.0-use.local + resolution: "@aztec/bb.js@portal:../../../../barretenberg/ts::locator=%40noir-lang%2Fbackend_barretenberg%40workspace%3Atooling%2Fnoir_js_backend_barretenberg" dependencies: comlink: ^4.4.1 commander: ^10.0.1 debug: ^4.3.4 tslib: ^2.4.0 bin: - bb.js: dest/node/main.js - checksum: 246953d4d2becc86001b8e6d49ab8c0b4fa4833a9bf1d2177d0fb4e271e66f9dc65e3b02b69b00fbfcb935a11e2f90b5ac229b8c8938c34604fe54b29b3accfb + bb.js: ./dest/node/main.js languageName: node - linkType: hard + linkType: soft "@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.10.4, @babel/code-frame@npm:^7.12.11, @babel/code-frame@npm:^7.16.0, @babel/code-frame@npm:^7.22.13, @babel/code-frame@npm:^7.23.5, @babel/code-frame@npm:^7.8.3": version: 7.23.5 @@ -4161,7 +4160,7 @@ __metadata: version: 0.0.0-use.local resolution: "@noir-lang/backend_barretenberg@workspace:tooling/noir_js_backend_barretenberg" dependencies: - "@aztec/bb.js": 0.51.1 + "@aztec/bb.js": "portal:../../../../barretenberg/ts" "@noir-lang/types": "workspace:*" "@types/node": ^20.6.2 "@types/prettier": ^3 From 28bf1b573b0fe913682c6f4f30e025aa9bf0a6f1 Mon Sep 17 00:00:00 2001 From: Tom French Date: Fri, 13 Sep 2024 10:54:06 +0100 Subject: [PATCH 3/4] fmt --- .../aztec-nr/address-note/src/address_note.nr | 10 +- .../aztec-nr/authwit/src/entrypoint/app.nr | 25 ++-- .../aztec-nr/authwit/src/entrypoint/fee.nr | 27 ++-- .../authwit/src/entrypoint/function_call.nr | 8 +- .../context/inputs/private_context_inputs.nr | 2 +- .../context/inputs/public_context_inputs.nr | 5 +- .../aztec/src/encrypted_logs/incoming_body.nr | 50 ++++--- .../aztec/src/history/contract_inclusion.nr | 10 +- .../aztec/src/history/note_validity.nr | 6 +- .../aztec/src/history/nullifier_inclusion.nr | 6 +- .../src/history/nullifier_non_inclusion.nr | 6 +- .../aztec-nr/aztec/src/keys/public_keys.nr | 24 ++-- .../aztec-nr/aztec/src/note/note_header.nr | 12 +- .../aztec-nr/aztec/src/oracle/logs_traits.nr | 128 ++++++++++++----- .../shared_mutable/scheduled_delay_change.nr | 21 ++- .../shared_mutable/scheduled_value_change.nr | 16 ++- .../aztec/src/test/mocks/mock_note.nr | 30 ++-- .../unencrypted_event_emission.nr | 24 +++- .../src/compressed_string.nr | 1 - .../src/field_compressed_string.nr | 12 +- .../aztec-nr/uint-note/src/uint_note.nr | 16 ++- .../aztec-nr/value-note/src/value_note.nr | 18 +-- .../src/dapp_payload.nr | 25 ++-- .../src/subscription_note.nr | 12 +- .../contracts/avm_test_contract/src/main.nr | 2 +- .../contracts/card_game_contract/src/cards.nr | 6 +- .../contracts/card_game_contract/src/game.nr | 10 +- .../events/private_function_broadcasted.nr | 7 +- .../unconstrained_function_broadcasted.nr | 7 +- .../src/types/card_note.nr | 20 +-- .../contracts/lending_contract/src/asset.nr | 7 +- .../lending_contract/src/position.nr | 8 +- .../private_fpc_contract/src/settings.nr | 5 +- .../src/public_key_note.nr | 12 +- .../src/types/roles.nr | 10 +- .../src/types/token_note.nr | 25 ++-- .../src/types/transparent_note.nr | 13 +- .../token_contract/src/types/token_note.nr | 23 ++- .../src/types/transparent_note.nr | 13 +- .../parity-lib/src/parity_public_inputs.nr | 28 ++-- .../parity-lib/src/root/root_parity_input.nr | 20 +-- .../src/root/root_rollup_parity_input.nr | 20 +-- .../src/private_kernel_empty.nr | 16 +-- .../src/reset/key_validation_hint.nr | 5 +- .../src/reset/read_request.nr | 4 +- .../base_or_merge_rollup_public_inputs.nr | 86 +++++------ ...block_root_or_block_merge_public_inputs.nr | 120 ++++++++-------- .../src/abis/constant_rollup_data.nr | 46 +++--- .../src/abis/previous_rollup_block_data.nr | 15 +- .../src/abis/previous_rollup_data.nr | 19 +-- .../block_merge/block_merge_rollup_inputs.nr | 4 +- .../block_root/block_root_rollup_inputs.nr | 2 +- .../src/merge/merge_rollup_inputs.nr | 4 +- .../rollup-lib/src/root/root_rollup_inputs.nr | 5 +- .../combined_accumulated_data.nr | 135 +++++++++-------- .../private_accumulated_data.nr | 136 ++++++++++-------- .../private_accumulated_data_builder.nr | 2 +- .../public_accumulated_data.nr | 99 ++++++++----- .../public_accumulated_data_builder.nr | 2 +- .../src/abis/append_only_tree_snapshot.nr | 5 +- .../crates/types/src/abis/call_context.nr | 16 +-- .../types/src/abis/combined_constant_data.nr | 52 +++---- .../contract_class_function_leaf_preimage.nr | 9 +- .../crates/types/src/abis/event_selector.nr | 4 +- .../crates/types/src/abis/function_data.nr | 16 +-- .../types/src/abis/function_selector.nr | 4 +- .../crates/types/src/abis/gas.nr | 2 +- .../crates/types/src/abis/gas_fees.nr | 5 +- .../crates/types/src/abis/gas_settings.nr | 16 ++- .../crates/types/src/abis/global_variables.nr | 18 +-- .../kernel_circuit_public_inputs.nr | 64 ++++----- .../private_kernel_circuit_public_inputs.nr | 104 +++++++------- .../public_kernel_circuit_public_inputs.nr | 75 +++++----- ...ic_kernel_circuit_public_inputs_builder.nr | 2 +- .../crates/types/src/abis/kernel_data.nr | 13 +- .../crates/types/src/abis/log_hash.nr | 74 +++------- .../crates/types/src/abis/max_block_number.nr | 7 +- .../crates/types/src/abis/note_hash.nr | 36 +++-- .../types/src/abis/note_hash_leaf_preimage.nr | 12 +- .../crates/types/src/abis/nullifier.nr | 35 ++--- .../types/src/abis/nullifier_leaf_preimage.nr | 16 +-- .../types/src/abis/private_call_request.nr | 10 +- .../types/src/abis/private_call_stack_item.nr | 10 +- .../src/abis/private_circuit_public_inputs.nr | 119 ++++++++++----- .../types/src/abis/public_call_request.nr | 37 ++--- .../abis/public_call_stack_item_compressed.nr | 30 ++-- .../src/abis/public_circuit_public_inputs.nr | 61 ++++++-- .../crates/types/src/abis/public_data_read.nr | 24 ++-- .../src/abis/public_data_update_request.nr | 31 ++-- .../types/src/abis/public_data_write.nr | 15 +- .../types/src/abis/public_kernel_data.nr | 13 +- .../crates/types/src/abis/read_request.nr | 27 ++-- .../types/src/abis/tree_leaf_read_request.nr | 10 +- .../key_validation_request.nr | 15 +- .../key_validation_request_and_generator.nr | 10 +- .../private_validation_requests.nr | 62 ++++---- .../private_validation_requests_builder.nr | 2 +- .../public_validation_requests.nr | 82 ++++++----- .../public_validation_requests_builder.nr | 2 +- .../rollup_validation_requests.nr | 30 ++-- ...ed_key_validation_request_and_generator.nr | 10 +- .../crates/types/src/address/aztec_address.nr | 6 +- .../crates/types/src/address/eth_address.nr | 6 +- .../types/src/address/partial_address.nr | 2 +- .../crates/types/src/content_commitment.nr | 54 +++---- .../crates/types/src/contract_class_id.nr | 2 +- .../crates/types/src/contract_instance.nr | 10 +- .../crates/types/src/contrakt/storage_read.nr | 16 +-- .../src/contrakt/storage_update_request.nr | 15 +- .../crates/types/src/data/public_data_hint.nr | 2 +- .../types/src/data/public_data_leaf_hint.nr | 5 +- .../types/src/data/public_data_tree_leaf.nr | 20 ++- .../data/public_data_tree_leaf_preimage.nr | 7 +- .../crates/types/src/header.nr | 10 +- .../types/src/merkle_tree/membership.nr | 5 +- .../types/src/merkle_tree/merkle_tree.nr | 5 +- .../types/src/messaging/l2_to_l1_message.nr | 26 ++-- .../types/src/partial_state_reference.nr | 24 ++-- .../crates/types/src/point.nr | 6 +- .../crates/types/src/recursion/proof.nr | 20 ++- .../types/src/recursion/verification_key.nr | 34 ++--- .../crates/types/src/scalar.nr | 6 +- .../crates/types/src/state_reference.nr | 10 +- .../crates/types/src/tests/fixture_builder.nr | 2 +- .../types/src/tests/merkle_tree_utils.nr | 2 +- .../crates/types/src/tests/types.nr | 4 +- .../crates/types/src/traits.nr | 96 ++++++++++--- .../types/src/transaction/tx_context.nr | 14 +- .../types/src/transaction/tx_request.nr | 12 +- .../crates/types/src/type_serialization.nr | 1 - 130 files changed, 1560 insertions(+), 1477 deletions(-) diff --git a/noir-projects/aztec-nr/address-note/src/address_note.nr b/noir-projects/aztec-nr/address-note/src/address_note.nr index d8bbbcbfdeb..6be58816d1e 100644 --- a/noir-projects/aztec-nr/address-note/src/address_note.nr +++ b/noir-projects/aztec-nr/address-note/src/address_note.nr @@ -27,22 +27,24 @@ impl NoteInterface for AddressNote { fn compute_nullifier(self, context: &mut PrivateContext, note_hash_for_nullify: Field) -> Field { let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([ + poseidon2_hash_with_separator( + [ note_hash_for_nullify, secret ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } fn compute_nullifier_without_context(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_nullify(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([ + poseidon2_hash_with_separator( + [ note_hash_for_nullify, secret ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } } diff --git a/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr b/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr index 663ae8044a6..c658539a306 100644 --- a/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr +++ b/noir-projects/aztec-nr/authwit/src/entrypoint/app.nr @@ -22,24 +22,21 @@ struct AppPayload { // docs:end:app-payload-struct impl Serialize for AppPayload { - // Serializes the entrypoint struct - fn serialize(self) -> [Field; APP_PAYLOAD_SIZE] { - let mut fields: BoundedVec = BoundedVec::new(); - for call in self.function_calls { - fields.extend_from_array(call.serialize()); + // Serializes the entrypoint struct + fn serialize(self) -> [Field; APP_PAYLOAD_SIZE] { + let mut fields: BoundedVec = BoundedVec::new(); + for call in self.function_calls { + fields.extend_from_array(call.serialize()); + } + fields.push(self.nonce); + fields.storage } - fields.push(self.nonce); - fields.storage - } } impl Hash for AppPayload { - fn hash(self) -> Field { - poseidon2_hash_with_separator( - self.serialize(), - GENERATOR_INDEX__SIGNATURE_PAYLOAD - ) - } + fn hash(self) -> Field { + poseidon2_hash_with_separator(self.serialize(), GENERATOR_INDEX__SIGNATURE_PAYLOAD) + } } impl AppPayload { diff --git a/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr b/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr index f7d0ea258fc..f2cf7a76eaf 100644 --- a/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr +++ b/noir-projects/aztec-nr/authwit/src/entrypoint/fee.nr @@ -22,25 +22,22 @@ struct FeePayload { // docs:end:fee-payload-struct impl Serialize for FeePayload { - // Serializes the entrypoint struct - fn serialize(self) -> [Field; FEE_PAYLOAD_SIZE] { - let mut fields: BoundedVec = BoundedVec::new(); - for i in 0..MAX_FEE_FUNCTION_CALLS { - fields.extend_from_array(self.function_calls[i].serialize()); + // Serializes the entrypoint struct + fn serialize(self) -> [Field; FEE_PAYLOAD_SIZE] { + let mut fields: BoundedVec = BoundedVec::new(); + for i in 0..MAX_FEE_FUNCTION_CALLS { + fields.extend_from_array(self.function_calls[i].serialize()); + } + fields.push(self.nonce); + fields.push(self.is_fee_payer as Field); + fields.storage } - fields.push(self.nonce); - fields.push(self.is_fee_payer as Field); - fields.storage - } } impl Hash for FeePayload { - fn hash(self) -> Field { - poseidon2_hash_with_separator( - self.serialize(), - GENERATOR_INDEX__FEE_PAYLOAD - ) - } + fn hash(self) -> Field { + poseidon2_hash_with_separator(self.serialize(), GENERATOR_INDEX__FEE_PAYLOAD) + } } impl FeePayload { diff --git a/noir-projects/aztec-nr/authwit/src/entrypoint/function_call.nr b/noir-projects/aztec-nr/authwit/src/entrypoint/function_call.nr index 18ed6acb11a..5ba2bf836b5 100644 --- a/noir-projects/aztec-nr/authwit/src/entrypoint/function_call.nr +++ b/noir-projects/aztec-nr/authwit/src/entrypoint/function_call.nr @@ -14,9 +14,11 @@ struct FunctionCall { } impl Serialize for FunctionCall { - fn serialize(self) -> [Field; FUNCTION_CALL_SIZE] { - [self.args_hash, self.function_selector.to_field(), self.target_address.to_field(), self.is_public as Field, self.is_static as Field] - } + fn serialize(self) -> [Field; FUNCTION_CALL_SIZE] { + [ + self.args_hash, self.function_selector.to_field(), self.target_address.to_field(), self.is_public as Field, self.is_static as Field + ] + } } impl FunctionCall { diff --git a/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr b/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr index b40bc974314..a1398c50c9f 100644 --- a/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr +++ b/noir-projects/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr @@ -16,7 +16,7 @@ impl Empty for PrivateContextInputs { call_context: CallContext::empty(), historical_header: Header::empty(), tx_context: TxContext::empty(), - start_side_effect_counter: 0 as u32, + start_side_effect_counter: 0 as u32 } } } diff --git a/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr b/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr index 6df5a120fbc..68dbb85b80b 100644 --- a/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr +++ b/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr @@ -9,9 +9,6 @@ struct PublicContextInputs { impl Empty for PublicContextInputs { fn empty() -> Self { - PublicContextInputs { - calldata_length: 0, - is_static_call: false - } + PublicContextInputs { calldata_length: 0, is_static_call: false } } } diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr index 3e17a64cfb5..2ba0ec2a8b7 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr @@ -67,11 +67,19 @@ mod test { 1 } - fn get_header(self) -> NoteHeader { self.header} + fn get_header(self) -> NoteHeader { + self.header + } - fn set_header(&mut self, header: NoteHeader) {self.header = header; } + fn set_header(&mut self, header: NoteHeader) { + self.header = header; + } - fn compute_nullifier(_self: Self, _context: &mut PrivateContext, _note_hash_for_nullify: Field) -> Field { + fn compute_nullifier( + _self: Self, + _context: &mut PrivateContext, + _note_hash_for_nullify: Field + ) -> Field { 1 } @@ -79,10 +87,17 @@ mod test { 1 } - fn serialize_content(self) -> [Field; ADDRESS_NOTE_LEN] { [self.address.to_field(), self.owner.to_field(), self.randomness]} + fn serialize_content(self) -> [Field; ADDRESS_NOTE_LEN] { + [self.address.to_field(), self.owner.to_field(), self.randomness] + } fn deserialize_content(fields: [Field; ADDRESS_NOTE_LEN]) -> Self { - AddressNote { address: AztecAddress::from_field(fields[0]), owner: AztecAddress::from_field(fields[1]), randomness: fields[2], header: NoteHeader::empty() } + AddressNote { + address: AztecAddress::from_field(fields[0]), + owner: AztecAddress::from_field(fields[1]), + randomness: fields[2], + header: NoteHeader::empty() + } } fn to_be_bytes(self, storage_slot: Field) -> [u8; ADDRESS_NOTE_BYTES_LEN] { @@ -177,7 +192,10 @@ mod test { impl EventInterface for TestEvent { fn get_event_type_id() -> EventSelector { - comptime { EventSelector::from_signature("TestEvent(Field,Field,Field)") } + comptime + { + EventSelector::from_signature("TestEvent(Field,Field,Field)") + } } fn private_to_be_bytes(self, randomness: Field) -> [u8; TEST_EVENT_BYTES_LEN] { @@ -204,24 +222,24 @@ mod test { } fn to_be_bytes(self) -> [u8; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS] { - let mut buffer: [u8; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS] = [0; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS]; + let mut buffer: [u8; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS] = [0; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS]; - let event_type_id_bytes: [u8; 32] = TestEvent::get_event_type_id().to_field().to_be_bytes(); + let event_type_id_bytes: [u8; 32] = TestEvent::get_event_type_id().to_field().to_be_bytes(); - for i in 0..32 { - buffer[i] = event_type_id_bytes[i]; + for i in 0..32 { + buffer[i] = event_type_id_bytes[i]; } - let serialized_event = self.serialize(); + let serialized_event = self.serialize(); - for i in 0..serialized_event.len() { - let bytes: [u8; 32] = serialized_event[i].to_be_bytes(); - for j in 0..32 { - buffer[32 + i * 32 + j] = bytes[j]; + for i in 0..serialized_event.len() { + let bytes: [u8; 32] = serialized_event[i].to_be_bytes(); + for j in 0..32 { + buffer[32 + i * 32 + j] = bytes[j]; } } - buffer + buffer } fn emit(self, _emit: fn[Env](Self) -> ()) { diff --git a/noir-projects/aztec-nr/aztec/src/history/contract_inclusion.nr b/noir-projects/aztec-nr/aztec/src/history/contract_inclusion.nr index 942de054bd9..46219e12e16 100644 --- a/noir-projects/aztec-nr/aztec/src/history/contract_inclusion.nr +++ b/noir-projects/aztec-nr/aztec/src/history/contract_inclusion.nr @@ -10,10 +10,7 @@ trait ProveContractDeployment { impl ProveContractDeployment for Header { fn prove_contract_deployment(self, contract_address: AztecAddress) { // Compute deployment nullifier - let nullifier = compute_siloed_nullifier( - DEPLOYER_CONTRACT_ADDRESS, - contract_address.to_field() - ); + let nullifier = compute_siloed_nullifier(DEPLOYER_CONTRACT_ADDRESS, contract_address.to_field()); self.prove_nullifier_inclusion(nullifier); } @@ -26,10 +23,7 @@ trait ProveContractNonDeployment { impl ProveContractNonDeployment for Header { fn prove_contract_non_deployment(self, contract_address: AztecAddress) { // Compute deployment nullifier - let nullifier = compute_siloed_nullifier( - DEPLOYER_CONTRACT_ADDRESS, - contract_address.to_field() - ); + let nullifier = compute_siloed_nullifier(DEPLOYER_CONTRACT_ADDRESS, contract_address.to_field()); // docs:start:prove_nullifier_non_inclusion self.prove_nullifier_non_inclusion(nullifier); diff --git a/noir-projects/aztec-nr/aztec/src/history/note_validity.nr b/noir-projects/aztec-nr/aztec/src/history/note_validity.nr index e0560ea39f8..8fa98581b90 100644 --- a/noir-projects/aztec-nr/aztec/src/history/note_validity.nr +++ b/noir-projects/aztec-nr/aztec/src/history/note_validity.nr @@ -7,7 +7,11 @@ trait ProveNoteValidity { } impl ProveNoteValidity for Header { - fn prove_note_validity(self, note: Note, context: &mut PrivateContext) where Note: NoteInterface { + fn prove_note_validity( + self, + note: Note, + context: &mut PrivateContext + ) where Note: NoteInterface { self.prove_note_inclusion(note); self.prove_note_not_nullified(note, context); } diff --git a/noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion.nr b/noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion.nr index 4c9b89788d1..fb67a6bf885 100644 --- a/noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion.nr +++ b/noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion.nr @@ -37,7 +37,11 @@ trait ProveNoteIsNullified { impl ProveNoteIsNullified for Header { // docs:start:prove_note_is_nullified - fn prove_note_is_nullified(self, note: Note, context: &mut PrivateContext) where Note: NoteInterface { + fn prove_note_is_nullified( + self, + note: Note, + context: &mut PrivateContext + ) where Note: NoteInterface { let nullifier = compute_siloed_nullifier(note, context); self.prove_nullifier_inclusion(nullifier); diff --git a/noir-projects/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr b/noir-projects/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr index 5238ca99c50..c70689473e5 100644 --- a/noir-projects/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr +++ b/noir-projects/aztec-nr/aztec/src/history/nullifier_non_inclusion.nr @@ -46,7 +46,11 @@ trait ProveNoteNotNullified { impl ProveNoteNotNullified for Header { // docs:start:prove_note_not_nullified - fn prove_note_not_nullified(self, note: Note, context: &mut PrivateContext) where Note: NoteInterface { + fn prove_note_not_nullified( + self, + note: Note, + context: &mut PrivateContext + ) where Note: NoteInterface { let nullifier = compute_siloed_nullifier(note, context); self.prove_nullifier_non_inclusion(nullifier); diff --git a/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr b/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr index 0cb4358fde0..c4114e030b5 100644 --- a/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr +++ b/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr @@ -91,20 +91,20 @@ impl ToPoint for TpkM { impl Empty for PublicKeys { fn empty() -> Self { PublicKeys { - npk_m : NpkM { inner: Point::empty() }, - ivpk_m : IvpkM { inner: Point::empty() }, - ovpk_m : OvpkM { inner: Point::empty() }, - tpk_m : TpkM { inner: Point::empty() } + npk_m: NpkM { inner: Point::empty() }, + ivpk_m: IvpkM { inner: Point::empty() }, + ovpk_m: OvpkM { inner: Point::empty() }, + tpk_m: TpkM { inner: Point::empty() } } } } impl Eq for PublicKeys { fn eq(self, other: PublicKeys) -> bool { - ( self.npk_m.inner == other.npk_m.inner ) & - ( self.ivpk_m.inner == other.ivpk_m.inner ) & - ( self.ovpk_m.inner == other.ovpk_m.inner ) & - ( self.tpk_m.inner == other.tpk_m.inner ) + (self.npk_m.inner == other.npk_m.inner) + & (self.ivpk_m.inner == other.ivpk_m.inner) + & (self.ovpk_m.inner == other.ovpk_m.inner) + & (self.tpk_m.inner == other.tpk_m.inner) } } @@ -142,10 +142,10 @@ impl Serialize for PublicKeys { impl Deserialize for PublicKeys { fn deserialize(serialized: [Field; PUBLIC_KEYS_LENGTH]) -> PublicKeys { PublicKeys { - npk_m: NpkM { inner: Point { x:serialized[0], y:serialized[1], is_infinite: serialized[2] as bool } }, - ivpk_m: IvpkM { inner: Point { x:serialized[3], y: serialized[4], is_infinite: serialized[5] as bool } }, - ovpk_m: OvpkM { inner: Point { x:serialized[6], y: serialized[7], is_infinite: serialized[8] as bool } }, - tpk_m: TpkM { inner: Point { x:serialized[9], y: serialized[10], is_infinite: serialized[11] as bool } } + npk_m: NpkM { inner: Point { x: serialized[0], y: serialized[1], is_infinite: serialized[2] as bool } }, + ivpk_m: IvpkM { inner: Point { x: serialized[3], y: serialized[4], is_infinite: serialized[5] as bool } }, + ovpk_m: OvpkM { inner: Point { x: serialized[6], y: serialized[7], is_infinite: serialized[8] as bool } }, + tpk_m: TpkM { inner: Point { x: serialized[9], y: serialized[10], is_infinite: serialized[11] as bool } } } } } diff --git a/noir-projects/aztec-nr/aztec/src/note/note_header.nr b/noir-projects/aztec-nr/aztec/src/note/note_header.nr index a2aca754461..2c20777fd4d 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_header.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_header.nr @@ -17,10 +17,10 @@ impl Empty for NoteHeader { impl Eq for NoteHeader { fn eq(self, other: Self) -> bool { - (self.contract_address == other.contract_address) & - (self.nonce == other.nonce) & - (self.storage_slot == other.storage_slot)& - (self.note_hash_counter == other.note_hash_counter) + (self.contract_address == other.contract_address) + & (self.nonce == other.nonce) + & (self.storage_slot == other.storage_slot) + & (self.note_hash_counter == other.note_hash_counter) } } @@ -38,6 +38,8 @@ impl Serialize for NoteHeader { // Note: If you change this function don't forget to update implementations of Serialize trait for notes. // (Serialize trait needs to be implemented for a note when it's passed as an argument to a contract function // --> then it's used when computing args hash.) - [self.contract_address.to_field(), self.nonce, self.storage_slot, self.note_hash_counter as Field] + [ + self.contract_address.to_field(), self.nonce, self.storage_slot, self.note_hash_counter as Field + ] } } diff --git a/noir-projects/aztec-nr/aztec/src/oracle/logs_traits.nr b/noir-projects/aztec-nr/aztec/src/oracle/logs_traits.nr index d9112a21324..9417dfe6224 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/logs_traits.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/logs_traits.nr @@ -17,52 +17,100 @@ trait LensForEncryptedLog { } impl LensForEncryptedLog<1, 448> for [Field; 1] { - fn output_fields(self) -> [Field; 1] {[self[0]; 1]} - fn output_bytes(self) -> [u8; 448] {[self[0] as u8; 448]} + fn output_fields(self) -> [Field; 1] { + [self[0]; 1] + } + fn output_bytes(self) -> [u8; 448] { + [self[0] as u8; 448] + } } impl LensForEncryptedLog<2, 480> for [Field; 2] { - fn output_fields(self) -> [Field; 2] {[self[0]; 2]} - fn output_bytes(self) -> [u8; 480] {[self[0] as u8; 480]} + fn output_fields(self) -> [Field; 2] { + [self[0]; 2] + } + fn output_bytes(self) -> [u8; 480] { + [self[0] as u8; 480] + } } impl LensForEncryptedLog<3, 512> for [Field; 3] { - fn output_fields(self) -> [Field; 3] {[self[0]; 3]} - fn output_bytes(self) -> [u8; 512] {[self[0] as u8; 512]} + fn output_fields(self) -> [Field; 3] { + [self[0]; 3] + } + fn output_bytes(self) -> [u8; 512] { + [self[0] as u8; 512] + } } impl LensForEncryptedLog<4, 544> for [Field; 4] { - fn output_fields(self) -> [Field; 4] {[self[0]; 4]} - fn output_bytes(self) -> [u8; 544] {[self[0] as u8; 544]} + fn output_fields(self) -> [Field; 4] { + [self[0]; 4] + } + fn output_bytes(self) -> [u8; 544] { + [self[0] as u8; 544] + } } impl LensForEncryptedLog<5, 576> for [Field; 5] { - fn output_fields(self) -> [Field; 5] {[self[0]; 5]} - fn output_bytes(self) -> [u8; 576] {[self[0] as u8; 576]} + fn output_fields(self) -> [Field; 5] { + [self[0]; 5] + } + fn output_bytes(self) -> [u8; 576] { + [self[0] as u8; 576] + } } impl LensForEncryptedLog<6, 608> for [Field; 6] { - fn output_fields(self) -> [Field; 6] {[self[0]; 6]} - fn output_bytes(self) -> [u8; 608] {[self[0] as u8; 608]} + fn output_fields(self) -> [Field; 6] { + [self[0]; 6] + } + fn output_bytes(self) -> [u8; 608] { + [self[0] as u8; 608] + } } impl LensForEncryptedLog<7, 640> for [Field; 7] { - fn output_fields(self) -> [Field; 7] {[self[0]; 7]} - fn output_bytes(self) -> [u8; 640] {[self[0] as u8; 640]} + fn output_fields(self) -> [Field; 7] { + [self[0]; 7] + } + fn output_bytes(self) -> [u8; 640] { + [self[0] as u8; 640] + } } impl LensForEncryptedLog<8, 672> for [Field; 8] { - fn output_fields(self) -> [Field; 8] {[self[0]; 8]} - fn output_bytes(self) -> [u8; 672] {[self[0] as u8; 672]} + fn output_fields(self) -> [Field; 8] { + [self[0]; 8] + } + fn output_bytes(self) -> [u8; 672] { + [self[0] as u8; 672] + } } impl LensForEncryptedLog<9, 704> for [Field; 9] { - fn output_fields(self) -> [Field; 9] {[self[0]; 9]} - fn output_bytes(self) -> [u8; 704] {[self[0] as u8; 704]} + fn output_fields(self) -> [Field; 9] { + [self[0]; 9] + } + fn output_bytes(self) -> [u8; 704] { + [self[0] as u8; 704] + } } impl LensForEncryptedLog<10, 736> for [Field; 10] { - fn output_fields(self) -> [Field; 10] {[self[0]; 10]} - fn output_bytes(self) -> [u8; 736] {[self[0] as u8; 736]} + fn output_fields(self) -> [Field; 10] { + [self[0]; 10] + } + fn output_bytes(self) -> [u8; 736] { + [self[0] as u8; 736] + } } impl LensForEncryptedLog<11, 768> for [Field; 11] { - fn output_fields(self) -> [Field; 11] {[self[0]; 11]} - fn output_bytes(self) -> [u8; 768] {[self[0] as u8; 768]} + fn output_fields(self) -> [Field; 11] { + [self[0]; 11] + } + fn output_bytes(self) -> [u8; 768] { + [self[0] as u8; 768] + } } impl LensForEncryptedLog<12, 800> for [Field; 12] { - fn output_fields(self) -> [Field; 12] {[self[0]; 12]} - fn output_bytes(self) -> [u8; 800] {[self[0] as u8; 800]} + fn output_fields(self) -> [Field; 12] { + [self[0]; 12] + } + fn output_bytes(self) -> [u8; 800] { + [self[0] as u8; 800] + } } trait LensForEncryptedEvent { @@ -72,22 +120,34 @@ trait LensForEncryptedEvent { } impl LensForEncryptedEvent<96, 448> for [u8; 96] { - fn output(self) -> [u8; 448] {[self[0] as u8; 448]} + fn output(self) -> [u8; 448] { + [self[0] as u8; 448] + } } impl LensForEncryptedEvent<128, 480> for [u8; 128] { - fn output(self) -> [u8; 480] {[self[0] as u8; 480]} + fn output(self) -> [u8; 480] { + [self[0] as u8; 480] + } } impl LensForEncryptedEvent<160, 512> for [u8; 160] { - fn output(self) -> [u8; 512] {[self[0] as u8; 512]} + fn output(self) -> [u8; 512] { + [self[0] as u8; 512] + } } impl LensForEncryptedEvent<192, 544> for [u8; 192] { - fn output(self) -> [u8; 544] {[self[0] as u8; 544]} + fn output(self) -> [u8; 544] { + [self[0] as u8; 544] + } } impl LensForEncryptedEvent<224, 576> for [u8; 224] { - fn output(self) -> [u8; 576] {[self[0] as u8; 576]} + fn output(self) -> [u8; 576] { + [self[0] as u8; 576] + } } impl LensForEncryptedEvent<256, 608> for [u8; 256] { - fn output(self) -> [u8; 608] {[self[0] as u8; 608]} + fn output(self) -> [u8; 608] { + [self[0] as u8; 608] + } } // This trait defines the length of the inputs in bytes to @@ -104,14 +164,18 @@ impl ToBytesForUnencryptedLog<32, 68> for Field { fn to_be_bytes_arr(self) -> [u8; 32] { self.to_be_bytes() } - fn output_bytes(self) -> [u8; 68] {[self as u8; 68]} + fn output_bytes(self) -> [u8; 68] { + [self as u8; 68] + } } impl ToBytesForUnencryptedLog<32, 68> for AztecAddress { fn to_be_bytes_arr(self) -> [u8; 32] { self.to_field().to_be_bytes() } - fn output_bytes(self) -> [u8; 68] {[self.to_field() as u8; 68]} + fn output_bytes(self) -> [u8; 68] { + [self.to_field() as u8; 68] + } } fn arr_to_be_bytes_arr(fields: [Field; L]) -> [u8; N] { diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/scheduled_delay_change.nr b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/scheduled_delay_change.nr index 57a2a089bfd..9773ee59f75 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/scheduled_delay_change.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/scheduled_delay_change.nr @@ -133,8 +133,7 @@ impl Serialize<1> for ScheduledDelayChange { // Low limb: [ pre_inner: u32 | post_inner: u32 ] // High limb: [ empty | pre_is_some: u8 | post_is_some: u8 | block_of_change: u32 ] - let lo = ((self.pre.unwrap_unchecked() as u64) * (1 << 32)) - + (self.post.unwrap_unchecked() as u64); + let lo = ((self.pre.unwrap_unchecked() as u64) * (1 << 32)) + (self.post.unwrap_unchecked() as u64); let hi = (self.pre.is_some() as u64) * (1 << 33) + (self.post.is_some() as u64 * (1 << 32)) @@ -161,15 +160,25 @@ impl Deserialize<1> for ScheduledDelayChange { let block_of_change = ((packed.hi as u64) % (1 << 32)) as u32; Self { - pre: if pre_is_some { Option::some(pre_inner) } else { Option::none() }, - post: if post_is_some { Option::some(post_inner) } else { Option::none() }, - block_of_change, + pre: if pre_is_some { + Option::some(pre_inner) + } else { + Option::none() + }, + post: if post_is_some { + Option::some(post_inner) + } else { + Option::none() + }, + block_of_change } } } impl Eq for ScheduledDelayChange { fn eq(self, other: Self) -> bool { - (self.pre == other.pre) & (self.post == other.post) & (self.block_of_change == other.block_of_change) + (self.pre == other.pre) + & (self.post == other.post) + & (self.block_of_change == other.block_of_change) } } diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/scheduled_value_change.nr b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/scheduled_value_change.nr index 665f1f1e0f7..91c13f21f33 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/scheduled_value_change.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/scheduled_value_change.nr @@ -144,17 +144,19 @@ impl Serialize<3> for ScheduledValueChange where T: ToField { } impl Deserialize<3> for ScheduledValueChange where T: FromField { - fn deserialize(input: [Field; 3]) -> Self { - Self { - pre: FromField::from_field(input[0]), - post: FromField::from_field(input[1]), - block_of_change: FromField::from_field(input[2]), + fn deserialize(input: [Field; 3]) -> Self { + Self { + pre: FromField::from_field(input[0]), + post: FromField::from_field(input[1]), + block_of_change: FromField::from_field(input[2]) + } } - } } impl Eq for ScheduledValueChange where T: Eq { fn eq(self, other: Self) -> bool { - (self.pre == other.pre) & (self.post == other.post) & (self.block_of_change == other.block_of_change) + (self.pre == other.pre) + & (self.post == other.post) + & (self.block_of_change == other.block_of_change) } } diff --git a/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr b/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr index cb9cc5f91c2..12e2e741260 100644 --- a/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr +++ b/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr @@ -17,14 +17,11 @@ struct MockNote { impl NoteInterface for MockNote { fn serialize_content(self) -> [Field; MOCK_NOTE_LENGTH] { - [self.value] + [self.value] } fn deserialize_content(fields: [Field; MOCK_NOTE_LENGTH]) -> Self { - Self { - value: fields[0], - header: NoteHeader::empty(), - } + Self { value: fields[0], header: NoteHeader::empty() } } fn compute_note_hiding_point(self: Self) -> Point { @@ -35,33 +32,39 @@ impl NoteInterface for MockNote { } fn get_header(self) -> NoteHeader { - self.header + self.header } fn set_header(&mut self, header: NoteHeader) -> () { - self.header = header; + self.header = header; } fn get_note_type_id() -> Field { - // randomly chose note type id - 4135 + // randomly chose note type id + 4135 } fn compute_nullifier(_self: Self, _context: &mut PrivateContext, note_hash_for_nullify: Field) -> Field { // We don't use any kind of secret here since this is only a mock note and having it here would make tests // more cumbersome - poseidon2_hash_with_separator([note_hash_for_nullify], GENERATOR_INDEX__NOTE_NULLIFIER as Field) + poseidon2_hash_with_separator( + [note_hash_for_nullify], + GENERATOR_INDEX__NOTE_NULLIFIER as Field + ) } fn compute_nullifier_without_context(self) -> Field { // We don't use any kind of secret here since this is only a mock note and having it here would make tests // more cumbersome let note_hash_for_nullify = compute_note_hash_for_nullify(self); - poseidon2_hash_with_separator([note_hash_for_nullify], GENERATOR_INDEX__NOTE_NULLIFIER as Field) + poseidon2_hash_with_separator( + [note_hash_for_nullify], + GENERATOR_INDEX__NOTE_NULLIFIER as Field + ) } fn to_be_bytes(self, storage_slot: Field) -> [u8; MOCK_NOTE_BYTES_LENGTH] { - let serialized_note = self.serialize_content(); + let serialized_note = self.serialize_content(); let mut buffer: [u8; MOCK_NOTE_BYTES_LENGTH] = [0; MOCK_NOTE_BYTES_LENGTH]; @@ -85,8 +88,7 @@ impl NoteInterface for MockNote { impl Eq for MockNote { fn eq(self, other: Self) -> bool { - (self.header == other.header) & - (self.value == other.value) + (self.header == other.header) & (self.value == other.value) } } diff --git a/noir-projects/aztec-nr/aztec/src/unencrypted_logs/unencrypted_event_emission.nr b/noir-projects/aztec-nr/aztec/src/unencrypted_logs/unencrypted_event_emission.nr index 255c988737e..b5b20f2b096 100644 --- a/noir-projects/aztec-nr/aztec/src/unencrypted_logs/unencrypted_event_emission.nr +++ b/noir-projects/aztec-nr/aztec/src/unencrypted_logs/unencrypted_event_emission.nr @@ -36,20 +36,32 @@ trait LensForEventSelector { } impl LensForEventSelector<1, 2> for [Field; 1] { - fn output(self) -> [Field; 2] {[self[0] as Field; 2]} + fn output(self) -> [Field; 2] { + [self[0] as Field; 2] + } } impl LensForEventSelector<2, 3> for [Field; 2] { - fn output(self) -> [Field; 3] {[self[0] as Field; 3]} + fn output(self) -> [Field; 3] { + [self[0] as Field; 3] + } } impl LensForEventSelector<3, 4> for [Field; 3] { - fn output(self) -> [Field; 4] {[self[0] as Field; 4]} + fn output(self) -> [Field; 4] { + [self[0] as Field; 4] + } } impl LensForEventSelector<4, 5> for [Field; 4] { - fn output(self) -> [Field; 5] {[self[0] as Field; 5]} + fn output(self) -> [Field; 5] { + [self[0] as Field; 5] + } } impl LensForEventSelector<5, 6> for [Field; 5] { - fn output(self) -> [Field; 6] {[self[0] as Field; 6]} + fn output(self) -> [Field; 6] { + [self[0] as Field; 6] + } } impl LensForEventSelector<6, 7> for [Field; 6] { - fn output(self) -> [Field; 7] {[self[0] as Field; 7]} + fn output(self) -> [Field; 7] { + [self[0] as Field; 7] + } } diff --git a/noir-projects/aztec-nr/compressed-string/src/compressed_string.nr b/noir-projects/aztec-nr/compressed-string/src/compressed_string.nr index 408db8a47d9..3211c3d89db 100644 --- a/noir-projects/aztec-nr/compressed-string/src/compressed_string.nr +++ b/noir-projects/aztec-nr/compressed-string/src/compressed_string.nr @@ -55,7 +55,6 @@ impl Eq for CompressedString { impl Serialize for CompressedString { fn serialize(self) -> [Field; N] { self.value - } } diff --git a/noir-projects/aztec-nr/compressed-string/src/field_compressed_string.nr b/noir-projects/aztec-nr/compressed-string/src/field_compressed_string.nr index 0207d1c0313..9b02c6419f8 100644 --- a/noir-projects/aztec-nr/compressed-string/src/field_compressed_string.nr +++ b/noir-projects/aztec-nr/compressed-string/src/field_compressed_string.nr @@ -7,15 +7,15 @@ struct FieldCompressedString{ } impl Serialize<1> for FieldCompressedString { - fn serialize(self) -> [Field; 1] { - [self.value] - } + fn serialize(self) -> [Field; 1] { + [self.value] + } } impl Deserialize<1> for FieldCompressedString { - fn deserialize(input: [Field; 1]) -> Self { - Self { value: input[0] } - } + fn deserialize(input: [Field; 1]) -> Self { + Self { value: input[0] } + } } impl FieldCompressedString { diff --git a/noir-projects/aztec-nr/uint-note/src/uint_note.nr b/noir-projects/aztec-nr/uint-note/src/uint_note.nr index 83889e1add6..96660b551d4 100644 --- a/noir-projects/aztec-nr/uint-note/src/uint_note.nr +++ b/noir-projects/aztec-nr/uint-note/src/uint_note.nr @@ -26,18 +26,22 @@ struct UintNote { impl NoteInterface for UintNote { fn compute_nullifier(self, context: &mut PrivateContext, note_hash_for_nullify: Field) -> Field { let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([ + poseidon2_hash_with_separator( + [ note_hash_for_nullify, secret ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } fn compute_nullifier_without_context(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_nullify(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([note_hash_for_nullify, secret],GENERATOR_INDEX__NOTE_NULLIFIER) + poseidon2_hash_with_separator( + [note_hash_for_nullify, secret], + GENERATOR_INDEX__NOTE_NULLIFIER + ) } fn compute_note_hiding_point(self) -> Point { @@ -103,8 +107,8 @@ impl Serialize for UintNoteHidingPoint { impl Eq for UintNote { fn eq(self, other: Self) -> bool { - (self.value == other.value) & - (self.npk_m_hash == other.npk_m_hash) & - (self.randomness == other.randomness) + (self.value == other.value) + & (self.npk_m_hash == other.npk_m_hash) + & (self.randomness == other.randomness) } } diff --git a/noir-projects/aztec-nr/value-note/src/value_note.nr b/noir-projects/aztec-nr/value-note/src/value_note.nr index a5e190046a2..356aaa4444e 100644 --- a/noir-projects/aztec-nr/value-note/src/value_note.nr +++ b/noir-projects/aztec-nr/value-note/src/value_note.nr @@ -29,11 +29,12 @@ impl NoteInterface for ValueNote { fn compute_nullifier(self, context: &mut PrivateContext, note_hash_for_nullify: Field) -> Field { let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([ + poseidon2_hash_with_separator( + [ note_hash_for_nullify, secret ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } @@ -42,11 +43,12 @@ impl NoteInterface for ValueNote { fn compute_nullifier_without_context(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_nullify(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([ + poseidon2_hash_with_separator( + [ note_hash_for_nullify, - secret, + secret ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } @@ -95,9 +97,9 @@ impl Serialize<7> for ValueNote { impl Eq for ValueNote { fn eq(self, other: Self) -> bool { - (self.value == other.value) & - (self.npk_m_hash == other.npk_m_hash) & - (self.randomness == other.randomness) + (self.value == other.value) + & (self.npk_m_hash == other.npk_m_hash) + & (self.randomness == other.randomness) } } diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/dapp_payload.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/dapp_payload.nr index d04cfb8f4f2..592f2cbe441 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/dapp_payload.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/dapp_payload.nr @@ -21,24 +21,21 @@ struct DAppPayload { // docs:end:app-payload-struct impl Serialize for DAppPayload { - // Serializes the entrypoint struct - fn serialize(self) -> [Field; DAPP_PAYLOAD_SIZE] { - let mut fields: BoundedVec = BoundedVec::new(); - for call in self.function_calls { - fields.extend_from_array(call.serialize()); + // Serializes the entrypoint struct + fn serialize(self) -> [Field; DAPP_PAYLOAD_SIZE] { + let mut fields: BoundedVec = BoundedVec::new(); + for call in self.function_calls { + fields.extend_from_array(call.serialize()); + } + fields.push(self.nonce); + fields.storage } - fields.push(self.nonce); - fields.storage - } } impl Hash for DAppPayload { - fn hash(self) -> Field { - poseidon2_hash_with_separator( - self.serialize(), - GENERATOR_INDEX__SIGNATURE_PAYLOAD - ) - } + fn hash(self) -> Field { + poseidon2_hash_with_separator(self.serialize(), GENERATOR_INDEX__SIGNATURE_PAYLOAD) + } } impl DAppPayload { diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr index b6b60d7d164..36ca60c7515 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr @@ -22,22 +22,24 @@ struct SubscriptionNote { impl NoteInterface for SubscriptionNote { fn compute_nullifier(self, context: &mut PrivateContext, note_hash_for_nullify: Field) -> Field { let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([ + poseidon2_hash_with_separator( + [ note_hash_for_nullify, secret ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } fn compute_nullifier_without_context(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_nullify(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([ + poseidon2_hash_with_separator( + [ note_hash_for_nullify, - secret, + secret ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } } diff --git a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr index f621ba153ae..a0fa23e74bc 100644 --- a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr @@ -13,7 +13,7 @@ impl Serialize<2> for Note { impl Deserialize<2> for Note { fn deserialize(wire: [Field; 2]) -> Note { - Note {a: wire[0], b: wire[1]} + Note { a: wire[0], b: wire[1] } } } diff --git a/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr b/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr index 9d572e091ce..543e33357d0 100644 --- a/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr +++ b/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr @@ -15,7 +15,7 @@ struct Card { } impl FromField for Card { - fn from_field(field: Field) -> Card { + fn from_field(field: Field) -> Card { let value_bytes: [u8; 32] = field.to_le_bytes(); let strength = (value_bytes[0] as u32) + (value_bytes[1] as u32) * 256; let points = (value_bytes[2] as u32) + (value_bytes[3] as u32) * 256; @@ -24,8 +24,8 @@ impl FromField for Card { } impl ToField for Card { - fn to_field(self) -> Field { - self.strength as Field + (self.points as Field)*65536 + fn to_field(self) -> Field { + self.strength as Field + (self.points as Field) * 65536 } } diff --git a/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr b/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr index e8501b88d8a..057c40640cc 100644 --- a/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr +++ b/noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr @@ -24,17 +24,15 @@ impl Deserialize for PlayerEntry { let deck_strength = fields[1] as u32; let points = fields[2] as u64; - PlayerEntry { - address, - deck_strength, - points - } + PlayerEntry { address, deck_strength, points } } } impl Eq for PlayerEntry { fn eq(self, other: PlayerEntry) -> bool { - self.address.eq(other.address) & self.deck_strength.eq(other.deck_strength) & self.points.eq(other.points) + self.address.eq(other.address) + & self.deck_strength.eq(other.deck_strength) + & self.points.eq(other.points) } } diff --git a/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/private_function_broadcasted.nr b/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/private_function_broadcasted.nr index 7c85f3e3238..3e23539c72f 100644 --- a/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/private_function_broadcasted.nr +++ b/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/private_function_broadcasted.nr @@ -57,17 +57,18 @@ struct ClassPrivateFunctionBroadcasted { impl Serialize for ClassPrivateFunctionBroadcasted { fn serialize(self: Self) -> [Field; MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS + REGISTERER_PRIVATE_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS] { - let mut packed = [0; MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS + REGISTERER_PRIVATE_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS]; + let mut packed = [0; MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS + + REGISTERER_PRIVATE_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS]; packed[0] = REGISTERER_PRIVATE_FUNCTION_BROADCASTED_MAGIC_VALUE; packed[1] = self.contract_class_id.to_field(); packed[2] = self.artifact_metadata_hash; packed[3] = self.unconstrained_functions_artifact_tree_root; for i in 0..FUNCTION_TREE_HEIGHT { - packed[i + 4] = self.private_function_tree_sibling_path[i]; + packed[i + 4] = self.private_function_tree_sibling_path[i]; } packed[4 + FUNCTION_TREE_HEIGHT] = self.private_function_tree_leaf_index; for i in 0..ARTIFACT_FUNCTION_TREE_MAX_HEIGHT { - packed[i + 5 + FUNCTION_TREE_HEIGHT] = self.artifact_function_tree_sibling_path[i]; + packed[i + 5 + FUNCTION_TREE_HEIGHT] = self.artifact_function_tree_sibling_path[i]; } packed[5 + ARTIFACT_FUNCTION_TREE_MAX_HEIGHT + FUNCTION_TREE_HEIGHT] = self.artifact_function_tree_leaf_index; let packed_function = self.function.serialize(); diff --git a/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/unconstrained_function_broadcasted.nr b/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/unconstrained_function_broadcasted.nr index 91233f5def3..382f94aac9f 100644 --- a/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/unconstrained_function_broadcasted.nr +++ b/noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/events/unconstrained_function_broadcasted.nr @@ -17,7 +17,7 @@ struct InnerUnconstrainedFunction { impl Serialize<2> for InnerUnconstrainedFunction { fn serialize(self: Self) -> [Field; 2] { - [ self.selector.to_field(), self.metadata_hash] + [self.selector.to_field(), self.metadata_hash] } } @@ -51,13 +51,14 @@ struct ClassUnconstrainedFunctionBroadcasted { impl Serialize for ClassUnconstrainedFunctionBroadcasted { fn serialize(self: Self) -> [Field; MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS + REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS] { - let mut packed = [0; MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS + REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS]; + let mut packed = [0; MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS + + REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS]; packed[0] = REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE; packed[1] = self.contract_class_id.to_field(); packed[2] = self.artifact_metadata_hash; packed[3] = self.private_functions_artifact_tree_root; for i in 0..ARTIFACT_FUNCTION_TREE_MAX_HEIGHT { - packed[i + 4] = self.artifact_function_tree_sibling_path[i]; + packed[i + 4] = self.artifact_function_tree_sibling_path[i]; } packed[4 + ARTIFACT_FUNCTION_TREE_MAX_HEIGHT] = self.artifact_function_tree_leaf_index; let packed_function = self.function.serialize(); diff --git a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr index 9a8353a1ca9..053db37aa93 100644 --- a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr +++ b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr @@ -32,22 +32,24 @@ impl CardNote { impl NoteInterface for CardNote { fn compute_nullifier(self, context: &mut PrivateContext, note_hash_for_nullify: Field) -> Field { let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([ + poseidon2_hash_with_separator( + [ note_hash_for_nullify, secret ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } fn compute_nullifier_without_context(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_nullify(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([ + poseidon2_hash_with_separator( + [ note_hash_for_nullify, - secret, + secret ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } } @@ -56,15 +58,15 @@ impl NoteInterface for CardNote { // docs:start:serialize impl Serialize<3> for CardNote { fn serialize(self) -> [Field; 3] { - [ self.points.to_field(), self.randomness, self.npk_m_hash.to_field() ] + [self.points.to_field(), self.randomness, self.npk_m_hash.to_field()] } } // docs:end:serialize impl Eq for CardNote { fn eq(self, other: Self) -> bool { - (self.points == other.points) & - (self.npk_m_hash == other.npk_m_hash) & - (self.randomness == other.randomness) + (self.points == other.points) + & (self.npk_m_hash == other.npk_m_hash) + & (self.randomness == other.randomness) } } diff --git a/noir-projects/noir-contracts/contracts/lending_contract/src/asset.nr b/noir-projects/noir-contracts/contracts/lending_contract/src/asset.nr index 54585a74eda..7440df2640f 100644 --- a/noir-projects/noir-contracts/contracts/lending_contract/src/asset.nr +++ b/noir-projects/noir-contracts/contracts/lending_contract/src/asset.nr @@ -37,11 +37,6 @@ impl Deserialize for Asset { let loan_to_value = U128 { lo: fields[3], hi: fields[4] }; let oracle = AztecAddress::from_field(fields[5]); - Asset { - interest_accumulator, - last_updated_ts, - loan_to_value, - oracle, - } + Asset { interest_accumulator, last_updated_ts, loan_to_value, oracle } } } diff --git a/noir-projects/noir-contracts/contracts/lending_contract/src/position.nr b/noir-projects/noir-contracts/contracts/lending_contract/src/position.nr index 1c05dc274a6..7a2b9a0cb1e 100644 --- a/noir-projects/noir-contracts/contracts/lending_contract/src/position.nr +++ b/noir-projects/noir-contracts/contracts/lending_contract/src/position.nr @@ -13,17 +13,13 @@ impl Serialize for Position { [ position.collateral.to_field(), position.static_debt.to_field(), - position.debt.to_field(), + position.debt.to_field() ] } } impl Deserialize for Position { fn deserialize(fields: [Field; POSITION_SERIALIZED_LEN]) -> Position { - Position { - collateral: fields[0], - static_debt: fields[1], - debt: fields[2], - } + Position { collateral: fields[0], static_debt: fields[1], debt: fields[2] } } } diff --git a/noir-projects/noir-contracts/contracts/private_fpc_contract/src/settings.nr b/noir-projects/noir-contracts/contracts/private_fpc_contract/src/settings.nr index 4d4fa24c18f..3c51a1861a0 100644 --- a/noir-projects/noir-contracts/contracts/private_fpc_contract/src/settings.nr +++ b/noir-projects/noir-contracts/contracts/private_fpc_contract/src/settings.nr @@ -15,9 +15,6 @@ impl Serialize for Settings { impl Deserialize for Settings { fn deserialize(fields: [Field; SETTINGS_LENGTH]) -> Self { - Settings { - other_asset: AztecAddress::from_field(fields[0]), - admin: AztecAddress::from_field(fields[1]), - } + Settings { other_asset: AztecAddress::from_field(fields[0]), admin: AztecAddress::from_field(fields[1]) } } } diff --git a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr index c1d85350827..948367a413a 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr @@ -21,22 +21,24 @@ struct PublicKeyNote { impl NoteInterface for PublicKeyNote { fn compute_nullifier(self, context: &mut PrivateContext, note_hash_for_nullify: Field) -> Field { let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([ + poseidon2_hash_with_separator( + [ note_hash_for_nullify, secret ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } fn compute_nullifier_without_context(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_nullify(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([ + poseidon2_hash_with_separator( + [ note_hash_for_nullify, - secret, + secret ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/roles.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/roles.nr index bbb93b0efa4..687feee2cc4 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/roles.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/roles.nr @@ -43,7 +43,9 @@ impl ToField for UserFlags { impl Eq for UserFlags { fn eq(self, other: Self) -> bool { - (self.is_admin == other.is_admin) & (self.is_minter == other.is_minter) & (self.is_blacklisted == other.is_blacklisted) + (self.is_admin == other.is_admin) + & (self.is_minter == other.is_minter) + & (self.is_blacklisted == other.is_blacklisted) } } @@ -62,11 +64,7 @@ impl Serialize<3> for UserFlags { // after having received the serialized value as a return-value impl Deserialize<3> for UserFlags { fn deserialize(fields: [Field; 3]) -> Self { - Self { - is_admin: fields[0] as bool, - is_minter: fields[1] as bool, - is_blacklisted: fields[2] as bool, - } + Self { is_admin: fields[0] as bool, is_minter: fields[1] as bool, is_blacklisted: fields[2] as bool } } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr index 58fa036d35e..21d1a365d03 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr @@ -28,11 +28,12 @@ impl NoteInterface for TokenNote { // docs:start:nullifier fn compute_nullifier(self, context: &mut PrivateContext, note_hash_for_nullify: Field) -> Field { let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([ + poseidon2_hash_with_separator( + [ note_hash_for_nullify, secret ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } // docs:end:nullifier @@ -40,31 +41,27 @@ impl NoteInterface for TokenNote { fn compute_nullifier_without_context(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_nullify(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([ + poseidon2_hash_with_separator( + [ note_hash_for_nullify, - secret, + secret ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } } impl Eq for TokenNote { fn eq(self, other: Self) -> bool { - (self.amount == other.amount) & - (self.npk_m_hash == other.npk_m_hash) & - (self.randomness == other.randomness) + (self.amount == other.amount) + & (self.npk_m_hash == other.npk_m_hash) + & (self.randomness == other.randomness) } } impl OwnedNote for TokenNote { fn new(amount: U128, owner_npk_m_hash: Field) -> Self { - Self { - amount, - npk_m_hash: owner_npk_m_hash, - randomness: unsafe_rand(), - header: NoteHeader::empty(), - } + Self { amount, npk_m_hash: owner_npk_m_hash, randomness: unsafe_rand(), header: NoteHeader::empty() } } fn get_amount(self) -> U128 { diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr index 3ac79408852..b3a5c8f3171 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr @@ -33,11 +33,7 @@ impl NoteInterface for Transpa // Custom deserialization since we don't have access to the secret plaintext fn deserialize_content(serialized_note: [Field; TRANSPARENT_NOTE_LEN]) -> Self { - TransparentNote { - amount: serialized_note[0], - secret_hash: serialized_note[1], - header: NoteHeader::empty(), - } + TransparentNote { amount: serialized_note[0], secret_hash: serialized_note[1], header: NoteHeader::empty() } } fn compute_nullifier(self, _context: &mut PrivateContext, _note_hash_for_nullify: Field) -> Field { @@ -54,10 +50,9 @@ impl NoteInterface for Transpa // This achieves that the note can only be spent by the party that knows the secret. fn compute_nullifier_without_context(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_nullify(self); - poseidon2_hash_with_separator([ - note_hash_for_nullify, - ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + poseidon2_hash_with_separator( + [note_hash_for_nullify], + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } } diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr index 2d678006e7f..2163c254a4e 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr @@ -34,11 +34,12 @@ impl NoteInterface for TokenNote { // docs:start:nullifier fn compute_nullifier(self, context: &mut PrivateContext, note_hash_for_nullify: Field) -> Field { let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([ + poseidon2_hash_with_separator( + [ note_hash_for_nullify, secret ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } // docs:end:nullifier @@ -46,7 +47,10 @@ impl NoteInterface for TokenNote { fn compute_nullifier_without_context(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_nullify(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash_with_separator([note_hash_for_nullify, secret],GENERATOR_INDEX__NOTE_NULLIFIER) + poseidon2_hash_with_separator( + [note_hash_for_nullify, secret], + GENERATOR_INDEX__NOTE_NULLIFIER + ) } // docs:start:compute_note_hiding_point @@ -114,20 +118,15 @@ impl Serialize for TokenNoteHidingPoint { impl Eq for TokenNote { fn eq(self, other: Self) -> bool { - (self.amount == other.amount) & - (self.npk_m_hash == other.npk_m_hash) & - (self.randomness == other.randomness) + (self.amount == other.amount) + & (self.npk_m_hash == other.npk_m_hash) + & (self.randomness == other.randomness) } } impl OwnedNote for TokenNote { fn new(amount: U128, owner_npk_m_hash: Field) -> Self { - Self { - amount, - npk_m_hash: owner_npk_m_hash, - randomness: unsafe_rand(), - header: NoteHeader::empty(), - } + Self { amount, npk_m_hash: owner_npk_m_hash, randomness: unsafe_rand(), header: NoteHeader::empty() } } fn get_amount(self) -> U128 { diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr index 1e543e3d4ad..867aa4d3467 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr @@ -33,11 +33,7 @@ impl NoteInterface for Transpa // Custom deserialization since we don't have access to the secret plaintext fn deserialize_content(serialized_note: [Field; TRANSPARENT_NOTE_LEN]) -> Self { - TransparentNote { - amount: serialized_note[0], - secret_hash: serialized_note[1], - header: NoteHeader::empty(), - } + TransparentNote { amount: serialized_note[0], secret_hash: serialized_note[1], header: NoteHeader::empty() } } fn compute_nullifier(self, _context: &mut PrivateContext, _note_hash_for_nullify: Field) -> Field { @@ -54,10 +50,9 @@ impl NoteInterface for Transpa // This achieves that the note can only be spent by the party that knows the secret. fn compute_nullifier_without_context(self) -> Field { let note_hash_for_nullify = compute_note_hash_for_nullify(self); - poseidon2_hash_with_separator([ - note_hash_for_nullify, - ], - GENERATOR_INDEX__NOTE_NULLIFIER as Field, + poseidon2_hash_with_separator( + [note_hash_for_nullify], + GENERATOR_INDEX__NOTE_NULLIFIER as Field ) } } diff --git a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/parity_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/parity_public_inputs.nr index d34f0587b14..6adbdaf250e 100644 --- a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/parity_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/parity_public_inputs.nr @@ -8,30 +8,22 @@ struct ParityPublicInputs { impl Empty for ParityPublicInputs { fn empty() -> Self { - ParityPublicInputs { - sha_root: 0, - converted_root: 0, - vk_tree_root: 0, - } + ParityPublicInputs { sha_root: 0, converted_root: 0, vk_tree_root: 0 } } } impl Serialize<3> for ParityPublicInputs { - fn serialize(self) -> [Field; 3] { - let mut fields = [0; 3]; - fields[0] = self.sha_root; - fields[1] = self.converted_root; - fields[2] = self.vk_tree_root; - fields - } + fn serialize(self) -> [Field; 3] { + let mut fields = [0; 3]; + fields[0] = self.sha_root; + fields[1] = self.converted_root; + fields[2] = self.vk_tree_root; + fields + } } impl Deserialize<3> for ParityPublicInputs { - fn deserialize(fields: [Field; 3]) -> Self { - ParityPublicInputs { - sha_root: fields[0], - converted_root: fields[1], - vk_tree_root: fields[2], + fn deserialize(fields: [Field; 3]) -> Self { + ParityPublicInputs { sha_root: fields[0], converted_root: fields[1], vk_tree_root: fields[2] } } - } } diff --git a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_input.nr b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_input.nr index fdbf0a76d2f..c84894e21c5 100644 --- a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_input.nr +++ b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_input.nr @@ -18,21 +18,21 @@ impl Empty for RootParityInput { proof: RecursiveProof::empty(), verification_key: VerificationKey::empty(), vk_path: [0; VK_TREE_HEIGHT], - public_inputs: ParityPublicInputs::empty(), + public_inputs: ParityPublicInputs::empty() } } } impl Verifiable for RootParityInput { - fn verify(self) { - let inputs = ParityPublicInputs::serialize(self.public_inputs); - std::verify_proof( - self.verification_key.key, - self.proof.fields, - inputs, - self.verification_key.hash - ); - } + fn verify(self) { + let inputs = ParityPublicInputs::serialize(self.public_inputs); + std::verify_proof( + self.verification_key.key, + self.proof.fields, + inputs, + self.verification_key.hash + ); + } } impl RootParityInput { diff --git a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr index eac42e449e7..da20609f839 100644 --- a/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr +++ b/noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr @@ -18,21 +18,21 @@ impl Empty for RootRollupParityInput { proof: NestedRecursiveProof::empty(), verification_key: VerificationKey::empty(), vk_path: [0; VK_TREE_HEIGHT], - public_inputs: ParityPublicInputs::empty(), + public_inputs: ParityPublicInputs::empty() } } } impl Verifiable for RootRollupParityInput { - fn verify(self) { - let inputs = ParityPublicInputs::serialize(self.public_inputs); - std::verify_proof( - self.verification_key.key, - self.proof.fields, - inputs, - self.verification_key.hash - ); - } + fn verify(self) { + let inputs = ParityPublicInputs::serialize(self.public_inputs); + std::verify_proof( + self.verification_key.key, + self.proof.fields, + inputs, + self.verification_key.hash + ); + } } impl RootRollupParityInput { diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_empty.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_empty.nr index 9d67777cbbf..453663f5e2b 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_empty.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_empty.nr @@ -9,22 +9,14 @@ struct EmptyNestedCircuitPublicInputs { } impl Verifiable for EmptyNestedCircuitPublicInputs { - fn verify(self) { - std::verify_proof( - self.vk.key, - self.proof.fields, - [], - self.vk.hash - ); - } + fn verify(self) { + std::verify_proof(self.vk.key, self.proof.fields, [], self.vk.hash); + } } impl Empty for EmptyNestedCircuitPublicInputs { fn empty() -> Self { - Self { - proof: RecursiveProof::empty(), - vk: VerificationKey::empty(), - } + Self { proof: RecursiveProof::empty(), vk: VerificationKey::empty() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/key_validation_hint.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/key_validation_hint.nr index 74b110ed2f0..e0c4de9dc1b 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/key_validation_hint.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/key_validation_hint.nr @@ -11,10 +11,7 @@ struct KeyValidationHint { impl Empty for KeyValidationHint { fn empty() -> Self { - KeyValidationHint { - sk_m: Scalar::empty(), - request_index: 0, - } + KeyValidationHint { sk_m: Scalar::empty(), request_index: 0 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/read_request.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/read_request.nr index 25e615381f9..b7196b494f2 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/read_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset/read_request.nr @@ -230,9 +230,7 @@ mod tests { impl Empty for TestLeafPreimage { fn empty() -> Self { - TestLeafPreimage { - value: 0, - } + TestLeafPreimage { value: 0 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/base_or_merge_rollup_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/base_or_merge_rollup_public_inputs.nr index 34b40ff3263..440272f7ba1 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/base_or_merge_rollup_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/base_or_merge_rollup_public_inputs.nr @@ -31,67 +31,67 @@ struct BaseOrMergeRollupPublicInputs { impl Empty for BaseOrMergeRollupPublicInputs { fn empty() -> Self { BaseOrMergeRollupPublicInputs { - rollup_type : 0 as u32, - num_txs : 0 as u32, - constants : ConstantRollupData::empty(), + rollup_type: 0 as u32, + num_txs: 0 as u32, + constants: ConstantRollupData::empty(), start: PartialStateReference::empty(), end: PartialStateReference::empty(), - txs_effects_hash : 0, - out_hash : 0, + txs_effects_hash: 0, + out_hash: 0, accumulated_fees: 0 } } } impl Eq for BaseOrMergeRollupPublicInputs { - fn eq(self, other: Self) -> bool { - (self.rollup_type == other.rollup_type) & - (self.num_txs == other.num_txs) & - (self.constants.eq(other.constants)) & - (self.start.eq(other.start)) & - (self.end.eq(other.end)) & - (self.txs_effects_hash == other.txs_effects_hash) & - (self.out_hash == other.out_hash) & - (self.accumulated_fees == other.accumulated_fees) - } + fn eq(self, other: Self) -> bool { + (self.rollup_type == other.rollup_type) + & (self.num_txs == other.num_txs) + & (self.constants.eq(other.constants)) + & (self.start.eq(other.start)) + & (self.end.eq(other.end)) + & (self.txs_effects_hash == other.txs_effects_hash) + & (self.out_hash == other.out_hash) + & (self.accumulated_fees == other.accumulated_fees) + } } impl Serialize for BaseOrMergeRollupPublicInputs { - fn serialize(self) -> [Field; BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); + fn serialize(self) -> [Field; BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); - fields.push(self.rollup_type as Field); - fields.push(self.num_txs as Field); - fields.extend_from_array(self.constants.serialize()); - fields.extend_from_array(self.start.serialize()); - fields.extend_from_array(self.end.serialize()); - fields.push(self.txs_effects_hash as Field); - fields.push(self.out_hash as Field); - fields.push(self.accumulated_fees as Field); + fields.push(self.rollup_type as Field); + fields.push(self.num_txs as Field); + fields.extend_from_array(self.constants.serialize()); + fields.extend_from_array(self.start.serialize()); + fields.extend_from_array(self.end.serialize()); + fields.push(self.txs_effects_hash as Field); + fields.push(self.out_hash as Field); + fields.push(self.accumulated_fees as Field); - assert_eq(fields.len(), BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH); + assert_eq(fields.len(), BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH); - fields.storage - } + fields.storage + } } impl Deserialize for BaseOrMergeRollupPublicInputs { - fn deserialize(fields: [Field; BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH]) -> BaseOrMergeRollupPublicInputs { - let mut reader = Reader::new(fields); - let item = Self { - rollup_type: reader.read() as u32, - num_txs: reader.read() as u32, - constants: reader.read_struct(ConstantRollupData::deserialize), - start: reader.read_struct(PartialStateReference::deserialize), - end: reader.read_struct(PartialStateReference::deserialize), - txs_effects_hash: reader.read(), - out_hash: reader.read(), - accumulated_fees: reader.read() - }; + fn deserialize(fields: [Field; BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH]) -> BaseOrMergeRollupPublicInputs { + let mut reader = Reader::new(fields); + let item = Self { + rollup_type: reader.read() as u32, + num_txs: reader.read() as u32, + constants: reader.read_struct(ConstantRollupData::deserialize), + start: reader.read_struct(PartialStateReference::deserialize), + end: reader.read_struct(PartialStateReference::deserialize), + txs_effects_hash: reader.read(), + out_hash: reader.read(), + accumulated_fees: reader.read() + }; - reader.finish(); - item - } + reader.finish(); + item + } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/block_root_or_block_merge_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/block_root_or_block_merge_public_inputs.nr index 56009c9e2ff..4c5fb902225 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/block_root_or_block_merge_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/block_root_or_block_merge_public_inputs.nr @@ -11,33 +11,27 @@ struct FeeRecipient { // TODO(#7346): Should the default empty value be MAX_FIELD? The zero addr may be a valid recipient impl Empty for FeeRecipient { - fn empty() -> Self { - FeeRecipient { - recipient: EthAddress::zero(), - value: 0, + fn empty() -> Self { + FeeRecipient { recipient: EthAddress::zero(), value: 0 } } - } } impl Serialize<2> for FeeRecipient { - fn serialize(self) -> [Field; 2] { - [self.recipient.to_field(), self.value] - } + fn serialize(self) -> [Field; 2] { + [self.recipient.to_field(), self.value] + } } impl Deserialize<2> for FeeRecipient { - fn deserialize(values: [Field; 2]) -> Self { - Self { - recipient: EthAddress::from_field(values[0]), - value: values[1] + fn deserialize(values: [Field; 2]) -> Self { + Self { recipient: EthAddress::from_field(values[0]), value: values[1] } } - } } impl Eq for FeeRecipient { - fn eq(self, other: Self) -> bool { - (self.recipient.eq(other.recipient)) & (self.value == other.value) - } + fn eq(self, other: Self) -> bool { + (self.recipient.eq(other.recipient)) & (self.value == other.value) + } } // TODO: instead of archives + global vars, use ConstantRollupData x2? It also includes vk root @@ -67,67 +61,67 @@ impl Empty for BlockRootOrBlockMergePublicInputs { out_hash: 0, fees: [FeeRecipient::empty(); 32], vk_tree_root: 0, - prover_id: 0, + prover_id: 0 } } } impl Eq for BlockRootOrBlockMergePublicInputs { - fn eq(self, other: Self) -> bool { - (self.previous_archive.eq(other.previous_archive)) & - (self.new_archive.eq(other.new_archive)) & - (self.previous_block_hash == other.previous_block_hash) & - (self.end_block_hash == other.end_block_hash) & - (self.start_global_variables.eq(other.start_global_variables)) & - (self.end_global_variables.eq(other.end_global_variables)) & - (self.out_hash == other.out_hash) & - (self.fees.eq(other.fees)) & - (self.vk_tree_root == other.vk_tree_root) & - (self.prover_id == other.prover_id) - } + fn eq(self, other: Self) -> bool { + (self.previous_archive.eq(other.previous_archive)) + & (self.new_archive.eq(other.new_archive)) + & (self.previous_block_hash == other.previous_block_hash) + & (self.end_block_hash == other.end_block_hash) + & (self.start_global_variables.eq(other.start_global_variables)) + & (self.end_global_variables.eq(other.end_global_variables)) + & (self.out_hash == other.out_hash) + & (self.fees.eq(other.fees)) + & (self.vk_tree_root == other.vk_tree_root) + & (self.prover_id == other.prover_id) + } } impl Serialize for BlockRootOrBlockMergePublicInputs { - fn serialize(self) -> [Field; BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); + fn serialize(self) -> [Field; BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); - fields.extend_from_array(self.previous_archive.serialize()); - fields.extend_from_array(self.new_archive.serialize()); - fields.push(self.previous_block_hash as Field); - fields.push(self.end_block_hash as Field); - fields.extend_from_array(self.start_global_variables.serialize()); - fields.extend_from_array(self.end_global_variables.serialize()); - fields.push(self.out_hash as Field); - for i in 0..32 { - fields.extend_from_array(self.fees[i].serialize()); - } - fields.push(self.vk_tree_root as Field); - fields.push(self.prover_id as Field); - assert_eq(fields.len(), BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH); + fields.extend_from_array(self.previous_archive.serialize()); + fields.extend_from_array(self.new_archive.serialize()); + fields.push(self.previous_block_hash as Field); + fields.push(self.end_block_hash as Field); + fields.extend_from_array(self.start_global_variables.serialize()); + fields.extend_from_array(self.end_global_variables.serialize()); + fields.push(self.out_hash as Field); + for i in 0..32 { + fields.extend_from_array(self.fees[i].serialize()); + } + fields.push(self.vk_tree_root as Field); + fields.push(self.prover_id as Field); + assert_eq(fields.len(), BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH); - fields.storage - } + fields.storage + } } impl Deserialize for BlockRootOrBlockMergePublicInputs { - fn deserialize(fields: [Field; BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH]) -> BlockRootOrBlockMergePublicInputs { - let mut reader = Reader::new(fields); - let item = Self { - previous_archive: reader.read_struct(AppendOnlyTreeSnapshot::deserialize), - new_archive: reader.read_struct(AppendOnlyTreeSnapshot::deserialize), - previous_block_hash: reader.read(), - end_block_hash: reader.read(), - start_global_variables: reader.read_struct(GlobalVariables::deserialize), - end_global_variables: reader.read_struct(GlobalVariables::deserialize), - out_hash: reader.read(), - fees: reader.read_struct_array(FeeRecipient::deserialize, [FeeRecipient::empty(); 32]), - vk_tree_root: reader.read(), - prover_id: reader.read(), - }; + fn deserialize(fields: [Field; BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH]) -> BlockRootOrBlockMergePublicInputs { + let mut reader = Reader::new(fields); + let item = Self { + previous_archive: reader.read_struct(AppendOnlyTreeSnapshot::deserialize), + new_archive: reader.read_struct(AppendOnlyTreeSnapshot::deserialize), + previous_block_hash: reader.read(), + end_block_hash: reader.read(), + start_global_variables: reader.read_struct(GlobalVariables::deserialize), + end_global_variables: reader.read_struct(GlobalVariables::deserialize), + out_hash: reader.read(), + fees: reader.read_struct_array(FeeRecipient::deserialize, [FeeRecipient::empty(); 32]), + vk_tree_root: reader.read(), + prover_id: reader.read() + }; - reader.finish(); - item - } + reader.finish(); + item + } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr index 8aa79f5b0dd..c41ed12c297 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr @@ -14,10 +14,10 @@ struct ConstantRollupData { } impl Eq for ConstantRollupData { - fn eq(self, other : ConstantRollupData) -> bool { - self.last_archive.eq(other.last_archive) & - self.global_variables.eq(other.global_variables) & - (self.vk_tree_root == other.vk_tree_root) + fn eq(self, other: ConstantRollupData) -> bool { + self.last_archive.eq(other.last_archive) + & self.global_variables.eq(other.global_variables) + & (self.vk_tree_root == other.vk_tree_root) } } @@ -26,37 +26,37 @@ impl Empty for ConstantRollupData { ConstantRollupData { last_archive: AppendOnlyTreeSnapshot::zero(), vk_tree_root: 0, - global_variables: GlobalVariables::empty(), + global_variables: GlobalVariables::empty() } } } impl Serialize for ConstantRollupData { - fn serialize(self) -> [Field; CONSTANT_ROLLUP_DATA_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); + fn serialize(self) -> [Field; CONSTANT_ROLLUP_DATA_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); - fields.extend_from_array(self.last_archive.serialize()); - fields.push(self.vk_tree_root as Field); - fields.extend_from_array(self.global_variables.serialize()); + fields.extend_from_array(self.last_archive.serialize()); + fields.push(self.vk_tree_root as Field); + fields.extend_from_array(self.global_variables.serialize()); - assert_eq(fields.len(), CONSTANT_ROLLUP_DATA_LENGTH); + assert_eq(fields.len(), CONSTANT_ROLLUP_DATA_LENGTH); - fields.storage - } + fields.storage + } } impl Deserialize for ConstantRollupData { - fn deserialize(fields: [Field; CONSTANT_ROLLUP_DATA_LENGTH]) -> ConstantRollupData { - let mut reader = Reader::new(fields); - let item = Self { - last_archive: reader.read_struct(AppendOnlyTreeSnapshot::deserialize), - vk_tree_root: reader.read(), - global_variables: reader.read_struct(GlobalVariables::deserialize), - }; + fn deserialize(fields: [Field; CONSTANT_ROLLUP_DATA_LENGTH]) -> ConstantRollupData { + let mut reader = Reader::new(fields); + let item = Self { + last_archive: reader.read_struct(AppendOnlyTreeSnapshot::deserialize), + vk_tree_root: reader.read(), + global_variables: reader.read_struct(GlobalVariables::deserialize) + }; - reader.finish(); - item - } + reader.finish(); + item + } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr index 593c44d2bab..02c3c126c4b 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_data.nr @@ -14,15 +14,10 @@ struct PreviousRollupBlockData { } impl Verifiable for PreviousRollupBlockData { - fn verify(self) { - let inputs = BlockRootOrBlockMergePublicInputs::serialize(self.block_root_or_block_merge_public_inputs); - std::verify_proof( - self.vk.key, - self.proof.fields, - inputs, - self.vk.hash - ); - } + fn verify(self) { + let inputs = BlockRootOrBlockMergePublicInputs::serialize(self.block_root_or_block_merge_public_inputs); + std::verify_proof(self.vk.key, self.proof.fields, inputs, self.vk.hash); + } } impl Empty for PreviousRollupBlockData { @@ -31,7 +26,7 @@ impl Empty for PreviousRollupBlockData { block_root_or_block_merge_public_inputs: BlockRootOrBlockMergePublicInputs::empty(), proof: NestedRecursiveProof::empty(), vk: VerificationKey::empty(), - vk_witness: MembershipWitness::empty(), + vk_witness: MembershipWitness::empty() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr index aa7e1de178b..39ba99e4406 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_data.nr @@ -14,24 +14,19 @@ struct PreviousRollupData{ } impl Verifiable for PreviousRollupData { - fn verify(self) { - let inputs = BaseOrMergeRollupPublicInputs::serialize(self.base_or_merge_rollup_public_inputs); - std::verify_proof( - self.vk.key, - self.proof.fields, - inputs, - self.vk.hash - ); - } + fn verify(self) { + let inputs = BaseOrMergeRollupPublicInputs::serialize(self.base_or_merge_rollup_public_inputs); + std::verify_proof(self.vk.key, self.proof.fields, inputs, self.vk.hash); + } } impl Empty for PreviousRollupData { fn empty() -> Self { PreviousRollupData { base_or_merge_rollup_public_inputs: BaseOrMergeRollupPublicInputs::empty(), - proof : NestedRecursiveProof::empty(), - vk : VerificationKey::empty(), - vk_witness : MembershipWitness::empty(), + proof: NestedRecursiveProof::empty(), + vk: VerificationKey::empty(), + vk_witness: MembershipWitness::empty() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr index dce74c2022f..d13216d391f 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_merge/block_merge_rollup_inputs.nr @@ -14,9 +14,7 @@ struct BlockMergeRollupInputs { impl Empty for BlockMergeRollupInputs { fn empty() -> Self { - BlockMergeRollupInputs { - previous_rollup_data: [PreviousRollupBlockData::empty(); 2] - } + BlockMergeRollupInputs { previous_rollup_data: [PreviousRollupBlockData::empty(); 2] } } } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr index aaea86a0bb7..f32c144b9cc 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr @@ -142,7 +142,7 @@ impl Empty for BlockRootRollupInputs { start_archive_snapshot: AppendOnlyTreeSnapshot::zero(), new_archive_sibling_path: [0; ARCHIVE_HEIGHT], previous_block_hash: 0, - prover_id: 0, + prover_id: 0 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr index 2aa9f12c273..785d471e668 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/merge/merge_rollup_inputs.nr @@ -15,9 +15,7 @@ struct MergeRollupInputs { impl Empty for MergeRollupInputs { fn empty() -> Self { - MergeRollupInputs { - previous_rollup_data: [PreviousRollupData::empty(); 2] - } + MergeRollupInputs { previous_rollup_data: [PreviousRollupData::empty(); 2] } } } diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr index f4d503a1918..e27538d300c 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/root/root_rollup_inputs.nr @@ -16,10 +16,7 @@ struct RootRollupInputs { impl Empty for RootRollupInputs { fn empty() -> Self { - RootRollupInputs { - previous_rollup_data: [PreviousRollupBlockData::empty(); 2], - prover_id: 0, - } + RootRollupInputs { previous_rollup_data: [PreviousRollupBlockData::empty(); 2], prover_id: 0 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr index 14d473672f9..b142411d12d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr @@ -48,75 +48,94 @@ impl Empty for CombinedAccumulatedData { } impl Serialize for CombinedAccumulatedData { - fn serialize(self) -> [Field; COMBINED_ACCUMULATED_DATA_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); + fn serialize(self) -> [Field; COMBINED_ACCUMULATED_DATA_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); - fields.extend_from_array(self.note_hashes); - fields.extend_from_array(self.nullifiers); - for i in 0..self.l2_to_l1_msgs.len() { - fields.extend_from_array(self.l2_to_l1_msgs[i].serialize()); - } - for i in 0..self.note_encrypted_logs_hashes.len() { - fields.extend_from_array(self.note_encrypted_logs_hashes[i].serialize()); - } - for i in 0..self.encrypted_logs_hashes.len() { - fields.extend_from_array(self.encrypted_logs_hashes[i].serialize()); - } - for i in 0..self.unencrypted_logs_hashes.len() { - fields.extend_from_array(self.unencrypted_logs_hashes[i].serialize()); - } - fields.push(self.note_encrypted_log_preimages_length); - fields.push(self.encrypted_log_preimages_length); - fields.push(self.unencrypted_log_preimages_length); + fields.extend_from_array(self.note_hashes); + fields.extend_from_array(self.nullifiers); + for i in 0..self.l2_to_l1_msgs.len() { + fields.extend_from_array(self.l2_to_l1_msgs[i].serialize()); + } + for i in 0..self.note_encrypted_logs_hashes.len() { + fields.extend_from_array(self.note_encrypted_logs_hashes[i].serialize()); + } + for i in 0..self.encrypted_logs_hashes.len() { + fields.extend_from_array(self.encrypted_logs_hashes[i].serialize()); + } + for i in 0..self.unencrypted_logs_hashes.len() { + fields.extend_from_array(self.unencrypted_logs_hashes[i].serialize()); + } + fields.push(self.note_encrypted_log_preimages_length); + fields.push(self.encrypted_log_preimages_length); + fields.push(self.unencrypted_log_preimages_length); - for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX { - fields.extend_from_array(self.public_data_update_requests[i].serialize()); - } + for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX { + fields.extend_from_array(self.public_data_update_requests[i].serialize()); + } - fields.extend_from_array(self.gas_used.serialize()); + fields.extend_from_array(self.gas_used.serialize()); - assert_eq(fields.len(), COMBINED_ACCUMULATED_DATA_LENGTH); + assert_eq(fields.len(), COMBINED_ACCUMULATED_DATA_LENGTH); - fields.storage - } + fields.storage + } } impl Deserialize for CombinedAccumulatedData { - fn deserialize(fields: [Field; COMBINED_ACCUMULATED_DATA_LENGTH]) -> CombinedAccumulatedData { - let mut reader = Reader::new(fields); - - let item = CombinedAccumulatedData { - note_hashes: reader.read_array([0; MAX_NOTE_HASHES_PER_TX]), - nullifiers: reader.read_array([0; MAX_NULLIFIERS_PER_TX]), - l2_to_l1_msgs: reader.read_struct_array(ScopedL2ToL1Message::deserialize,[ScopedL2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_TX]), - note_encrypted_logs_hashes: reader.read_struct_array(LogHash::deserialize, [LogHash::empty(); MAX_NOTE_ENCRYPTED_LOGS_PER_TX]), - encrypted_logs_hashes: reader.read_struct_array(ScopedLogHash::deserialize, [ScopedLogHash::empty(); MAX_ENCRYPTED_LOGS_PER_TX]), - unencrypted_logs_hashes: reader.read_struct_array(ScopedLogHash::deserialize, [ScopedLogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_TX]), - note_encrypted_log_preimages_length: reader.read(), - encrypted_log_preimages_length: reader.read(), - unencrypted_log_preimages_length: reader.read(), - public_data_update_requests: reader.read_struct_array(PublicDataUpdateRequest::deserialize, [PublicDataUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]), - gas_used: reader.read_struct(Gas::deserialize), - }; - reader.finish(); - item - } + fn deserialize(fields: [Field; COMBINED_ACCUMULATED_DATA_LENGTH]) -> CombinedAccumulatedData { + let mut reader = Reader::new(fields); + + let item = CombinedAccumulatedData { + note_hashes: reader.read_array([0; MAX_NOTE_HASHES_PER_TX]), + nullifiers: reader.read_array([0; MAX_NULLIFIERS_PER_TX]), + l2_to_l1_msgs: reader.read_struct_array( + ScopedL2ToL1Message::deserialize, + [ScopedL2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_TX] + ), + note_encrypted_logs_hashes: reader.read_struct_array( + LogHash::deserialize, + [LogHash::empty(); MAX_NOTE_ENCRYPTED_LOGS_PER_TX] + ), + encrypted_logs_hashes: reader.read_struct_array( + ScopedLogHash::deserialize, + [ScopedLogHash::empty(); MAX_ENCRYPTED_LOGS_PER_TX] + ), + unencrypted_logs_hashes: reader.read_struct_array( + ScopedLogHash::deserialize, + [ScopedLogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_TX] + ), + note_encrypted_log_preimages_length: reader.read(), + encrypted_log_preimages_length: reader.read(), + unencrypted_log_preimages_length: reader.read(), + public_data_update_requests: reader.read_struct_array( + PublicDataUpdateRequest::deserialize, + [PublicDataUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX] + ), + gas_used: reader.read_struct(Gas::deserialize) + }; + reader.finish(); + item + } } impl Eq for CombinedAccumulatedData { - fn eq(self, other: Self) -> bool { - (self.note_hashes == other.note_hashes) & - (self.nullifiers == other.nullifiers) & - (self.l2_to_l1_msgs == other.l2_to_l1_msgs) & - (self.note_encrypted_logs_hashes == other.note_encrypted_logs_hashes) & - (self.encrypted_logs_hashes == other.encrypted_logs_hashes) & - (self.unencrypted_logs_hashes == other.unencrypted_logs_hashes) & - (self.note_encrypted_log_preimages_length == other.note_encrypted_log_preimages_length) & - (self.encrypted_log_preimages_length == other.encrypted_log_preimages_length) & - (self.unencrypted_log_preimages_length == other.unencrypted_log_preimages_length) & - (self.public_data_update_requests == other.public_data_update_requests) & - (self.gas_used == other.gas_used) - } + fn eq(self, other: Self) -> bool { + (self.note_hashes == other.note_hashes) + & (self.nullifiers == other.nullifiers) + & (self.l2_to_l1_msgs == other.l2_to_l1_msgs) + & (self.note_encrypted_logs_hashes == other.note_encrypted_logs_hashes) + & (self.encrypted_logs_hashes == other.encrypted_logs_hashes) + & (self.unencrypted_logs_hashes == other.unencrypted_logs_hashes) + & (self.note_encrypted_log_preimages_length + == other.note_encrypted_log_preimages_length) + & (self.encrypted_log_preimages_length + == other.encrypted_log_preimages_length) + & (self.unencrypted_log_preimages_length + == other.unencrypted_log_preimages_length) + & (self.public_data_update_requests + == other.public_data_update_requests) + & (self.gas_used == other.gas_used) + } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data.nr index ab74f51e033..bfa47b82795 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data.nr @@ -27,77 +27,101 @@ struct PrivateAccumulatedData { } impl Serialize for PrivateAccumulatedData { - fn serialize(self) -> [Field; PRIVATE_ACCUMULATED_DATA_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); + fn serialize(self) -> [Field; PRIVATE_ACCUMULATED_DATA_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); - for i in 0..MAX_NOTE_HASHES_PER_TX { - fields.extend_from_array(self.note_hashes[i].serialize()); - } + for i in 0..MAX_NOTE_HASHES_PER_TX { + fields.extend_from_array(self.note_hashes[i].serialize()); + } - for i in 0..MAX_NULLIFIERS_PER_TX { - fields.extend_from_array(self.nullifiers[i].serialize()); - } + for i in 0..MAX_NULLIFIERS_PER_TX { + fields.extend_from_array(self.nullifiers[i].serialize()); + } - for i in 0..MAX_L2_TO_L1_MSGS_PER_TX { - fields.extend_from_array(self.l2_to_l1_msgs[i].serialize()); - } + for i in 0..MAX_L2_TO_L1_MSGS_PER_TX { + fields.extend_from_array(self.l2_to_l1_msgs[i].serialize()); + } - for i in 0..MAX_NOTE_ENCRYPTED_LOGS_PER_TX { - fields.extend_from_array(self.note_encrypted_logs_hashes[i].serialize()); - } + for i in 0..MAX_NOTE_ENCRYPTED_LOGS_PER_TX { + fields.extend_from_array(self.note_encrypted_logs_hashes[i].serialize()); + } - for i in 0..MAX_ENCRYPTED_LOGS_PER_TX { - fields.extend_from_array(self.encrypted_logs_hashes[i].serialize()); - } + for i in 0..MAX_ENCRYPTED_LOGS_PER_TX { + fields.extend_from_array(self.encrypted_logs_hashes[i].serialize()); + } - for i in 0..MAX_UNENCRYPTED_LOGS_PER_TX { - fields.extend_from_array(self.unencrypted_logs_hashes[i].serialize()); - } + for i in 0..MAX_UNENCRYPTED_LOGS_PER_TX { + fields.extend_from_array(self.unencrypted_logs_hashes[i].serialize()); + } - for i in 0..MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX { - fields.extend_from_array(self.public_call_requests[i].serialize()); - } + for i in 0..MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX { + fields.extend_from_array(self.public_call_requests[i].serialize()); + } - for i in 0..MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX { - fields.extend_from_array(self.private_call_stack[i].serialize()); - } + for i in 0..MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX { + fields.extend_from_array(self.private_call_stack[i].serialize()); + } - assert_eq(fields.len(), PRIVATE_ACCUMULATED_DATA_LENGTH); + assert_eq(fields.len(), PRIVATE_ACCUMULATED_DATA_LENGTH); - fields.storage - } + fields.storage + } } impl Deserialize for PrivateAccumulatedData { - fn deserialize(fields: [Field; PRIVATE_ACCUMULATED_DATA_LENGTH]) -> PrivateAccumulatedData { - let mut reader = Reader::new(fields); - - let item = PrivateAccumulatedData { - note_hashes: reader.read_struct_array(ScopedNoteHash::deserialize, [ScopedNoteHash::empty(); MAX_NOTE_HASHES_PER_TX]), - nullifiers: reader.read_struct_array(ScopedNullifier::deserialize, [ScopedNullifier::empty(); MAX_NULLIFIERS_PER_TX]), - l2_to_l1_msgs: reader.read_struct_array(ScopedL2ToL1Message::deserialize, [ScopedL2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_TX]), - note_encrypted_logs_hashes: reader.read_struct_array(NoteLogHash::deserialize, [NoteLogHash::empty(); MAX_NOTE_ENCRYPTED_LOGS_PER_TX]), - encrypted_logs_hashes: reader.read_struct_array(ScopedEncryptedLogHash::deserialize, [ScopedEncryptedLogHash::empty(); MAX_ENCRYPTED_LOGS_PER_TX]), - unencrypted_logs_hashes: reader.read_struct_array(ScopedLogHash::deserialize, [ScopedLogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_TX]), - public_call_requests: reader.read_struct_array(PublicCallRequest::deserialize, [PublicCallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX]), - private_call_stack: reader.read_struct_array(PrivateCallRequest::deserialize, [PrivateCallRequest::empty(); MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX]), - }; - reader.finish(); - item - } + fn deserialize(fields: [Field; PRIVATE_ACCUMULATED_DATA_LENGTH]) -> PrivateAccumulatedData { + let mut reader = Reader::new(fields); + + let item = PrivateAccumulatedData { + note_hashes: reader.read_struct_array( + ScopedNoteHash::deserialize, + [ScopedNoteHash::empty(); MAX_NOTE_HASHES_PER_TX] + ), + nullifiers: reader.read_struct_array( + ScopedNullifier::deserialize, + [ScopedNullifier::empty(); MAX_NULLIFIERS_PER_TX] + ), + l2_to_l1_msgs: reader.read_struct_array( + ScopedL2ToL1Message::deserialize, + [ScopedL2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_TX] + ), + note_encrypted_logs_hashes: reader.read_struct_array( + NoteLogHash::deserialize, + [NoteLogHash::empty(); MAX_NOTE_ENCRYPTED_LOGS_PER_TX] + ), + encrypted_logs_hashes: reader.read_struct_array( + ScopedEncryptedLogHash::deserialize, + [ScopedEncryptedLogHash::empty(); MAX_ENCRYPTED_LOGS_PER_TX] + ), + unencrypted_logs_hashes: reader.read_struct_array( + ScopedLogHash::deserialize, + [ScopedLogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_TX] + ), + public_call_requests: reader.read_struct_array( + PublicCallRequest::deserialize, + [PublicCallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX] + ), + private_call_stack: reader.read_struct_array( + PrivateCallRequest::deserialize, + [PrivateCallRequest::empty(); MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX] + ) + }; + reader.finish(); + item + } } impl Eq for PrivateAccumulatedData { - fn eq(self, other: Self) -> bool { - (self.note_hashes == other.note_hashes) & - (self.nullifiers == other.nullifiers) & - (self.l2_to_l1_msgs == other.l2_to_l1_msgs) & - (self.note_encrypted_logs_hashes == other.note_encrypted_logs_hashes) & - (self.encrypted_logs_hashes == other.encrypted_logs_hashes) & - (self.unencrypted_logs_hashes == other.unencrypted_logs_hashes) & - (self.public_call_requests == other.public_call_requests) & - (self.private_call_stack == other.private_call_stack) - } + fn eq(self, other: Self) -> bool { + (self.note_hashes == other.note_hashes) + & (self.nullifiers == other.nullifiers) + & (self.l2_to_l1_msgs == other.l2_to_l1_msgs) + & (self.note_encrypted_logs_hashes == other.note_encrypted_logs_hashes) + & (self.encrypted_logs_hashes == other.encrypted_logs_hashes) + & (self.unencrypted_logs_hashes == other.unencrypted_logs_hashes) + & (self.public_call_requests == other.public_call_requests) + & (self.private_call_stack == other.private_call_stack) + } } impl Empty for PrivateAccumulatedData { @@ -110,7 +134,7 @@ impl Empty for PrivateAccumulatedData { encrypted_logs_hashes: [ScopedEncryptedLogHash::empty(); MAX_ENCRYPTED_LOGS_PER_TX], unencrypted_logs_hashes: [ScopedLogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_TX], public_call_requests: [PublicCallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX], - private_call_stack: [PrivateCallRequest::empty(); MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX], + private_call_stack: [PrivateCallRequest::empty(); MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX] } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr index 7b02b2c5c28..7f8441bd464 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data_builder.nr @@ -52,7 +52,7 @@ impl Empty for PrivateAccumulatedDataBuilder { encrypted_logs_hashes: BoundedVec::new(), unencrypted_logs_hashes: BoundedVec::new(), public_call_requests: BoundedVec::new(), - private_call_stack: BoundedVec::new(), + private_call_stack: BoundedVec::new() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr index 732571f90bb..d461fba114c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr @@ -39,7 +39,7 @@ impl Empty for PublicAccumulatedData { unencrypted_logs_hashes: [ScopedLogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_TX], public_data_update_requests: [PublicDataUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], public_call_stack: [PublicCallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX], - gas_used: Gas::empty(), + gas_used: Gas::empty() } } } @@ -49,35 +49,35 @@ impl Serialize for PublicAccumulatedData { let mut fields: BoundedVec = BoundedVec::new(); for i in 0..MAX_NOTE_HASHES_PER_TX { - fields.extend_from_array(self.note_hashes[i].serialize()); + fields.extend_from_array(self.note_hashes[i].serialize()); } for i in 0..MAX_NULLIFIERS_PER_TX { - fields.extend_from_array(self.nullifiers[i].serialize()); + fields.extend_from_array(self.nullifiers[i].serialize()); } for i in 0..MAX_L2_TO_L1_MSGS_PER_TX { - fields.extend_from_array(self.l2_to_l1_msgs[i].serialize()); + fields.extend_from_array(self.l2_to_l1_msgs[i].serialize()); } for i in 0..MAX_NOTE_ENCRYPTED_LOGS_PER_TX { - fields.extend_from_array(self.note_encrypted_logs_hashes[i].serialize()); + fields.extend_from_array(self.note_encrypted_logs_hashes[i].serialize()); } for i in 0..MAX_ENCRYPTED_LOGS_PER_TX { - fields.extend_from_array(self.encrypted_logs_hashes[i].serialize()); + fields.extend_from_array(self.encrypted_logs_hashes[i].serialize()); } for i in 0..MAX_UNENCRYPTED_LOGS_PER_TX { - fields.extend_from_array(self.unencrypted_logs_hashes[i].serialize()); + fields.extend_from_array(self.unencrypted_logs_hashes[i].serialize()); } for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX { - fields.extend_from_array(self.public_data_update_requests[i].serialize()); + fields.extend_from_array(self.public_data_update_requests[i].serialize()); } for i in 0..MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX { - fields.extend_from_array(self.public_call_stack[i].serialize()); + fields.extend_from_array(self.public_call_stack[i].serialize()); } fields.extend_from_array(self.gas_used.serialize()); @@ -89,37 +89,62 @@ impl Serialize for PublicAccumulatedData { } impl Deserialize for PublicAccumulatedData { - fn deserialize(fields: [Field; PUBLIC_ACCUMULATED_DATA_LENGTH]) -> PublicAccumulatedData { - let mut reader = Reader::new(fields); - - let item = PublicAccumulatedData { - note_hashes: reader.read_struct_array(ScopedNoteHash::deserialize, [ScopedNoteHash::empty(); MAX_NOTE_HASHES_PER_TX]), - nullifiers: reader.read_struct_array(Nullifier::deserialize, [Nullifier::empty(); MAX_NULLIFIERS_PER_TX]), - l2_to_l1_msgs: reader.read_struct_array(ScopedL2ToL1Message::deserialize, [ScopedL2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_TX]), - note_encrypted_logs_hashes: reader.read_struct_array(LogHash::deserialize, [LogHash::empty(); MAX_NOTE_ENCRYPTED_LOGS_PER_TX]), - encrypted_logs_hashes: reader.read_struct_array(ScopedLogHash::deserialize, [ScopedLogHash::empty(); MAX_ENCRYPTED_LOGS_PER_TX]), - unencrypted_logs_hashes: reader.read_struct_array(ScopedLogHash::deserialize, [ScopedLogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_TX]), - public_data_update_requests: reader.read_struct_array(PublicDataUpdateRequest::deserialize, [PublicDataUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]), - public_call_stack: reader.read_struct_array(PublicCallRequest::deserialize, [PublicCallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX]), - gas_used: reader.read_struct(Gas::deserialize), - }; - reader.finish(); - item - } + fn deserialize(fields: [Field; PUBLIC_ACCUMULATED_DATA_LENGTH]) -> PublicAccumulatedData { + let mut reader = Reader::new(fields); + + let item = PublicAccumulatedData { + note_hashes: reader.read_struct_array( + ScopedNoteHash::deserialize, + [ScopedNoteHash::empty(); MAX_NOTE_HASHES_PER_TX] + ), + nullifiers: reader.read_struct_array( + Nullifier::deserialize, + [Nullifier::empty(); MAX_NULLIFIERS_PER_TX] + ), + l2_to_l1_msgs: reader.read_struct_array( + ScopedL2ToL1Message::deserialize, + [ScopedL2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_TX] + ), + note_encrypted_logs_hashes: reader.read_struct_array( + LogHash::deserialize, + [LogHash::empty(); MAX_NOTE_ENCRYPTED_LOGS_PER_TX] + ), + encrypted_logs_hashes: reader.read_struct_array( + ScopedLogHash::deserialize, + [ScopedLogHash::empty(); MAX_ENCRYPTED_LOGS_PER_TX] + ), + unencrypted_logs_hashes: reader.read_struct_array( + ScopedLogHash::deserialize, + [ScopedLogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_TX] + ), + public_data_update_requests: reader.read_struct_array( + PublicDataUpdateRequest::deserialize, + [PublicDataUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX] + ), + public_call_stack: reader.read_struct_array( + PublicCallRequest::deserialize, + [PublicCallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX] + ), + gas_used: reader.read_struct(Gas::deserialize) + }; + reader.finish(); + item + } } impl Eq for PublicAccumulatedData { - fn eq(self, other: Self) -> bool { - (self.note_hashes == other.note_hashes) & - (self.nullifiers == other.nullifiers) & - (self.l2_to_l1_msgs == other.l2_to_l1_msgs) & - (self.note_encrypted_logs_hashes == other.note_encrypted_logs_hashes) & - (self.encrypted_logs_hashes == other.encrypted_logs_hashes) & - (self.unencrypted_logs_hashes == other.unencrypted_logs_hashes) & - (self.public_data_update_requests == other.public_data_update_requests) & - (self.public_call_stack == other.public_call_stack) & - (self.gas_used == other.gas_used) - } + fn eq(self, other: Self) -> bool { + (self.note_hashes == other.note_hashes) + & (self.nullifiers == other.nullifiers) + & (self.l2_to_l1_msgs == other.l2_to_l1_msgs) + & (self.note_encrypted_logs_hashes == other.note_encrypted_logs_hashes) + & (self.encrypted_logs_hashes == other.encrypted_logs_hashes) + & (self.unencrypted_logs_hashes == other.unencrypted_logs_hashes) + & (self.public_data_update_requests + == other.public_data_update_requests) + & (self.public_call_stack == other.public_call_stack) + & (self.gas_used == other.gas_used) + } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr index 2488befe838..b1f768852a1 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data_builder.nr @@ -70,7 +70,7 @@ impl Empty for PublicAccumulatedDataBuilder { unencrypted_logs_hashes: BoundedVec::new(), public_data_update_requests: BoundedVec::new(), public_call_stack: BoundedVec::new(), - gas_used: Gas::empty(), + gas_used: Gas::empty() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr index 05dac0f9af0..a4527980e83 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr @@ -21,7 +21,8 @@ impl AppendOnlyTreeSnapshot { } impl Eq for AppendOnlyTreeSnapshot { - fn eq(self, other : AppendOnlyTreeSnapshot) -> bool { - (self.root == other.root) & (self.next_available_leaf_index == other.next_available_leaf_index) + fn eq(self, other: AppendOnlyTreeSnapshot) -> bool { + (self.root == other.root) + & (self.next_available_leaf_index == other.next_available_leaf_index) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr index 698c4b116b4..269a8cf15cb 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr @@ -15,11 +15,11 @@ struct CallContext { impl Eq for CallContext { fn eq(self, other: CallContext) -> bool { - (self.msg_sender == other.msg_sender) & - (self.storage_contract_address == other.storage_contract_address) & - (self.function_selector == other.function_selector) & - (self.is_delegate_call == other.is_delegate_call) & - (self.is_static_call == other.is_static_call) + (self.msg_sender == other.msg_sender) + & (self.storage_contract_address == other.storage_contract_address) + & (self.function_selector == other.function_selector) + & (self.is_delegate_call == other.is_delegate_call) + & (self.is_static_call == other.is_static_call) } } @@ -32,7 +32,7 @@ impl Serialize for CallContext { serialized.push(self.function_selector.to_field()); serialized.push(self.is_delegate_call as Field); serialized.push(self.is_static_call as Field); - + serialized.storage } } @@ -45,7 +45,7 @@ impl Deserialize for CallContext { storage_contract_address: AztecAddress::from_field(reader.read()), function_selector: FunctionSelector::from_field(reader.read()), is_delegate_call: reader.read() as bool, - is_static_call: reader.read() as bool, + is_static_call: reader.read() as bool } } } @@ -57,7 +57,7 @@ impl Empty for CallContext { storage_contract_address: AztecAddress::empty(), function_selector: FunctionSelector::empty(), is_delegate_call: false, - is_static_call: false, + is_static_call: false } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr index bf4620385c0..8d0f074c353 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr @@ -41,42 +41,42 @@ impl Empty for CombinedConstantData { } impl Serialize for CombinedConstantData { - fn serialize(self) -> [Field; COMBINED_CONSTANT_DATA_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); + fn serialize(self) -> [Field; COMBINED_CONSTANT_DATA_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); - fields.extend_from_array(self.historical_header.serialize()); - fields.extend_from_array(self.tx_context.serialize()); - fields.push(self.vk_tree_root); - fields.extend_from_array(self.global_variables.serialize()); + fields.extend_from_array(self.historical_header.serialize()); + fields.extend_from_array(self.tx_context.serialize()); + fields.push(self.vk_tree_root); + fields.extend_from_array(self.global_variables.serialize()); - assert_eq(fields.len(), COMBINED_CONSTANT_DATA_LENGTH); + assert_eq(fields.len(), COMBINED_CONSTANT_DATA_LENGTH); - fields.storage - } + fields.storage + } } impl Deserialize for CombinedConstantData { - fn deserialize(fields: [Field; COMBINED_CONSTANT_DATA_LENGTH]) -> CombinedConstantData { - let mut reader = Reader::new(fields); + fn deserialize(fields: [Field; COMBINED_CONSTANT_DATA_LENGTH]) -> CombinedConstantData { + let mut reader = Reader::new(fields); - let item = CombinedConstantData { - historical_header: reader.read_struct(Header::deserialize), - tx_context: reader.read_struct(TxContext::deserialize), - vk_tree_root: reader.read(), - global_variables: reader.read_struct(GlobalVariables::deserialize), - }; - reader.finish(); - item - } + let item = CombinedConstantData { + historical_header: reader.read_struct(Header::deserialize), + tx_context: reader.read_struct(TxContext::deserialize), + vk_tree_root: reader.read(), + global_variables: reader.read_struct(GlobalVariables::deserialize) + }; + reader.finish(); + item + } } impl Eq for CombinedConstantData { - fn eq(self, other: Self) -> bool { - (self.historical_header.eq(other.historical_header)) & - (self.tx_context.eq(other.tx_context)) & - (self.vk_tree_root.eq(other.vk_tree_root)) & - (self.global_variables.eq(other.global_variables)) - } + fn eq(self, other: Self) -> bool { + (self.historical_header.eq(other.historical_header)) + & (self.tx_context.eq(other.tx_context)) + & (self.vk_tree_root.eq(other.vk_tree_root)) + & (self.global_variables.eq(other.global_variables)) + } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/contract_class_function_leaf_preimage.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/contract_class_function_leaf_preimage.nr index aa6e4b05864..2e2097bc9be 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/contract_class_function_leaf_preimage.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/contract_class_function_leaf_preimage.nr @@ -10,9 +10,12 @@ struct ContractClassFunctionLeafPreimage { impl Hash for ContractClassFunctionLeafPreimage { fn hash(self) -> Field { - poseidon2_hash_with_separator([ + poseidon2_hash_with_separator( + [ self.selector.to_field(), - self.vk_hash, - ], GENERATOR_INDEX__FUNCTION_LEAF) + self.vk_hash + ], + GENERATOR_INDEX__FUNCTION_LEAF + ) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/event_selector.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/event_selector.nr index 063e186006a..25a41ad1b35 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/event_selector.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/event_selector.nr @@ -22,9 +22,7 @@ impl Serialize<1> for EventSelector { impl Deserialize<1> for EventSelector { fn deserialize(fields: [Field; 1]) -> Self { - Self { - inner: fields[0] as u32 - } + Self { inner: fields[0] as u32 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr index fa3ff5b485a..a32c9fc9907 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_data.nr @@ -10,8 +10,7 @@ struct FunctionData { impl Eq for FunctionData { fn eq(self, other: Self) -> bool { - self.selector.eq(other.selector) & - (self.is_private == other.is_private) + self.selector.eq(other.selector) & (self.is_private == other.is_private) } } @@ -22,28 +21,21 @@ impl Serialize for FunctionData { fn serialize(self) -> [Field; FUNCTION_DATA_LENGTH] { [ self.selector.to_field(), - self.is_private as Field, + self.is_private as Field ] } } impl Deserialize for FunctionData { fn deserialize(serialized: [Field; FUNCTION_DATA_LENGTH]) -> Self { - Self { - selector: FunctionSelector::from_field(serialized[0]), - is_private: serialized[1] as bool, - } + Self { selector: FunctionSelector::from_field(serialized[0]), is_private: serialized[1] as bool } } } impl Empty for FunctionData { fn empty() -> Self { - FunctionData { - selector: FunctionSelector::empty(), - is_private: false - } + FunctionData { selector: FunctionSelector::empty(), is_private: false } } - } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr index 9e3ba609118..80075b751bd 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/function_selector.nr @@ -22,9 +22,7 @@ impl Serialize<1> for FunctionSelector { impl Deserialize<1> for FunctionSelector { fn deserialize(fields: [Field; 1]) -> Self { - Self { - inner: fields[0] as u32 - } + Self { inner: fields[0] as u32 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas.nr index 5969d30fbf4..d0622d27cde 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas.nr @@ -56,7 +56,7 @@ impl Deserialize for Gas { } impl Eq for Gas { - fn eq(self, other : Gas) -> bool { + fn eq(self, other: Gas) -> bool { (self.da_gas == other.da_gas) & (self.l2_gas == other.l2_gas) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_fees.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_fees.nr index 90a7e1fb426..f87ca6f31e2 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_fees.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_fees.nr @@ -32,8 +32,9 @@ impl Deserialize for GasFees { } impl Eq for GasFees { - fn eq(self, other : GasFees) -> bool { - (self.fee_per_da_gas == other.fee_per_da_gas) & (self.fee_per_l2_gas == other.fee_per_l2_gas) + fn eq(self, other: GasFees) -> bool { + (self.fee_per_da_gas == other.fee_per_da_gas) + & (self.fee_per_l2_gas == other.fee_per_l2_gas) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_settings.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_settings.nr index 11126ce25e3..ec380971601 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_settings.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_settings.nr @@ -36,15 +36,16 @@ impl GasSettings { impl Eq for GasSettings { fn eq(self, other: Self) -> bool { - (self.gas_limits == other.gas_limits) & (self.teardown_gas_limits == other.teardown_gas_limits) & (self.max_fees_per_gas == other.max_fees_per_gas) & (self.inclusion_fee == other.inclusion_fee) + (self.gas_limits == other.gas_limits) + & (self.teardown_gas_limits == other.teardown_gas_limits) + & (self.max_fees_per_gas == other.max_fees_per_gas) + & (self.inclusion_fee == other.inclusion_fee) } } impl Empty for GasSettings { fn empty() -> Self { - GasSettings::new( - Gas::empty(), Gas::empty(), GasFees::empty(), 0 - ) + GasSettings::new(Gas::empty(), Gas::empty(), GasFees::empty(), 0) } } @@ -64,7 +65,12 @@ impl Serialize for GasSettings { impl Deserialize for GasSettings { fn deserialize(serialized: [Field; GAS_SETTINGS_LENGTH]) -> GasSettings { let mut reader = Reader::new(serialized); - GasSettings::new(reader.read_struct(Gas::deserialize), reader.read_struct(Gas::deserialize), reader.read_struct(GasFees::deserialize), reader.read()) + GasSettings::new( + reader.read_struct(Gas::deserialize), + reader.read_struct(Gas::deserialize), + reader.read_struct(GasFees::deserialize), + reader.read() + ) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr index 05b59ff38a1..7dde548565e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr @@ -63,15 +63,15 @@ impl Deserialize for GlobalVariables { } impl Eq for GlobalVariables { - fn eq(self, other : GlobalVariables) -> bool { - (self.chain_id == other.chain_id) & - (self.version == other.version) & - (self.block_number == other.block_number) & - (self.slot_number == other.slot_number) & - (self.timestamp == other.timestamp) & - (self.coinbase == other.coinbase) & - (self.fee_recipient == other.fee_recipient) & - (self.gas_fees == other.gas_fees) + fn eq(self, other: GlobalVariables) -> bool { + (self.chain_id == other.chain_id) + & (self.version == other.version) + & (self.block_number == other.block_number) + & (self.slot_number == other.slot_number) + & (self.timestamp == other.timestamp) + & (self.coinbase == other.coinbase) + & (self.fee_recipient == other.fee_recipient) + & (self.gas_fees == other.gas_fees) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/kernel_circuit_public_inputs.nr index 71b37b8dffa..ffa2bc7ab45 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/kernel_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/kernel_circuit_public_inputs.nr @@ -38,48 +38,48 @@ impl Empty for KernelCircuitPublicInputs { } impl Eq for KernelCircuitPublicInputs { - fn eq(self, other: Self) -> bool { - (self.rollup_validation_requests.eq(other.rollup_validation_requests)) & - (self.end.eq(other.end)) & - (self.constants.eq(other.constants)) & - (self.start_state.eq(other.start_state)) & - (self.revert_code == other.revert_code) & - (self.fee_payer.eq(other.fee_payer)) - } + fn eq(self, other: Self) -> bool { + (self.rollup_validation_requests.eq(other.rollup_validation_requests)) + & (self.end.eq(other.end)) + & (self.constants.eq(other.constants)) + & (self.start_state.eq(other.start_state)) + & (self.revert_code == other.revert_code) + & (self.fee_payer.eq(other.fee_payer)) + } } impl Serialize for KernelCircuitPublicInputs { - fn serialize(self) -> [Field; KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); + fn serialize(self) -> [Field; KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); - fields.extend_from_array(self.rollup_validation_requests.serialize()); - fields.extend_from_array(self.end.serialize()); - fields.extend_from_array(self.constants.serialize()); - fields.extend_from_array(self.start_state.serialize()); - fields.push(self.revert_code as Field); - fields.extend_from_array(self.fee_payer.serialize()); + fields.extend_from_array(self.rollup_validation_requests.serialize()); + fields.extend_from_array(self.end.serialize()); + fields.extend_from_array(self.constants.serialize()); + fields.extend_from_array(self.start_state.serialize()); + fields.push(self.revert_code as Field); + fields.extend_from_array(self.fee_payer.serialize()); - assert_eq(fields.len(), KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH); + assert_eq(fields.len(), KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH); - fields.storage - } + fields.storage + } } impl Deserialize for KernelCircuitPublicInputs { - fn deserialize(fields: [Field; KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH]) -> KernelCircuitPublicInputs { - let mut reader = Reader::new(fields); - let item = Self { - rollup_validation_requests: reader.read_struct(RollupValidationRequests::deserialize), - end: reader.read_struct(CombinedAccumulatedData::deserialize), - constants: reader.read_struct(CombinedConstantData::deserialize), - start_state: reader.read_struct(PartialStateReference::deserialize), - revert_code: reader.read() as u8, - fee_payer: reader.read_struct(AztecAddress::deserialize), - }; + fn deserialize(fields: [Field; KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH]) -> KernelCircuitPublicInputs { + let mut reader = Reader::new(fields); + let item = Self { + rollup_validation_requests: reader.read_struct(RollupValidationRequests::deserialize), + end: reader.read_struct(CombinedAccumulatedData::deserialize), + constants: reader.read_struct(CombinedConstantData::deserialize), + start_state: reader.read_struct(PartialStateReference::deserialize), + revert_code: reader.read() as u8, + fee_payer: reader.read_struct(AztecAddress::deserialize) + }; - reader.finish(); - item - } + reader.finish(); + item + } } mod tests { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_circuit_public_inputs.nr index f02854b6815..ff93719dd87 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_circuit_public_inputs.nr @@ -57,17 +57,19 @@ impl PrivateKernelCircuitPublicInputsArrayLengths { impl Eq for PrivateKernelCircuitPublicInputsArrayLengths { fn eq(self, other: Self) -> bool { - (self.note_hash_read_requests == other.note_hash_read_requests) & - (self.nullifier_read_requests == other.nullifier_read_requests) & - (self.scoped_key_validation_requests_and_generators == other.scoped_key_validation_requests_and_generators) & - (self.note_hashes == other.note_hashes) & - (self.nullifiers == other.nullifiers) & - (self.l2_to_l1_msgs == other.l2_to_l1_msgs) & - (self.note_encrypted_logs_hashes == other.note_encrypted_logs_hashes) & - (self.encrypted_logs_hashes == other.encrypted_logs_hashes) & - (self.unencrypted_logs_hashes == other.unencrypted_logs_hashes) & - (self.public_call_requests== other.public_call_requests) & - (self.private_call_stack == other.private_call_stack) + (self.note_hash_read_requests == other.note_hash_read_requests) + & (self.nullifier_read_requests == other.nullifier_read_requests) + & (self.scoped_key_validation_requests_and_generators + == other.scoped_key_validation_requests_and_generators) + & (self.note_hashes == other.note_hashes) + & (self.nullifiers == other.nullifiers) + & (self.l2_to_l1_msgs == other.l2_to_l1_msgs) + & (self.note_encrypted_logs_hashes == other.note_encrypted_logs_hashes) + & (self.encrypted_logs_hashes == other.encrypted_logs_hashes) + & (self.unencrypted_logs_hashes + == other.unencrypted_logs_hashes) + & (self.public_call_requests == other.public_call_requests) + & (self.private_call_stack == other.private_call_stack) } } @@ -81,60 +83,60 @@ struct PrivateKernelCircuitPublicInputs { } impl Serialize for PrivateKernelCircuitPublicInputs { - fn serialize(self) -> [Field; PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); + fn serialize(self) -> [Field; PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); - fields.push(self.min_revertible_side_effect_counter as Field); - fields.extend_from_array(self.validation_requests.serialize()); - fields.extend_from_array(self.end.serialize()); - fields.extend_from_array(self.constants.serialize()); - fields.extend_from_array(self.public_teardown_call_request.serialize()); - fields.extend_from_array(self.fee_payer.serialize()); + fields.push(self.min_revertible_side_effect_counter as Field); + fields.extend_from_array(self.validation_requests.serialize()); + fields.extend_from_array(self.end.serialize()); + fields.extend_from_array(self.constants.serialize()); + fields.extend_from_array(self.public_teardown_call_request.serialize()); + fields.extend_from_array(self.fee_payer.serialize()); - assert_eq(fields.len(), PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH); + assert_eq(fields.len(), PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH); - fields.storage - } + fields.storage + } } impl Deserialize for PrivateKernelCircuitPublicInputs { - fn deserialize(fields: [Field; PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH]) -> PrivateKernelCircuitPublicInputs { - let mut reader = Reader::new(fields); - let item = Self { - min_revertible_side_effect_counter: reader.read() as u32, - validation_requests: reader.read_struct(PrivateValidationRequests::deserialize), - end: reader.read_struct(PrivateAccumulatedData::deserialize), - constants: reader.read_struct(CombinedConstantData::deserialize), - public_teardown_call_request: reader.read_struct(PublicCallRequest::deserialize), - fee_payer: reader.read_struct(AztecAddress::deserialize), - }; + fn deserialize(fields: [Field; PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH]) -> PrivateKernelCircuitPublicInputs { + let mut reader = Reader::new(fields); + let item = Self { + min_revertible_side_effect_counter: reader.read() as u32, + validation_requests: reader.read_struct(PrivateValidationRequests::deserialize), + end: reader.read_struct(PrivateAccumulatedData::deserialize), + constants: reader.read_struct(CombinedConstantData::deserialize), + public_teardown_call_request: reader.read_struct(PublicCallRequest::deserialize), + fee_payer: reader.read_struct(AztecAddress::deserialize) + }; - reader.finish(); - item - } + reader.finish(); + item + } } impl Eq for PrivateKernelCircuitPublicInputs { - fn eq(self, other: Self) -> bool { - (self.min_revertible_side_effect_counter == other.min_revertible_side_effect_counter) & - (self.validation_requests.eq(other.validation_requests)) & - (self.end.eq(other.end)) & - (self.constants.eq(other.constants)) & - (self.public_teardown_call_request.eq(other.public_teardown_call_request)) - } + fn eq(self, other: Self) -> bool { + (self.min_revertible_side_effect_counter == other.min_revertible_side_effect_counter) + & (self.validation_requests.eq(other.validation_requests)) + & (self.end.eq(other.end)) + & (self.constants.eq(other.constants)) + & (self.public_teardown_call_request.eq(other.public_teardown_call_request)) + } } impl Empty for PrivateKernelCircuitPublicInputs { - fn empty() -> Self { - Self { - min_revertible_side_effect_counter: 0, - validation_requests: PrivateValidationRequests::empty(), - end: PrivateAccumulatedData::empty(), - constants: CombinedConstantData::empty(), - public_teardown_call_request: PublicCallRequest::empty(), - fee_payer: AztecAddress::empty() + fn empty() -> Self { + Self { + min_revertible_side_effect_counter: 0, + validation_requests: PrivateValidationRequests::empty(), + end: PrivateAccumulatedData::empty(), + constants: CombinedConstantData::empty(), + public_teardown_call_request: PublicCallRequest::empty(), + fee_payer: AztecAddress::empty() + } } - } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr index 8bc2692a719..0f24e976331 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr @@ -33,54 +33,57 @@ impl Empty for PublicKernelCircuitPublicInputs { } impl Serialize for PublicKernelCircuitPublicInputs { - fn serialize(self) -> [Field; PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); + fn serialize(self) -> [Field; PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); - fields.extend_from_array(self.validation_requests.serialize()); - fields.extend_from_array(self.end_non_revertible.serialize()); - fields.extend_from_array(self.end.serialize()); - fields.extend_from_array(self.constants.serialize()); - fields.push(self.revert_code as Field); + fields.extend_from_array(self.validation_requests.serialize()); + fields.extend_from_array(self.end_non_revertible.serialize()); + fields.extend_from_array(self.end.serialize()); + fields.extend_from_array(self.constants.serialize()); + fields.push(self.revert_code as Field); - for i in 0..MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX { - fields.extend_from_array(self.public_teardown_call_stack[i].serialize()); - } + for i in 0..MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX { + fields.extend_from_array(self.public_teardown_call_stack[i].serialize()); + } - fields.extend_from_array(self.fee_payer.serialize()); + fields.extend_from_array(self.fee_payer.serialize()); - assert_eq(fields.len(), PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH); + assert_eq(fields.len(), PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH); - fields.storage - } + fields.storage + } } impl Deserialize for PublicKernelCircuitPublicInputs { - fn deserialize(fields: [Field; PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH]) -> PublicKernelCircuitPublicInputs { - let mut reader = Reader::new(fields); + fn deserialize(fields: [Field; PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH]) -> PublicKernelCircuitPublicInputs { + let mut reader = Reader::new(fields); - let item = PublicKernelCircuitPublicInputs { - validation_requests: reader.read_struct(PublicValidationRequests::deserialize), - end_non_revertible: reader.read_struct(PublicAccumulatedData::deserialize), - end: reader.read_struct(PublicAccumulatedData::deserialize), - constants: reader.read_struct(CombinedConstantData::deserialize), - revert_code: reader.read() as u8, - public_teardown_call_stack: reader.read_struct_array(PublicCallRequest::deserialize, [PublicCallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX]), - fee_payer: reader.read_struct(AztecAddress::deserialize), - }; - reader.finish(); - item - } + let item = PublicKernelCircuitPublicInputs { + validation_requests: reader.read_struct(PublicValidationRequests::deserialize), + end_non_revertible: reader.read_struct(PublicAccumulatedData::deserialize), + end: reader.read_struct(PublicAccumulatedData::deserialize), + constants: reader.read_struct(CombinedConstantData::deserialize), + revert_code: reader.read() as u8, + public_teardown_call_stack: reader.read_struct_array( + PublicCallRequest::deserialize, + [PublicCallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX] + ), + fee_payer: reader.read_struct(AztecAddress::deserialize) + }; + reader.finish(); + item + } } impl Eq for PublicKernelCircuitPublicInputs { - fn eq(self, other: Self) -> bool { - (self.validation_requests == other.validation_requests) & - (self.end_non_revertible == other.end_non_revertible) & - (self.end == other.end) & - (self.constants == other.constants) & - (self.revert_code == other.revert_code) & - (self.public_teardown_call_stack == other.public_teardown_call_stack) - } + fn eq(self, other: Self) -> bool { + (self.validation_requests == other.validation_requests) + & (self.end_non_revertible == other.end_non_revertible) + & (self.end == other.end) + & (self.constants == other.constants) + & (self.revert_code == other.revert_code) + & (self.public_teardown_call_stack == other.public_teardown_call_stack) + } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr index eaf5f67baf5..0da08008e81 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs_builder.nr @@ -56,7 +56,7 @@ impl Empty for PublicKernelCircuitPublicInputsBuilder { constants: CombinedConstantData::empty(), revert_code: 0 as u8, public_teardown_call_stack: BoundedVec::new(), - fee_payer: AztecAddress::empty(), + fee_payer: AztecAddress::empty() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr index deb99b2911b..49390ded212 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr @@ -14,15 +14,10 @@ struct KernelData { } impl Verifiable for KernelData { - fn verify(self) { - let inputs = KernelCircuitPublicInputs::serialize(self.public_inputs); - std::verify_proof( - self.vk.key, - self.proof.fields, - inputs, - self.vk.hash - ); - } + fn verify(self) { + let inputs = KernelCircuitPublicInputs::serialize(self.public_inputs); + std::verify_proof(self.vk.key, self.proof.fields, inputs, self.vk.hash); + } } impl KernelData { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/log_hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/log_hash.nr index 9945e7b4fa7..034b99e8e15 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/log_hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/log_hash.nr @@ -32,17 +32,13 @@ impl Eq for LogHash { fn eq(self, other: LogHash) -> bool { (self.value == other.value) & (self.counter == other.counter) - & (self.length == other.length) + & (self.length == other.length) } } impl Empty for LogHash { fn empty() -> Self { - LogHash { - value: 0, - counter: 0, - length: 0, - } + LogHash { value: 0, counter: 0, length: 0 } } } @@ -54,11 +50,7 @@ impl Serialize for LogHash { impl Deserialize for LogHash { fn deserialize(values: [Field; LOG_HASH_LENGTH]) -> Self { - Self { - value: values[0], - counter: values[1] as u32, - length: values[2], - } + Self { value: values[0], counter: values[1] as u32, length: values[2] } } } @@ -99,23 +91,19 @@ impl OrderedValue for ScopedLogHash { impl Eq for ScopedLogHash { fn eq(self, other: ScopedLogHash) -> bool { - (self.log_hash == other.log_hash) - & (self.contract_address == other.contract_address) + (self.log_hash == other.log_hash) & (self.contract_address == other.contract_address) } } impl Empty for ScopedLogHash { fn empty() -> Self { - ScopedLogHash { - log_hash: LogHash::empty(), - contract_address: AztecAddress::empty(), - } + ScopedLogHash { log_hash: LogHash::empty(), contract_address: AztecAddress::empty() } } } impl Serialize for ScopedLogHash { fn serialize(self) -> [Field; SCOPED_LOG_HASH_LENGTH] { - array_concat(self.log_hash.serialize(), [self.contract_address.to_field()]) + array_concat(self.log_hash.serialize(), [self.contract_address.to_field()]) } } @@ -124,7 +112,7 @@ impl Deserialize for ScopedLogHash { let mut reader = Reader::new(values); let res = Self { log_hash: reader.read_struct(LogHash::deserialize), - contract_address: reader.read_struct(AztecAddress::deserialize), + contract_address: reader.read_struct(AztecAddress::deserialize) }; reader.finish(); res @@ -167,19 +155,14 @@ impl Eq for EncryptedLogHash { fn eq(self, other: EncryptedLogHash) -> bool { (self.value == other.value) & (self.counter == other.counter) - & (self.length == other.length) - & (self.randomness == other.randomness) + & (self.length == other.length) + & (self.randomness == other.randomness) } } impl Empty for EncryptedLogHash { fn empty() -> Self { - EncryptedLogHash { - value: 0, - counter: 0, - length: 0, - randomness: 0, - } + EncryptedLogHash { value: 0, counter: 0, length: 0, randomness: 0 } } } @@ -191,12 +174,7 @@ impl Serialize for EncryptedLogHash { impl Deserialize for EncryptedLogHash { fn deserialize(values: [Field; ENCRYPTED_LOG_HASH_LENGTH]) -> Self { - Self { - value: values[0], - counter: values[1] as u32, - length: values[2], - randomness: values[3], - } + Self { value: values[0], counter: values[1] as u32, length: values[2], randomness: values[3] } } } @@ -248,23 +226,19 @@ impl OrderedValue for ScopedEncryptedLogHash { impl Eq for ScopedEncryptedLogHash { fn eq(self, other: ScopedEncryptedLogHash) -> bool { - (self.log_hash == other.log_hash) - & (self.contract_address == other.contract_address) + (self.log_hash == other.log_hash) & (self.contract_address == other.contract_address) } } impl Empty for ScopedEncryptedLogHash { fn empty() -> Self { - ScopedEncryptedLogHash { - log_hash: EncryptedLogHash::empty(), - contract_address: AztecAddress::empty(), - } + ScopedEncryptedLogHash { log_hash: EncryptedLogHash::empty(), contract_address: AztecAddress::empty() } } } impl Serialize for ScopedEncryptedLogHash { fn serialize(self) -> [Field; SCOPED_ENCRYPTED_LOG_HASH_LENGTH] { - array_concat(self.log_hash.serialize(), [self.contract_address.to_field()]) + array_concat(self.log_hash.serialize(), [self.contract_address.to_field()]) } } @@ -273,7 +247,7 @@ impl Deserialize for ScopedEncryptedLogHash { let mut reader = Reader::new(values); let res = Self { log_hash: reader.read_struct(EncryptedLogHash::deserialize), - contract_address: reader.read_struct(AztecAddress::deserialize), + contract_address: reader.read_struct(AztecAddress::deserialize) }; reader.finish(); res @@ -315,19 +289,14 @@ impl Eq for NoteLogHash { fn eq(self, other: NoteLogHash) -> bool { (self.value == other.value) & (self.counter == other.counter) - & (self.length == other.length) - & (self.note_hash_counter == other.note_hash_counter) + & (self.length == other.length) + & (self.note_hash_counter == other.note_hash_counter) } } impl Empty for NoteLogHash { fn empty() -> Self { - NoteLogHash { - value: 0, - counter: 0, - length: 0, - note_hash_counter: 0, - } + NoteLogHash { value: 0, counter: 0, length: 0, note_hash_counter: 0 } } } @@ -339,11 +308,6 @@ impl Serialize for NoteLogHash { impl Deserialize for NoteLogHash { fn deserialize(values: [Field; NOTE_LOG_HASH_LENGTH]) -> Self { - Self { - value: values[0], - counter: values[1] as u32, - length: values[2], - note_hash_counter: values[3] as u32, - } + Self { value: values[0], counter: values[1] as u32, length: values[2], note_hash_counter: values[3] as u32 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/max_block_number.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/max_block_number.nr index 6aa7d5db67f..05aafd9b80c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/max_block_number.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/max_block_number.nr @@ -24,12 +24,7 @@ impl Serialize for MaxBlockNumber { impl Deserialize for MaxBlockNumber { fn deserialize(serialized: [Field; MAX_BLOCK_NUMBER_LENGTH]) -> MaxBlockNumber { - MaxBlockNumber { - _opt: Option { - _is_some: serialized[0] as bool, - _value: serialized[1] as u32, - } - } + MaxBlockNumber { _opt: Option { _is_some: serialized[0] as bool, _value: serialized[1] as u32 } } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash.nr index 2b0504a745b..ad3ed114ab6 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash.nr @@ -18,17 +18,13 @@ impl Ordered for NoteHash { impl Eq for NoteHash { fn eq(self, other: NoteHash) -> bool { - (self.value == other.value) - & (self.counter == other.counter) + (self.value == other.value) & (self.counter == other.counter) } } impl Empty for NoteHash { fn empty() -> Self { - NoteHash { - value: 0, - counter: 0, - } + NoteHash { value: 0, counter: 0 } } } @@ -40,10 +36,7 @@ impl Serialize for NoteHash { impl Deserialize for NoteHash { fn deserialize(values: [Field; NOTE_HASH_LENGTH]) -> Self { - Self { - value: values[0], - counter: values[1] as u32, - } + Self { value: values[0], counter: values[1] as u32 } } } @@ -84,23 +77,22 @@ impl OrderedValue for ScopedNoteHash { impl Eq for ScopedNoteHash { fn eq(self, other: ScopedNoteHash) -> bool { - (self.note_hash == other.note_hash) - & (self.contract_address == other.contract_address) + (self.note_hash == other.note_hash) & (self.contract_address == other.contract_address) } } impl Empty for ScopedNoteHash { fn empty() -> Self { - ScopedNoteHash { - note_hash: NoteHash::empty(), - contract_address: AztecAddress::zero(), - } + ScopedNoteHash { note_hash: NoteHash::empty(), contract_address: AztecAddress::zero() } } } impl Serialize for ScopedNoteHash { fn serialize(self) -> [Field; SCOPED_NOTE_HASH_LENGTH] { - array_concat(self.note_hash.serialize(), [self.contract_address.to_field()]) + array_concat( + self.note_hash.serialize(), + [self.contract_address.to_field()] + ) } } @@ -109,7 +101,7 @@ impl Deserialize for ScopedNoteHash { let mut reader = Reader::new(values); let res = Self { note_hash: reader.read_struct(NoteHash::deserialize), - contract_address: reader.read_struct(AztecAddress::deserialize), + contract_address: reader.read_struct(AztecAddress::deserialize) }; reader.finish(); res @@ -118,8 +110,12 @@ impl Deserialize for ScopedNoteHash { impl Readable for ScopedNoteHash { fn assert_match_read_request(self, read_request: ScopedReadRequest) { - assert_eq(self.note_hash.value, read_request.value(), "Value of the note hash does not match read request"); - assert_eq(self.contract_address, read_request.contract_address, "Contract address of the note hash does not match read request"); + assert_eq( + self.note_hash.value, read_request.value(), "Value of the note hash does not match read request" + ); + assert_eq( + self.contract_address, read_request.contract_address, "Contract address of the note hash does not match read request" + ); assert( read_request.counter() > self.note_hash.counter, "Read request counter must be greater than the counter of the note hash" ); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash_leaf_preimage.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash_leaf_preimage.nr index 7fa6b73e174..652f8bf3732 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash_leaf_preimage.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash_leaf_preimage.nr @@ -11,9 +11,7 @@ struct NoteHashLeafPreimage { impl Empty for NoteHashLeafPreimage { fn empty() -> Self { - Self { - value : 0, - } + Self { value: 0 } } } @@ -48,10 +46,10 @@ impl NoteHashLeafPreimage { } } -impl Eq for NoteHashLeafPreimage{ - fn eq(self, other: Self) -> bool { - self.value == other.value - } +impl Eq for NoteHashLeafPreimage { + fn eq(self, other: Self) -> bool { + self.value == other.value + } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier.nr index f31a0658f6b..13b2105c640 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier.nr @@ -36,11 +36,7 @@ impl Eq for Nullifier { impl Empty for Nullifier { fn empty() -> Self { - Nullifier { - value: 0, - counter: 0, - note_hash: 0, - } + Nullifier { value: 0, counter: 0, note_hash: 0 } } } @@ -52,11 +48,7 @@ impl Serialize for Nullifier { impl Deserialize for Nullifier { fn deserialize(values: [Field; NULLIFIER_LENGTH]) -> Self { - Self { - value: values[0], - counter: values[1] as u32, - note_hash: values[2], - } + Self { value: values[0], counter: values[1] as u32, note_hash: values[2] } } } @@ -109,23 +101,22 @@ impl OrderedValue for ScopedNullifier { impl Eq for ScopedNullifier { fn eq(self, other: ScopedNullifier) -> bool { - (self.nullifier == other.nullifier) - & (self.contract_address == other.contract_address) + (self.nullifier == other.nullifier) & (self.contract_address == other.contract_address) } } impl Empty for ScopedNullifier { fn empty() -> Self { - ScopedNullifier { - nullifier: Nullifier::empty(), - contract_address: AztecAddress::empty(), - } + ScopedNullifier { nullifier: Nullifier::empty(), contract_address: AztecAddress::empty() } } } impl Serialize for ScopedNullifier { fn serialize(self) -> [Field; SCOPED_NULLIFIER_LENGTH] { - array_concat(self.nullifier.serialize(), [self.contract_address.to_field()]) + array_concat( + self.nullifier.serialize(), + [self.contract_address.to_field()] + ) } } @@ -134,7 +125,7 @@ impl Deserialize for ScopedNullifier { let mut reader = Reader::new(values); let res = Self { nullifier: reader.read_struct(Nullifier::deserialize), - contract_address: reader.read_struct(AztecAddress::deserialize), + contract_address: reader.read_struct(AztecAddress::deserialize) }; reader.finish(); res @@ -143,8 +134,12 @@ impl Deserialize for ScopedNullifier { impl Readable for ScopedNullifier { fn assert_match_read_request(self, read_request: ScopedReadRequest) { - assert_eq(self.nullifier.value, read_request.value(), "Value of the nullifier does not match read request"); - assert_eq(self.contract_address, read_request.contract_address, "Contract address of the nullifier does not match read request"); + assert_eq( + self.nullifier.value, read_request.value(), "Value of the nullifier does not match read request" + ); + assert_eq( + self.contract_address, read_request.contract_address, "Contract address of the nullifier does not match read request" + ); assert( read_request.counter() > self.nullifier.counter, "Read request counter must be greater than the counter of the nullifier" ); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr index 835510584b9..e3e40bd7bf6 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr @@ -13,11 +13,7 @@ struct NullifierLeafPreimage { impl Empty for NullifierLeafPreimage { fn empty() -> Self { - Self { - nullifier : 0, - next_nullifier : 0, - next_index : 0, - } + Self { nullifier: 0, next_nullifier: 0, next_index: 0 } } } @@ -77,11 +73,11 @@ impl NullifierLeafPreimage { } impl Eq for NullifierLeafPreimage { - fn eq(self, other: Self) -> bool { - (self.nullifier == other.nullifier) & - (self.next_nullifier == other.next_nullifier) & - (self.next_index == other.next_index) - } + fn eq(self, other: Self) -> bool { + (self.nullifier == other.nullifier) + & (self.next_nullifier == other.next_nullifier) + & (self.next_index == other.next_index) + } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_request.nr index ab462a60c4a..d0b64e0890b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_request.nr @@ -30,9 +30,9 @@ impl RangeOrdered for PrivateCallRequest { impl Eq for PrivateCallRequest { fn eq(self, other: PrivateCallRequest) -> bool { - (self.contract_address == other.contract_address) - & (self.call_context == other.call_context) - & (self.args_hash == other.args_hash) + (self.contract_address == other.contract_address) + & (self.call_context == other.call_context) + & (self.args_hash == other.args_hash) & (self.returns_hash == other.returns_hash) & (self.start_side_effect_counter == other.start_side_effect_counter) & (self.end_side_effect_counter == other.end_side_effect_counter) @@ -47,7 +47,7 @@ impl Empty for PrivateCallRequest { args_hash: 0, returns_hash: 0, start_side_effect_counter: 0, - end_side_effect_counter: 0, + end_side_effect_counter: 0 } } } @@ -78,7 +78,7 @@ impl Deserialize for PrivateCallRequest { args_hash: reader.read(), returns_hash: reader.read(), start_side_effect_counter: reader.read_u32(), - end_side_effect_counter: reader.read_u32(), + end_side_effect_counter: reader.read_u32() }; reader.finish(); item diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr index 428af577c41..5cd0a86d6aa 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr @@ -17,9 +17,9 @@ struct PrivateCallStackItem { impl Eq for PrivateCallStackItem { fn eq(self, other: Self) -> bool { - self.contract_address.eq(other.contract_address) & - self.function_data.eq(other.function_data) & - self.public_inputs.eq(other.public_inputs) + self.contract_address.eq(other.contract_address) + & self.function_data.eq(other.function_data) + & self.public_inputs.eq(other.public_inputs) } } @@ -45,7 +45,7 @@ impl Deserialize for PrivateCallStackItem { let item = Self { contract_address: reader.read_struct(AztecAddress::deserialize), function_data: reader.read_struct(FunctionData::deserialize), - public_inputs: reader.read_struct(PrivateCircuitPublicInputs::deserialize), + public_inputs: reader.read_struct(PrivateCircuitPublicInputs::deserialize) }; reader.finish(); @@ -58,7 +58,7 @@ impl Empty for PrivateCallStackItem { PrivateCallStackItem { contract_address: AztecAddress::empty(), function_data: FunctionData::empty(), - public_inputs: PrivateCircuitPublicInputs::empty(), + public_inputs: PrivateCircuitPublicInputs::empty() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr index 97ab5675046..a1565d85df3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr @@ -87,27 +87,41 @@ struct PrivateCircuitPublicInputs { impl Eq for PrivateCircuitPublicInputs { fn eq(self, other: Self) -> bool { - self.call_context.eq(other.call_context) & - self.args_hash.eq(other.args_hash) & - (self.returns_hash == other.returns_hash) & - (self.min_revertible_side_effect_counter == other.min_revertible_side_effect_counter) & - (self.is_fee_payer == other.is_fee_payer) & - (self.max_block_number == other.max_block_number) & - (self.note_hash_read_requests == other.note_hash_read_requests) & - (self.nullifier_read_requests == other.nullifier_read_requests) & - (self.key_validation_requests_and_generators == other.key_validation_requests_and_generators) & - (self.note_hashes == other.note_hashes) & - (self.nullifiers == other.nullifiers) & - (self.private_call_requests == other.private_call_requests) & - (self.public_call_requests == other.public_call_requests) & - (self.l2_to_l1_msgs == other.l2_to_l1_msgs) & - (self.start_side_effect_counter == other.start_side_effect_counter) & - (self.end_side_effect_counter == other.end_side_effect_counter) & - (self.note_encrypted_logs_hashes == other.note_encrypted_logs_hashes) & - (self.encrypted_logs_hashes == other.encrypted_logs_hashes) & - (self.unencrypted_logs_hashes == other.unencrypted_logs_hashes) & - self.historical_header.eq(other.historical_header) & - self.tx_context.eq(other.tx_context) + self.call_context.eq(other.call_context) + & self.args_hash.eq(other.args_hash) + & (self.returns_hash == other.returns_hash) + & (self.min_revertible_side_effect_counter + == other.min_revertible_side_effect_counter) + & (self.is_fee_payer == other.is_fee_payer) + & (self.max_block_number == other.max_block_number) + & (self.note_hash_read_requests == other.note_hash_read_requests) + & (self.nullifier_read_requests == other.nullifier_read_requests) + & (self.key_validation_requests_and_generators + == other.key_validation_requests_and_generators) + & (self.note_hashes == other.note_hashes) + & (self.nullifiers == other.nullifiers) + & (self.private_call_requests + == other.private_call_requests) + & (self.public_call_requests + == other.public_call_requests) + & (self.l2_to_l1_msgs + == other.l2_to_l1_msgs) + & (self.start_side_effect_counter + == other.start_side_effect_counter) + & (self.end_side_effect_counter + == other.end_side_effect_counter) + & (self.note_encrypted_logs_hashes + == other.note_encrypted_logs_hashes) + & (self.encrypted_logs_hashes + == other.encrypted_logs_hashes) + & (self.unencrypted_logs_hashes + == other.unencrypted_logs_hashes) + & self.historical_header.eq( + other.historical_header + ) + & self.tx_context.eq( + other.tx_context + ) } } @@ -179,22 +193,55 @@ impl Deserialize for PrivateCircuitPublicI min_revertible_side_effect_counter: reader.read() as u32, is_fee_payer: reader.read() == 1, max_block_number: reader.read_struct(MaxBlockNumber::deserialize), - note_hash_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]), - nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), - key_validation_requests_and_generators: reader.read_struct_array(KeyValidationRequestAndGenerator::deserialize, [KeyValidationRequestAndGenerator::empty(); MAX_KEY_VALIDATION_REQUESTS_PER_CALL]), - note_hashes: reader.read_struct_array(NoteHash::deserialize, [NoteHash::empty(); MAX_NOTE_HASHES_PER_CALL]), - nullifiers: reader.read_struct_array(Nullifier::deserialize, [Nullifier::empty(); MAX_NULLIFIERS_PER_CALL]), - private_call_requests: reader.read_struct_array(PrivateCallRequest::deserialize, [PrivateCallRequest::empty(); MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL]), - public_call_requests: reader.read_struct_array(PublicCallRequest::deserialize, [PublicCallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL]), + note_hash_read_requests: reader.read_struct_array( + ReadRequest::deserialize, + [ReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] + ), + nullifier_read_requests: reader.read_struct_array( + ReadRequest::deserialize, + [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL] + ), + key_validation_requests_and_generators: reader.read_struct_array( + KeyValidationRequestAndGenerator::deserialize, + [KeyValidationRequestAndGenerator::empty(); MAX_KEY_VALIDATION_REQUESTS_PER_CALL] + ), + note_hashes: reader.read_struct_array( + NoteHash::deserialize, + [NoteHash::empty(); MAX_NOTE_HASHES_PER_CALL] + ), + nullifiers: reader.read_struct_array( + Nullifier::deserialize, + [Nullifier::empty(); MAX_NULLIFIERS_PER_CALL] + ), + private_call_requests: reader.read_struct_array( + PrivateCallRequest::deserialize, + [PrivateCallRequest::empty(); MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL] + ), + public_call_requests: reader.read_struct_array( + PublicCallRequest::deserialize, + [PublicCallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL] + ), public_teardown_call_request: reader.read_struct(PublicCallRequest::deserialize), - l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_CALL]), + l2_to_l1_msgs: reader.read_struct_array( + L2ToL1Message::deserialize, + [L2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_CALL] + ), start_side_effect_counter: reader.read() as u32, end_side_effect_counter: reader.read() as u32, - note_encrypted_logs_hashes: reader.read_struct_array(NoteLogHash::deserialize, [NoteLogHash::empty(); MAX_NOTE_ENCRYPTED_LOGS_PER_CALL]), - encrypted_logs_hashes: reader.read_struct_array(EncryptedLogHash::deserialize, [EncryptedLogHash::empty(); MAX_ENCRYPTED_LOGS_PER_CALL]), - unencrypted_logs_hashes: reader.read_struct_array(LogHash::deserialize, [LogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_CALL]), + note_encrypted_logs_hashes: reader.read_struct_array( + NoteLogHash::deserialize, + [NoteLogHash::empty(); MAX_NOTE_ENCRYPTED_LOGS_PER_CALL] + ), + encrypted_logs_hashes: reader.read_struct_array( + EncryptedLogHash::deserialize, + [EncryptedLogHash::empty(); MAX_ENCRYPTED_LOGS_PER_CALL] + ), + unencrypted_logs_hashes: reader.read_struct_array( + LogHash::deserialize, + [LogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_CALL] + ), historical_header: reader.read_struct(Header::deserialize), - tx_context: reader.read_struct(TxContext::deserialize), + tx_context: reader.read_struct(TxContext::deserialize) }; reader.finish(); @@ -220,13 +267,13 @@ impl Empty for PrivateCircuitPublicInputs { public_call_requests: [PublicCallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], public_teardown_call_request: PublicCallRequest::empty(), l2_to_l1_msgs: [L2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_CALL], - start_side_effect_counter : 0 as u32, - end_side_effect_counter : 0 as u32, + start_side_effect_counter: 0 as u32, + end_side_effect_counter: 0 as u32, note_encrypted_logs_hashes: [NoteLogHash::empty(); MAX_NOTE_ENCRYPTED_LOGS_PER_CALL], encrypted_logs_hashes: [EncryptedLogHash::empty(); MAX_ENCRYPTED_LOGS_PER_CALL], unencrypted_logs_hashes: [LogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_CALL], historical_header: Header::empty(), - tx_context: TxContext::empty(), + tx_context: TxContext::empty() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_request.nr index b5cfb29fadc..26fe27373ff 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_request.nr @@ -17,17 +17,13 @@ impl Ordered for PublicCallRequest { impl Eq for PublicCallRequest { fn eq(self, other: PublicCallRequest) -> bool { - (other.item == self.item) - & (other.counter == self.counter) + (other.item == self.item) & (other.counter == self.counter) } } impl Empty for PublicCallRequest { fn empty() -> Self { - PublicCallRequest { - item: PublicCallStackItemCompressed::empty(), - counter: 0, - } + PublicCallRequest { item: PublicCallStackItemCompressed::empty(), counter: 0 } } } @@ -38,29 +34,26 @@ impl PublicCallRequest { } impl Serialize for PublicCallRequest { - fn serialize(self) -> [Field; PUBLIC_CALL_REQUEST_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); + fn serialize(self) -> [Field; PUBLIC_CALL_REQUEST_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); - fields.extend_from_array(self.item.serialize()); - fields.push(self.counter as Field); + fields.extend_from_array(self.item.serialize()); + fields.push(self.counter as Field); - assert_eq(fields.len(), PUBLIC_CALL_REQUEST_LENGTH); + assert_eq(fields.len(), PUBLIC_CALL_REQUEST_LENGTH); - fields.storage - } + fields.storage + } } impl Deserialize for PublicCallRequest { - fn deserialize(fields: [Field; PUBLIC_CALL_REQUEST_LENGTH]) -> PublicCallRequest { - let mut reader = Reader::new(fields); + fn deserialize(fields: [Field; PUBLIC_CALL_REQUEST_LENGTH]) -> PublicCallRequest { + let mut reader = Reader::new(fields); - let request = PublicCallRequest { - item: reader.read_struct(PublicCallStackItemCompressed::deserialize), - counter: reader.read_u32(), - }; - reader.finish(); - request - } + let request = PublicCallRequest { item: reader.read_struct(PublicCallStackItemCompressed::deserialize), counter: reader.read_u32() }; + reader.finish(); + request + } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item_compressed.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item_compressed.nr index 0efb273a879..b2eb5280142 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item_compressed.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item_compressed.nr @@ -49,7 +49,7 @@ impl Empty for PublicCallStackItemCompressed { returns_hash: 0, revert_code: 0, start_gas_left: Gas::empty(), - end_gas_left: Gas::empty(), + end_gas_left: Gas::empty() } } } @@ -73,19 +73,19 @@ impl Serialize for PublicCallStackItem } impl Deserialize for PublicCallStackItemCompressed { - fn deserialize(fields: [Field; PUBLIC_CALL_STACK_ITEM_COMPRESSED_LENGTH]) -> PublicCallStackItemCompressed { - let mut reader = Reader::new(fields); + fn deserialize(fields: [Field; PUBLIC_CALL_STACK_ITEM_COMPRESSED_LENGTH]) -> PublicCallStackItemCompressed { + let mut reader = Reader::new(fields); - let item = PublicCallStackItemCompressed { - contract_address: reader.read_struct(AztecAddress::deserialize), - call_context: reader.read_struct(CallContext::deserialize), - args_hash: reader.read(), - returns_hash: reader.read(), - revert_code: reader.read() as u8, - start_gas_left: reader.read_struct(Gas::deserialize), - end_gas_left: reader.read_struct(Gas::deserialize), - }; - reader.finish(); - item - } + let item = PublicCallStackItemCompressed { + contract_address: reader.read_struct(AztecAddress::deserialize), + call_context: reader.read_struct(CallContext::deserialize), + args_hash: reader.read(), + returns_hash: reader.read(), + revert_code: reader.read() as u8, + start_gas_left: reader.read_struct(Gas::deserialize), + end_gas_left: reader.read_struct(Gas::deserialize) + }; + reader.finish(); + item + } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr index b70557d9cda..8721797316c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr @@ -104,7 +104,7 @@ impl Serialize for PublicCircuitPublicInput fields.push(self.start_side_effect_counter as Field); fields.push(self.end_side_effect_counter as Field); - for i in 0..MAX_UNENCRYPTED_LOGS_PER_CALL{ + for i in 0..MAX_UNENCRYPTED_LOGS_PER_CALL { fields.extend_from_array(self.unencrypted_logs_hashes[i].serialize()); } fields.extend_from_array(self.historical_header.serialize()); @@ -126,26 +126,59 @@ impl Deserialize for PublicCircuitPublicInp call_context: reader.read_struct(CallContext::deserialize), args_hash: reader.read(), returns_hash: reader.read(), - note_hash_read_requests: reader.read_struct_array(TreeLeafReadRequest::deserialize, [TreeLeafReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]), - nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), - nullifier_non_existent_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL]), - l1_to_l2_msg_read_requests: reader.read_struct_array(TreeLeafReadRequest::deserialize, [TreeLeafReadRequest::empty(); MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL]), - contract_storage_update_requests: reader.read_struct_array(StorageUpdateRequest::deserialize, [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL]), - contract_storage_reads: reader.read_struct_array(StorageRead::deserialize, [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL]), - public_call_requests: reader.read_struct_array(PublicCallRequest::deserialize, [PublicCallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL]), - note_hashes: reader.read_struct_array(NoteHash::deserialize, [NoteHash::empty(); MAX_NOTE_HASHES_PER_CALL]), - nullifiers: reader.read_struct_array(Nullifier::deserialize, [Nullifier::empty(); MAX_NULLIFIERS_PER_CALL]), - l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_CALL]), + note_hash_read_requests: reader.read_struct_array( + TreeLeafReadRequest::deserialize, + [TreeLeafReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] + ), + nullifier_read_requests: reader.read_struct_array( + ReadRequest::deserialize, + [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL] + ), + nullifier_non_existent_read_requests: reader.read_struct_array( + ReadRequest::deserialize, + [ReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL] + ), + l1_to_l2_msg_read_requests: reader.read_struct_array( + TreeLeafReadRequest::deserialize, + [TreeLeafReadRequest::empty(); MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL] + ), + contract_storage_update_requests: reader.read_struct_array( + StorageUpdateRequest::deserialize, + [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL] + ), + contract_storage_reads: reader.read_struct_array( + StorageRead::deserialize, + [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL] + ), + public_call_requests: reader.read_struct_array( + PublicCallRequest::deserialize, + [PublicCallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL] + ), + note_hashes: reader.read_struct_array( + NoteHash::deserialize, + [NoteHash::empty(); MAX_NOTE_HASHES_PER_CALL] + ), + nullifiers: reader.read_struct_array( + Nullifier::deserialize, + [Nullifier::empty(); MAX_NULLIFIERS_PER_CALL] + ), + l2_to_l1_msgs: reader.read_struct_array( + L2ToL1Message::deserialize, + [L2ToL1Message::empty(); MAX_L2_TO_L1_MSGS_PER_CALL] + ), start_side_effect_counter: reader.read() as u32, end_side_effect_counter: reader.read() as u32, - unencrypted_logs_hashes: reader.read_struct_array(LogHash::deserialize, [LogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_CALL]), + unencrypted_logs_hashes: reader.read_struct_array( + LogHash::deserialize, + [LogHash::empty(); MAX_UNENCRYPTED_LOGS_PER_CALL] + ), historical_header: reader.read_struct(Header::deserialize), global_variables: reader.read_struct(GlobalVariables::deserialize), prover_address: reader.read_struct(AztecAddress::deserialize), revert_code: reader.read() as u8, start_gas_left: reader.read_struct(Gas::deserialize), end_gas_left: reader.read_struct(Gas::deserialize), - transaction_fee: reader.read(), + transaction_fee: reader.read() }; reader.finish(); @@ -178,7 +211,7 @@ impl Empty for PublicCircuitPublicInputs { revert_code: 0 as u8, start_gas_left: Gas::empty(), end_gas_left: Gas::empty(), - transaction_fee: 0, + transaction_fee: 0 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr index 3cceed1ad15..f5a3ce9d067 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr @@ -23,17 +23,15 @@ impl PublicDataRead { impl Eq for PublicDataRead { fn eq(self, other: PublicDataRead) -> bool { - (other.leaf_slot == self.leaf_slot) & (other.value == self.value) & (other.counter == self.counter) + (other.leaf_slot == self.leaf_slot) + & (other.value == self.value) + & (other.counter == self.counter) } } impl Empty for PublicDataRead { fn empty() -> Self { - Self { - leaf_slot: 0, - value: 0, - counter: 0, - } + Self { leaf_slot: 0, value: 0, counter: 0 } } } @@ -50,19 +48,15 @@ impl PublicDataRead { } impl Serialize for PublicDataRead { - fn serialize(self) -> [Field; PUBLIC_DATA_READ_LENGTH] { - [self.leaf_slot, self.value, self.counter as Field] - } + fn serialize(self) -> [Field; PUBLIC_DATA_READ_LENGTH] { + [self.leaf_slot, self.value, self.counter as Field] + } } impl Deserialize for PublicDataRead { - fn deserialize(fields: [Field; PUBLIC_DATA_READ_LENGTH]) -> Self { - PublicDataRead { - leaf_slot: fields[0], - value: fields[1], - counter: fields[2] as u32, + fn deserialize(fields: [Field; PUBLIC_DATA_READ_LENGTH]) -> Self { + PublicDataRead { leaf_slot: fields[0], value: fields[1], counter: fields[2] as u32 } } - } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr index 367e8a9db1f..2516e214fa3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr @@ -29,36 +29,27 @@ impl PublicDataUpdateRequest { } impl Ordered for PublicDataUpdateRequest { - fn counter(self)-> u32{ + fn counter(self) -> u32 { self.counter } } impl Eq for PublicDataUpdateRequest { fn eq(self, update_request: PublicDataUpdateRequest) -> bool { - (update_request.leaf_slot == self.leaf_slot) - & (update_request.new_value == self.new_value) + (update_request.leaf_slot == self.leaf_slot) & (update_request.new_value == self.new_value) } } impl Empty for PublicDataUpdateRequest { fn empty() -> Self { - Self { - leaf_slot : 0, - new_value : 0, - counter : 0 - } + Self { leaf_slot: 0, new_value: 0, counter: 0 } } } impl From for PublicDataTreeLeaf { fn from(update_request: PublicDataUpdateRequest) -> PublicDataTreeLeaf { - PublicDataTreeLeaf { - slot: update_request.leaf_slot, - value: update_request.new_value - } + PublicDataTreeLeaf { slot: update_request.leaf_slot, value: update_request.new_value } } - } impl PublicDataUpdateRequest { @@ -68,19 +59,15 @@ impl PublicDataUpdateRequest { } impl Serialize for PublicDataUpdateRequest { - fn serialize(self) -> [Field; PUBLIC_DATA_UPDATE_REQUEST_LENGTH] { - [self.leaf_slot, self.new_value, self.counter as Field] - } + fn serialize(self) -> [Field; PUBLIC_DATA_UPDATE_REQUEST_LENGTH] { + [self.leaf_slot, self.new_value, self.counter as Field] + } } impl Deserialize for PublicDataUpdateRequest { - fn deserialize(fields: [Field; PUBLIC_DATA_UPDATE_REQUEST_LENGTH]) -> PublicDataUpdateRequest { - PublicDataUpdateRequest { - leaf_slot: fields[0], - new_value: fields[1], - counter: fields[2] as u32 + fn deserialize(fields: [Field; PUBLIC_DATA_UPDATE_REQUEST_LENGTH]) -> PublicDataUpdateRequest { + PublicDataUpdateRequest { leaf_slot: fields[0], new_value: fields[1], counter: fields[2] as u32 } } - } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_write.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_write.nr index 251d31a1af6..c7b9b7ce047 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_write.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_write.nr @@ -19,23 +19,24 @@ impl Eq for OverridablePublicDataWrite { impl Empty for OverridablePublicDataWrite { fn empty() -> Self { - Self { - write: PublicDataUpdateRequest::empty(), - override_counter: 0, - } + Self { write: PublicDataUpdateRequest::empty(), override_counter: 0 } } } impl Ordered for OverridablePublicDataWrite { - fn counter(self)-> u32{ + fn counter(self) -> u32 { self.write.counter() } } impl Readable for OverridablePublicDataWrite { fn assert_match_read_request(self, read_request: PublicDataRead) { - assert_eq(self.write.leaf_slot, read_request.leaf_slot, "leaf_slot in OverridablePublicDataWrite does not match read request"); - assert_eq(self.write.new_value, read_request.value, "value in OverridablePublicDataWrite does not match read request"); + assert_eq( + self.write.leaf_slot, read_request.leaf_slot, "leaf_slot in OverridablePublicDataWrite does not match read request" + ); + assert_eq( + self.write.new_value, read_request.value, "value in OverridablePublicDataWrite does not match read request" + ); } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr index fd739fa45a3..62053755e1a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr @@ -14,15 +14,10 @@ struct PublicKernelData { } impl Verifiable for PublicKernelData { - fn verify(self) { - let inputs = PublicKernelCircuitPublicInputs::serialize(self.public_inputs); - std::verify_proof( - self.vk.key, - self.proof.fields, - inputs, - self.vk.hash - ); - } + fn verify(self) { + let inputs = PublicKernelCircuitPublicInputs::serialize(self.public_inputs); + std::verify_proof(self.vk.key, self.proof.fields, inputs, self.vk.hash); + } } impl PublicKernelData { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr index fce87307f01..b68d480c5a1 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr @@ -17,17 +17,13 @@ impl Ordered for ReadRequest { impl Eq for ReadRequest { fn eq(self, read_request: ReadRequest) -> bool { - (self.value == read_request.value) - & (self.counter == read_request.counter) + (self.value == read_request.value) & (self.counter == read_request.counter) } } impl Empty for ReadRequest { fn empty() -> Self { - ReadRequest { - value: 0, - counter: 0, - } + ReadRequest { value: 0, counter: 0 } } } @@ -39,10 +35,7 @@ impl Serialize for ReadRequest { impl Deserialize for ReadRequest { fn deserialize(values: [Field; READ_REQUEST_LENGTH]) -> Self { - Self { - value: values[0], - counter: values[1] as u32, - } + Self { value: values[0], counter: values[1] as u32 } } } @@ -69,22 +62,22 @@ impl Scoped for ScopedReadRequest { impl Eq for ScopedReadRequest { fn eq(self, other: ScopedReadRequest) -> bool { (self.read_request == other.read_request) - & (self.contract_address.eq(other.contract_address)) + & (self.contract_address.eq(other.contract_address)) } } impl Empty for ScopedReadRequest { fn empty() -> Self { - ScopedReadRequest { - read_request: ReadRequest::empty(), - contract_address: AztecAddress::empty(), - } + ScopedReadRequest { read_request: ReadRequest::empty(), contract_address: AztecAddress::empty() } } } impl Serialize for ScopedReadRequest { fn serialize(self) -> [Field; SCOPED_READ_REQUEST_LEN] { - array_concat(self.read_request.serialize(), [self.contract_address.to_field()]) + array_concat( + self.read_request.serialize(), + [self.contract_address.to_field()] + ) } } @@ -93,7 +86,7 @@ impl Deserialize for ScopedReadRequest { let mut reader = Reader::new(values); let res = Self { read_request: reader.read_struct(ReadRequest::deserialize), - contract_address: reader.read_struct(AztecAddress::deserialize), + contract_address: reader.read_struct(AztecAddress::deserialize) }; reader.finish(); res diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/tree_leaf_read_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/tree_leaf_read_request.nr index 69dee4db52d..4a8a386fe55 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/tree_leaf_read_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/tree_leaf_read_request.nr @@ -13,10 +13,7 @@ impl Eq for TreeLeafReadRequest { impl Empty for TreeLeafReadRequest { fn empty() -> Self { - TreeLeafReadRequest { - value: 0, - leaf_index: 0, - } + TreeLeafReadRequest { value: 0, leaf_index: 0 } } } @@ -28,10 +25,7 @@ impl Serialize for TreeLeafReadRequest { impl Deserialize for TreeLeafReadRequest { fn deserialize(values: [Field; TREE_LEAF_READ_REQUEST_LENGTH]) -> Self { - Self { - value: values[0], - leaf_index: values[1], - } + Self { value: values[0], leaf_index: values[1] } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/key_validation_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/key_validation_request.nr index 245c5fa0c8c..ec0a59ab834 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/key_validation_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/key_validation_request.nr @@ -8,17 +8,13 @@ struct KeyValidationRequest { impl Eq for KeyValidationRequest { fn eq(self, request: KeyValidationRequest) -> bool { - (request.pk_m.eq(self.pk_m)) - & (request.sk_app.eq(self.sk_app)) + (request.pk_m.eq(self.pk_m)) & (request.sk_app.eq(self.sk_app)) } } impl Empty for KeyValidationRequest { fn empty() -> Self { - KeyValidationRequest { - pk_m: Point::empty(), - sk_app: 0, - } + KeyValidationRequest { pk_m: Point::empty(), sk_app: 0 } } } @@ -28,17 +24,14 @@ impl Serialize for KeyValidationRequest { self.pk_m.x, self.pk_m.y, self.pk_m.is_infinite as Field, - self.sk_app, + self.sk_app ] } } impl Deserialize for KeyValidationRequest { fn deserialize(fields: [Field; KEY_VALIDATION_REQUEST_LENGTH]) -> Self { - Self { - pk_m: Point { x:fields[0], y: fields[1], is_infinite: fields[2] as bool}, - sk_app: fields[3], - } + Self { pk_m: Point { x: fields[0], y: fields[1], is_infinite: fields[2] as bool }, sk_app: fields[3] } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/key_validation_request_and_generator.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/key_validation_request_and_generator.nr index d319ee190c9..c35e1289696 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/key_validation_request_and_generator.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/key_validation_request_and_generator.nr @@ -21,10 +21,7 @@ impl Eq for KeyValidationRequestAndGenerator { impl Empty for KeyValidationRequestAndGenerator { fn empty() -> Self { - KeyValidationRequestAndGenerator { - request: KeyValidationRequest::empty(), - sk_app_generator: 0, - } + KeyValidationRequestAndGenerator { request: KeyValidationRequest::empty(), sk_app_generator: 0 } } } @@ -37,10 +34,7 @@ impl Serialize for KeyValidationReq impl Deserialize for KeyValidationRequestAndGenerator { fn deserialize(fields: [Field; KEY_VALIDATION_REQUEST_AND_GENERATOR_LENGTH]) -> Self { let mut reader = Reader::new(fields); - let res = Self { - request: reader.read_struct(KeyValidationRequest::deserialize), - sk_app_generator: reader.read(), - }; + let res = Self { request: reader.read_struct(KeyValidationRequest::deserialize), sk_app_generator: reader.read() }; reader.finish(); res } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/private_validation_requests.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/private_validation_requests.nr index 45213a9a857..763bc2f685e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/private_validation_requests.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/private_validation_requests.nr @@ -22,30 +22,30 @@ struct PrivateValidationRequests { } impl Serialize for PrivateValidationRequests { - fn serialize(self) -> [Field; PRIVATE_VALIDATION_REQUESTS_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); + fn serialize(self) -> [Field; PRIVATE_VALIDATION_REQUESTS_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); - fields.extend_from_array(self.for_rollup.serialize()); + fields.extend_from_array(self.for_rollup.serialize()); - for i in 0..MAX_NOTE_HASH_READ_REQUESTS_PER_TX { - fields.extend_from_array(self.note_hash_read_requests[i].serialize()); - } + for i in 0..MAX_NOTE_HASH_READ_REQUESTS_PER_TX { + fields.extend_from_array(self.note_hash_read_requests[i].serialize()); + } - for i in 0..MAX_NULLIFIER_READ_REQUESTS_PER_TX { - fields.extend_from_array(self.nullifier_read_requests[i].serialize()); - } + for i in 0..MAX_NULLIFIER_READ_REQUESTS_PER_TX { + fields.extend_from_array(self.nullifier_read_requests[i].serialize()); + } - for i in 0..MAX_KEY_VALIDATION_REQUESTS_PER_TX { - fields.extend_from_array(self.scoped_key_validation_requests_and_generators[i].serialize()); - } + for i in 0..MAX_KEY_VALIDATION_REQUESTS_PER_TX { + fields.extend_from_array(self.scoped_key_validation_requests_and_generators[i].serialize()); + } - fields.push(self.split_counter.is_some() as Field); - fields.push(self.split_counter.unwrap_unchecked() as Field); + fields.push(self.split_counter.is_some() as Field); + fields.push(self.split_counter.unwrap_unchecked() as Field); - assert_eq(fields.len(), PRIVATE_VALIDATION_REQUESTS_LENGTH); + assert_eq(fields.len(), PRIVATE_VALIDATION_REQUESTS_LENGTH); - fields.storage - } + fields.storage + } } impl Deserialize for PrivateValidationRequests { @@ -53,9 +53,18 @@ impl Deserialize for PrivateValidationReques let mut reader = Reader::new(serialized); let item = Self { for_rollup: reader.read_struct(RollupValidationRequests::deserialize), - note_hash_read_requests: reader.read_struct_array(ScopedReadRequest::deserialize, [ScopedReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_TX]), - nullifier_read_requests: reader.read_struct_array(ScopedReadRequest::deserialize, [ScopedReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_TX]), - scoped_key_validation_requests_and_generators: reader.read_struct_array(ScopedKeyValidationRequestAndGenerator::deserialize, [ScopedKeyValidationRequestAndGenerator::empty(); MAX_KEY_VALIDATION_REQUESTS_PER_TX]), + note_hash_read_requests: reader.read_struct_array( + ScopedReadRequest::deserialize, + [ScopedReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_TX] + ), + nullifier_read_requests: reader.read_struct_array( + ScopedReadRequest::deserialize, + [ScopedReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_TX] + ), + scoped_key_validation_requests_and_generators: reader.read_struct_array( + ScopedKeyValidationRequestAndGenerator::deserialize, + [ScopedKeyValidationRequestAndGenerator::empty(); MAX_KEY_VALIDATION_REQUESTS_PER_TX] + ), split_counter: Option { _is_some: reader.read_bool(), _value: reader.read_u32() } }; @@ -71,18 +80,19 @@ impl Empty for PrivateValidationRequests { note_hash_read_requests: [ScopedReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_TX], nullifier_read_requests: [ScopedReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_TX], scoped_key_validation_requests_and_generators: [ScopedKeyValidationRequestAndGenerator::empty(); MAX_KEY_VALIDATION_REQUESTS_PER_TX], - split_counter: Option::none(), + split_counter: Option::none() } } } impl Eq for PrivateValidationRequests { fn eq(self, other: Self) -> bool { - (self.for_rollup.eq(other.for_rollup)) & - (self.note_hash_read_requests == other.note_hash_read_requests) & - (self.nullifier_read_requests == other.nullifier_read_requests) & - (self.scoped_key_validation_requests_and_generators == other.scoped_key_validation_requests_and_generators) & - (self.split_counter == other.split_counter) + (self.for_rollup.eq(other.for_rollup)) + & (self.note_hash_read_requests == other.note_hash_read_requests) + & (self.nullifier_read_requests == other.nullifier_read_requests) + & (self.scoped_key_validation_requests_and_generators + == other.scoped_key_validation_requests_and_generators) + & (self.split_counter == other.split_counter) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/private_validation_requests_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/private_validation_requests_builder.nr index 227cd34a594..3cee3e151e0 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/private_validation_requests_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/private_validation_requests_builder.nr @@ -45,7 +45,7 @@ impl Empty for PrivateValidationRequestsBuilder { note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), scoped_key_validation_requests_and_generators: BoundedVec::new(), - split_counter: Option::none(), + split_counter: Option::none() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/public_validation_requests.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/public_validation_requests.nr index e9853592622..616cc69764f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/public_validation_requests.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/public_validation_requests.nr @@ -22,35 +22,35 @@ struct PublicValidationRequests { } impl Serialize for PublicValidationRequests { - fn serialize(self) -> [Field; PUBLIC_VALIDATION_REQUESTS_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); + fn serialize(self) -> [Field; PUBLIC_VALIDATION_REQUESTS_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); - fields.extend_from_array(self.for_rollup.serialize()); + fields.extend_from_array(self.for_rollup.serialize()); - for i in 0..self.note_hash_read_requests.len() { - fields.extend_from_array(self.note_hash_read_requests[i].serialize()); - } + for i in 0..self.note_hash_read_requests.len() { + fields.extend_from_array(self.note_hash_read_requests[i].serialize()); + } - for i in 0..self.nullifier_read_requests.len() { - fields.extend_from_array(self.nullifier_read_requests[i].serialize()); - } + for i in 0..self.nullifier_read_requests.len() { + fields.extend_from_array(self.nullifier_read_requests[i].serialize()); + } - for i in 0..self.nullifier_non_existent_read_requests.len() { - fields.extend_from_array(self.nullifier_non_existent_read_requests[i].serialize()); - } + for i in 0..self.nullifier_non_existent_read_requests.len() { + fields.extend_from_array(self.nullifier_non_existent_read_requests[i].serialize()); + } - for i in 0..self.l1_to_l2_msg_read_requests.len() { - fields.extend_from_array(self.l1_to_l2_msg_read_requests[i].serialize()); - } + for i in 0..self.l1_to_l2_msg_read_requests.len() { + fields.extend_from_array(self.l1_to_l2_msg_read_requests[i].serialize()); + } - for i in 0..self.public_data_reads.len() { - fields.extend_from_array(self.public_data_reads[i].serialize()); - } + for i in 0..self.public_data_reads.len() { + fields.extend_from_array(self.public_data_reads[i].serialize()); + } - assert_eq(fields.len(), PUBLIC_VALIDATION_REQUESTS_LENGTH); + assert_eq(fields.len(), PUBLIC_VALIDATION_REQUESTS_LENGTH); - fields.storage - } + fields.storage + } } impl Deserialize for PublicValidationRequests { @@ -59,11 +59,26 @@ impl Deserialize for PublicValidationRequests let mut reader = Reader::new(serialized); let item = Self { for_rollup: reader.read_struct(RollupValidationRequests::deserialize), - note_hash_read_requests: reader.read_struct_array(TreeLeafReadRequest::deserialize, [TreeLeafReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_TX]), - nullifier_read_requests: reader.read_struct_array(ScopedReadRequest::deserialize, [ScopedReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_TX]), - nullifier_non_existent_read_requests: reader.read_struct_array(ScopedReadRequest::deserialize, [ScopedReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX]), - l1_to_l2_msg_read_requests: reader.read_struct_array(TreeLeafReadRequest::deserialize, [TreeLeafReadRequest::empty(); MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_TX]), - public_data_reads: reader.read_struct_array(PublicDataRead::deserialize, [PublicDataRead::empty(); MAX_PUBLIC_DATA_READS_PER_TX]), + note_hash_read_requests: reader.read_struct_array( + TreeLeafReadRequest::deserialize, + [TreeLeafReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_TX] + ), + nullifier_read_requests: reader.read_struct_array( + ScopedReadRequest::deserialize, + [ScopedReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_TX] + ), + nullifier_non_existent_read_requests: reader.read_struct_array( + ScopedReadRequest::deserialize, + [ScopedReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX] + ), + l1_to_l2_msg_read_requests: reader.read_struct_array( + TreeLeafReadRequest::deserialize, + [TreeLeafReadRequest::empty(); MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_TX] + ), + public_data_reads: reader.read_struct_array( + PublicDataRead::deserialize, + [PublicDataRead::empty(); MAX_PUBLIC_DATA_READS_PER_TX] + ) }; reader.finish(); @@ -79,19 +94,20 @@ impl Empty for PublicValidationRequests { nullifier_read_requests: [ScopedReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_TX], nullifier_non_existent_read_requests: [ScopedReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX], l1_to_l2_msg_read_requests: [TreeLeafReadRequest::empty(); MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_TX], - public_data_reads: [PublicDataRead::empty(); MAX_PUBLIC_DATA_READS_PER_TX], + public_data_reads: [PublicDataRead::empty(); MAX_PUBLIC_DATA_READS_PER_TX] } } } impl Eq for PublicValidationRequests { fn eq(self, other: Self) -> bool { - (self.for_rollup.eq(other.for_rollup)) & - (self.note_hash_read_requests == other.note_hash_read_requests) & - (self.nullifier_read_requests == other.nullifier_read_requests) & - (self.nullifier_non_existent_read_requests == other.nullifier_non_existent_read_requests) & - (self.l1_to_l2_msg_read_requests == other.l1_to_l2_msg_read_requests) & - (self.public_data_reads == other.public_data_reads) + (self.for_rollup.eq(other.for_rollup)) + & (self.note_hash_read_requests == other.note_hash_read_requests) + & (self.nullifier_read_requests == other.nullifier_read_requests) + & (self.nullifier_non_existent_read_requests + == other.nullifier_non_existent_read_requests) + & (self.l1_to_l2_msg_read_requests == other.l1_to_l2_msg_read_requests) + & (self.public_data_reads == other.public_data_reads) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/public_validation_requests_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/public_validation_requests_builder.nr index 4a14f852f0c..4cf894617f3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/public_validation_requests_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/public_validation_requests_builder.nr @@ -60,7 +60,7 @@ impl Empty for PublicValidationRequestsBuilder { nullifier_read_requests: BoundedVec::new(), nullifier_non_existent_read_requests: BoundedVec::new(), public_data_reads: BoundedVec::new(), - l1_to_l2_msg_read_requests: BoundedVec::new(), + l1_to_l2_msg_read_requests: BoundedVec::new() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/rollup_validation_requests.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/rollup_validation_requests.nr index 56688fe64fb..9cfac17a676 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/rollup_validation_requests.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/rollup_validation_requests.nr @@ -11,33 +11,29 @@ struct RollupValidationRequests { impl Empty for RollupValidationRequests { fn empty() -> Self { - RollupValidationRequests { - max_block_number: MaxBlockNumber::empty(), - } + RollupValidationRequests { max_block_number: MaxBlockNumber::empty() } } } impl Serialize for RollupValidationRequests { - fn serialize(self) -> [Field; ROLLUP_VALIDATION_REQUESTS_LENGTH] { - MaxBlockNumber::serialize(self.max_block_number) - } + fn serialize(self) -> [Field; ROLLUP_VALIDATION_REQUESTS_LENGTH] { + MaxBlockNumber::serialize(self.max_block_number) + } } impl Deserialize for RollupValidationRequests { - fn deserialize(fields: [Field; ROLLUP_VALIDATION_REQUESTS_LENGTH]) -> RollupValidationRequests { - let mut reader = Reader::new(fields); - let item = Self { - max_block_number: reader.read_struct(MaxBlockNumber::deserialize), - }; - reader.finish(); - item - } + fn deserialize(fields: [Field; ROLLUP_VALIDATION_REQUESTS_LENGTH]) -> RollupValidationRequests { + let mut reader = Reader::new(fields); + let item = Self { max_block_number: reader.read_struct(MaxBlockNumber::deserialize) }; + reader.finish(); + item + } } impl Eq for RollupValidationRequests { - fn eq(self, other: Self) -> bool { - self.max_block_number.eq(other.max_block_number) - } + fn eq(self, other: Self) -> bool { + self.max_block_number.eq(other.max_block_number) + } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/scoped_key_validation_request_and_generator.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/scoped_key_validation_request_and_generator.nr index e8eebb0e575..ecceea2812f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/scoped_key_validation_request_and_generator.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/scoped_key_validation_request_and_generator.nr @@ -23,17 +23,13 @@ impl Scoped for ScopedKeyValidationRequestAndG impl Eq for ScopedKeyValidationRequestAndGenerator { fn eq(self, other: ScopedKeyValidationRequestAndGenerator) -> bool { - (self.request.eq(other.request)) - & (self.contract_address.eq(other.contract_address)) + (self.request.eq(other.request)) & (self.contract_address.eq(other.contract_address)) } } impl Empty for ScopedKeyValidationRequestAndGenerator { fn empty() -> Self { - ScopedKeyValidationRequestAndGenerator { - request: KeyValidationRequestAndGenerator::empty(), - contract_address: AztecAddress::zero(), - } + ScopedKeyValidationRequestAndGenerator { request: KeyValidationRequestAndGenerator::empty(), contract_address: AztecAddress::zero() } } } @@ -48,7 +44,7 @@ impl Deserialize for ScopedK let mut reader = Reader::new(fields); let res = Self { request: reader.read_struct(KeyValidationRequestAndGenerator::deserialize), - contract_address: reader.read_struct(AztecAddress::deserialize), + contract_address: reader.read_struct(AztecAddress::deserialize) }; reader.finish(); res diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr index 0f81993be85..db9787ffbce 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr @@ -11,16 +11,14 @@ struct AztecAddress { } impl Eq for AztecAddress { - fn eq(self, other : Self) -> bool { + fn eq(self, other: Self) -> bool { self.to_field() == other.to_field() } } impl Empty for AztecAddress { fn empty() -> Self { - Self { - inner : 0 - } + Self { inner: 0 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr index 101a16da637..cc3a7e292f7 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/eth_address.nr @@ -5,16 +5,14 @@ struct EthAddress{ } impl Eq for EthAddress { - fn eq(self, other : Self) -> bool { + fn eq(self, other: Self) -> bool { self.to_field() == other.to_field() } } impl Empty for EthAddress { fn empty() -> Self { - Self { - inner : 0 - } + Self { inner: 0 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/partial_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/partial_address.nr index 148df7d70bf..0e118db7070 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/partial_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/partial_address.nr @@ -25,7 +25,7 @@ impl Serialize for PartialAddress { impl Deserialize for PartialAddress { fn deserialize(fields: [Field; PARTIAL_ADDRESS_LENGTH]) -> Self { - PartialAddress { inner: fields[0] } + PartialAddress { inner: fields[0] } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/content_commitment.nr b/noir-projects/noir-protocol-circuits/crates/types/src/content_commitment.nr index aaac9302864..03b54424d73 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/content_commitment.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/content_commitment.nr @@ -8,55 +8,45 @@ struct ContentCommitment { } impl Serialize for ContentCommitment { - fn serialize(self) -> [Field; CONTENT_COMMITMENT_LENGTH] { - let mut fields: BoundedVec = BoundedVec::new(); + fn serialize(self) -> [Field; CONTENT_COMMITMENT_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); - fields.push(self.num_txs); - fields.push(self.txs_effects_hash); - fields.push(self.in_hash); - fields.push(self.out_hash); + fields.push(self.num_txs); + fields.push(self.txs_effects_hash); + fields.push(self.in_hash); + fields.push(self.out_hash); - fields.storage - } + fields.storage + } } impl Deserialize for ContentCommitment { - fn deserialize(serialized: [Field; CONTENT_COMMITMENT_LENGTH]) -> Self { - let num_txs = serialized[0]; + fn deserialize(serialized: [Field; CONTENT_COMMITMENT_LENGTH]) -> Self { + let num_txs = serialized[0]; - let txs_effects_hash = serialized[1]; + let txs_effects_hash = serialized[1]; - let in_hash = serialized[2]; + let in_hash = serialized[2]; - let out_hash = serialized[3]; + let out_hash = serialized[3]; - Self { - num_txs, - txs_effects_hash, - in_hash, - out_hash, + Self { num_txs, txs_effects_hash, in_hash, out_hash } } - } } impl Empty for ContentCommitment { - fn empty() -> Self { - Self { - num_txs: 0, - txs_effects_hash: 0, - in_hash: 0, - out_hash: 0, + fn empty() -> Self { + Self { num_txs: 0, txs_effects_hash: 0, in_hash: 0, out_hash: 0 } } - } } impl Eq for ContentCommitment { - fn eq(self, other: Self) -> bool { - (self.num_txs == other.num_txs) - & (self.txs_effects_hash == other.txs_effects_hash) - & (self.in_hash == other.in_hash) - & (self.out_hash == other.out_hash) - } + fn eq(self, other: Self) -> bool { + (self.num_txs == other.num_txs) + & (self.txs_effects_hash == other.txs_effects_hash) + & (self.in_hash == other.in_hash) + & (self.out_hash == other.out_hash) + } } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contract_class_id.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contract_class_id.nr index 365d7141532..0060031f1a3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contract_class_id.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contract_class_id.nr @@ -30,7 +30,7 @@ impl Serialize<1> for ContractClassId { } impl Deserialize<1> for ContractClassId { - fn deserialize(fields: [Field; 1]) -> Self { + fn deserialize(fields: [Field; 1]) -> Self { Self { inner: fields[0] } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contract_instance.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contract_instance.nr index 6d22a482b76..be2f0f48833 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contract_instance.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contract_instance.nr @@ -14,10 +14,10 @@ struct ContractInstance { impl Eq for ContractInstance { fn eq(self, other: Self) -> bool { - self.public_keys_hash.eq(other.public_keys_hash) & - self.initialization_hash.eq(other.initialization_hash) & - self.contract_class_id.eq(other.contract_class_id) & - self.salt.eq(other.salt) + self.public_keys_hash.eq(other.public_keys_hash) + & self.initialization_hash.eq(other.initialization_hash) + & self.contract_class_id.eq(other.contract_class_id) + & self.salt.eq(other.salt) } } @@ -40,7 +40,7 @@ impl Deserialize for ContractInstance { deployer: AztecAddress::from_field(serialized[1]), contract_class_id: ContractClassId::from_field(serialized[2]), initialization_hash: serialized[3], - public_keys_hash: PublicKeysHash::from_field(serialized[4]), + public_keys_hash: PublicKeysHash::from_field(serialized[4]) } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr index 6ed6251c8e3..e7dfed3542e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr @@ -8,17 +8,15 @@ struct StorageRead { impl Eq for StorageRead { fn eq(self, other: Self) -> bool { - (self.storage_slot == other.storage_slot) & (self.current_value == other.current_value) & (self.current_value == other.current_value) + (self.storage_slot == other.storage_slot) + & (self.current_value == other.current_value) + & (self.current_value == other.current_value) } } impl Empty for StorageRead { fn empty() -> Self { - Self { - storage_slot: 0, - current_value: 0, - counter: 0, - } + Self { storage_slot: 0, current_value: 0, counter: 0 } } } @@ -30,11 +28,7 @@ impl Serialize for StorageRead { impl Deserialize for StorageRead { fn deserialize(serialized: [Field; CONTRACT_STORAGE_READ_LENGTH]) -> Self { - Self { - storage_slot: serialized[0], - current_value: serialized[1], - counter: serialized[2] as u32, - } + Self { storage_slot: serialized[0], current_value: serialized[1], counter: serialized[2] as u32 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr index 767c22f5116..e082b3c3990 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr @@ -8,18 +8,13 @@ struct StorageUpdateRequest { impl Eq for StorageUpdateRequest { fn eq(self, request: Self) -> bool { - (request.storage_slot == self.storage_slot) - & (request.new_value == self.new_value) + (request.storage_slot == self.storage_slot) & (request.new_value == self.new_value) } } impl Empty for StorageUpdateRequest { fn empty() -> Self { - StorageUpdateRequest { - storage_slot: 0, - new_value: 0, - counter: 0 - } + StorageUpdateRequest { storage_slot: 0, new_value: 0, counter: 0 } } } @@ -31,11 +26,7 @@ impl Serialize for StorageUpdateRequest impl Deserialize for StorageUpdateRequest { fn deserialize(serialized: [Field; CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH]) -> Self { - StorageUpdateRequest { - storage_slot: serialized[0], - new_value: serialized[1], - counter: serialized[2] as u32 - } + StorageUpdateRequest { storage_slot: serialized[0], new_value: serialized[1], counter: serialized[2] as u32 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_hint.nr b/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_hint.nr index a19b9a03cf5..23252c3a22c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_hint.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_hint.nr @@ -44,7 +44,7 @@ impl Empty for PublicDataHint { value: 0, override_counter: 0, membership_witness: MembershipWitness::empty(), - leaf_preimage: PublicDataTreeLeafPreimage::empty(), + leaf_preimage: PublicDataTreeLeafPreimage::empty() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_leaf_hint.nr b/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_leaf_hint.nr index 2d2c0becd9b..ba6640318e2 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_leaf_hint.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_leaf_hint.nr @@ -10,9 +10,6 @@ struct PublicDataLeafHint { impl Empty for PublicDataLeafHint { fn empty() -> Self { - PublicDataLeafHint { - preimage: PublicDataTreeLeafPreimage::empty(), - membership_witness: MembershipWitness::empty(), - } + PublicDataLeafHint { preimage: PublicDataTreeLeafPreimage::empty(), membership_witness: MembershipWitness::empty() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_tree_leaf.nr b/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_tree_leaf.nr index d1149066df9..22741788061 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_tree_leaf.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_tree_leaf.nr @@ -11,12 +11,9 @@ impl Eq for PublicDataTreeLeaf { } } -impl Empty for PublicDataTreeLeaf { +impl Empty for PublicDataTreeLeaf { fn empty() -> Self { - Self { - slot: 0, - value: 0, - } + Self { slot: 0, value: 0 } } } @@ -33,17 +30,18 @@ struct OverridablePublicDataTreeLeaf { impl Empty for OverridablePublicDataTreeLeaf { fn empty() -> Self { - OverridablePublicDataTreeLeaf { - leaf: PublicDataTreeLeaf::empty(), - override_counter: 0, - } + OverridablePublicDataTreeLeaf { leaf: PublicDataTreeLeaf::empty(), override_counter: 0 } } } impl Readable for OverridablePublicDataTreeLeaf { fn assert_match_read_request(self, read_request: PublicDataRead) { - assert_eq(self.leaf.slot, read_request.leaf_slot, "leaf_slot in OverridablePublicDataTreeLeaf does not match read request"); - assert_eq(self.leaf.value, read_request.value, "value in OverridablePublicDataTreeLeaf does not match read request"); + assert_eq( + self.leaf.slot, read_request.leaf_slot, "leaf_slot in OverridablePublicDataTreeLeaf does not match read request" + ); + assert_eq( + self.leaf.value, read_request.value, "value in OverridablePublicDataTreeLeaf does not match read request" + ); } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_tree_leaf_preimage.nr b/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_tree_leaf_preimage.nr index 37e505aaaf8..89fc59187c0 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_tree_leaf_preimage.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/data/public_data_tree_leaf_preimage.nr @@ -9,12 +9,7 @@ struct PublicDataTreeLeafPreimage { impl Empty for PublicDataTreeLeafPreimage { fn empty() -> Self { - Self { - slot: 0, - value: 0, - next_slot: 0, - next_index: 0, - } + Self { slot: 0, value: 0, next_slot: 0, next_index: 0 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr index e6f69333319..0421cf76181 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/header.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/header.nr @@ -24,11 +24,11 @@ struct Header { impl Eq for Header { fn eq(self, other: Self) -> bool { - self.last_archive.eq(other.last_archive) & - self.content_commitment.eq(other.content_commitment) & - self.state.eq(other.state) & - self.global_variables.eq(other.global_variables) & - self.total_fees.eq(other.total_fees) + self.last_archive.eq(other.last_archive) + & self.content_commitment.eq(other.content_commitment) + & self.state.eq(other.state) + & self.global_variables.eq(other.global_variables) + & self.total_fees.eq(other.total_fees) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr index 51665f85ba4..72e77f13ffa 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/membership.nr @@ -13,10 +13,7 @@ struct MembershipWitness { impl Empty for MembershipWitness { fn empty() -> Self { - MembershipWitness { - leaf_index: 0, - sibling_path: [0; N] - } + MembershipWitness { leaf_index: 0, sibling_path: [0; N] } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr index f4b6bc3e8a0..90f346cfa62 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/merkle_tree/merkle_tree.nr @@ -7,10 +7,7 @@ struct MerkleTree { impl Empty for MerkleTree { fn empty() -> Self { - MerkleTree { - leaves: [0; N], - nodes: [0; N] - } + MerkleTree { leaves: [0; N], nodes: [0; N] } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr index ce6b62c09e6..2ba5999897c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr @@ -20,17 +20,15 @@ impl Ordered for L2ToL1Message { impl Empty for L2ToL1Message { fn empty() -> Self { - Self { - recipient: EthAddress::empty(), - content: 0, - counter: 0, - } + Self { recipient: EthAddress::empty(), content: 0, counter: 0 } } } impl Eq for L2ToL1Message { fn eq(self, other: Self) -> bool { - (self.recipient == other.recipient) & (self.content == other.content) & (self.counter == other.counter) + (self.recipient == other.recipient) + & (self.content == other.content) + & (self.counter == other.counter) } } @@ -42,11 +40,7 @@ impl Serialize for L2ToL1Message { impl Deserialize for L2ToL1Message { fn deserialize(values: [Field; L2_TO_L1_MESSAGE_LENGTH]) -> Self { - Self { - recipient: EthAddress::from_field(values[0]), - content: values[1], - counter: values[2] as u32, - } + Self { recipient: EthAddress::from_field(values[0]), content: values[1], counter: values[2] as u32 } } } @@ -88,17 +82,13 @@ impl Ordered for ScopedL2ToL1Message { impl Eq for ScopedL2ToL1Message { fn eq(self, other: ScopedL2ToL1Message) -> bool { - (self.message == other.message) - & (self.contract_address == other.contract_address) + (self.message == other.message) & (self.contract_address == other.contract_address) } } impl Empty for ScopedL2ToL1Message { fn empty() -> Self { - ScopedL2ToL1Message { - message: L2ToL1Message::empty(), - contract_address: AztecAddress::empty(), - } + ScopedL2ToL1Message { message: L2ToL1Message::empty(), contract_address: AztecAddress::empty() } } } @@ -113,7 +103,7 @@ impl Deserialize for ScopedL2ToL1Message { let mut reader = Reader::new(values); let res = Self { message: reader.read_struct(L2ToL1Message::deserialize), - contract_address: reader.read_struct(AztecAddress::deserialize), + contract_address: reader.read_struct(AztecAddress::deserialize) }; reader.finish(); res diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr b/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr index 556bd435c5f..c1a9dd30433 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/partial_state_reference.nr @@ -11,9 +11,9 @@ struct PartialStateReference { impl Eq for PartialStateReference { fn eq(self, other: PartialStateReference) -> bool { - self.note_hash_tree.eq(other.note_hash_tree) & - self.nullifier_tree.eq(other.nullifier_tree) & - self.public_data_tree.eq(other.public_data_tree) + self.note_hash_tree.eq(other.note_hash_tree) + & self.nullifier_tree.eq(other.nullifier_tree) + & self.public_data_tree.eq(other.public_data_tree) } } @@ -24,12 +24,12 @@ impl Serialize for PartialStateReference { let serialized_public_data_tree = self.public_data_tree.serialize(); [ - serialized_note_hash_tree[0], + serialized_note_hash_tree[0], serialized_note_hash_tree[1], serialized_nullifier_tree[0], serialized_nullifier_tree[1], serialized_public_data_tree[0], - serialized_public_data_tree[1], + serialized_public_data_tree[1] ] } } @@ -37,15 +37,9 @@ impl Serialize for PartialStateReference { impl Deserialize for PartialStateReference { fn deserialize(serialized: [Field; PARTIAL_STATE_REFERENCE_LENGTH]) -> PartialStateReference { PartialStateReference { - note_hash_tree: AppendOnlyTreeSnapshot::deserialize( - [serialized[0], serialized[1]] - ), - nullifier_tree: AppendOnlyTreeSnapshot::deserialize( - [serialized[2], serialized[3]] - ), - public_data_tree: AppendOnlyTreeSnapshot::deserialize( - [serialized[4], serialized[5]] - ), + note_hash_tree: AppendOnlyTreeSnapshot::deserialize([serialized[0], serialized[1]]), + nullifier_tree: AppendOnlyTreeSnapshot::deserialize([serialized[2], serialized[3]]), + public_data_tree: AppendOnlyTreeSnapshot::deserialize([serialized[4], serialized[5]]) } } } @@ -55,7 +49,7 @@ impl Empty for PartialStateReference { Self { note_hash_tree: AppendOnlyTreeSnapshot::zero(), nullifier_tree: AppendOnlyTreeSnapshot::zero(), - public_data_tree: AppendOnlyTreeSnapshot::zero(), + public_data_tree: AppendOnlyTreeSnapshot::zero() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/point.nr b/noir-projects/noir-protocol-circuits/crates/types/src/point.nr index 0a835e19816..d7aea653c61 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/point.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/point.nr @@ -19,10 +19,6 @@ impl Empty for Point { /// Note: Does not return a valid point on curve - instead represents an empty/"unpopulated" point struct (e.g. /// empty/unpopulated value in an array of points). fn empty() -> Self { - Point { - x: 0, - y: 0, - is_infinite: false - } + Point { x: 0, y: 0, is_infinite: false } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/recursion/proof.nr b/noir-projects/noir-protocol-circuits/crates/types/src/recursion/proof.nr index eb1bd1a2af4..4d3d97280a3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/recursion/proof.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/recursion/proof.nr @@ -9,22 +9,20 @@ struct RecursiveProof { impl Serialize for RecursiveProof { fn serialize(self) -> [Field; RECURSIVE_PROOF_LENGTH] { - self.fields + self.fields } } impl Deserialize for RecursiveProof { fn deserialize(fields: [Field; RECURSIVE_PROOF_LENGTH]) -> Self { - RecursiveProof { fields } + RecursiveProof { fields } } } impl Empty for RecursiveProof { - fn empty() -> Self { - RecursiveProof { - fields: [0; RECURSIVE_PROOF_LENGTH], + fn empty() -> Self { + RecursiveProof { fields: [0; RECURSIVE_PROOF_LENGTH] } } - } } struct NestedRecursiveProof { @@ -33,22 +31,20 @@ struct NestedRecursiveProof { impl Serialize for NestedRecursiveProof { fn serialize(self) -> [Field; NESTED_RECURSIVE_PROOF_LENGTH] { - self.fields + self.fields } } impl Deserialize for NestedRecursiveProof { fn deserialize(fields: [Field; NESTED_RECURSIVE_PROOF_LENGTH]) -> Self { - NestedRecursiveProof { fields } + NestedRecursiveProof { fields } } } impl Empty for NestedRecursiveProof { - fn empty() -> Self { - NestedRecursiveProof { - fields: [0; NESTED_RECURSIVE_PROOF_LENGTH], + fn empty() -> Self { + NestedRecursiveProof { fields: [0; NESTED_RECURSIVE_PROOF_LENGTH] } } - } } impl Eq for RecursiveProof { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr b/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr index 59f27758760..4c5be1ef939 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr @@ -9,39 +9,35 @@ struct VerificationKey { impl Serialize for VerificationKey { fn serialize(self) -> [Field; SERIALIZED_VERIFICATION_KEY_LENGTH] { - let mut fields = [0; SERIALIZED_VERIFICATION_KEY_LENGTH]; - for i in 0..VERIFICATION_KEY_LENGTH_IN_FIELDS { - fields[i] = self.key[i]; - } - fields[VERIFICATION_KEY_LENGTH_IN_FIELDS] = self.hash; - fields + let mut fields = [0; SERIALIZED_VERIFICATION_KEY_LENGTH]; + for i in 0..VERIFICATION_KEY_LENGTH_IN_FIELDS { + fields[i] = self.key[i]; + } + fields[VERIFICATION_KEY_LENGTH_IN_FIELDS] = self.hash; + fields } } impl Deserialize for VerificationKey { fn deserialize(fields: [Field; SERIALIZED_VERIFICATION_KEY_LENGTH]) -> Self { - let mut key = VerificationKey::empty(); - for i in 0..VERIFICATION_KEY_LENGTH_IN_FIELDS { - key.key[i] = fields[i]; - } - key.hash = fields[VERIFICATION_KEY_LENGTH_IN_FIELDS]; - key + let mut key = VerificationKey::empty(); + for i in 0..VERIFICATION_KEY_LENGTH_IN_FIELDS { + key.key[i] = fields[i]; + } + key.hash = fields[VERIFICATION_KEY_LENGTH_IN_FIELDS]; + key } } impl Empty for VerificationKey { - fn empty() -> Self { - VerificationKey { - hash: 0, - key: [0; VERIFICATION_KEY_LENGTH_IN_FIELDS], + fn empty() -> Self { + VerificationKey { hash: 0, key: [0; VERIFICATION_KEY_LENGTH_IN_FIELDS] } } - } } impl Eq for VerificationKey { fn eq(self, other: Self) -> bool { - (self.hash == other.hash) & - (self.key == other.key) + (self.hash == other.hash) & (self.key == other.key) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/scalar.nr b/noir-projects/noir-protocol-circuits/crates/types/src/scalar.nr index d06aa49c6b5..ac674bf24c9 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/scalar.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/scalar.nr @@ -10,7 +10,7 @@ impl Empty for Scalar { } impl Serialize for Scalar { - fn serialize(self) -> [Field; SCALAR_SIZE] { - [self.lo, self.hi] - } + fn serialize(self) -> [Field; SCALAR_SIZE] { + [self.lo, self.hi] + } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr b/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr index bb8449d8ef5..1f0ca7a64e5 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/state_reference.nr @@ -12,8 +12,7 @@ struct StateReference { impl Eq for StateReference { fn eq(self, other: StateReference) -> bool { - self.l1_to_l2_message_tree.eq(other.l1_to_l2_message_tree) & - self.partial.eq(other.partial) + self.l1_to_l2_message_tree.eq(other.l1_to_l2_message_tree) & self.partial.eq(other.partial) } } @@ -39,17 +38,14 @@ impl Deserialize for StateReference { StateReference { l1_to_l2_message_tree: AppendOnlyTreeSnapshot::deserialize(l1_to_l2_message_tree_fields), - partial: PartialStateReference::deserialize(partial_fields), + partial: PartialStateReference::deserialize(partial_fields) } } } impl Empty for StateReference { fn empty() -> Self { - Self { - l1_to_l2_message_tree: AppendOnlyTreeSnapshot::zero(), - partial: PartialStateReference::empty(), - } + Self { l1_to_l2_message_tree: AppendOnlyTreeSnapshot::zero(), partial: PartialStateReference::empty() } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr index 970d06352d3..b9e33389e8f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr @@ -1215,7 +1215,7 @@ impl Empty for FixtureBuilder { end_gas_left: Gas::empty(), transaction_fee: 0, public_teardown_call_stack: BoundedVec::new(), - value_offset: 0, + value_offset: 0 } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr index 0a4cda20b8c..4cc3700875a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/merkle_tree_utils.nr @@ -78,7 +78,7 @@ impl bool { - (self.value_1 == other.value_1) & (self.value_2 == other.value_2) & (self.counter == other.counter) + (self.value_1 == other.value_1) + & (self.value_2 == other.value_2) + & (self.counter == other.counter) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr index 774197d3082..f7d4058bcb5 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr @@ -15,13 +15,37 @@ trait Empty { fn empty() -> Self; } -impl Empty for Field { fn empty() -> Self {0} } +impl Empty for Field { + fn empty() -> Self { + 0 + } +} -impl Empty for u1 { fn empty() -> Self {0} } -impl Empty for u8 { fn empty() -> Self {0} } -impl Empty for u32 { fn empty() -> Self {0} } -impl Empty for u64 { fn empty() -> Self {0} } -impl Empty for U128 { fn empty() -> Self {U128::from_integer(0)} } +impl Empty for u1 { + fn empty() -> Self { + 0 + } +} +impl Empty for u8 { + fn empty() -> Self { + 0 + } +} +impl Empty for u32 { + fn empty() -> Self { + 0 + } +} +impl Empty for u64 { + fn empty() -> Self { + 0 + } +} +impl Empty for U128 { + fn empty() -> Self { + U128::from_integer(0) + } +} pub fn is_empty(item: T) -> bool where T: Empty + Eq { item.eq(T::empty()) @@ -45,11 +69,31 @@ impl ToField for Field { } } -impl ToField for bool { fn to_field(self) -> Field { self as Field } } -impl ToField for u1 { fn to_field(self) -> Field { self as Field } } -impl ToField for u8 { fn to_field(self) -> Field { self as Field } } -impl ToField for u32 { fn to_field(self) -> Field { self as Field } } -impl ToField for u64 { fn to_field(self) -> Field { self as Field } } +impl ToField for bool { + fn to_field(self) -> Field { + self as Field + } +} +impl ToField for u1 { + fn to_field(self) -> Field { + self as Field + } +} +impl ToField for u8 { + fn to_field(self) -> Field { + self as Field + } +} +impl ToField for u32 { + fn to_field(self) -> Field { + self as Field + } +} +impl ToField for u64 { + fn to_field(self) -> Field { + self as Field + } +} impl ToField for U128 { fn to_field(self) -> Field { self.to_integer() @@ -72,11 +116,31 @@ impl FromField for Field { } } -impl FromField for bool { fn from_field(value: Field) -> Self { value as bool } } -impl FromField for u1 { fn from_field(value: Field) -> Self { value as u1 } } -impl FromField for u8 { fn from_field(value: Field) -> Self { value as u8 } } -impl FromField for u32 { fn from_field(value: Field) -> Self { value as u32 } } -impl FromField for u64 { fn from_field(value: Field) -> Self { value as u64 } } +impl FromField for bool { + fn from_field(value: Field) -> Self { + value as bool + } +} +impl FromField for u1 { + fn from_field(value: Field) -> Self { + value as u1 + } +} +impl FromField for u8 { + fn from_field(value: Field) -> Self { + value as u8 + } +} +impl FromField for u32 { + fn from_field(value: Field) -> Self { + value as u32 + } +} +impl FromField for u64 { + fn from_field(value: Field) -> Self { + value as u64 + } +} impl FromField for U128 { fn from_field(value: Field) -> Self { U128::from_integer(value) diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr index 9fa947006ca..f450a1a0eb3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr @@ -19,19 +19,15 @@ impl TxContext { impl Eq for TxContext { fn eq(self, other: Self) -> bool { - (self.chain_id == other.chain_id) & - (self.version == other.version) & - (self.gas_settings.eq(other.gas_settings)) + (self.chain_id == other.chain_id) + & (self.version == other.version) + & (self.gas_settings.eq(other.gas_settings)) } } impl Empty for TxContext { fn empty() -> Self { - TxContext { - chain_id: 0, - version: 0, - gas_settings: GasSettings::empty(), - } + TxContext { chain_id: 0, version: 0, gas_settings: GasSettings::empty() } } } @@ -57,7 +53,7 @@ impl Deserialize for TxContext { let context = Self { chain_id: reader.read(), version: reader.read(), - gas_settings: reader.read_struct(GasSettings::deserialize), + gas_settings: reader.read_struct(GasSettings::deserialize) }; reader.finish(); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr index 0501d52f85a..5bc79a41c83 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_request.nr @@ -18,17 +18,17 @@ impl Empty for TxRequest { origin: AztecAddress::empty(), args_hash: 0, tx_context: TxContext::empty(), - function_data: FunctionData::empty(), + function_data: FunctionData::empty() } } } impl Eq for TxRequest { fn eq(self, other: Self) -> bool { - (self.origin == other.origin) & - (self.args_hash == other.args_hash) & - (self.tx_context == other.tx_context) & - (self.function_data == other.function_data) + (self.origin == other.origin) + & (self.args_hash == other.args_hash) + & (self.tx_context == other.tx_context) + & (self.function_data == other.function_data) } } @@ -62,7 +62,7 @@ impl Deserialize for TxRequest { origin: reader.read_struct(AztecAddress::deserialize), args_hash: reader.read(), tx_context: reader.read_struct(TxContext::deserialize), - function_data: reader.read_struct(FunctionData::deserialize), + function_data: reader.read_struct(FunctionData::deserialize) }; reader.finish(); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/type_serialization.nr b/noir-projects/noir-protocol-circuits/crates/types/src/type_serialization.nr index e7aac333e59..474901eec9c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/type_serialization.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/type_serialization.nr @@ -59,7 +59,6 @@ impl Serialize for U128 { fn serialize(self) -> [Field; 1] { [self.to_integer()] } - } impl Deserialize for U128 { From b6c529fd33c81942947f0747877d2aa2931916e7 Mon Sep 17 00:00:00 2001 From: Tom French Date: Fri, 13 Sep 2024 11:02:26 +0100 Subject: [PATCH 4/4] . --- .../crates/mock-types/src/lib.nr | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/noir-projects/mock-protocol-circuits/crates/mock-types/src/lib.nr b/noir-projects/mock-protocol-circuits/crates/mock-types/src/lib.nr index b596ed82b9e..46936a79499 100644 --- a/noir-projects/mock-protocol-circuits/crates/mock-types/src/lib.nr +++ b/noir-projects/mock-protocol-circuits/crates/mock-types/src/lib.nr @@ -14,10 +14,7 @@ struct AppPublicInputs { impl Default for AppPublicInputs { fn default() -> Self { - Self { - commitments: [0; MAX_COMMITMENTS_PER_CALL], - read_requests: [0; MAX_COMMITMENT_READ_REQUESTS_PER_CALL], - } + Self { commitments: [0; MAX_COMMITMENTS_PER_CALL], read_requests: [0; MAX_COMMITMENT_READ_REQUESTS_PER_CALL] } } } @@ -32,7 +29,7 @@ impl Default for PrivateKernelPublicInputs { Self { remaining_calls: 0, commitments: [0; MAX_COMMITMENTS_PER_TX], - read_requests: [0; MAX_COMMITMENT_READ_REQUESTS_PER_TX], + read_requests: [0; MAX_COMMITMENT_READ_REQUESTS_PER_TX] } } } @@ -98,9 +95,7 @@ struct KernelPublicInputs { impl Default for KernelPublicInputs { fn default() -> Self { - Self { - commitments: [0; MAX_COMMITMENTS_PER_TX], - } + Self { commitments: [0; MAX_COMMITMENTS_PER_TX] } } }