From bc7aae577cdd74574bd8fb4c8925081697c7726d Mon Sep 17 00:00:00 2001 From: Tom French Date: Fri, 31 May 2024 14:08:51 +0100 Subject: [PATCH 1/5] chore!: remove `param_witnesses` and `return_witnesses` from ABI --- compiler/noirc_driver/src/abi_gen.rs | 93 +------------ compiler/noirc_driver/src/lib.rs | 21 +-- .../getting_started/tooling/noir_codegen.md | 3 +- tooling/nargo_cli/src/cli/debug_cmd.rs | 3 +- tooling/nargo_cli/src/cli/execute_cmd.rs | 3 +- .../test/public_input_deflattening.test.ts | 15 --- tooling/noir_js_types/src/types.ts | 2 - tooling/noirc_abi/src/input_parser/mod.rs | 3 - tooling/noirc_abi/src/lib.rs | 122 +++++------------- 9 files changed, 44 insertions(+), 221 deletions(-) diff --git a/compiler/noirc_driver/src/abi_gen.rs b/compiler/noirc_driver/src/abi_gen.rs index 609c88b92c2..71dd1b18761 100644 --- a/compiler/noirc_driver/src/abi_gen.rs +++ b/compiler/noirc_driver/src/abi_gen.rs @@ -1,8 +1,7 @@ use std::collections::BTreeMap; use acvm::acir::circuit::ErrorSelector; -use acvm::acir::native_types::Witness; -use iter_extended::{btree_map, vecmap}; +use iter_extended::vecmap; use noirc_abi::{Abi, AbiErrorType, AbiParameter, AbiReturnType, AbiType, AbiValue}; use noirc_frontend::ast::Visibility; use noirc_frontend::{ @@ -11,27 +10,23 @@ use noirc_frontend::{ macros_api::{HirExpression, HirLiteral}, node_interner::{FuncId, NodeInterner}, }; -use std::ops::Range; /// Arranges a function signature and a generated circuit's return witnesses into a /// `noirc_abi::Abi`. pub(super) fn gen_abi( context: &Context, func_id: &FuncId, - input_witnesses: Vec, - return_witnesses: Vec, return_visibility: Visibility, error_types: BTreeMap, ) -> Abi { let (parameters, return_type) = compute_function_abi(context, func_id); - let param_witnesses = param_witnesses_from_abi_param(¶meters, input_witnesses); let return_type = return_type .map(|typ| AbiReturnType { abi_type: typ, visibility: return_visibility.into() }); let error_types = error_types .into_iter() .map(|(selector, typ)| (selector, AbiErrorType::from_type(context, &typ))) .collect(); - Abi { parameters, return_type, param_witnesses, return_witnesses, error_types } + Abi { parameters, return_type, error_types } } pub(super) fn compute_function_abi( @@ -67,55 +62,6 @@ fn into_abi_params(context: &Context, params: Vec) -> Vec { }) } -// Takes each abi parameter and shallowly maps to the expected witness range in which the -// parameter's constituent values live. -fn param_witnesses_from_abi_param( - abi_params: &[AbiParameter], - input_witnesses: Vec, -) -> BTreeMap>> { - let mut idx = 0_usize; - if input_witnesses.is_empty() { - return BTreeMap::new(); - } - - btree_map(abi_params, |param| { - let num_field_elements_needed = param.typ.field_count() as usize; - let param_witnesses = &input_witnesses[idx..idx + num_field_elements_needed]; - - // It's likely that `param_witnesses` will consist of mostly incrementing witness indices. - // We then want to collapse these into `Range`s to save space. - let param_witnesses = collapse_ranges(param_witnesses); - idx += num_field_elements_needed; - (param.name.clone(), param_witnesses) - }) -} - -/// Takes a vector of [`Witnesses`][`Witness`] and collapses it into a vector of [`Range`]s of [`Witnesses`][`Witness`]. -fn collapse_ranges(witnesses: &[Witness]) -> Vec> { - if witnesses.is_empty() { - return Vec::new(); - } - let mut wit = Vec::new(); - let mut last_wit: Witness = witnesses[0]; - - for (i, witness) in witnesses.iter().enumerate() { - if i == 0 { - continue; - }; - let witness_index = witness.witness_index(); - let prev_witness_index = witnesses[i - 1].witness_index(); - if witness_index != prev_witness_index + 1 { - wit.push(last_wit..Witness(prev_witness_index + 1)); - last_wit = *witness; - }; - } - - let last_witness = witnesses.last().unwrap().witness_index(); - wit.push(last_wit..Witness(last_witness + 1)); - - wit -} - pub(super) fn value_from_hir_expression(context: &Context, expression: HirExpression) -> AbiValue { match expression { HirExpression::Tuple(expr_ids) => { @@ -169,38 +115,3 @@ pub(super) fn value_from_hir_expression(context: &Context, expression: HirExpres _ => unreachable!("Type cannot be used in the abi {:?}", expression), } } - -#[cfg(test)] -mod test { - use std::ops::Range; - - use acvm::acir::native_types::Witness; - - use super::collapse_ranges; - - #[test] - fn collapses_single_range() { - let witnesses: Vec<_> = vec![1, 2, 3].into_iter().map(Witness::from).collect(); - - let collapsed_witnesses = collapse_ranges(&witnesses); - - assert_eq!(collapsed_witnesses, vec![Range { start: Witness(1), end: Witness(4) },]); - } - - #[test] - fn collapse_ranges_correctly() { - let witnesses: Vec<_> = - vec![1, 2, 3, 5, 6, 2, 3, 4].into_iter().map(Witness::from).collect(); - - let collapsed_witnesses = collapse_ranges(&witnesses); - - assert_eq!( - collapsed_witnesses, - vec![ - Range { start: Witness(1), end: Witness(4) }, - Range { start: Witness(5), end: Witness(7) }, - Range { start: Witness(2), end: Witness(5) } - ] - ); - } -} diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index d7368f299b8..ea53ed1da55 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -531,17 +531,9 @@ pub fn compile_no_check( info!("Program matches existing artifact, returning early"); return Ok(cached_program.expect("cache must exist for hashes to match")); } - let visibility = program.return_visibility; + let return_visibility = program.return_visibility; - let SsaProgramArtifact { - program, - debug, - warnings, - main_input_witnesses, - main_return_witnesses, - names, - error_types, - } = create_program( + let SsaProgramArtifact { program, debug, warnings, names, error_types, .. } = create_program( program, options.show_ssa, options.show_brillig, @@ -549,14 +541,7 @@ pub fn compile_no_check( options.benchmark_codegen, )?; - let abi = abi_gen::gen_abi( - context, - &main_function, - main_input_witnesses, - main_return_witnesses, - visibility, - error_types, - ); + let abi = abi_gen::gen_abi(context, &main_function, return_visibility, error_types); let file_map = filter_relevant_files(&debug, &context.file_manager); Ok(CompiledProgram { diff --git a/docs/docs/getting_started/tooling/noir_codegen.md b/docs/docs/getting_started/tooling/noir_codegen.md index 1c040585340..f7505bef7ab 100644 --- a/docs/docs/getting_started/tooling/noir_codegen.md +++ b/docs/docs/getting_started/tooling/noir_codegen.md @@ -100,7 +100,8 @@ After the export and codegen steps, you should have an `index.ts` like: export type Field = string; -export const is_equal_circuit: CompiledCircuit = {"abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"private"},{"name":"y","type":{"kind":"field"},"visibility":"private"}],"param_witnesses":{"x":[{"start":0,"end":1}],"y":[{"start":1,"end":2}]},"return_type":{"abi_type":{"kind":"boolean"},"visibility":"private"},"return_witnesses":[4]},"bytecode":"H4sIAAAAAAAA/7WUMQ7DIAxFQ0Krrr2JjSGYLVcpKrn/CaqqDQN12WK+hPBgmWd/wEyHbF1SS923uhOs3pfoChI+wKXMAXzIKyNj4PB0TFTYc0w5RUjoqeAeEu1wqK0F54RGkWvW44LPzExnlkbMEs4JNZmN8PxS42uHv82T8a3Jeyn2Ks+VLPcO558HmyLMCDOXAXXtpPt4R/Rt9T36ss6dS9HGPx/eG17nGegKBQAA"}; +export const is_equal_circuit: CompiledCircuit = +{"abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"private"},{"name":"y","type":{"kind":"field"},"visibility":"private"}],"return_type":{"abi_type":{"kind":"boolean"},"visibility":"private"}},"bytecode":"H4sIAAAAAAAA/7WUMQ7DIAxFQ0Krrr2JjSGYLVcpKrn/CaqqDQN12WK+hPBgmWd/wEyHbF1SS923uhOs3pfoChI+wKXMAXzIKyNj4PB0TFTYc0w5RUjoqeAeEu1wqK0F54RGkWvW44LPzExnlkbMEs4JNZmN8PxS42uHv82T8a3Jeyn2Ks+VLPcO558HmyLMCDOXAXXtpPt4R/Rt9T36ss6dS9HGPx/eG17nGegKBQAA"}; export async function is_equal(x: Field, y: Field, foreignCallHandler?: ForeignCallHandler): Promise { const program = new Noir(is_equal_circuit); diff --git a/tooling/nargo_cli/src/cli/debug_cmd.rs b/tooling/nargo_cli/src/cli/debug_cmd.rs index ebcd9ff6569..086dddc27e5 100644 --- a/tooling/nargo_cli/src/cli/debug_cmd.rs +++ b/tooling/nargo_cli/src/cli/debug_cmd.rs @@ -205,11 +205,10 @@ fn debug_program_and_decode( let (inputs_map, _) = read_inputs_from_file(&package.root_dir, prover_name, Format::Toml, &program.abi)?; let solved_witness = debug_program(&program, &inputs_map)?; - let public_abi = program.abi.public_abi(); match solved_witness { Some(witness) => { - let (_, return_value) = public_abi.decode(&witness)?; + let (_, return_value) = program.abi.decode(&witness)?; Ok((return_value, Some(witness))) } None => Ok((None, None)), diff --git a/tooling/nargo_cli/src/cli/execute_cmd.rs b/tooling/nargo_cli/src/cli/execute_cmd.rs index 5d6754b29f7..b548336275b 100644 --- a/tooling/nargo_cli/src/cli/execute_cmd.rs +++ b/tooling/nargo_cli/src/cli/execute_cmd.rs @@ -97,11 +97,10 @@ fn execute_program_and_decode( let (inputs_map, _) = read_inputs_from_file(&package.root_dir, prover_name, Format::Toml, &program.abi)?; let witness_stack = execute_program(&program, &inputs_map, foreign_call_resolver_url)?; - let public_abi = program.abi.public_abi(); // Get the entry point witness for the ABI let main_witness = &witness_stack.peek().expect("Should have at least one witness on the stack").witness; - let (_, return_value) = public_abi.decode(main_witness)?; + let (_, return_value) = program.abi.decode(main_witness)?; Ok((return_value, witness_stack)) } diff --git a/tooling/noir_js_backend_barretenberg/test/public_input_deflattening.test.ts b/tooling/noir_js_backend_barretenberg/test/public_input_deflattening.test.ts index cfd43eff250..cfcf93ecd2c 100644 --- a/tooling/noir_js_backend_barretenberg/test/public_input_deflattening.test.ts +++ b/tooling/noir_js_backend_barretenberg/test/public_input_deflattening.test.ts @@ -23,20 +23,6 @@ const abi: Abi = { visibility: 'public', }, ], - param_witnesses: { - array_with_returned_element: [ - { - start: 1, - end: 11, - }, - ], - pub_field: [ - { - start: 11, - end: 12, - }, - ], - }, return_type: { abi_type: { kind: 'tuple', @@ -54,7 +40,6 @@ const abi: Abi = { }, visibility: 'public', }, - return_witnesses: [2, 13, 13], error_types: {}, }; diff --git a/tooling/noir_js_types/src/types.ts b/tooling/noir_js_types/src/types.ts index 0258f2f90c9..dd6548ddb6c 100644 --- a/tooling/noir_js_types/src/types.ts +++ b/tooling/noir_js_types/src/types.ts @@ -38,9 +38,7 @@ export type WitnessMap = Map; export type Abi = { parameters: AbiParameter[]; - param_witnesses: Record; return_type: { abi_type: AbiType; visibility: Visibility } | null; - return_witnesses: number[]; error_types: Record; }; diff --git a/tooling/noirc_abi/src/input_parser/mod.rs b/tooling/noirc_abi/src/input_parser/mod.rs index 14d92bc71b3..d7bbb0adfe3 100644 --- a/tooling/noirc_abi/src/input_parser/mod.rs +++ b/tooling/noirc_abi/src/input_parser/mod.rs @@ -267,9 +267,6 @@ mod serialization_tests { abi_type: AbiType::String { length: 5 }, visibility: AbiVisibility::Public, }), - // These two fields are unused when serializing/deserializing to file. - param_witnesses: BTreeMap::new(), - return_witnesses: Vec::new(), error_types: Default::default(), }; diff --git a/tooling/noirc_abi/src/lib.rs b/tooling/noirc_abi/src/lib.rs index 0acace71fb3..94fb5799515 100644 --- a/tooling/noirc_abi/src/lib.rs +++ b/tooling/noirc_abi/src/lib.rs @@ -20,7 +20,7 @@ use noirc_printable_type::{ PrintableValueDisplay, }; use serde::{Deserialize, Serialize}; -use std::{borrow::Borrow, ops::Range}; +use std::borrow::Borrow; use std::{collections::BTreeMap, str}; // This is the ABI used to bridge the different TOML formats for the initial // witness, the partial witness generator and the interpreter. @@ -267,11 +267,7 @@ pub struct AbiReturnType { pub struct Abi { /// An ordered list of the arguments to the program's `main` function, specifying their types and visibility. pub parameters: Vec, - /// A map from the ABI's parameters to the indices they are written to in the [`WitnessMap`]. - /// This defines how to convert between the [`InputMap`] and [`WitnessMap`]. - pub param_witnesses: BTreeMap>>, pub return_type: Option, - pub return_witnesses: Vec, pub error_types: BTreeMap, } @@ -307,25 +303,6 @@ impl Abi { map } - /// ABI with only the public parameters - #[must_use] - pub fn public_abi(self) -> Abi { - let parameters: Vec<_> = - self.parameters.into_iter().filter(|param| param.is_public()).collect(); - let param_witnesses = self - .param_witnesses - .into_iter() - .filter(|(param_name, _)| parameters.iter().any(|param| ¶m.name == param_name)) - .collect(); - Abi { - parameters, - param_witnesses, - return_type: self.return_type, - return_witnesses: self.return_witnesses, - error_types: self.error_types, - } - } - /// Encode a set of inputs as described in the ABI into a `WitnessMap`. pub fn encode( &self, @@ -341,34 +318,21 @@ impl Abi { } // First encode each input separately, performing any input validation. - let encoded_input_map: BTreeMap> = self - .to_btree_map() - .into_iter() - .map(|(param_name, expected_type)| { + let mut encoded_inputs: Vec> = self + .parameters + .iter() + .map(|param| { let value = input_map - .get(¶m_name) - .ok_or_else(|| AbiError::MissingParam(param_name.clone()))? + .get(¶m.name) + .ok_or_else(|| AbiError::MissingParam(param.name.clone()))? .clone(); - value.find_type_mismatch(&expected_type, param_name.clone())?; + value.find_type_mismatch(¶m.typ, param.name.clone())?; - Self::encode_value(value, &expected_type).map(|v| (param_name, v)) + Self::encode_value(value, ¶m.typ) }) .collect::>()?; - // Write input field elements into witness indices specified in `self.param_witnesses`. - let mut witness_map: BTreeMap = encoded_input_map - .iter() - .flat_map(|(param_name, encoded_param_fields)| { - let param_witness_indices = range_to_vec(&self.param_witnesses[param_name]); - param_witness_indices - .iter() - .zip(encoded_param_fields.iter()) - .map(|(&witness, &field_element)| (witness, field_element)) - .collect::>() - }) - .collect::>(); - // When encoding public inputs to be passed to the verifier, the user can must provide a return value // to be inserted into the witness map. This is not needed when generating a witness when proving the circuit. match (&self.return_type, return_value) { @@ -380,18 +344,7 @@ impl Abi { }); } let encoded_return_fields = Self::encode_value(return_value, return_type)?; - - // We need to be more careful when writing the return value's witness values. - // This is as it may share witness indices with other public inputs so we must check that when - // this occurs the witness values are consistent with each other. - self.return_witnesses.iter().zip(encoded_return_fields.iter()).try_for_each( - |(&witness, &field_element)| match witness_map.insert(witness, field_element) { - Some(existing_value) if existing_value != field_element => { - Err(AbiError::InconsistentWitnessAssignment(witness)) - } - _ => Ok(()), - }, - )?; + encoded_inputs.push(encoded_return_fields); } (None, Some(return_value)) => { return Err(AbiError::UnexpectedReturnValue(return_value)) @@ -401,6 +354,14 @@ impl Abi { (_, None) => {} } + // Write input field elements into witness map. + let witness_map: BTreeMap = encoded_inputs + .into_iter() + .flatten() + .enumerate() + .map(|(index, field_element)| (Witness(index as u32), field_element)) + .collect::>(); + Ok(witness_map.into()) } @@ -441,18 +402,21 @@ impl Abi { &self, witness_map: &WitnessMap, ) -> Result<(InputMap, Option), AbiError> { + let mut pointer: u32 = 0; let public_inputs_map = try_btree_map(self.parameters.clone(), |AbiParameter { name, typ, .. }| { - let param_witness_values = - try_vecmap(range_to_vec(&self.param_witnesses[&name]), |witness_index| { - witness_map - .get(&witness_index) - .ok_or_else(|| AbiError::MissingParamWitnessValue { - name: name.clone(), - witness_index, - }) - .copied() - })?; + let num_fields = typ.field_count(); + let param_witness_values = try_vecmap(0..num_fields, |index| { + let witness_index = Witness(pointer + index); + witness_map + .get(&witness_index) + .ok_or_else(|| AbiError::MissingParamWitnessValue { + name: name.clone(), + witness_index, + }) + .copied() + })?; + pointer += num_fields; decode_value(&mut param_witness_values.into_iter(), &typ) .map(|input_value| (name.clone(), input_value)) @@ -461,7 +425,8 @@ impl Abi { // We also attempt to decode the circuit's return value from `witness_map`. let return_value = if let Some(return_type) = &self.return_type { if let Ok(return_witness_values) = - try_vecmap(self.return_witnesses.clone(), |witness_index| { + try_vecmap(0..return_type.abi_type.field_count(), |index| { + let witness_index = Witness(pointer + index); witness_map .get(&witness_index) .ok_or_else(|| AbiError::MissingParamWitnessValue { @@ -587,16 +552,6 @@ pub enum AbiValue { }, } -fn range_to_vec(ranges: &[Range]) -> Vec { - let mut result = Vec::new(); - for range in ranges { - for witness in range.start.witness_index()..range.end.witness_index() { - result.push(witness.into()); - } - } - result -} - #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(tag = "error_kind", rename_all = "lowercase")] pub enum AbiErrorType { @@ -652,7 +607,7 @@ pub fn display_abi_error( mod test { use std::collections::BTreeMap; - use acvm::{acir::native_types::Witness, AcirField, FieldElement}; + use acvm::{AcirField, FieldElement}; use crate::{ input_parser::InputValue, Abi, AbiParameter, AbiReturnType, AbiType, AbiVisibility, @@ -674,16 +629,10 @@ mod test { visibility: AbiVisibility::Public, }, ], - // Note that the return value shares a witness with `thing2` - param_witnesses: BTreeMap::from([ - ("thing1".to_string(), vec![(Witness(1)..Witness(3))]), - ("thing2".to_string(), vec![(Witness(3)..Witness(4))]), - ]), return_type: Some(AbiReturnType { abi_type: AbiType::Field, visibility: AbiVisibility::Public, }), - return_witnesses: vec![Witness(3)], error_types: BTreeMap::default(), }; @@ -706,7 +655,6 @@ mod test { assert_eq!(reconstructed_inputs[&key], expected_value); } - // We also decode the return value (we can do this immediately as we know it shares a witness with an input). - assert_eq!(return_value.unwrap(), reconstructed_inputs["thing2"]); + assert!(return_value.is_none()); } } From bf0a1a6e587152e2a94ff6092108af7d20e8d026 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Tue, 4 Jun 2024 11:45:41 +0000 Subject: [PATCH 2/5] chore: remove `publicInputsToWitnessMap` --- .../noir_js_backend_barretenberg/src/index.ts | 1 - .../src/public_inputs.ts | 26 +------------------ 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/tooling/noir_js_backend_barretenberg/src/index.ts b/tooling/noir_js_backend_barretenberg/src/index.ts index f28abb9a658..cefef07520f 100644 --- a/tooling/noir_js_backend_barretenberg/src/index.ts +++ b/tooling/noir_js_backend_barretenberg/src/index.ts @@ -1,6 +1,5 @@ export { BarretenbergBackend } from './backend.js'; export { BarretenbergVerifier } from './verifier.js'; -export { publicInputsToWitnessMap } from './public_inputs.js'; // typedoc exports export { Backend, CompiledCircuit, ProofData } from '@noir-lang/types'; diff --git a/tooling/noir_js_backend_barretenberg/src/public_inputs.ts b/tooling/noir_js_backend_barretenberg/src/public_inputs.ts index 75ee0de6800..ed771ab0d34 100644 --- a/tooling/noir_js_backend_barretenberg/src/public_inputs.ts +++ b/tooling/noir_js_backend_barretenberg/src/public_inputs.ts @@ -1,4 +1,4 @@ -import { Abi, WitnessMap } from '@noir-lang/types'; +import { WitnessMap } from '@noir-lang/types'; export function flattenPublicInputsAsArray(publicInputs: string[]): Uint8Array { const flattenedPublicInputs = publicInputs.map(hexToUint8Array); @@ -23,30 +23,6 @@ export function witnessMapToPublicInputs(publicInputs: WitnessMap): string[] { return flattenedPublicInputs; } -export function publicInputsToWitnessMap(publicInputs: string[], abi: Abi): WitnessMap { - const return_value_witnesses = abi.return_witnesses; - const public_parameters = abi.parameters.filter((param) => param.visibility === 'public'); - const public_parameter_witnesses: number[] = public_parameters.flatMap((param) => - abi.param_witnesses[param.name].flatMap((witness_range) => - Array.from({ length: witness_range.end - witness_range.start }, (_, i) => witness_range.start + i), - ), - ); - - // We now have an array of witness indices which have been deduplicated and sorted in ascending order. - // The elements of this array should correspond to the elements of `flattenedPublicInputs` so that we can build up a `WitnessMap`. - const public_input_witnesses = [...new Set(public_parameter_witnesses.concat(return_value_witnesses))].sort( - (a, b) => a - b, - ); - - const witnessMap: WitnessMap = new Map(); - public_input_witnesses.forEach((witness_index, index) => { - const witness_value = publicInputs[index]; - witnessMap.set(witness_index, witness_value); - }); - - return witnessMap; -} - function flattenUint8Arrays(arrays: Uint8Array[]): Uint8Array { const totalLength = arrays.reduce((acc, val) => acc + val.length, 0); const result = new Uint8Array(totalLength); From 69a538bf5b63aa1e35ad2a5ec7d269b3bee683cf Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Tue, 4 Jun 2024 12:22:23 +0000 Subject: [PATCH 3/5] chore: remove unnecessary tests --- .../test/public_input_deflattening.test.ts | 82 ------------------- 1 file changed, 82 deletions(-) delete mode 100644 tooling/noir_js_backend_barretenberg/test/public_input_deflattening.test.ts diff --git a/tooling/noir_js_backend_barretenberg/test/public_input_deflattening.test.ts b/tooling/noir_js_backend_barretenberg/test/public_input_deflattening.test.ts deleted file mode 100644 index cfcf93ecd2c..00000000000 --- a/tooling/noir_js_backend_barretenberg/test/public_input_deflattening.test.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { Abi } from '@noir-lang/types'; -import { expect } from 'chai'; -import { witnessMapToPublicInputs, publicInputsToWitnessMap } from '../src/public_inputs.js'; - -const abi: Abi = { - parameters: [ - { - name: 'array_with_returned_element', - type: { - kind: 'array', - type: { - kind: 'field', - }, - length: 10, - }, - visibility: 'private', - }, - { - name: 'pub_field', - type: { - kind: 'field', - }, - visibility: 'public', - }, - ], - return_type: { - abi_type: { - kind: 'tuple', - fields: [ - { - kind: 'field', - }, - { - kind: 'field', - }, - { - kind: 'field', - }, - ], - }, - visibility: 'public', - }, - error_types: {}, -}; - -it('flattens a witness map in order of its witness indices', async () => { - // Note that these are not in ascending order. This means that if we read from `witness_map` in insertion order - // then the witness values will be sorted incorrectly. - const public_input_indices = [2, 13, 11]; - - const witness_map = new Map( - public_input_indices.map((witness_index) => [ - witness_index, - '0x' + BigInt(witness_index).toString(16).padStart(64, '0'), - ]), - ); - - const flattened_public_inputs = witnessMapToPublicInputs(witness_map); - expect(flattened_public_inputs).to.be.deep.eq([ - '0x0000000000000000000000000000000000000000000000000000000000000002', - '0x000000000000000000000000000000000000000000000000000000000000000b', - '0x000000000000000000000000000000000000000000000000000000000000000d', - ]); -}); - -it('recovers the original witness map when deflattening a public input array', async () => { - // Note that these are not in ascending order. This means that if we read from `witness_map` in insertion order - // then the witness values will be sorted incorrectly. - const public_input_indices = [2, 13, 11]; - - const witness_map = new Map( - public_input_indices.map((witness_index) => [ - witness_index, - '0x' + BigInt(witness_index).toString(16).padStart(64, '0'), - ]), - ); - - const flattened_public_inputs = witnessMapToPublicInputs(witness_map); - const deflattened_public_inputs = publicInputsToWitnessMap(flattened_public_inputs, abi); - - expect(deflattened_public_inputs).to.be.deep.eq(witness_map); -}); From 34e272225dbb0323643c6fd9f07064a193eb0041 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Tue, 4 Jun 2024 14:08:29 +0000 Subject: [PATCH 4/5] chore: remove tests from `noir_js_backend_barretenberg` --- tooling/noir_js_backend_barretenberg/package.json | 3 --- yarn.lock | 2 -- 2 files changed, 5 deletions(-) diff --git a/tooling/noir_js_backend_barretenberg/package.json b/tooling/noir_js_backend_barretenberg/package.json index 10fd14a0090..af3011068bf 100644 --- a/tooling/noir_js_backend_barretenberg/package.json +++ b/tooling/noir_js_backend_barretenberg/package.json @@ -34,7 +34,6 @@ "generate:package": "bash ./fixup.sh", "build": "yarn clean && tsc && tsc -p ./tsconfig.cjs.json && yarn generate:package", "clean": "rm -rf ./lib", - "test": "mocha --timeout 25000 --exit --config ./.mocharc.json", "prettier": "prettier 'src/**/*.ts'", "prettier:fix": "prettier --write 'src/**/*.ts' 'test/**/*.ts'", "nightly:version": "jq --arg new_version \"-$(git rev-parse --short HEAD)$1\" '.version = .version + $new_version' package.json > package-tmp.json && mv package-tmp.json package.json", @@ -49,10 +48,8 @@ "devDependencies": { "@types/node": "^20.6.2", "@types/prettier": "^3", - "chai": "^4.4.1", "eslint": "^8.57.0", "eslint-plugin-prettier": "^5.1.3", - "mocha": "^10.2.0", "prettier": "3.2.5", "ts-node": "^10.9.1", "typescript": "5.4.2" diff --git a/yarn.lock b/yarn.lock index 8fb574afa30..a947ec56aba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4400,11 +4400,9 @@ __metadata: "@noir-lang/types": "workspace:*" "@types/node": ^20.6.2 "@types/prettier": ^3 - chai: ^4.4.1 eslint: ^8.57.0 eslint-plugin-prettier: ^5.1.3 fflate: ^0.8.0 - mocha: ^10.2.0 prettier: 3.2.5 ts-node: ^10.9.1 typescript: 5.4.2 From c7281e82e45b55cbd8861eb6c77d4f1939d66838 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Tue, 4 Jun 2024 14:13:39 +0000 Subject: [PATCH 5/5] chore: remove job from CI --- .github/workflows/test-js-packages.yml | 27 -------------------------- 1 file changed, 27 deletions(-) diff --git a/.github/workflows/test-js-packages.yml b/.github/workflows/test-js-packages.yml index db162e21269..9f46e6f98e8 100644 --- a/.github/workflows/test-js-packages.yml +++ b/.github/workflows/test-js-packages.yml @@ -221,32 +221,6 @@ jobs: - name: Run browser tests run: yarn workspace @noir-lang/noirc_abi test:browser - test-noir-js-backend-barretenberg: - needs: [build-noirc-abi] - name: noir-js-backend-barretenberg - runs-on: ubuntu-latest - timeout-minutes: 30 - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Download wasm package artifact - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: ./tooling/noirc_abi_wasm - - - name: Install Yarn dependencies - uses: ./.github/actions/setup - - - name: Build noir_js_types - run: yarn workspace @noir-lang/types build - - - name: Run barretenberg wrapper tests - run: | - yarn workspace @noir-lang/backend_barretenberg test - test-noir-js: needs: [build-nargo, build-acvm-js, build-noirc-abi] name: Noir JS @@ -546,7 +520,6 @@ jobs: - test-acvm_js-node - test-acvm_js-browser - test-noirc-abi - - test-noir-js-backend-barretenberg - test-noir-js - test-noir-wasm - test-noir-codegen