diff --git a/Cargo.lock b/Cargo.lock index 6051d356fca..407b4771af5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,7 +30,6 @@ dependencies = [ "cfg-if", "hex", "num-bigint", - "num-traits", "serde", ] diff --git a/acvm-repo/acir_field/Cargo.toml b/acvm-repo/acir_field/Cargo.toml index 10027519d6d..7d059e9e4be 100644 --- a/acvm-repo/acir_field/Cargo.toml +++ b/acvm-repo/acir_field/Cargo.toml @@ -16,7 +16,6 @@ repository.workspace = true hex.workspace = true num-bigint.workspace = true serde.workspace = true -num-traits.workspace = true ark-bn254 = { version = "^0.4.0", optional = true, default-features = false, features = [ "curve", diff --git a/acvm-repo/acir_field/src/lib.rs b/acvm-repo/acir_field/src/lib.rs index eafe4bb2ad4..6d4547868cc 100644 --- a/acvm-repo/acir_field/src/lib.rs +++ b/acvm-repo/acir_field/src/lib.rs @@ -3,9 +3,6 @@ #![warn(clippy::semicolon_if_nothing_returned)] #![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))] -use num_bigint::BigUint; -use num_traits::Num; - cfg_if::cfg_if! { if #[cfg(feature = "bn254")] { mod generic_ark; @@ -21,33 +18,12 @@ cfg_if::cfg_if! { } } -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug)] pub enum FieldOptions { BN254, BLS12_381, } -impl FieldOptions { - pub fn to_string(&self) -> &str { - match self { - FieldOptions::BN254 => "bn254", - FieldOptions::BLS12_381 => "bls12_381", - } - } - - pub fn is_native_field(str: &str) -> bool { - let big_num = if let Some(hex) = str.strip_prefix("0x") { - BigUint::from_str_radix(hex, 16) - } else { - BigUint::from_str_radix(str, 10) - }; - if let Ok(big_num) = big_num { - big_num == FieldElement::modulus() - } else { - CHOSEN_FIELD.to_string() == str - } - } -} // This is needed because features are additive through the dependency graph; if a dependency turns on the bn254, then it // will be turned on in all crates that depend on it #[macro_export] diff --git a/acvm-repo/acvm/src/compiler/optimizers/general.rs b/acvm-repo/acvm/src/compiler/optimizers/general.rs index 2bd781f7bb5..50271348c11 100644 --- a/acvm-repo/acvm/src/compiler/optimizers/general.rs +++ b/acvm-repo/acvm/src/compiler/optimizers/general.rs @@ -31,7 +31,7 @@ fn simplify_mul_terms(mut gate: Expression) -> Expression { let mut hash_map: IndexMap<(Witness, Witness), FieldElement> = IndexMap::new(); // Canonicalize the ordering of the multiplication, lets just order by variable name - for (scale, w_l, w_r) in gate.mul_terms.into_iter() { + for (scale, w_l, w_r) in gate.mul_terms.clone().into_iter() { let mut pair = [w_l, w_r]; // Sort using rust sort algorithm pair.sort(); diff --git a/acvm-repo/acvm/src/compiler/optimizers/mod.rs b/acvm-repo/acvm/src/compiler/optimizers/mod.rs index 627ddbb4117..c63cfdf9c82 100644 --- a/acvm-repo/acvm/src/compiler/optimizers/mod.rs +++ b/acvm-repo/acvm/src/compiler/optimizers/mod.rs @@ -23,22 +23,20 @@ pub fn optimize(acir: Circuit) -> (Circuit, AcirTransformationMap) { /// Applies [`ProofSystemCompiler`][crate::ProofSystemCompiler] independent optimizations to a [`Circuit`]. pub(super) fn optimize_internal(acir: Circuit) -> (Circuit, AcirTransformationMap) { // General optimizer pass - let opcodes: Vec = acir - .opcodes - .into_iter() - .map(|opcode| { - if let Opcode::Arithmetic(arith_expr) = opcode { - Opcode::Arithmetic(GeneralOptimizer::optimize(arith_expr)) - } else { - opcode + let mut opcodes: Vec = Vec::new(); + for opcode in acir.opcodes { + match opcode { + Opcode::Arithmetic(arith_expr) => { + opcodes.push(Opcode::Arithmetic(GeneralOptimizer::optimize(arith_expr))); } - }) - .collect(); + other_opcode => opcodes.push(other_opcode), + }; + } let acir = Circuit { opcodes, ..acir }; // Track original acir opcode positions throughout the transformation passes of the compilation // by applying the modifications done to the circuit opcodes and also to the opcode_positions (delete and insert) - let acir_opcode_positions = (0..acir.opcodes.len()).collect(); + let acir_opcode_positions = acir.opcodes.iter().enumerate().map(|(i, _)| i).collect(); // Unused memory optimization pass let memory_optimizer = UnusedMemoryOptimizer::new(acir); diff --git a/acvm-repo/acvm/src/compiler/optimizers/redundant_range.rs b/acvm-repo/acvm/src/compiler/optimizers/redundant_range.rs index b1696704108..9833a31a199 100644 --- a/acvm-repo/acvm/src/compiler/optimizers/redundant_range.rs +++ b/acvm-repo/acvm/src/compiler/optimizers/redundant_range.rs @@ -74,13 +74,13 @@ 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 extract_range_opcode(&opcode) { + for (idx, opcode) in self.circuit.opcodes.iter().enumerate() { + let (witness, num_bits) = match extract_range_opcode(opcode) { Some(range_opcode) => range_opcode, None => { // If its not the range opcode, add it to the opcode // list and continue; - optimized_opcodes.push(opcode); + optimized_opcodes.push(opcode.clone()); new_order_list.push(order_list[idx]); continue; } @@ -101,11 +101,18 @@ impl RangeOptimizer { if is_lowest_bit_size { already_seen_witness.insert(witness); new_order_list.push(order_list[idx]); - optimized_opcodes.push(opcode); + optimized_opcodes.push(opcode.clone()); } } - (Circuit { opcodes: optimized_opcodes, ..self.circuit }, new_order_list) + ( + Circuit { + current_witness_index: self.circuit.current_witness_index, + opcodes: optimized_opcodes, + ..self.circuit + }, + new_order_list, + ) } } diff --git a/acvm-repo/acvm/src/compiler/optimizers/unused_memory.rs b/acvm-repo/acvm/src/compiler/optimizers/unused_memory.rs index 18eefa79ac2..eccea631723 100644 --- a/acvm-repo/acvm/src/compiler/optimizers/unused_memory.rs +++ b/acvm-repo/acvm/src/compiler/optimizers/unused_memory.rs @@ -42,16 +42,16 @@ impl UnusedMemoryOptimizer { ) -> (Circuit, Vec) { 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() { + for (idx, opcode) in self.circuit.opcodes.iter().enumerate() { match opcode { Opcode::MemoryInit { block_id, .. } - if self.unused_memory_initializations.contains(&block_id) => + if self.unused_memory_initializations.contains(block_id) => { // Drop opcode } _ => { new_order_list.push(order_list[idx]); - optimized_opcodes.push(opcode); + optimized_opcodes.push(opcode.clone()); } } } diff --git a/acvm-repo/acvm/src/compiler/transformers/mod.rs b/acvm-repo/acvm/src/compiler/transformers/mod.rs index 6f9d78e4b93..3a3a013e8eb 100644 --- a/acvm-repo/acvm/src/compiler/transformers/mod.rs +++ b/acvm-repo/acvm/src/compiler/transformers/mod.rs @@ -76,13 +76,13 @@ pub(super) fn transform_internal( // maps a normalized expression to the intermediate variable which represents the expression, along with its 'norm' // the 'norm' is simply the value of the first non zero coefficient in the expression, taken from the linear terms, or quadratic terms if there is none. let mut intermediate_variables: IndexMap = IndexMap::new(); - for (index, opcode) in acir.opcodes.into_iter().enumerate() { + for (index, opcode) in acir.opcodes.iter().enumerate() { match opcode { Opcode::Arithmetic(arith_expr) => { let len = intermediate_variables.len(); let arith_expr = transformer.transform( - arith_expr, + arith_expr.clone(), &mut intermediate_variables, &mut next_witness_index, ); @@ -104,7 +104,7 @@ pub(super) fn transform_internal( transformed_opcodes.push(Opcode::Arithmetic(opcode)); } } - Opcode::BlackBoxFuncCall(ref func) => { + Opcode::BlackBoxFuncCall(func) => { match func { acir::circuit::opcodes::BlackBoxFuncCall::AND { output, .. } | acir::circuit::opcodes::BlackBoxFuncCall::XOR { output, .. } => { @@ -146,9 +146,9 @@ pub(super) fn transform_internal( } new_acir_opcode_positions.push(acir_opcode_positions[index]); - transformed_opcodes.push(opcode); + transformed_opcodes.push(opcode.clone()); } - Opcode::Directive(ref directive) => { + Opcode::Directive(directive) => { match directive { Directive::Quotient(quotient_directive) => { transformer.mark_solvable(quotient_directive.q); @@ -166,14 +166,14 @@ pub(super) fn transform_internal( } } new_acir_opcode_positions.push(acir_opcode_positions[index]); - transformed_opcodes.push(opcode); + transformed_opcodes.push(opcode.clone()); } Opcode::MemoryInit { .. } => { // `MemoryInit` does not write values to the `WitnessMap` new_acir_opcode_positions.push(acir_opcode_positions[index]); - transformed_opcodes.push(opcode); + transformed_opcodes.push(opcode.clone()); } - Opcode::MemoryOp { ref op, .. } => { + Opcode::MemoryOp { op, .. } => { for (_, witness1, witness2) in &op.value.mul_terms { transformer.mark_solvable(*witness1); transformer.mark_solvable(*witness2); @@ -182,9 +182,9 @@ pub(super) fn transform_internal( transformer.mark_solvable(*witness); } new_acir_opcode_positions.push(acir_opcode_positions[index]); - transformed_opcodes.push(opcode); + transformed_opcodes.push(opcode.clone()); } - Opcode::Brillig(ref brillig) => { + Opcode::Brillig(brillig) => { for output in &brillig.outputs { match output { BrilligOutputs::Simple(w) => transformer.mark_solvable(*w), @@ -196,7 +196,7 @@ pub(super) fn transform_internal( } } new_acir_opcode_positions.push(acir_opcode_positions[index]); - transformed_opcodes.push(opcode); + transformed_opcodes.push(opcode.clone()); } } } diff --git a/compiler/integration-tests/test/browser/recursion.test.ts b/compiler/integration-tests/test/browser/recursion.test.ts index bdc44d8db5a..c773e80ea43 100644 --- a/compiler/integration-tests/test/browser/recursion.test.ts +++ b/compiler/integration-tests/test/browser/recursion.test.ts @@ -9,7 +9,6 @@ import { acvm, abi, generateWitness } from '@noir-lang/noir_js'; import * as TOML from 'smol-toml'; import { BarretenbergBackend } from '@noir-lang/backend_barretenberg'; import { getFile } from './utils.js'; -import { Field, InputMap } from '@noir-lang/noirc_abi'; const logger = new Logger({ name: 'test', minLevel: TEST_LOG_LEVEL }); @@ -51,7 +50,7 @@ describe('It compiles noir program code, receiving circuit bytes and abi object. it('Should generate valid inner proof for correct input, then verify proof within a proof', async () => { const main_program = await getCircuit(circuit_main_source); - const main_inputs: InputMap = TOML.parse(circuit_main_toml) as InputMap; + const main_inputs = TOML.parse(circuit_main_toml); const main_backend = new BarretenbergBackend(main_program); @@ -70,10 +69,10 @@ describe('It compiles noir program code, receiving circuit bytes and abi object. numPublicInputs, ); - const recursion_inputs: InputMap = { + const recursion_inputs = { verification_key: vkAsFields, proof: proofAsFields, - public_inputs: [main_inputs.y as Field], + public_inputs: [main_inputs.y], key_hash: vkHash, input_aggregation_object: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'], }; diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs index 36e54132a38..3feeaba58b0 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs @@ -766,36 +766,6 @@ impl Context { Ok(AcirValue::Array(elements)) } - ( - AcirValue::DynamicArray(AcirDynamicArray { block_id, len, .. }), - AcirValue::Array(dummy_values), - ) => { - let dummy_values = dummy_values - .into_iter() - .flat_map(|val| val.clone().flatten()) - .map(|(var, typ)| AcirValue::Var(var, typ)) - .collect::>(); - - assert_eq!( - *len, - dummy_values.len(), - "ICE: The store value and dummy must have the same number of inner values" - ); - - let values = try_vecmap(0..*len, |i| { - let index_var = self.acir_context.add_constant(FieldElement::from(i as u128)); - - let read = self.acir_context.read_from_memory(*block_id, &index_var)?; - Ok::(AcirValue::Var(read, AcirType::field())) - })?; - - let mut elements = im::Vector::new(); - for (val, dummy_val) in values.iter().zip(dummy_values) { - elements.push_back(self.convert_array_set_store_value(val, &dummy_val)?); - } - - Ok(AcirValue::Array(elements)) - } (AcirValue::DynamicArray(_), AcirValue::DynamicArray(_)) => { unimplemented!("ICE: setting a dynamic array not supported"); } @@ -955,14 +925,8 @@ impl Context { self.array_set_value(value, block_id, var_index)?; } } - AcirValue::DynamicArray(AcirDynamicArray { block_id: inner_block_id, len, .. }) => { - let values = try_vecmap(0..len, |i| { - let index_var = self.acir_context.add_constant(FieldElement::from(i as u128)); - - let read = self.acir_context.read_from_memory(inner_block_id, &index_var)?; - Ok::(AcirValue::Var(read, AcirType::field())) - })?; - self.array_set_value(AcirValue::Array(values.into()), block_id, var_index)?; + AcirValue::DynamicArray(_) => { + unimplemented!("ICE: setting a dynamic array not supported"); } } Ok(()) @@ -987,7 +951,7 @@ impl Context { if !already_initialized { let value = &dfg[array_id]; match value { - Value::Array { .. } | Value::Instruction { .. } => { + Value::Array { .. } => { let value = self.convert_value(array_id, dfg); let len = if matches!(array_typ, Type::Array(_, _)) { array_typ.flattened_size() @@ -1001,7 +965,7 @@ impl Context { message: format!("Array {array_id} should be initialized"), call_stack: self.acir_context.get_call_stack(), } - .into()); + .into()) } } } diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs index 45b84cc97d9..3a12d508f95 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs @@ -646,11 +646,15 @@ impl Binary { let operand_type = dfg.type_of_value(self.lhs); if let (Some(lhs), Some(rhs)) = (lhs, rhs) { - return match eval_constant_binary_op(lhs, rhs, self.operator, operand_type) { - Some((result, result_type)) => { - let value = dfg.make_constant(result, result_type); - SimplifyResult::SimplifiedTo(value) - } + // If the rhs of a division is zero, attempting to evaluate the divison will cause a compiler panic. + // Thus, we do not evaluate this divison as we want to avoid triggering a panic, + // and division by zero should be handled by laying down constraints during ACIR generation. + if matches!(self.operator, BinaryOp::Div | BinaryOp::Mod) && rhs == FieldElement::zero() + { + return SimplifyResult::None; + } + return match self.eval_constants(dfg, lhs, rhs, operand_type) { + Some(value) => SimplifyResult::SimplifiedTo(value), None => SimplifyResult::None, }; } @@ -771,51 +775,47 @@ impl Binary { } SimplifyResult::None } -} -/// Evaluate a binary operation with constant arguments. -fn eval_constant_binary_op( - lhs: FieldElement, - rhs: FieldElement, - operator: BinaryOp, - mut operand_type: Type, -) -> Option<(FieldElement, Type)> { - let value = match &operand_type { - Type::Numeric(NumericType::NativeField) => { - // If the rhs of a division is zero, attempting to evaluate the division will cause a compiler panic. - // Thus, we do not evaluate the division in this method, as we want to avoid triggering a panic, - // and the operation should be handled by ACIR generation. - if matches!(operator, BinaryOp::Div | BinaryOp::Mod) && rhs == FieldElement::zero() { - return None; - } - operator.get_field_function()?(lhs, rhs) - } - Type::Numeric(NumericType::Unsigned { bit_size }) => { - let function = operator.get_u128_function(); + /// Evaluate the two constants with the operation specified by self.operator. + /// Pushes the resulting value to the given DataFlowGraph's constants and returns it. + fn eval_constants( + &self, + dfg: &mut DataFlowGraph, + lhs: FieldElement, + rhs: FieldElement, + mut operand_type: Type, + ) -> Option> { + let value = match &operand_type { + Type::Numeric(NumericType::NativeField) => { + self.operator.get_field_function()?(lhs, rhs) + } + Type::Numeric(NumericType::Unsigned { bit_size }) => { + let function = self.operator.get_u128_function(); + + let lhs = truncate(lhs.try_into_u128()?, *bit_size); + let rhs = truncate(rhs.try_into_u128()?, *bit_size); - let lhs = truncate(lhs.try_into_u128()?, *bit_size); - let rhs = truncate(rhs.try_into_u128()?, *bit_size); + // The divisor is being truncated into the type of the operand, which can potentially + // lead to the rhs being zero. + // If the rhs of a division is zero, attempting to evaluate the divison will cause a compiler panic. + // Thus, we do not evaluate the division in this method, as we want to avoid triggering a panic, + // and the operation should be handled by ACIR generation. + if matches!(self.operator, BinaryOp::Div) && rhs == 0 { + return None; + } - // The divisor is being truncated into the type of the operand, which can potentially - // lead to the rhs being zero. - // If the rhs of a division is zero, attempting to evaluate the division will cause a compiler panic. - // Thus, we do not evaluate the division in this method, as we want to avoid triggering a panic, - // and the operation should be handled by ACIR generation. - if matches!(operator, BinaryOp::Div | BinaryOp::Mod) && rhs == 0 { - return None; + let result = function(lhs, rhs); + truncate(result, *bit_size).into() } + _ => return None, + }; - let result = function(lhs, rhs); - truncate(result, *bit_size).into() + if matches!(self.operator, BinaryOp::Eq | BinaryOp::Lt) { + operand_type = Type::bool(); } - _ => return None, - }; - if matches!(operator, BinaryOp::Eq | BinaryOp::Lt) { - operand_type = Type::bool(); + Some(dfg.make_constant(value, operand_type)) } - - Some((value, operand_type)) } fn truncate(int: u128, bit_size: u32) -> u128 { diff --git a/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs b/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs index 803ffbc41fe..dc99546f798 100644 --- a/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs +++ b/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs @@ -1,6 +1,5 @@ use std::vec; -use acvm::acir::acir_field::FieldOptions; use fm::FileId; use noirc_errors::Location; @@ -203,13 +202,6 @@ impl<'a> ModCollector<'a> { let module = ModuleId { krate, local_id: self.module_id }; for function in functions { - // check if optional field attribute is compatible with native field - if let Some(field) = function.attributes().get_field_attribute() { - if !FieldOptions::is_native_field(&field) { - continue; - } - } - let name = function.name_ident().clone(); let func_id = context.def_interner.push_empty_fn(); diff --git a/compiler/noirc_frontend/src/hir/type_check/stmt.rs b/compiler/noirc_frontend/src/hir/type_check/stmt.rs index a3cb49c6d2e..cc251375c57 100644 --- a/compiler/noirc_frontend/src/hir/type_check/stmt.rs +++ b/compiler/noirc_frontend/src/hir/type_check/stmt.rs @@ -140,7 +140,12 @@ impl<'interner> TypeChecker<'interner> { fn check_assign_stmt(&mut self, assign_stmt: HirAssignStatement, stmt_id: &StmtId) { let expr_type = self.check_expression(&assign_stmt.expression); let span = self.interner.expr_span(&assign_stmt.expression); - let (lvalue_type, new_lvalue) = self.check_lvalue(assign_stmt.lvalue, span); + let (lvalue_type, new_lvalue, mutable) = self.check_lvalue(&assign_stmt.lvalue, span); + + if !mutable { + let (name, span) = self.get_lvalue_name_and_span(&assign_stmt.lvalue); + self.errors.push(TypeCheckError::VariableMustBeMutable { name, span }); + } // Must push new lvalue to the interner, we've resolved any field indices self.interner.update_statement(stmt_id, |stmt| match stmt { @@ -159,39 +164,52 @@ impl<'interner> TypeChecker<'interner> { }); } + fn get_lvalue_name_and_span(&self, lvalue: &HirLValue) -> (String, Span) { + match lvalue { + HirLValue::Ident(name, _) => { + let span = name.location.span; + + if let Some(definition) = self.interner.try_definition(name.id) { + (definition.name.clone(), span) + } else { + ("(undeclared variable)".into(), span) + } + } + HirLValue::MemberAccess { object, .. } => self.get_lvalue_name_and_span(object), + HirLValue::Index { array, .. } => self.get_lvalue_name_and_span(array), + HirLValue::Dereference { lvalue, .. } => self.get_lvalue_name_and_span(lvalue), + } + } + /// Type check an lvalue - the left hand side of an assignment statement. - fn check_lvalue(&mut self, lvalue: HirLValue, assign_span: Span) -> (Type, HirLValue) { + fn check_lvalue(&mut self, lvalue: &HirLValue, assign_span: Span) -> (Type, HirLValue, bool) { match lvalue { HirLValue::Ident(ident, _) => { + let mut mutable = true; + let typ = if ident.id == DefinitionId::dummy_id() { Type::Error } else { - // Do we need to store TypeBindings here? - let typ = self.interner.id_type(ident.id).instantiate(self.interner).0; - let typ = typ.follow_bindings(); - if let Some(definition) = self.interner.try_definition(ident.id) { - if !definition.mutable && !matches!(typ, Type::MutableReference(_)) { - self.errors.push(TypeCheckError::VariableMustBeMutable { - name: definition.name.clone(), - span: ident.location.span, - }); - } + mutable = definition.mutable; } - typ + let typ = self.interner.id_type(ident.id).instantiate(self.interner).0; + typ.follow_bindings() }; - (typ.clone(), HirLValue::Ident(ident, typ)) + (typ.clone(), HirLValue::Ident(*ident, typ), mutable) } HirLValue::MemberAccess { object, field_name, .. } => { - let (lhs_type, object) = self.check_lvalue(*object, assign_span); + let (lhs_type, object, mut mutable) = self.check_lvalue(object, assign_span); let mut object = Box::new(object); let span = field_name.span(); + let field_name = field_name.clone(); let object_ref = &mut object; + let mutable_ref = &mut mutable; - let (typ, field_index) = self + let (object_type, field_index) = self .check_field_access( &lhs_type, &field_name.0.contents, @@ -206,16 +224,19 @@ impl<'interner> TypeChecker<'interner> { let lvalue = std::mem::replace(object_ref, Box::new(tmp_value)); *object_ref = Box::new(HirLValue::Dereference { lvalue, element_type }); + *mutable_ref = true; }, ) .unwrap_or((Type::Error, 0)); let field_index = Some(field_index); - (typ.clone(), HirLValue::MemberAccess { object, field_name, field_index, typ }) + let typ = object_type.clone(); + let lvalue = HirLValue::MemberAccess { object, field_name, field_index, typ }; + (object_type, lvalue, mutable) } HirLValue::Index { array, index, .. } => { - let index_type = self.check_expression(&index); - let expr_span = self.interner.expr_span(&index); + let index_type = self.check_expression(index); + let expr_span = self.interner.expr_span(index); index_type.unify( &Type::polymorphic_integer(self.interner), @@ -227,7 +248,7 @@ impl<'interner> TypeChecker<'interner> { }, ); - let (array_type, array) = self.check_lvalue(*array, assign_span); + let (array_type, array, mutable) = self.check_lvalue(array, assign_span); let array = Box::new(array); let typ = match array_type.follow_bindings() { @@ -236,7 +257,7 @@ impl<'interner> TypeChecker<'interner> { other => { // TODO: Need a better span here self.errors.push(TypeCheckError::TypeMismatch { - expected_typ: "array".to_string(), + expected_typ: "an array".to_string(), expr_typ: other.to_string(), expr_span: assign_span, }); @@ -244,22 +265,22 @@ impl<'interner> TypeChecker<'interner> { } }; - (typ.clone(), HirLValue::Index { array, index, typ }) + (typ.clone(), HirLValue::Index { array, index: *index, typ }, mutable) } HirLValue::Dereference { lvalue, element_type: _ } => { - let (reference_type, lvalue) = self.check_lvalue(*lvalue, assign_span); + let (reference_type, lvalue, _) = self.check_lvalue(lvalue, assign_span); let lvalue = Box::new(lvalue); let element_type = Type::type_variable(self.interner.next_type_variable_id()); let expected_type = Type::MutableReference(Box::new(element_type.clone())); - self.unify(&reference_type, &expected_type, || TypeCheckError::TypeMismatch { expected_typ: expected_type.to_string(), expr_typ: reference_type.to_string(), expr_span: assign_span, }); - (element_type.clone(), HirLValue::Dereference { lvalue, element_type }) + // Dereferences are always mutable since we already type checked against a &mut T + (element_type.clone(), HirLValue::Dereference { lvalue, element_type }, true) } } } diff --git a/compiler/noirc_frontend/src/lexer/token.rs b/compiler/noirc_frontend/src/lexer/token.rs index 2ad2f3902b1..ad81b163801 100644 --- a/compiler/noirc_frontend/src/lexer/token.rs +++ b/compiler/noirc_frontend/src/lexer/token.rs @@ -395,15 +395,6 @@ impl Attributes { _ => None, }) } - - pub fn get_field_attribute(&self) -> Option { - for secondary in &self.secondary { - if let SecondaryAttribute::Field(field) = secondary { - return Some(field.to_lowercase()); - } - } - None - } } /// An Attribute can be either a Primary Attribute or a Secondary Attribute @@ -475,10 +466,6 @@ impl Attribute { None => return Err(malformed_scope), } } - ["field", name] => { - validate(name)?; - Attribute::Secondary(SecondaryAttribute::Field(name.to_string())) - } // Secondary attributes ["deprecated"] => Attribute::Secondary(SecondaryAttribute::Deprecated(None)), ["contract_library_method"] => { @@ -563,7 +550,6 @@ pub enum SecondaryAttribute { // the entry point. ContractLibraryMethod, Event, - Field(String), Custom(String), } @@ -577,7 +563,6 @@ impl fmt::Display for SecondaryAttribute { SecondaryAttribute::Custom(ref k) => write!(f, "#[{k}]"), SecondaryAttribute::ContractLibraryMethod => write!(f, "#[contract_library_method]"), SecondaryAttribute::Event => write!(f, "#[event]"), - SecondaryAttribute::Field(ref k) => write!(f, "#[field({k})]"), } } } @@ -598,7 +583,7 @@ impl AsRef for SecondaryAttribute { match self { SecondaryAttribute::Deprecated(Some(string)) => string, SecondaryAttribute::Deprecated(None) => "", - SecondaryAttribute::Custom(string) | SecondaryAttribute::Field(string) => string, + SecondaryAttribute::Custom(string) => string, SecondaryAttribute::ContractLibraryMethod => "", SecondaryAttribute::Event => "", } diff --git a/compiler/noirc_frontend/src/parser/parser.rs b/compiler/noirc_frontend/src/parser/parser.rs index 2da17c997c1..702f056adcd 100644 --- a/compiler/noirc_frontend/src/parser/parser.rs +++ b/compiler/noirc_frontend/src/parser/parser.rs @@ -949,34 +949,29 @@ enum LValueRhs { Index(Expression), } -fn lvalue<'a, P>(expr_parser: P) -> impl NoirParser + 'a +fn lvalue<'a, P>(expr_parser: P) -> impl NoirParser where P: ExprParser + 'a, { - recursive(|lvalue| { - let l_ident = ident().map(LValue::Ident); + let l_ident = ident().map(LValue::Ident); - let dereferences = just(Token::Star) - .ignore_then(lvalue.clone()) - .map(|lvalue| LValue::Dereference(Box::new(lvalue))); + let l_member_rhs = just(Token::Dot).ignore_then(field_name()).map(LValueRhs::MemberAccess); - let parenthesized = lvalue.delimited_by(just(Token::LeftParen), just(Token::RightParen)); - - let term = choice((parenthesized, dereferences, l_ident)); - - let l_member_rhs = just(Token::Dot).ignore_then(field_name()).map(LValueRhs::MemberAccess); + let l_index = expr_parser + .delimited_by(just(Token::LeftBracket), just(Token::RightBracket)) + .map(LValueRhs::Index); - let l_index = expr_parser - .delimited_by(just(Token::LeftBracket), just(Token::RightBracket)) - .map(LValueRhs::Index); + let dereferences = just(Token::Star).repeated(); - term.then(l_member_rhs.or(l_index).repeated()).foldl(|lvalue, rhs| match rhs { + let lvalues = + l_ident.then(l_member_rhs.or(l_index).repeated()).foldl(|lvalue, rhs| match rhs { LValueRhs::MemberAccess(field_name) => { LValue::MemberAccess { object: Box::new(lvalue), field_name } } LValueRhs::Index(index) => LValue::Index { array: Box::new(lvalue), index }, - }) - }) + }); + + dereferences.then(lvalues).foldr(|_, lvalue| LValue::Dereference(Box::new(lvalue))) } fn parse_type<'a>() -> impl NoirParser + 'a { diff --git a/noir_stdlib/src/field.nr b/noir_stdlib/src/field.nr index 3959f1ea175..fe887aa89b0 100644 --- a/noir_stdlib/src/field.nr +++ b/noir_stdlib/src/field.nr @@ -1,52 +1,23 @@ impl Field { - pub fn to_le_bits(self: Self, bit_size: u32) -> [u1] { - crate::assert_constant(bit_size); - self.__to_le_bits(bit_size) - } - - pub fn to_be_bits(self: Self, bit_size: u32) -> [u1] { - crate::assert_constant(bit_size); - self.__to_be_bits(bit_size) - } - #[builtin(to_le_bits)] - fn __to_le_bits(_self: Self, _bit_size: u32) -> [u1] {} - + pub fn to_le_bits(_x : Field, _bit_size: u32) -> [u1] {} #[builtin(to_be_bits)] - fn __to_be_bits(_self: Self, _bit_size: u32) -> [u1] {} - - pub fn to_le_bytes(self: Self, byte_size: u32) -> [u8] { - self.to_le_radix(256, byte_size) - } - - pub fn to_be_bytes(self: Self, byte_size: u32) -> [u8] { - self.to_be_radix(256, byte_size) - } - + pub fn to_be_bits(_x : Field, _bit_size: u32) -> [u1] {} - pub fn to_le_radix(self: Self, radix: u32, result_len: u32) -> [u8] { - crate::assert_constant(radix); - crate::assert_constant(result_len); - self.__to_le_radix(radix, result_len) + pub fn to_le_bytes(x : Field, byte_size: u32) -> [u8] { + x.to_le_radix(256, byte_size) } - - pub fn to_be_radix(self: Self, radix: u32, result_len: u32) -> [u8] { - crate::assert_constant(radix); - crate::assert_constant(result_len); - self.__to_be_radix(radix, result_len) + pub fn to_be_bytes(x : Field, byte_size: u32) -> [u8] { + x.to_be_radix(256, byte_size) } - - - // decompose `_self` into a `_result_len` vector over the `_radix` basis - // `_radix` must be less than 256 #[builtin(to_le_radix)] - fn __to_le_radix(_self: Self, _radix: u32, _result_len: u32) -> [u8] {} - + //decompose _x into a _result_len vector over the _radix basis + //_radix must be less than 256 + pub fn to_le_radix(_x : Field, _radix: u32, _result_len: u32) -> [u8] {} #[builtin(to_be_radix)] - fn __to_be_radix(_self: Self, _radix: u32, _result_len: u32) -> [u8] {} - + pub fn to_be_radix(_x : Field, _radix: u32, _result_len: u32) -> [u8] {} // Returns self to the power of the given exponent value. // Caution: we assume the exponent fits into 32 bits diff --git a/tooling/nargo_cli/tests/compile_failure/mutability_regression_2911/Nargo.toml b/tooling/nargo_cli/tests/compile_failure/mutability_regression_2911/Nargo.toml new file mode 100644 index 00000000000..5136fad35ce --- /dev/null +++ b/tooling/nargo_cli/tests/compile_failure/mutability_regression_2911/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "mutability_regression_2911" +type = "bin" +authors = [""] +compiler_version = "0.9.0" + +[dependencies] diff --git a/tooling/nargo_cli/tests/compile_failure/mutability_regression_2911/src/main.nr b/tooling/nargo_cli/tests/compile_failure/mutability_regression_2911/src/main.nr new file mode 100644 index 00000000000..a0d53706f97 --- /dev/null +++ b/tooling/nargo_cli/tests/compile_failure/mutability_regression_2911/src/main.nr @@ -0,0 +1,5 @@ +// Expect 'Variable must be mutable to be assigned to' error +fn main() { + let slice : &mut [Field] = &mut []; + slice = &mut (*slice).push_back(1); +} diff --git a/tooling/nargo_cli/tests/compile_failure/radix_non_constant_length/Nargo.toml b/tooling/nargo_cli/tests/compile_failure/radix_non_constant_length/Nargo.toml deleted file mode 100644 index b8b1a2417dc..00000000000 --- a/tooling/nargo_cli/tests/compile_failure/radix_non_constant_length/Nargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "radix_non_constant_length" -type = "bin" -authors = [""] -compiler_version = "0.10.2" - -[dependencies] diff --git a/tooling/nargo_cli/tests/compile_failure/radix_non_constant_length/Prover.toml b/tooling/nargo_cli/tests/compile_failure/radix_non_constant_length/Prover.toml deleted file mode 100644 index f28f2f8cc48..00000000000 --- a/tooling/nargo_cli/tests/compile_failure/radix_non_constant_length/Prover.toml +++ /dev/null @@ -1,2 +0,0 @@ -x = "5" -y = "10" diff --git a/tooling/nargo_cli/tests/compile_failure/radix_non_constant_length/src/main.nr b/tooling/nargo_cli/tests/compile_failure/radix_non_constant_length/src/main.nr deleted file mode 100644 index adfbd265a1d..00000000000 --- a/tooling/nargo_cli/tests/compile_failure/radix_non_constant_length/src/main.nr +++ /dev/null @@ -1,4 +0,0 @@ -fn main(x : Field, y : pub u32) { - let bytes = x.to_be_bytes(y); - assert(bytes[0] == 0); -} diff --git a/tooling/nargo_cli/tests/execution_success/assign_ex/src/main.nr b/tooling/nargo_cli/tests/execution_success/assign_ex/src/main.nr index 75cd841a301..b0626d63c8e 100644 --- a/tooling/nargo_cli/tests/execution_success/assign_ex/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/assign_ex/src/main.nr @@ -3,13 +3,4 @@ fn main(x: Field, y: Field) { assert(z == 3); z = x * y; assert(z == 2); - - regression_3057(); -} - -// Ensure parsing parenthesized lvalues works -fn regression_3057() { - let mut array = [[0, 1], [2, 3]]; - (array[0])[1] = 2; - assert(array[0][1] == 2); } diff --git a/tooling/nargo_cli/tests/execution_success/field_attribute/Nargo.toml b/tooling/nargo_cli/tests/execution_success/field_attribute/Nargo.toml deleted file mode 100644 index f625d7e41f2..00000000000 --- a/tooling/nargo_cli/tests/execution_success/field_attribute/Nargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "field_attribute" -type = "bin" -authors = [""] -compiler_version = "0.1" - -[dependencies] diff --git a/tooling/nargo_cli/tests/execution_success/field_attribute/Prover.toml b/tooling/nargo_cli/tests/execution_success/field_attribute/Prover.toml deleted file mode 100644 index 07890234a19..00000000000 --- a/tooling/nargo_cli/tests/execution_success/field_attribute/Prover.toml +++ /dev/null @@ -1 +0,0 @@ -x = "3" diff --git a/tooling/nargo_cli/tests/execution_success/field_attribute/src/main.nr b/tooling/nargo_cli/tests/execution_success/field_attribute/src/main.nr deleted file mode 100644 index d6d71781899..00000000000 --- a/tooling/nargo_cli/tests/execution_success/field_attribute/src/main.nr +++ /dev/null @@ -1,19 +0,0 @@ -// Test integer addition: 3 + 4 = 7 -fn main(mut x: u32) { - assert(x > foo()); -} - -#[field(bn254)] -fn foo() -> u32 { - 1 -} - -#[field(23)] -fn foo() -> u32 { - 2 -} - -#[field(bls12_381)] -fn foo() -> u32 { - 3 -} \ No newline at end of file diff --git a/tooling/nargo_cli/tests/execution_success/nested_array_dynamic/src/main.nr b/tooling/nargo_cli/tests/execution_success/nested_array_dynamic/src/main.nr index 5f15905dfba..076c2b68f11 100644 --- a/tooling/nargo_cli/tests/execution_success/nested_array_dynamic/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/nested_array_dynamic/src/main.nr @@ -8,11 +8,6 @@ struct Foo { bar: Bar, } -struct FooParent { - array: [Field; 3], - foos: [Foo; 4], -} - fn main(mut x : [Foo; 4], y : pub Field) { assert(x[y - 3].a == 1); assert(x[y - 3].b == [2, 3, 20]); @@ -43,37 +38,5 @@ fn main(mut x : [Foo; 4], y : pub Field) { assert(x[y - 2].bar.inner == [103, 104, 105]); assert(x[y - 1].bar.inner == [106, 107, 108]); assert(x[y].bar.inner == [109, 110, 111]); - - let foo_parent_one = FooParent { array: [0, 1, 2], foos: x }; - let foo_parent_two = FooParent { array: [3, 4, 5], foos: x }; - let mut foo_parents = [foo_parent_one, foo_parent_two]; - - assert(foo_parents[y - 3].foos[y - 3].b == [2, 3, 20]); - assert(foo_parents[y - 3].foos[y - 2].b == [5, 6, 21]); - assert(foo_parents[y - 3].foos[y - 1].b == [100, 101, 102]); - assert(foo_parents[y - 3].foos[y].b == [11, 12, 23]); - - assert(foo_parents[y - 3].foos[y].a == 50); - - assert(foo_parents[1].foos[1].b == [5, 6, 21]); - if y == 2 { - foo_parents[y - 2].foos[y - 2].b = [10, 9, 8]; - } else { - foo_parents[y - 2].foos[y - 2].b = [20, 19, 18]; - } - assert(foo_parents[1].foos[1].b == [20, 19, 18]); - - assert(foo_parents[1].foos[1].b[2] == 18); - if y == 3 { - foo_parents[y - 2].foos[y - 2].b[y - 1] = 5000; - } else { - foo_parents[y - 2].foos[y - 2].b[y - 1] = 1000; - } - assert(foo_parents[1].foos[1].b[2] == 5000); - - // Set a dynamic array value - foo_parents[y - 2].foos[y - 3].b = foo_parents[y - 2].foos[y - 2].b; - assert(foo_parents[1].foos[0].b == [20, 19, 5000]); - } diff --git a/tooling/nargo_cli/tests/execution_success/trait_function_calls/src/main.nr b/tooling/nargo_cli/tests/execution_success/trait_function_calls/src/main.nr index a3a19fe9dec..5f92b45dcd3 100644 --- a/tooling/nargo_cli/tests/execution_success/trait_function_calls/src/main.nr +++ b/tooling/nargo_cli/tests/execution_success/trait_function_calls/src/main.nr @@ -4,6 +4,9 @@ // *) method (has self parameter) vs function (no self parameter) // *) default vs overriden vs overriden (no default) +// TODO: function calls via `Self::` are not yet implemented +// Once this is implemented, this test should be updated. + // test order is: // 1) trait method -> trait method // 1a) trait default method -> trait default method @@ -163,430 +166,6 @@ impl Trait1i for Struct1i { } } -// 2) trait method -> trait function -// 2a) trait default method -> trait default function -trait Trait2a { - fn trait_method1(self) -> Field { - Self::trait_function2() * 2385 - self.vl - } - fn trait_function2() -> Field { - 7843 - } -} -struct Struct2a { vl: Field } -impl Trait2a for Struct2a { } - -// 2b) trait default method -> trait overriden function -trait Trait2b { - fn trait_method1(self) -> Field { - Self::trait_function2() * 6583 - self.vl - } - fn trait_function2() -> Field { - 3752 - } -} -struct Struct2b { vl: Field } -impl Trait2b for Struct2b { - fn trait_function2() -> Field { - 8477 - } -} - -// 2c) trait default method -> trait overriden (no default) function -trait Trait2c { - fn trait_method1(self) -> Field { - Self::trait_function2() * 2831 - self.vl - } - fn trait_function2() -> Field; -} -struct Struct2c { vl: Field } -impl Trait2c for Struct2c { - fn trait_function2() -> Field { - 8342 - } -} - -// 2d) trait overriden method -> trait default function -trait Trait2d { - fn trait_method1(self) -> Field { - Self::trait_function2() * 924 - self.vl - } - fn trait_function2() -> Field { - 384 - } -} -struct Struct2d { vl: Field } -impl Trait2d for Struct2d { - fn trait_method1(self) -> Field { - Self::trait_function2() * 3984 - self.vl - } -} - -// 2e) trait overriden method -> trait overriden function -trait Trait2e { - fn trait_method1(self) -> Field { - Self::trait_function2() * 3642 - self.vl - } - fn trait_function2() -> Field { - 97342 - } -} -struct Struct2e { vl: Field } -impl Trait2e for Struct2e { - fn trait_method1(self) -> Field { - Self::trait_function2() * 7363 - self.vl - } - fn trait_function2() -> Field { - 39400 - } -} - -// 2f) trait overriden method -> trait overriden (no default) function -trait Trait2f { - fn trait_method1(self) -> Field { - Self::trait_function2() * 2783 - self.vl - } - fn trait_function2() -> Field; -} -struct Struct2f { vl: Field } -impl Trait2f for Struct2f { - fn trait_method1(self) -> Field { - Self::trait_function2() * 6362 - self.vl - } - fn trait_function2() -> Field { - 72311 - } -} - -// 2g) trait overriden (no default) method -> trait default function -trait Trait2g { - fn trait_method1(self) -> Field; - fn trait_function2() -> Field { - 19273 - } -} -struct Struct2g { vl: Field } -impl Trait2g for Struct2g { - fn trait_method1(self) -> Field { - Self::trait_function2() * 9123 - self.vl - } -} - -// 2h) trait overriden (no default) method -> trait overriden function -trait Trait2h { - fn trait_method1(self) -> Field; - fn trait_function2() -> Field { - 1281 - } -} -struct Struct2h { vl: Field } -impl Trait2h for Struct2h { - fn trait_method1(self) -> Field { - Self::trait_function2() * 4833 - self.vl - } - fn trait_function2() -> Field { - 5335 - } -} - -// 2i) trait overriden (no default) method -> trait overriden (no default) function -trait Trait2i { - fn trait_method1(self) -> Field; - fn trait_function2() -> Field; -} -struct Struct2i { vl: Field } -impl Trait2i for Struct2i { - fn trait_method1(self) -> Field { - Self::trait_function2() * 2291 - self.vl - } - fn trait_function2() -> Field { - 3322 - } -} - -// 3 trait function -> trait method -// 3a) trait default function -> trait default method -trait Trait3a { - fn trait_function1(a: Field, b: Self) -> Field { - b.trait_method2() * 8344 - b.vl + a - } - fn trait_method2(self) -> Field { - 19212 - } -} -struct Struct3a { vl: Field } -impl Trait3a for Struct3a { } - -// 3b) trait default function -> trait overriden method -trait Trait3b { - fn trait_function1(a: Field, b: Self) -> Field { - b.trait_method2() * 9233 - b.vl + a - } - fn trait_method2(self) -> Field { - 9111 - } -} -struct Struct3b { vl: Field } -impl Trait3b for Struct3b { - fn trait_method2(self) -> Field { - 2392 - } -} - -// 3c) trait default function -> trait overriden (no default) method -trait Trait3c { - fn trait_function1(a: Field, b: Self) -> Field { - b.trait_method2() * 2822 - b.vl + a - } - fn trait_method2(self) -> Field; -} -struct Struct3c { vl: Field } -impl Trait3c for Struct3c { - fn trait_method2(self) -> Field { - 7743 - } -} - -// 3d) trait overriden function -> trait default method -trait Trait3d { - fn trait_function1(a: Field, b: Self) -> Field { - b.trait_method2() * 291 - b.vl + a - } - fn trait_method2(self) -> Field { - 3328 - } -} -struct Struct3d { vl: Field } -impl Trait3d for Struct3d { - fn trait_function1(a: Field, b: Self) -> Field { - b.trait_method2() * 4933 - b.vl + a - } -} - -// 3e) trait overriden function -> trait overriden method -trait Trait3e { - fn trait_function1(a: Field, b: Self) -> Field { - b.trait_method2() * 71231 - b.vl + a - } - fn trait_method2(self) -> Field { - 373 - } -} -struct Struct3e { vl: Field } -impl Trait3e for Struct3e { - fn trait_function1(a: Field, b: Self) -> Field { - b.trait_method2() * 81232 - b.vl + a - } - fn trait_method2(self) -> Field { - 80002 - } -} - -// 3f) trait overriden function -> trait overriden (no default) method -trait Trait3f { - fn trait_function1(a: Field, b: Self) -> Field { - b.trait_method2() * 28223 - b.vl + a - } - fn trait_method2(self) -> Field; -} -struct Struct3f { vl: Field } -impl Trait3f for Struct3f { - fn trait_function1(a: Field, b: Self) -> Field { - b.trait_method2() * 29223 - b.vl + a - } - fn trait_method2(self) -> Field { - 63532 - } -} - -// 3g) trait overriden (no default) function -> trait default method -trait Trait3g { - fn trait_function1(a: Field, b: Self) -> Field; - fn trait_method2(self) -> Field { - 8887 - } -} -struct Struct3g { vl: Field } -impl Trait3g for Struct3g { - fn trait_function1(a: Field, b: Self) -> Field { - b.trait_method2() * 31337 - b.vl + a - } -} - -// 3h) trait overriden (no default) function -> trait overriden method -trait Trait3h { - fn trait_function1(a: Field, b: Self) -> Field; - fn trait_method2(self) -> Field { - 293 - } -} -struct Struct3h { vl: Field } -impl Trait3h for Struct3h { - fn trait_function1(a: Field, b: Self) -> Field { - b.trait_method2() * 74747 - b.vl + a - } - fn trait_method2(self) -> Field { - 6283 - } -} - -// 3i) trait overriden (no default) function -> trait overriden (no default) method -trait Trait3i { - fn trait_function1(a: Field, b: Self) -> Field; - fn trait_method2(self) -> Field; -} -struct Struct3i { vl: Field } -impl Trait3i for Struct3i { - fn trait_function1(a: Field, b: Self) -> Field { - b.trait_method2() * 1237 - b.vl + a - } - fn trait_method2(self) -> Field { - 84352 - } -} - -// 4) trait function -> trait function -// 4a) trait default function -> trait default function -trait Trait4a { - fn trait_function1() -> Field { - Self::trait_function2() * 3842 - } - fn trait_function2() -> Field { - 2932 - } -} -struct Struct4a { vl: Field } -impl Trait4a for Struct4a { } - -// 4b) trait default function -> trait overriden function -trait Trait4b { - fn trait_function1() -> Field { - Self::trait_function2() * 3842 - } - fn trait_function2() -> Field { - 2932 - } -} -struct Struct4b { vl: Field } -impl Trait4b for Struct4b { - fn trait_function2() -> Field { - 9353 - } -} - -// 4c) trait default function -> trait overriden (no default) function -trait Trait4c { - fn trait_function1() -> Field { - Self::trait_function2() * 7832 - } - fn trait_function2() -> Field; -} -struct Struct4c { vl: Field } -impl Trait4c for Struct4c { - fn trait_function2() -> Field { - 2928 - } -} - -// 4d) trait overriden function -> trait default function -trait Trait4d { - fn trait_function1() -> Field { - Self::trait_function2() * 2283 - } - fn trait_function2() -> Field { - 9332 - } -} -struct Struct4d { vl: Field } -impl Trait4d for Struct4d { - fn trait_function1() -> Field { - Self::trait_function2() * 8374 - } -} - -// 4e) trait overriden function -> trait overriden function -trait Trait4e { - fn trait_function1() -> Field { - Self::trait_function2() * 94329 - } - fn trait_function2() -> Field { - 28328 - } -} -struct Struct4e { vl: Field } -impl Trait4e for Struct4e { - fn trait_function1() -> Field { - Self::trait_function2() * 12323 - } - fn trait_function2() -> Field { - 38434 - } -} - -// 4f) trait overriden function -> trait overriden (no default) function -trait Trait4f { - fn trait_function1() -> Field { - Self::trait_function2() * 23723 - } - fn trait_function2() -> Field; -} -struct Struct4f { vl: Field } -impl Trait4f for Struct4f { - fn trait_function1() -> Field { - Self::trait_function2() * 21392 - } - fn trait_function2() -> Field { - 4394 - } -} - -// 4g) trait overriden (no default) function -> trait default function -trait Trait4g { - fn trait_function1() -> Field; - fn trait_function2() -> Field { - 2932 - } -} -struct Struct4g { vl: Field } -impl Trait4g for Struct4g { - fn trait_function1() -> Field { - Self::trait_function2() * 3345 - } -} - -// 4h) trait overriden (no default) function -> trait overriden function -trait Trait4h { - fn trait_function1() -> Field; - fn trait_function2() -> Field { - 5756 - } -} -struct Struct4h { vl: Field } -impl Trait4h for Struct4h { - fn trait_function1() -> Field { - Self::trait_function2() * 6478 - } - fn trait_function2() -> Field { - 5435 - } -} - -// 4i) trait overriden (no default) function -> trait overriden (no default) function -trait Trait4i { - fn trait_function1() -> Field; - fn trait_function2() -> Field; -} -struct Struct4i { vl: Field } -impl Trait4i for Struct4i { - fn trait_function1() -> Field { - Self::trait_function2() * 8239 - } - fn trait_function2() -> Field { - 2032 - } -} - - fn main() { let t1a = Struct1a { vl: 1234 }; assert(t1a.trait_method1() == 341548742); @@ -606,49 +185,4 @@ fn main() { assert(t1h.trait_method1() == 29739260); let t1i = Struct1i { vl: 9234 }; assert(t1i.trait_method1() == 2313583320); - let t2a = Struct2a { vl: 4362 }; - assert(t2a.trait_method1() == 18701193); - let t2b = Struct2b { vl: 8347 }; - assert(t2b.trait_method1() == 55795744); - let t2c = Struct2c { vl: 1923 }; - assert(t2c.trait_method1() == 23614279); - let t2d = Struct2d { vl: 92384 }; - assert(t2d.trait_method1() == 1437472); - let t2e = Struct2e { vl: 83943 }; - assert(t2e.trait_method1() == 290018257); - let t2f = Struct2f { vl: 8237 }; - assert(t2f.trait_method1() == 460034345); - let t2g = Struct2g { vl: 1232 }; - assert(t2g.trait_method1() == 175826347); - let t2h = Struct2h { vl: 7222 }; - assert(t2h.trait_method1() == 25776833); - let t2i = Struct2i { vl: 1821 }; - assert(t2i.trait_method1() == 7608881); - let t3a = Struct3a { vl: 93248 }; - assert(Struct3a::trait_function1(5, t3a) == 160211685); - let t3b = Struct3b { vl: 76763 }; - assert(Struct3b::trait_function1(62, t3b) == 22008635); - let t3c = Struct3c { vl: 3833 }; - assert(Struct3c::trait_function1(25, t3c) == 21846938); - let t3d = Struct3d { vl: 5645 }; - assert(Struct3d::trait_function1(73, t3d) == 16411452); - let t3e = Struct3e { vl: 22912 }; - assert(Struct3e::trait_function1(92, t3e) == 6498699644); - let t3f = Struct3f { vl: 3256 }; - assert(Struct3f::trait_function1(77, t3f) == 1856592457); - let t3g = Struct3g { vl: 22832 }; - assert(Struct3g::trait_function1(23, t3g) == 278469110); - let t3h = Struct3h { vl: 4933 }; - assert(Struct3h::trait_function1(17, t3h) == 469630485); - let t3i = Struct3i { vl: 39432 }; - assert(Struct3i::trait_function1(54, t3i) == 104304046); - assert(Struct4a::trait_function1() == 11264744); - assert(Struct4b::trait_function1() == 35934226); - assert(Struct4c::trait_function1() == 22932096); - assert(Struct4d::trait_function1() == 78146168); - assert(Struct4e::trait_function1() == 473622182); - assert(Struct4f::trait_function1() == 93996448); - assert(Struct4g::trait_function1() == 9807540); - assert(Struct4h::trait_function1() == 35207930); - assert(Struct4i::trait_function1() == 16741648); } diff --git a/tooling/nargo_fmt/src/visitor/expr.rs b/tooling/nargo_fmt/src/visitor/expr.rs index fa55ac71f78..bf93f8ff394 100644 --- a/tooling/nargo_fmt/src/visitor/expr.rs +++ b/tooling/nargo_fmt/src/visitor/expr.rs @@ -28,9 +28,6 @@ impl FmtVisitor<'_> { ExpressionKind::Prefix(prefix) => { format!("{}{}", prefix.operator, self.format_expr(prefix.rhs)) } - ExpressionKind::Cast(cast) => { - format!("{} as {}", self.format_expr(cast.lhs), cast.r#type) - } ExpressionKind::Infix(infix) => { format!( "{} {} {}", diff --git a/tooling/nargo_fmt/tests/expected/cast.nr b/tooling/nargo_fmt/tests/expected/cast.nr deleted file mode 100644 index 63008168f84..00000000000 --- a/tooling/nargo_fmt/tests/expected/cast.nr +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - x as u8 -} diff --git a/tooling/nargo_fmt/tests/input/cast.nr b/tooling/nargo_fmt/tests/input/cast.nr deleted file mode 100644 index dfbb370e2bb..00000000000 --- a/tooling/nargo_fmt/tests/input/cast.nr +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - -x as u8 -} diff --git a/tooling/noir_js/src/witness_generation.ts b/tooling/noir_js/src/witness_generation.ts index f3307837736..3b1dfd90109 100644 --- a/tooling/noir_js/src/witness_generation.ts +++ b/tooling/noir_js/src/witness_generation.ts @@ -1,13 +1,13 @@ -import { abiEncode, InputMap } from '@noir-lang/noirc_abi'; +import { abiEncode } from '@noir-lang/noirc_abi'; import { base64Decode } from './base64_decode.js'; import { executeCircuit } from '@noir-lang/acvm_js'; import { witnessMapToUint8Array } from './serialize.js'; import { CompiledCircuit } from '@noir-lang/types'; // Generates the witnesses needed to feed into the chosen proving system -export async function generateWitness(compiledProgram: CompiledCircuit, inputs: InputMap): Promise { +export async function generateWitness(compiledProgram: CompiledCircuit, inputs: unknown): Promise { // Throws on ABI encoding error - const witnessMap = abiEncode(compiledProgram.abi, inputs); + const witnessMap = abiEncode(compiledProgram.abi, inputs, null); // Execute the circuit to generate the rest of the witnesses and serialize // them into a Uint8Array. diff --git a/tooling/noir_js/test/node/e2e.test.ts b/tooling/noir_js/test/node/e2e.test.ts index 3182f95ca10..d1cd0a94775 100644 --- a/tooling/noir_js/test/node/e2e.test.ts +++ b/tooling/noir_js/test/node/e2e.test.ts @@ -2,9 +2,6 @@ import { expect } from 'chai'; import assert_lt_json from '../noir_compiled_examples/assert_lt/target/assert_lt.json' assert { type: 'json' }; import { Noir, generateWitness } from '@noir-lang/noir_js'; import { BarretenbergBackend as Backend } from '@noir-lang/backend_barretenberg'; -import { CompiledCircuit } from '@noir-lang/types'; - -const assert_lt_program = assert_lt_json as CompiledCircuit; it('end-to-end proof creation and verification (outer)', async () => { // Noir.Js part @@ -12,12 +9,12 @@ it('end-to-end proof creation and verification (outer)', async () => { x: '2', y: '3', }; - const serializedWitness = await generateWitness(assert_lt_program, inputs); + const serializedWitness = await generateWitness(assert_lt_json, inputs); // bb.js part // // Proof creation - const prover = new Backend(assert_lt_program); + const prover = new Backend(assert_lt_json); const proof = await prover.generateFinalProof(serializedWitness); // Proof verification @@ -33,9 +30,9 @@ it('end-to-end proof creation and verification (outer) -- Program API', async () }; // Initialize backend - const backend = new Backend(assert_lt_program); + const backend = new Backend(assert_lt_json); // Initialize program - const program = new Noir(assert_lt_program, backend); + const program = new Noir(assert_lt_json, backend); // Generate proof const proof = await program.generateFinalProof(inputs); @@ -50,12 +47,12 @@ it('end-to-end proof creation and verification (inner)', async () => { x: '2', y: '3', }; - const serializedWitness = await generateWitness(assert_lt_program, inputs); + const serializedWitness = await generateWitness(assert_lt_json, inputs); // bb.js part // // Proof creation - const prover = new Backend(assert_lt_program); + const prover = new Backend(assert_lt_json); const proof = await prover.generateIntermediateProof(serializedWitness); // Proof verification @@ -81,15 +78,15 @@ it('[BUG] -- bb.js null function or function signature mismatch (different insta x: '2', y: '3', }; - const serializedWitness = await generateWitness(assert_lt_program, inputs); + const serializedWitness = await generateWitness(assert_lt_json, inputs); // bb.js part - const prover = new Backend(assert_lt_program); + const prover = new Backend(assert_lt_json); const proof = await prover.generateFinalProof(serializedWitness); try { - const verifier = new Backend(assert_lt_program); + const verifier = new Backend(assert_lt_json); await verifier.verifyFinalProof(proof); expect.fail( 'bb.js currently returns a bug when we try to verify a proof with a different Barretenberg instance that created it.', @@ -113,13 +110,13 @@ it('[BUG] -- bb.js null function or function signature mismatch (outer-inner) ', x: '2', y: '3', }; - const serializedWitness = await generateWitness(assert_lt_program, inputs); + const serializedWitness = await generateWitness(assert_lt_json, inputs); // bb.js part // // Proof creation // - const prover = new Backend(assert_lt_program); + const prover = new Backend(assert_lt_json); // Create a proof using both proving systems, the majority of the time // one would only use outer proofs. const proofOuter = await prover.generateFinalProof(serializedWitness); diff --git a/tooling/noir_js/test/node/smoke.test.ts b/tooling/noir_js/test/node/smoke.test.ts index 739dcbfcb62..44e7d06f5ac 100644 --- a/tooling/noir_js/test/node/smoke.test.ts +++ b/tooling/noir_js/test/node/smoke.test.ts @@ -10,7 +10,7 @@ it('generates witnesses successfully', async () => { x: '2', y: '3', }; - expect(() => generateWitness(assert_lt_program, inputs)).to.not.throw; + expect(() => generateWitness(assert_lt_json, inputs)).to.not.throw; }); it('string input and number input are the same', async () => { @@ -22,8 +22,8 @@ it('string input and number input are the same', async () => { x: 2, y: 3, }; - const solvedWitnessString = await generateWitness(assert_lt_program, inputsString); - const solvedWitnessNumber = await generateWitness(assert_lt_program, inputsNumber); + const solvedWitnessString = await generateWitness(assert_lt_json, inputsString); + const solvedWitnessNumber = await generateWitness(assert_lt_json, inputsNumber); expect(solvedWitnessString).to.deep.equal(solvedWitnessNumber); }); @@ -37,8 +37,8 @@ it('string input and number input are the same', async () => { y: 3, }; - const solvedWitnessString = await generateWitness(assert_lt_program, inputsString); - const solvedWitnessNumber = await generateWitness(assert_lt_program, inputsNumber); + const solvedWitnessString = await generateWitness(assert_lt_json, inputsString); + const solvedWitnessNumber = await generateWitness(assert_lt_json, inputsNumber); expect(solvedWitnessString).to.deep.equal(solvedWitnessNumber); }); @@ -49,7 +49,7 @@ it('0x prefixed string input for inputs will throw', async () => { }; try { - await generateWitness(assert_lt_program, inputsHexPrefix); + await generateWitness(assert_lt_json, inputsHexPrefix); expect.fail('Expected generatedWitness to throw, due to inputs being prefixed with 0x. Currently not supported'); } catch (error) { // Successfully errored due to 0x not being supported. Update this test once/if we choose @@ -65,7 +65,7 @@ describe('input validation', () => { }; try { - await generateWitness(assert_lt_program, inputs); + await generateWitness(assert_lt_json, inputs); expect.fail('Expected generatedWitness to throw, due to x not being convertible to a uint64'); } catch (error) { const knownError = error as Error; diff --git a/tooling/noir_js_types/package.json b/tooling/noir_js_types/package.json index f4801a546c7..eb913f16ca3 100644 --- a/tooling/noir_js_types/package.json +++ b/tooling/noir_js_types/package.json @@ -28,9 +28,6 @@ "types": "./lib/esm/types.d.ts" } }, - "dependencies": { - "@noir-lang/noirc_abi": "workspace:*" - }, "devDependencies": { "@types/prettier": "^3", "eslint": "^8.50.0", diff --git a/tooling/noir_js_types/src/types.ts b/tooling/noir_js_types/src/types.ts index 6285972d1e9..357e440f155 100644 --- a/tooling/noir_js_types/src/types.ts +++ b/tooling/noir_js_types/src/types.ts @@ -1,5 +1,3 @@ -import { Abi } from '@noir-lang/noirc_abi'; - export interface Backend { // Generate an outer proof. This is the proof for the circuit which will verify // inner proofs and or can be seen as the proof created for regular circuits. @@ -21,5 +19,5 @@ export type ProofData = { export type CompiledCircuit = { bytecode: string; - abi: Abi; + abi: object; }; diff --git a/tooling/noirc_abi_wasm/src/lib.rs b/tooling/noirc_abi_wasm/src/lib.rs index ea03aa8abe7..ba8c35e4c44 100644 --- a/tooling/noirc_abi_wasm/src/lib.rs +++ b/tooling/noirc_abi_wasm/src/lib.rs @@ -24,70 +24,14 @@ mod js_witness_map; use errors::JsAbiError; use js_witness_map::JsWitnessMap; -#[wasm_bindgen(typescript_custom_section)] -const INPUT_MAP: &'static str = r#" -export type Field = string | number | boolean; -export type InputValue = Field | Field[] | InputMap; -export type InputMap = { [key: string]: InputValue }; -"#; - -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(extends = js_sys::Object, js_name = "InputMap", typescript_type = "InputMap")] - #[derive(Clone, Debug, PartialEq, Eq)] - pub type JsInputMap; -} - -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(extends = js_sys::Object, js_name = "InputValue", typescript_type = "InputValue")] - #[derive(Clone, Debug, PartialEq, Eq)] - pub type JsInputValue; -} - -#[wasm_bindgen(typescript_custom_section)] -const ABI: &'static str = r#" -export type Visibility = "public" | "private"; -export type Sign = "unsigned" | "signed"; -export type AbiType = - { kind: "field" } | - { kind: "boolean" } | - { kind: "string", length: number } | - { kind: "integer", sign: Sign, width: number } | - { kind: "array", length: number, type: AbiType } | - { kind: "tuple", fields: AbiType[] } | - { kind: "struct", path: string, fields: [string, AbiType][] }; - -export type AbiParameter = { - name: string, - type: AbiType, - visibility: Visibility, -}; - -export type Abi = { - parameters: AbiParameter[], - param_witnesses: Record, - return_type: AbiType | null, - return_witnesses: number[], -} -"#; - -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(extends = js_sys::Object, js_name = "Abi", typescript_type = "Abi")] - #[derive(Clone, Debug, PartialEq, Eq)] - pub type JsAbi; -} - #[wasm_bindgen(js_name = abiEncode)] pub fn abi_encode( - abi: JsAbi, - inputs: JsInputMap, - return_value: Option, + abi: JsValue, + inputs: JsValue, + return_value: JsValue, ) -> Result { console_error_panic_hook::set_once(); - let abi: Abi = - JsValueSerdeExt::into_serde(&JsValue::from(abi)).map_err(|err| err.to_string())?; + let abi: Abi = JsValueSerdeExt::into_serde(&abi).map_err(|err| err.to_string())?; let inputs: BTreeMap = JsValueSerdeExt::into_serde(&JsValue::from(inputs)).map_err(|err| err.to_string())?; let return_value: Option = return_value @@ -119,10 +63,9 @@ pub fn abi_encode( } #[wasm_bindgen(js_name = abiDecode)] -pub fn abi_decode(abi: JsAbi, witness_map: JsWitnessMap) -> Result { +pub fn abi_decode(abi: JsValue, witness_map: JsWitnessMap) -> Result { console_error_panic_hook::set_once(); - let abi: Abi = - JsValueSerdeExt::into_serde(&JsValue::from(abi)).map_err(|err| err.to_string())?; + let abi: Abi = JsValueSerdeExt::into_serde(&abi).map_err(|err| err.to_string())?; let witness_map = WitnessMap::from(witness_map); diff --git a/tooling/noirc_abi_wasm/test/browser/abi_encode.test.ts b/tooling/noirc_abi_wasm/test/browser/abi_encode.test.ts index e1aaf0dc2c0..5e604aa5b66 100644 --- a/tooling/noirc_abi_wasm/test/browser/abi_encode.test.ts +++ b/tooling/noirc_abi_wasm/test/browser/abi_encode.test.ts @@ -1,5 +1,5 @@ import { expect } from '@esm-bundle/chai'; -import initNoirAbi, { abiEncode, abiDecode, WitnessMap, Field } from '@noir-lang/noirc_abi'; +import initNoirAbi, { abiEncode, abiDecode, WitnessMap } from '@noir-lang/noirc_abi'; import { DecodedInputs } from '../types'; beforeEach(async () => { @@ -9,13 +9,11 @@ beforeEach(async () => { it('recovers original inputs when abi encoding and decoding', async () => { const { abi, inputs } = await import('../shared/abi_encode'); - const initial_witness: WitnessMap = abiEncode(abi, inputs); + const initial_witness: WitnessMap = abiEncode(abi, inputs, null); const decoded_inputs: DecodedInputs = abiDecode(abi, initial_witness); - const foo: Field = inputs.foo as Field; - const bar: Field[] = inputs.bar as Field[]; - expect(BigInt(decoded_inputs.inputs.foo)).to.be.equal(BigInt(foo)); - expect(BigInt(decoded_inputs.inputs.bar[0])).to.be.equal(BigInt(bar[0])); - expect(BigInt(decoded_inputs.inputs.bar[1])).to.be.equal(BigInt(bar[1])); + expect(BigInt(decoded_inputs.inputs.foo)).to.be.equal(BigInt(inputs.foo)); + expect(BigInt(decoded_inputs.inputs.bar[0])).to.be.equal(BigInt(inputs.bar[0])); + expect(BigInt(decoded_inputs.inputs.bar[1])).to.be.equal(BigInt(inputs.bar[1])); expect(decoded_inputs.return_value).to.be.null; }); diff --git a/tooling/noirc_abi_wasm/test/browser/errors.test.ts b/tooling/noirc_abi_wasm/test/browser/errors.test.ts index 429a2d446a3..5f9b40a195c 100644 --- a/tooling/noirc_abi_wasm/test/browser/errors.test.ts +++ b/tooling/noirc_abi_wasm/test/browser/errors.test.ts @@ -8,7 +8,7 @@ beforeEach(async () => { it('errors when an integer input overflows', async () => { const { abi, inputs } = await import('../shared/uint_overflow'); - expect(() => abiEncode(abi, inputs)).to.throw( + expect(() => abiEncode(abi, inputs, null)).to.throw( 'The parameter foo is expected to be a Integer { sign: Unsigned, width: 32 } but found incompatible value Field(2³⁸)', ); }); @@ -16,11 +16,11 @@ it('errors when an integer input overflows', async () => { it('errors when passing a field in place of an array', async () => { const { abi, inputs } = await import('../shared/field_as_array'); - expect(() => abiEncode(abi, inputs)).to.throw('cannot parse value into Array { length: 2, typ: Field }'); + expect(() => abiEncode(abi, inputs, null)).to.throw('cannot parse value into Array { length: 2, typ: Field }'); }); it('errors when passing an array in place of a field', async () => { const { abi, inputs } = await import('../shared/array_as_field'); - expect(() => abiEncode(abi, inputs)).to.throw('cannot parse value into Field'); + expect(() => abiEncode(abi, inputs, null)).to.throw('cannot parse value into Field'); }); diff --git a/tooling/noirc_abi_wasm/test/node/abi_encode.test.ts b/tooling/noirc_abi_wasm/test/node/abi_encode.test.ts index a49c10b6ea6..830e45cf10b 100644 --- a/tooling/noirc_abi_wasm/test/node/abi_encode.test.ts +++ b/tooling/noirc_abi_wasm/test/node/abi_encode.test.ts @@ -1,17 +1,15 @@ import { expect } from 'chai'; -import { abiEncode, abiDecode, WitnessMap, Field } from '@noir-lang/noirc_abi'; +import { abiEncode, abiDecode, WitnessMap } from '@noir-lang/noirc_abi'; import { DecodedInputs } from '../types'; it('recovers original inputs when abi encoding and decoding', async () => { const { abi, inputs } = await import('../shared/abi_encode'); - const initial_witness: WitnessMap = abiEncode(abi, inputs); + const initial_witness: WitnessMap = abiEncode(abi, inputs, null); const decoded_inputs: DecodedInputs = abiDecode(abi, initial_witness); - const foo: Field = inputs.foo as Field; - const bar: Field[] = inputs.bar as Field[]; - expect(BigInt(decoded_inputs.inputs.foo)).to.be.equal(BigInt(foo)); - expect(BigInt(decoded_inputs.inputs.bar[0])).to.be.equal(BigInt(bar[0])); - expect(BigInt(decoded_inputs.inputs.bar[1])).to.be.equal(BigInt(bar[1])); + expect(BigInt(decoded_inputs.inputs.foo)).to.be.equal(BigInt(inputs.foo)); + expect(BigInt(decoded_inputs.inputs.bar[0])).to.be.equal(BigInt(inputs.bar[0])); + expect(BigInt(decoded_inputs.inputs.bar[1])).to.be.equal(BigInt(inputs.bar[1])); expect(decoded_inputs.return_value).to.be.null; }); diff --git a/tooling/noirc_abi_wasm/test/node/errors.test.ts b/tooling/noirc_abi_wasm/test/node/errors.test.ts index 0d007e64803..ee0670ab5be 100644 --- a/tooling/noirc_abi_wasm/test/node/errors.test.ts +++ b/tooling/noirc_abi_wasm/test/node/errors.test.ts @@ -4,7 +4,7 @@ import { abiEncode } from '@noir-lang/noirc_abi'; it('errors when an integer input overflows', async () => { const { abi, inputs } = await import('../shared/uint_overflow'); - expect(() => abiEncode(abi, inputs)).to.throw( + expect(() => abiEncode(abi, inputs, null)).to.throw( 'The parameter foo is expected to be a Integer { sign: Unsigned, width: 32 } but found incompatible value Field(2³⁸)', ); }); @@ -12,11 +12,11 @@ it('errors when an integer input overflows', async () => { it('errors when passing a field in place of an array', async () => { const { abi, inputs } = await import('../shared/field_as_array'); - expect(() => abiEncode(abi, inputs)).to.throw('cannot parse value into Array { length: 2, typ: Field }'); + expect(() => abiEncode(abi, inputs, null)).to.throw('cannot parse value into Array { length: 2, typ: Field }'); }); it('errors when passing an array in place of a field', async () => { const { abi, inputs } = await import('../shared/array_as_field'); - expect(() => abiEncode(abi, inputs)).to.throw('cannot parse value into Field'); + expect(() => abiEncode(abi, inputs, null)).to.throw('cannot parse value into Field'); }); diff --git a/tooling/noirc_abi_wasm/test/shared/abi_encode.ts b/tooling/noirc_abi_wasm/test/shared/abi_encode.ts index 28379745dec..0f9c93a4f76 100644 --- a/tooling/noirc_abi_wasm/test/shared/abi_encode.ts +++ b/tooling/noirc_abi_wasm/test/shared/abi_encode.ts @@ -1,6 +1,6 @@ -import { Abi, InputMap } from '@noir-lang/noirc_abi'; +// TODO: Add type definitions for these -export const abi: Abi = { +export const abi = { parameters: [ { name: 'foo', type: { kind: 'field' }, visibility: 'private' }, { @@ -14,7 +14,7 @@ export const abi: Abi = { return_witnesses: [], }; -export const inputs: InputMap = { +export const inputs = { foo: '1', bar: ['1', '2'], }; diff --git a/tooling/noirc_abi_wasm/test/shared/array_as_field.ts b/tooling/noirc_abi_wasm/test/shared/array_as_field.ts index ba58f075702..06e6a7beebf 100644 --- a/tooling/noirc_abi_wasm/test/shared/array_as_field.ts +++ b/tooling/noirc_abi_wasm/test/shared/array_as_field.ts @@ -1,6 +1,4 @@ -import { Abi, InputMap } from '@noir-lang/noirc_abi'; - -export const abi: Abi = { +export const abi = { parameters: [ { name: 'foo', @@ -13,6 +11,6 @@ export const abi: Abi = { return_witnesses: [], }; -export const inputs: InputMap = { +export const inputs = { foo: ['1', '2'], }; diff --git a/tooling/noirc_abi_wasm/test/shared/field_as_array.ts b/tooling/noirc_abi_wasm/test/shared/field_as_array.ts index 931720d5e1b..89ae529d6b1 100644 --- a/tooling/noirc_abi_wasm/test/shared/field_as_array.ts +++ b/tooling/noirc_abi_wasm/test/shared/field_as_array.ts @@ -1,6 +1,4 @@ -import { Abi, InputMap } from '@noir-lang/noirc_abi'; - -export const abi: Abi = { +export const abi = { parameters: [ { name: 'foo', @@ -13,6 +11,6 @@ export const abi: Abi = { return_witnesses: [], }; -export const inputs: InputMap = { +export const inputs = { foo: '1', }; diff --git a/tooling/noirc_abi_wasm/test/shared/uint_overflow.ts b/tooling/noirc_abi_wasm/test/shared/uint_overflow.ts index ee87e050b23..87f59b1440e 100644 --- a/tooling/noirc_abi_wasm/test/shared/uint_overflow.ts +++ b/tooling/noirc_abi_wasm/test/shared/uint_overflow.ts @@ -1,6 +1,4 @@ -import { Abi, InputMap } from '@noir-lang/noirc_abi'; - -export const abi: Abi = { +export const abi = { parameters: [ { name: 'foo', @@ -13,6 +11,6 @@ export const abi: Abi = { return_witnesses: [], }; -export const inputs: InputMap = { +export const inputs = { foo: `0x${(1n << 38n).toString(16)}`, };