From 3de70d25bff58938f3b2cc1f58bd403f47309ffe Mon Sep 17 00:00:00 2001 From: AztecBot Date: Thu, 12 Sep 2024 07:16:16 +0000 Subject: [PATCH] [1 changes] chore: single install script for cargo-binstall (https://github.com/noir-lang/noir/pull/5998) fix: Error when mutating comptime variables in non-comptime code (https://github.com/noir-lang/noir/pull/6003) fix: help link was outdated (https://github.com/noir-lang/noir/pull/6004) feat: Extract brillig slice ops to reusable procedures (https://github.com/noir-lang/noir/pull/6002) feat: add assertions for ACVM `FunctionInput` `bit_size` (https://github.com/noir-lang/noir/pull/5864) feat: Sync from aztec-packages (https://github.com/noir-lang/noir/pull/6001) fix: Fix some mistakes in arithmetic generics docs (https://github.com/noir-lang/noir/pull/5999) feat: use Zac's quicksort algorithm in stdlib sorting (https://github.com/noir-lang/noir/pull/5940) fix: Fix using lazily elaborated comptime globals (https://github.com/noir-lang/noir/pull/5995) --- .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/utils/errors.rs | 2 +- .../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_frontend/src/elaborator/patterns.rs | 9 - .../src/elaborator/statements.rs | 7 + .../src/hir/comptime/interpreter.rs | 23 +- .../noirc_frontend/src/hir/comptime/value.rs | 5 + .../src/hir/resolution/errors.rs | 9 + .../noirc_frontend/src/hir_def/types.rs | 10 + .../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 +- .../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 ++ .../src/main.nr | 2 +- .../arithmetic_generics_underflow/src/main.nr | 2 +- .../comptime_globals_regression/Nargo.toml | 7 + .../comptime_globals_regression/src/main.nr | 23 + .../higher_order_functions/src/main.nr | 2 +- .../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/nargo/src/errors.rs | 4 + .../tooling/nargo/src/ops/execute.rs | 4 + noir/noir-repo/tooling/nargo/src/ops/test.rs | 12 +- .../noir_js_backend_barretenberg/package.json | 2 +- .../noir-repo/tooling/noirc_abi_wasm/build.sh | 2 +- noir/noir-repo/yarn.lock | 13 +- 80 files changed, 1281 insertions(+), 702 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/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 diff --git a/.noir-sync-commit b/.noir-sync-commit index f2fa0b3c445..b5725323376 100644 --- a/.noir-sync-commit +++ b/.noir-sync-commit @@ -1 +1 @@ -3c3ed1e3d28946a02071c524dd128afe131bc3da +21425dedcc31287431a4a25589d52d5397e974bc 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/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/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_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/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/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..180d773ff8d 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 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/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/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/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/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/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/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/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