@aztec/noir-test-contracts.js 2.0.3-rc.2 → 2.0.3-rc.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23530,7 +23530,7 @@
23530
23530
  },
23531
23531
  "109": {
23532
23532
  "path": "/home/aztec-dev/aztec-packages/noir-projects/aztec-nr/aztec/src/macros/utils.nr",
23533
- "source": "use dep::protocol_types::meta::derive_serialize;\nuse std::meta::unquote;\n\npub(crate) comptime fn get_fn_visibility(f: FunctionDefinition) -> Quoted {\n if f.has_named_attribute(\"private\") {\n quote { private }\n } else if f.has_named_attribute(\"public\") {\n quote { public }\n } else {\n panic(f\"Function is neither private nor public\")\n }\n}\n\npub(crate) comptime fn is_fn_private(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"private\")\n}\n\npub(crate) comptime fn is_fn_public(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"public\")\n}\n\npub(crate) comptime fn is_fn_utility(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"utility\")\n}\n\npub(crate) comptime fn is_fn_contract_library_method(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"contract_library_method\")\n}\n\npub(crate) comptime fn is_fn_test(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"test\")\n}\n\npub(crate) comptime fn is_fn_view(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"view\")\n}\n\npub(crate) comptime fn is_fn_internal(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"internal\")\n}\n\npub(crate) comptime fn is_fn_initializer(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"initializer\")\n}\n\npub(crate) comptime fn fn_has_noinitcheck(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"noinitcheck\")\n}\n\npub(crate) comptime fn fn_has_authorize_once(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"authorize_once\")\n}\n\n/// Takes a function body as a collection of expressions, and alters it by prepending and appending quoted values.\npub(crate) comptime fn modify_fn_body(body: [Expr], prepend: Quoted, append: Quoted) -> Expr {\n // We need to quote the body before we can alter its contents, so we fold it by quoting each expression.\n let mut body_quote = body.fold(quote {}, |full_quote: Quoted, expr: Expr| {\n let expr_quote = expr.quoted();\n quote {\n $full_quote\n $expr_quote\n }\n });\n body_quote = quote {\n {\n $prepend\n $body_quote\n $append\n }\n };\n let body_expr = body_quote.as_expr();\n body_expr.expect(f\"Body is not an expression: {body_quote}\")\n}\n\n/// Adds a value to a field array. Structs and values inside arrays are required to implement the Serialize trait.\n///\n/// The function takes the name of the array, the index in the array where the value should be added, the name of the\n/// variable to be added, and the type of the variable. It returns a quoted expression that can be used in a function body.\n///\n/// The returned quoted expression will increment the `index_name` variable by the number of fields added to the array,\n/// which is typically 1 for simple types, but can be more for complex types like structs or arrays.\npub(crate) comptime fn add_to_field_array(\n array_name: Quoted,\n index_name: Quoted,\n name: Quoted,\n typ: Type,\n) -> Quoted {\n let serialized_name = f\"{name}_serialized\".quoted_contents();\n\n if typ.is_field() | typ.as_integer().is_some() | typ.is_bool() {\n quote { \n $array_name[$index_name] = $name as Field;\n $index_name += 1;\n }\n } else if typ.as_data_type().is_some() {\n // We invoke serialize as a static trait function rather than calling $name.serialize() directly in the quote\n // to avoid \"trait not in scope\" compiler warnings.\n quote { \n let $serialized_name = aztec::protocol_types::traits::Serialize::serialize($name);\n for i in 0..$serialized_name.len() {\n $array_name[$index_name] = $serialized_name[i];\n $index_name += 1;\n }\n }\n } else if typ.as_array().is_some() {\n // We invoke serialize as a static trait function rather than calling x.serialize() directly in the quote\n // to avoid \"trait not in scope\" compiler warnings.\n quote {\n for i in 0..$name.len() {\n let $serialized_name = aztec::protocol_types::traits::Serialize::serialize($name[i]);\n for i in 0..$serialized_name.len() {\n $array_name[$index_name] = $serialized_name[i];\n $index_name += 1;\n }\n }\n }\n } else if typ.as_str().is_some() {\n quote {\n let $serialized_name = $name.as_bytes();\n for i in 0..$serialized_name.len() {\n $array_name[$index_name] = $serialized_name[i] as Field;\n $index_name += 1;\n }\n }\n } else {\n panic(\n f\"Cannot add to slice: unsupported type {typ} variable {name}\",\n )\n }\n}\n\n/// Adds a value to a hash::ArgsHasher. Structs and values inside arrays are required to implement the Serialize trait.\npub(crate) comptime fn add_to_hasher(hasher_name: Quoted, name: Quoted, typ: Type) -> Quoted {\n if typ.is_field() | typ.as_integer().is_some() | typ.is_bool() {\n quote { $hasher_name.add($name as Field); }\n } else if typ.as_data_type().is_some() {\n quote { $hasher_name.add_multiple(dep::aztec::protocol_types::traits::Serialize::serialize($name)); }\n } else if typ.as_array().is_some() {\n let (element_type, _) = typ.as_array().unwrap();\n let serialized_name = f\"{name}_serialized\".quoted_contents();\n quote {\n let $serialized_name = $name.map(|x: $element_type | dep::aztec::protocol_types::traits::Serialize::serialize(x));\n for i in 0..$name.len() {\n $hasher_name.add_multiple($serialized_name[i]);\n }\n }\n } else if typ.as_tuple().is_some() {\n let tuple_len = typ.as_tuple().unwrap().len();\n let mut tuple_quotes: [Quoted] = [];\n for i in 0..tuple_len {\n let element_quote = quote { $hasher_name.add_multiple(dep::aztec::protocol_types::traits::Serialize::serialize($name.$i)); };\n tuple_quotes = tuple_quotes.push_back(element_quote);\n }\n tuple_quotes.join(quote {})\n } else if typ.as_str().is_some() {\n quote {\n $hasher_name.add_multiple($name.as_bytes().map(| byte: u8 | byte as Field));\n }\n } else {\n panic(\n f\"Cannot add to hasher: unsupported type {typ} of variable {name}\",\n )\n }\n}\n\ncomptime fn signature_of_type(typ: Type) -> Quoted {\n if typ.is_field() {\n quote {Field}\n } else if typ.as_integer().is_some() {\n let (is_signed, bit_size) = typ.as_integer().unwrap();\n if is_signed {\n f\"i{bit_size}\".quoted_contents()\n } else {\n f\"u{bit_size}\".quoted_contents()\n }\n } else if typ.is_bool() {\n quote {bool}\n } else if typ.as_str().is_some() {\n let str_len_typ = typ.as_str().unwrap();\n let str_len = str_len_typ.as_constant().unwrap();\n f\"str<{str_len}>\".quoted_contents()\n } else if typ.as_array().is_some() {\n let (element_type, array_len) = typ.as_array().unwrap();\n let array_len = if array_len.as_constant().is_some() {\n let const_len = array_len.as_constant().unwrap();\n f\"{const_len}\".quoted_contents()\n } else {\n // If array length is not a constant, chances are it's a numeric generic\n // This will make the signature of a type like Struct<N> be the same regardless\n // of the value of N, but at least this fn will not crash. It is up to the caller\n // to decide whether this is acceptable.\n f\"{array_len}\".quoted_contents()\n };\n\n let element_typ_quote = signature_of_type(element_type);\n f\"[{element_typ_quote};{array_len}]\".quoted_contents()\n } else if typ.as_data_type().is_some() {\n let (s, generics) = typ.as_data_type().unwrap();\n let field_signatures =\n s.fields(generics).map(|(_, typ, _)| signature_of_type(typ)).join(quote {,});\n f\"({field_signatures})\".quoted_contents()\n } else if typ.as_tuple().is_some() {\n // Note that tuples are handled the same way as structs\n let types = typ.as_tuple().unwrap();\n let field_signatures = types.map(|typ: Type| signature_of_type(typ)).join(quote {,});\n f\"({field_signatures})\".quoted_contents()\n } else {\n panic(f\"Unsupported type {typ}\")\n }\n}\n\npub trait AsStrQuote {\n fn as_str_quote(self) -> (Self, u32);\n}\n\nimpl<let N: u32, Env> AsStrQuote for Quoted {\n // Used to convert an arbitrary quoted type into a quoted string, removing whitespace between tokens\n comptime fn as_str_quote(self) -> (Quoted, u32) {\n let tokens = self.tokens();\n let mut acc: [u8] = &[];\n let mut total_len: u32 = 0;\n for token in tokens {\n let token_as_fmt_str = f\"{token}\";\n let token_as_str = unquote!(quote {$token_as_fmt_str});\n let token_len = unquote!(quote { $token_as_str.as_bytes().len() });\n let token_as_bytes = unquote!(quote { $token_as_str.as_bytes().as_slice() });\n total_len += token_len;\n acc = acc.append(token_as_bytes);\n }\n let result = unquote!(\n quote {\n let signature_as_array: [u8; $total_len] = $acc.as_array();\n signature_as_array.as_str_unchecked()\n },\n );\n (quote { $result }, total_len)\n }\n}\n\npub(crate) comptime fn compute_fn_selector(f: FunctionDefinition) -> Field {\n // The function selector is computed from the function signature, which is made up of the function name and types of\n // parameters, but not including the return type. For example, given:\n //\n // fn foo(a: Field, b: AztecAddress) -> Field\n //\n // The signature will be \"foo(Field,AztecAddress)\".\n let fn_name = f.name();\n let args_signatures = f.parameters().map(|(_, typ)| signature_of_type(typ)).join(quote {,});\n let signature_quote = quote { $fn_name($args_signatures) };\n let (signature_str_quote, _) = signature_quote.as_str_quote();\n\n let computation_quote = quote {\n protocol_types::traits::ToField::to_field(protocol_types::abis::function_selector::FunctionSelector::from_signature($signature_str_quote))\n };\n unquote!(computation_quote)\n}\n\npub(crate) comptime fn compute_struct_selector(\n s: TypeDefinition,\n from_signature_fn: Quoted,\n) -> Field {\n // The struct selector is computed from the type signature, similar to how one might type\n // the constructor function. For example, given:\n //\n // struct Foo {\n // a: Field,\n // b: AztecAddress,\n // }\n //\n // The signature will be \"Foo(Field,AztecAddress)\".\n let struct_name = s.name();\n let args_signatures = s\n .fields_as_written()\n .map(|(_, typ, _)| {\n // signature_of_type can handle structs, so this supports nested structs\n // FIXME: Field generics are not handled here!\n signature_of_type(typ)\n })\n .join(quote {,});\n let signature_quote = quote { $struct_name($args_signatures) };\n let (signature_str_quote, _) = signature_quote.as_str_quote();\n\n let computation_quote = quote {\n protocol_types::traits::ToField::to_field($from_signature_fn($signature_str_quote))\n };\n unquote!(computation_quote)\n}\n\n/// Returns how many storage slots a type needs to reserve for itself. State variables must implement the Storage trait\n/// for slots to be allocated for them.\npub(crate) comptime fn get_storage_size(typ: Type) -> u32 {\n // We create a type variable for the storage size. We can't simply read the value used in the implementation because\n // it may not be a constant (e.g. N + 1). We then bind it to the implementation of the Storage trait.\n let storage_size = std::meta::typ::fresh_type_variable();\n assert(\n typ.implements(quote { crate::state_vars::HasStorageSlot<$storage_size> }\n .as_trait_constraint()),\n f\"Attempted to fetch storage size, but {typ} does not implement the HasStorageSlot trait\",\n );\n\n storage_size.as_constant().unwrap()\n}\n\npub(crate) comptime fn module_has_storage(m: Module) -> bool {\n m.structs().any(|s: TypeDefinition| {\n s.has_named_attribute(\"storage\") | s.has_named_attribute(\"storage_no_init\")\n })\n}\n\npub(crate) comptime fn module_has_initializer(m: Module) -> bool {\n m.functions().any(|f: FunctionDefinition| is_fn_initializer(f))\n}\n\n/// Returns the typed expression of a trait method implementation.\n///\n/// This helper function is preferred over directly inlining with `$typ::target_method()` in a quote,\n/// as direct inlining would result in missing import warnings in the generated code (specifically,\n/// warnings that the trait implementation is not in scope).\n///\n/// # Note\n/// A copy of this function exists in `noir-protocol-circuits/crates/types/src/meta/mod.nr`. We maintain separate\n/// copies because importing it here from there would cause the `target_trait` to be interpreted in the context\n/// of the protocol circuits types crate, making it impossible to compile code for traits from this crate\n/// (e.g. NoteType).\npub(crate) comptime fn get_trait_impl_method(\n typ: Type,\n target_trait: Quoted,\n target_method: Quoted,\n) -> TypedExpr {\n let trait_constraint = target_trait.as_trait_constraint();\n typ\n .get_trait_impl(trait_constraint)\n .expect(f\"Type does not implement trait\")\n .methods()\n .filter(|m| m.name() == target_method)[0]\n .as_typed_expr()\n}\n\npub comptime fn size_in_fields(typ: Type) -> u32 {\n array_size_in_fields(typ)\n .or_else(|| bool_size_in_fields(typ))\n .or_else(|| constant_size_in_fields(typ))\n .or_else(|| field_size_in_fields(typ))\n .or_else(|| int_size_in_fields(typ))\n .or_else(|| str_size_in_fields(typ))\n .or_else(|| struct_size_in_fields(typ))\n .or_else(|| tuple_size_in_fields(typ))\n .expect(f\"Can't determine size in fields of {typ}\")\n}\n\ncomptime fn array_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_array().and_then(|typ: (Type, Type)| {\n let (typ, element_size) = typ;\n element_size.as_constant().map(|x: u32| x * size_in_fields(typ))\n })\n}\n\ncomptime fn bool_size_in_fields(typ: Type) -> Option<u32> {\n if typ.is_bool() {\n Option::some(1)\n } else {\n Option::none()\n }\n}\n\ncomptime fn field_size_in_fields(typ: Type) -> Option<u32> {\n if typ.is_field() {\n Option::some(1)\n } else {\n Option::none()\n }\n}\n\ncomptime fn int_size_in_fields(typ: Type) -> Option<u32> {\n if typ.as_integer().is_some() {\n Option::some(1)\n } else {\n Option::none()\n }\n}\n\ncomptime fn constant_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_constant()\n}\n\ncomptime fn str_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_str().map(|typ| size_in_fields(typ))\n}\n\ncomptime fn struct_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_data_type().map(|typ: (TypeDefinition, [Type])| {\n let struct_type = typ.0;\n let generics = typ.1;\n let mut size = 0;\n for field in struct_type.fields(generics) {\n size += size_in_fields(field.1);\n }\n size\n })\n}\n\ncomptime fn tuple_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_tuple().map(|types: [Type]| {\n let mut size = 0;\n for typ in types {\n size += size_in_fields(typ);\n }\n size\n })\n}\n\n/// Generates a quote that implements `Serialize` for a given struct `s`.\n/// If the struct already implements `Serialize`, we return an empty quote.\npub comptime fn derive_serialize_if_not_implemented(s: TypeDefinition) -> Quoted {\n if s.as_type().implements(quote { crate::protocol_types::traits::Serialize }\n .as_trait_constraint()) {\n // We got some serialized length meaning that the struct implements `Serialize`. For this reason we return\n // an empty quote for the implementation.\n quote {}\n } else {\n // We didn't manage to get the serialized length which means the struct doesn't implement `Serialize`\n // so we derive it.\n derive_serialize(s)\n }\n}\n"
23533
+ "source": "use dep::protocol_types::meta::derive_serialize;\nuse std::meta::unquote;\n\npub(crate) comptime fn get_fn_visibility(f: FunctionDefinition) -> Quoted {\n if f.has_named_attribute(\"private\") {\n quote { private }\n } else if f.has_named_attribute(\"public\") {\n quote { public }\n } else {\n panic(f\"Function is neither private nor public\")\n }\n}\n\npub(crate) comptime fn is_fn_private(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"private\")\n}\n\npub(crate) comptime fn is_fn_public(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"public\")\n}\n\npub(crate) comptime fn is_fn_utility(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"utility\")\n}\n\npub(crate) comptime fn is_fn_contract_library_method(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"contract_library_method\")\n}\n\npub(crate) comptime fn is_fn_test(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"test\")\n}\n\npub(crate) comptime fn is_fn_view(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"view\")\n}\n\npub(crate) comptime fn is_fn_internal(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"internal\")\n}\n\npub(crate) comptime fn is_fn_initializer(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"initializer\")\n}\n\npub(crate) comptime fn fn_has_noinitcheck(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"noinitcheck\")\n}\n\npub(crate) comptime fn fn_has_authorize_once(f: FunctionDefinition) -> bool {\n f.has_named_attribute(\"authorize_once\")\n}\n\n/// Takes a function body as a collection of expressions, and alters it by prepending and appending quoted values.\npub(crate) comptime fn modify_fn_body(body: [Expr], prepend: Quoted, append: Quoted) -> Expr {\n // We need to quote the body before we can alter its contents, so we fold it by quoting each expression.\n let mut body_quote = body.fold(quote {}, |full_quote: Quoted, expr: Expr| {\n let expr_quote = expr.quoted();\n quote {\n $full_quote\n $expr_quote\n }\n });\n body_quote = quote {\n {\n $prepend\n $body_quote\n $append\n }\n };\n let body_expr = body_quote.as_expr();\n body_expr.expect(f\"Body is not an expression: {body_quote}\")\n}\n\n/// Adds a value to a field array. Structs and values inside arrays are required to implement the Serialize trait.\n///\n/// The function takes the name of the array, the index in the array where the value should be added, the name of the\n/// variable to be added, and the type of the variable. It returns a quoted expression that can be used in a function body.\n///\n/// The returned quoted expression will increment the `index_name` variable by the number of fields added to the array,\n/// which is typically 1 for simple types, but can be more for complex types like structs or arrays.\npub(crate) comptime fn add_to_field_array(\n array_name: Quoted,\n index_name: Quoted,\n name: Quoted,\n typ: Type,\n) -> Quoted {\n let serialized_name = f\"{name}_serialized\".quoted_contents();\n\n if typ.is_field() | typ.as_integer().is_some() | typ.is_bool() {\n quote { \n $array_name[$index_name] = $name as Field;\n $index_name += 1;\n }\n } else if typ.as_data_type().is_some() {\n // We invoke serialize as a static trait function rather than calling $name.serialize() directly in the quote\n // to avoid \"trait not in scope\" compiler warnings.\n quote { \n let $serialized_name = aztec::protocol_types::traits::Serialize::serialize($name);\n for i in 0..$serialized_name.len() {\n $array_name[$index_name] = $serialized_name[i];\n $index_name += 1;\n }\n }\n } else if typ.as_array().is_some() {\n // We invoke serialize as a static trait function rather than calling x.serialize() directly in the quote\n // to avoid \"trait not in scope\" compiler warnings.\n quote {\n for i in 0..$name.len() {\n let $serialized_name = aztec::protocol_types::traits::Serialize::serialize($name[i]);\n for i in 0..$serialized_name.len() {\n $array_name[$index_name] = $serialized_name[i];\n $index_name += 1;\n }\n }\n }\n } else if typ.as_str().is_some() {\n quote {\n let $serialized_name = $name.as_bytes();\n for i in 0..$serialized_name.len() {\n $array_name[$index_name] = $serialized_name[i] as Field;\n $index_name += 1;\n }\n }\n } else {\n panic(\n f\"Cannot add to slice: unsupported type {typ} variable {name}\",\n )\n }\n}\n\n/// Adds a value to a hash::ArgsHasher. Structs and values inside arrays are required to implement the Serialize trait.\npub(crate) comptime fn add_to_hasher(hasher_name: Quoted, name: Quoted, typ: Type) -> Quoted {\n if typ.is_field() | typ.as_integer().is_some() | typ.is_bool() {\n quote { $hasher_name.add($name as Field); }\n } else if typ.as_data_type().is_some() {\n quote { $hasher_name.add_multiple(dep::aztec::protocol_types::traits::Serialize::serialize($name)); }\n } else if typ.as_array().is_some() {\n let (element_type, _) = typ.as_array().unwrap();\n let serialized_name = f\"{name}_serialized\".quoted_contents();\n quote {\n let $serialized_name = $name.map(|x: $element_type | dep::aztec::protocol_types::traits::Serialize::serialize(x));\n for i in 0..$name.len() {\n $hasher_name.add_multiple($serialized_name[i]);\n }\n }\n } else if typ.as_tuple().is_some() {\n let tuple_len = typ.as_tuple().unwrap().len();\n let mut tuple_quotes: [Quoted] = [];\n for i in 0..tuple_len {\n let element_quote = quote { $hasher_name.add_multiple(dep::aztec::protocol_types::traits::Serialize::serialize($name.$i)); };\n tuple_quotes = tuple_quotes.push_back(element_quote);\n }\n tuple_quotes.join(quote {})\n } else if typ.as_str().is_some() {\n quote {\n $hasher_name.add_multiple($name.as_bytes().map(| byte: u8 | byte as Field));\n }\n } else {\n panic(\n f\"Cannot add to hasher: unsupported type {typ} of variable {name}\",\n )\n }\n}\n\ncomptime fn signature_of_type(typ: Type) -> Quoted {\n if typ.is_field() {\n quote {Field}\n } else if typ.as_integer().is_some() {\n let (is_signed, bit_size) = typ.as_integer().unwrap();\n if is_signed {\n f\"i{bit_size}\".quoted_contents()\n } else {\n f\"u{bit_size}\".quoted_contents()\n }\n } else if typ.is_bool() {\n quote {bool}\n } else if typ.as_str().is_some() {\n let str_len_typ = typ.as_str().unwrap();\n let str_len = str_len_typ.as_constant().unwrap();\n f\"str<{str_len}>\".quoted_contents()\n } else if typ.as_array().is_some() {\n let (element_type, array_len) = typ.as_array().unwrap();\n let array_len = if array_len.as_constant().is_some() {\n let const_len = array_len.as_constant().unwrap();\n f\"{const_len}\".quoted_contents()\n } else {\n // If array length is not a constant, chances are it's a numeric generic\n // This will make the signature of a type like Struct<N> be the same regardless\n // of the value of N, but at least this fn will not crash. It is up to the caller\n // to decide whether this is acceptable.\n f\"{array_len}\".quoted_contents()\n };\n\n let element_typ_quote = signature_of_type(element_type);\n f\"[{element_typ_quote};{array_len}]\".quoted_contents()\n } else if typ.as_data_type().is_some() {\n let (s, generics) = typ.as_data_type().unwrap();\n let field_signatures =\n s.fields(generics).map(|(_, typ, _)| signature_of_type(typ)).join(quote {,});\n f\"({field_signatures})\".quoted_contents()\n } else if typ.as_tuple().is_some() {\n // Note that tuples are handled the same way as structs\n let types = typ.as_tuple().unwrap();\n let field_signatures = types.map(|typ: Type| signature_of_type(typ)).join(quote {,});\n f\"({field_signatures})\".quoted_contents()\n } else {\n panic(f\"Unsupported type {typ}\")\n }\n}\n\npub trait AsStrQuote {\n fn as_str_quote(self) -> (Self, u32);\n}\n\nimpl AsStrQuote for Quoted {\n // Used to convert an arbitrary quoted type into a quoted string, removing whitespace between tokens\n comptime fn as_str_quote(self) -> (Quoted, u32) {\n let tokens = self.tokens();\n let mut acc: [u8] = &[];\n let mut total_len: u32 = 0;\n for token in tokens {\n let token_as_fmt_str = f\"{token}\";\n let token_as_str = unquote!(quote {$token_as_fmt_str});\n let token_len = unquote!(quote { $token_as_str.as_bytes().len() });\n let token_as_bytes = unquote!(quote { $token_as_str.as_bytes().as_slice() });\n total_len += token_len;\n acc = acc.append(token_as_bytes);\n }\n let result = unquote!(\n quote {\n let signature_as_array: [u8; $total_len] = $acc.as_array();\n signature_as_array.as_str_unchecked()\n },\n );\n (quote { $result }, total_len)\n }\n}\n\npub(crate) comptime fn compute_fn_selector(f: FunctionDefinition) -> Field {\n // The function selector is computed from the function signature, which is made up of the function name and types of\n // parameters, but not including the return type. For example, given:\n //\n // fn foo(a: Field, b: AztecAddress) -> Field\n //\n // The signature will be \"foo(Field,AztecAddress)\".\n let fn_name = f.name();\n let args_signatures = f.parameters().map(|(_, typ)| signature_of_type(typ)).join(quote {,});\n let signature_quote = quote { $fn_name($args_signatures) };\n let (signature_str_quote, _) = signature_quote.as_str_quote();\n\n let computation_quote = quote {\n protocol_types::traits::ToField::to_field(protocol_types::abis::function_selector::FunctionSelector::from_signature($signature_str_quote))\n };\n unquote!(computation_quote)\n}\n\npub(crate) comptime fn compute_struct_selector(\n s: TypeDefinition,\n from_signature_fn: Quoted,\n) -> Field {\n // The struct selector is computed from the type signature, similar to how one might type\n // the constructor function. For example, given:\n //\n // struct Foo {\n // a: Field,\n // b: AztecAddress,\n // }\n //\n // The signature will be \"Foo(Field,AztecAddress)\".\n let struct_name = s.name();\n let args_signatures = s\n .fields_as_written()\n .map(|(_, typ, _)| {\n // signature_of_type can handle structs, so this supports nested structs\n // FIXME: Field generics are not handled here!\n signature_of_type(typ)\n })\n .join(quote {,});\n let signature_quote = quote { $struct_name($args_signatures) };\n let (signature_str_quote, _) = signature_quote.as_str_quote();\n\n let computation_quote = quote {\n protocol_types::traits::ToField::to_field($from_signature_fn($signature_str_quote))\n };\n unquote!(computation_quote)\n}\n\n/// Returns how many storage slots a type needs to reserve for itself. State variables must implement the Storage trait\n/// for slots to be allocated for them.\npub(crate) comptime fn get_storage_size(typ: Type) -> u32 {\n // We create a type variable for the storage size. We can't simply read the value used in the implementation because\n // it may not be a constant (e.g. N + 1). We then bind it to the implementation of the Storage trait.\n let storage_size = std::meta::typ::fresh_type_variable();\n assert(\n typ.implements(quote { crate::state_vars::HasStorageSlot<$storage_size> }\n .as_trait_constraint()),\n f\"Attempted to fetch storage size, but {typ} does not implement the HasStorageSlot trait\",\n );\n\n storage_size.as_constant().unwrap()\n}\n\npub(crate) comptime fn module_has_storage(m: Module) -> bool {\n m.structs().any(|s: TypeDefinition| {\n s.has_named_attribute(\"storage\") | s.has_named_attribute(\"storage_no_init\")\n })\n}\n\npub(crate) comptime fn module_has_initializer(m: Module) -> bool {\n m.functions().any(|f: FunctionDefinition| is_fn_initializer(f))\n}\n\n/// Returns the typed expression of a trait method implementation.\n///\n/// This helper function is preferred over directly inlining with `$typ::target_method()` in a quote,\n/// as direct inlining would result in missing import warnings in the generated code (specifically,\n/// warnings that the trait implementation is not in scope).\n///\n/// # Note\n/// A copy of this function exists in `noir-protocol-circuits/crates/types/src/meta/mod.nr`. We maintain separate\n/// copies because importing it here from there would cause the `target_trait` to be interpreted in the context\n/// of the protocol circuits types crate, making it impossible to compile code for traits from this crate\n/// (e.g. NoteType).\npub(crate) comptime fn get_trait_impl_method(\n typ: Type,\n target_trait: Quoted,\n target_method: Quoted,\n) -> TypedExpr {\n let trait_constraint = target_trait.as_trait_constraint();\n typ\n .get_trait_impl(trait_constraint)\n .expect(f\"Type does not implement trait\")\n .methods()\n .filter(|m| m.name() == target_method)[0]\n .as_typed_expr()\n}\n\npub comptime fn size_in_fields(typ: Type) -> u32 {\n array_size_in_fields(typ)\n .or_else(|| bool_size_in_fields(typ))\n .or_else(|| constant_size_in_fields(typ))\n .or_else(|| field_size_in_fields(typ))\n .or_else(|| int_size_in_fields(typ))\n .or_else(|| str_size_in_fields(typ))\n .or_else(|| struct_size_in_fields(typ))\n .or_else(|| tuple_size_in_fields(typ))\n .expect(f\"Can't determine size in fields of {typ}\")\n}\n\ncomptime fn array_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_array().and_then(|typ: (Type, Type)| {\n let (typ, element_size) = typ;\n element_size.as_constant().map(|x: u32| x * size_in_fields(typ))\n })\n}\n\ncomptime fn bool_size_in_fields(typ: Type) -> Option<u32> {\n if typ.is_bool() {\n Option::some(1)\n } else {\n Option::none()\n }\n}\n\ncomptime fn field_size_in_fields(typ: Type) -> Option<u32> {\n if typ.is_field() {\n Option::some(1)\n } else {\n Option::none()\n }\n}\n\ncomptime fn int_size_in_fields(typ: Type) -> Option<u32> {\n if typ.as_integer().is_some() {\n Option::some(1)\n } else {\n Option::none()\n }\n}\n\ncomptime fn constant_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_constant()\n}\n\ncomptime fn str_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_str().map(|typ| size_in_fields(typ))\n}\n\ncomptime fn struct_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_data_type().map(|typ: (TypeDefinition, [Type])| {\n let struct_type = typ.0;\n let generics = typ.1;\n let mut size = 0;\n for field in struct_type.fields(generics) {\n size += size_in_fields(field.1);\n }\n size\n })\n}\n\ncomptime fn tuple_size_in_fields(typ: Type) -> Option<u32> {\n typ.as_tuple().map(|types: [Type]| {\n let mut size = 0;\n for typ in types {\n size += size_in_fields(typ);\n }\n size\n })\n}\n\n/// Generates a quote that implements `Serialize` for a given struct `s`.\n/// If the struct already implements `Serialize`, we return an empty quote.\npub comptime fn derive_serialize_if_not_implemented(s: TypeDefinition) -> Quoted {\n if s.as_type().implements(quote { crate::protocol_types::traits::Serialize }\n .as_trait_constraint()) {\n // We got some serialized length meaning that the struct implements `Serialize`. For this reason we return\n // an empty quote for the implementation.\n quote {}\n } else {\n // We didn't manage to get the serialized length which means the struct doesn't implement `Serialize`\n // so we derive it.\n derive_serialize(s)\n }\n}\n"
23534
23534
  },
23535
23535
  "110": {
23536
23536
  "path": "/home/aztec-dev/aztec-packages/noir-projects/aztec-nr/aztec/src/messages/discovery/mod.nr",
package/dest/Counter.d.ts CHANGED
@@ -41,8 +41,6 @@ export declare class CounterContract extends ContractBase {
41
41
  methods: {
42
42
  /** decrement(owner: struct) */
43
43
  decrement: ((owner: AztecAddressLike) => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
44
- /** emit_in_public(n: field) */
45
- emit_in_public: ((n: FieldLike) => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
46
44
  /** get_counter(owner: struct) */
47
45
  get_counter: ((owner: AztecAddressLike) => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
48
46
  /** increment(owner: struct) */
@@ -1 +1 @@
1
- {"version":3,"file":"Counter.d.ts","sourceRoot":"","sources":["../src/Counter.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,YAAY,EACZ,KAAK,gBAAgB,EAGrB,KAAK,gBAAgB,EACrB,YAAY,EACZ,2BAA2B,EAE3B,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAE1B,YAAY,EAIZ,KAAK,SAAS,EAQd,UAAU,EACV,KAAK,MAAM,EAGZ,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,uBAAuB,kBAA4E,CAAC;AAIjH;;GAEG;AACH,qBAAa,eAAgB,SAAQ,YAAY;IAE/C,OAAO;IASP;;;;;OAKG;WACiB,EAAE,CACpB,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,MAAM;IAMhB;;OAEG;WACW,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,KAAK,EAAE,gBAAgB;IAI1F;;OAEG;WACW,oBAAoB,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,EAA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BAA2B,CAAC,GAAG,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;QAE3G,2BAA2B;QAC3B,kBAAkB,EAAE,CAAC,MAAM,2BAA2B,CAAC,GAAG,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;KAC5F,CAAC;CAGH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/noir-test-contracts.js",
3
- "version": "2.0.3-rc.2",
3
+ "version": "2.0.3-rc.21",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -59,11 +59,11 @@
59
59
  ]
60
60
  },
61
61
  "dependencies": {
62
- "@aztec/aztec.js": "2.0.3-rc.2",
62
+ "@aztec/aztec.js": "2.0.3-rc.21",
63
63
  "tslib": "^2.4.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@aztec/builder": "2.0.3-rc.2",
66
+ "@aztec/builder": "2.0.3-rc.21",
67
67
  "@jest/globals": "^30.0.0",
68
68
  "@types/jest": "^30.0.0",
69
69
  "jest": "^30.0.0",
package/src/Counter.ts CHANGED
@@ -128,9 +128,6 @@ export class CounterContract extends ContractBase {
128
128
  /** decrement(owner: struct) */
129
129
  decrement: ((owner: AztecAddressLike) => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
130
130
 
131
- /** emit_in_public(n: field) */
132
- emit_in_public: ((n: FieldLike) => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
133
-
134
131
  /** get_counter(owner: struct) */
135
132
  get_counter: ((owner: AztecAddressLike) => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
136
133