diff --git a/docs/docs/aztec/concepts/smart_contracts/functions/context.md b/docs/docs/aztec/concepts/smart_contracts/functions/context.md index ddb8bfb3e55..a105d246acc 100644 --- a/docs/docs/aztec/concepts/smart_contracts/functions/context.md +++ b/docs/docs/aztec/concepts/smart_contracts/functions/context.md @@ -1,5 +1,7 @@ --- title: Understanding Function Context +sidebar_position: 1 +tags: [functions, context] --- ## What is the context diff --git a/docs/docs/aztec/concepts/smart_contracts/functions/public_private_unconstrained.md b/docs/docs/aztec/concepts/smart_contracts/functions/function_types_macros.md similarity index 62% rename from docs/docs/aztec/concepts/smart_contracts/functions/public_private_unconstrained.md rename to docs/docs/aztec/concepts/smart_contracts/functions/function_types_macros.md index 83b2506faad..144abb2be2d 100644 --- a/docs/docs/aztec/concepts/smart_contracts/functions/public_private_unconstrained.md +++ b/docs/docs/aztec/concepts/smart_contracts/functions/function_types_macros.md @@ -1,8 +1,29 @@ --- -title: Public, Private, and Unconstrained Functions +title: Function Macros +sidebar_position: 2 +tags: [functions, macros] --- -This page explains the three types of functions that exist on Aztec - public, private, and unconstrained. For a deeper dive into how these functions work under the hood, check out the [Inner Workings](./inner_workings.md) page. +This page explains three types of functions that exist on Aztec - public, private, and unconstrained; as well as all macros. + +## All Aztec macros + +In addition to the function macros in Noir, Aztec also has its own macros for specific functions. An Aztec contract function can be annotated with more than 1 macro. +It is also worth mentioning Noir's `unconstrained` function type [here](https://noir-lang.org/docs/noir/concepts/unconstrained/). + +- `#[aztec(public)]` or `#[aztec(private)]` - Whether the function is public or private (more in next section) +- `#[aztec(initializer)]` - If one or more functions are marked as an initializer, then one of them must be called before any non-initilizer functions +- `#[aztec(noinitcheck)]` - The function is able to be called before an initializer (if one exists) +- `#[aztec(view)]` - Makes calls to the function static (see also [Static calls](../../../../protocol-specs/calls/static-calls)) +- `#[aztec(internal)]` - Function can only be called from within the contract + +## Example + +See [Private token contract](./../../../../tutorials/contract_tutorials/token_contract.md). + +# Public, Private, and unconstrained types + +For a deeper dive into how some of these functions work under the hood, check out the [Inner Workings](./inner_workings.md) page. ## `Public` Functions diff --git a/docs/docs/aztec/concepts/smart_contracts/functions/index.md b/docs/docs/aztec/concepts/smart_contracts/functions/index.md index 63a7797becf..4c181e199b4 100644 --- a/docs/docs/aztec/concepts/smart_contracts/functions/index.md +++ b/docs/docs/aztec/concepts/smart_contracts/functions/index.md @@ -21,7 +21,7 @@ There are also special oracle functions, which can get data from outside of the Explore this section to learn: - [How function visibility works in Aztec](./visibility.md) -- [Public, private, and unconstrained functions](./public_private_unconstrained.md), and how to write them +- [Function types and Macros](./function_types_macros.md), and how to write them - How to write an [initializer function](../../../../guides/smart_contracts/writing_contracts/initializers.md) - [Calling functions from within the same smart contract and from different contracts](../../../../guides/smart_contracts/writing_contracts/call_functions.md), including calling private functions from private functions, public from public, and even private from public - [Oracles](../oracles/index.md) and how Aztec smart contracts might use them diff --git a/docs/docs/aztec/concepts/smart_contracts/functions/inner_workings.md b/docs/docs/aztec/concepts/smart_contracts/functions/inner_workings.md index 924045470a6..4a46590ad2a 100644 --- a/docs/docs/aztec/concepts/smart_contracts/functions/inner_workings.md +++ b/docs/docs/aztec/concepts/smart_contracts/functions/inner_workings.md @@ -1,5 +1,7 @@ --- title: Inner Workings of Functions +sidebar_position: 3 +tags: [functions] --- Below, we go more into depth of what is happening under the hood when you create a function in an Aztec contract and what the attributes are really doing. diff --git a/docs/docs/aztec/concepts/smart_contracts/functions/visibility.md b/docs/docs/aztec/concepts/smart_contracts/functions/visibility.md index 80cbd78bbce..d534953aa65 100644 --- a/docs/docs/aztec/concepts/smart_contracts/functions/visibility.md +++ b/docs/docs/aztec/concepts/smart_contracts/functions/visibility.md @@ -1,5 +1,7 @@ --- title: Visibility +sidebar_position: 0 +tags: [functions] --- In Aztec there are multiple different types of visibility that can be applied to functions. Namely we have `data visibility` and `function visibility`. This page explains these types of visibility. diff --git a/docs/docs/tutorials/contract_tutorials/token_contract.md b/docs/docs/tutorials/contract_tutorials/token_contract.md index 297b97f69ed..2a21152707f 100644 --- a/docs/docs/tutorials/contract_tutorials/token_contract.md +++ b/docs/docs/tutorials/contract_tutorials/token_contract.md @@ -133,9 +133,9 @@ This specifies the interface of the `Token` contract. Don't worry if you get som Before we through the interface and implement each function, let's review the functions to get a sense of what the contract does. -### Constructor interface +### Initializer interface -There is a `constructor` function that will be executed once, when the contract is deployed, similar to the constructor function in Solidity. This is marked private, so the function logic will not be transparent. To execute public function logic in the constructor, this function will call `_initialize` (marked internal, more detail below). +There is one `initilizer` function in this contract, and it will be selected and executed once when the contract is deployed, similar to a constructor in Solidity. This is marked private, so the function logic will not be transparent. To execute public function logic in the constructor, this function will call `_initialize` (marked internal, more detail below). ### Public functions diff --git a/noir/noir-repo/docs/docs/noir/concepts/functions.md b/noir/noir-repo/docs/docs/noir/concepts/functions.md index f656cdfd97a..b63c3ecd55b 100644 --- a/noir/noir-repo/docs/docs/noir/concepts/functions.md +++ b/noir/noir-repo/docs/docs/noir/concepts/functions.md @@ -184,7 +184,7 @@ See [Lambdas](./lambdas.md) for more details. Attributes are metadata that can be applied to a function, using the following syntax: `#[attribute(value)]`. -Supported attributes include: +A few supported attributes include: - **builtin**: the function is implemented by the compiler, for efficiency purposes. - **deprecated**: mark the function as _deprecated_. Calling the function will generate a warning: `warning: use of deprecated function` @@ -192,6 +192,8 @@ Supported attributes include: - **oracle**: mark the function as _oracle_; meaning it is an external unconstrained function, implemented in noir_js. See [Unconstrained](./unconstrained.md) and [NoirJS](../../reference/NoirJS/noir_js/index.md) for more details. - **test**: mark the function as unit tests. See [Tests](../../tooling/testing.md) for more details +See the Noir compiler for the full list of supported attributes [here](https://github.com/noir-lang/noir/blob/master/compiler/noirc_frontend/src/lexer/token.rs) (inside `let attribute = match &word_segments[..]` at the time of writing). + ### Field Attribute The field attribute defines which field the function is compatible for. The function is conditionally compiled, under the condition that the field attribute matches the Noir native field.