Skip to content

Commit 57078d4

Browse files
jzakicritesjosh
andauthored
docs: aztec macros (#6935)
Closes AztecProtocol/dev-rel#189 --------- Co-authored-by: josh crites <critesjosh@gmail.com>
1 parent b70bc98 commit 57078d4

7 files changed

Lines changed: 35 additions & 6 deletions

File tree

docs/docs/aztec/concepts/smart_contracts/functions/context.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
title: Understanding Function Context
3+
sidebar_position: 1
4+
tags: [functions, context]
35
---
46

57
## What is the context

docs/docs/aztec/concepts/smart_contracts/functions/public_private_unconstrained.md renamed to docs/docs/aztec/concepts/smart_contracts/functions/function_types_macros.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
11
---
2-
title: Public, Private, and Unconstrained Functions
2+
title: Function Macros
3+
sidebar_position: 2
4+
tags: [functions, macros]
35
---
46

5-
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.
7+
This page explains three types of functions that exist on Aztec - public, private, and unconstrained; as well as all macros.
8+
9+
## All Aztec macros
10+
11+
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.
12+
It is also worth mentioning Noir's `unconstrained` function type [here](https://noir-lang.org/docs/noir/concepts/unconstrained/).
13+
14+
- `#[aztec(public)]` or `#[aztec(private)]` - Whether the function is public or private (more in next section)
15+
- `#[aztec(initializer)]` - If one or more functions are marked as an initializer, then one of them must be called before any non-initilizer functions
16+
- `#[aztec(noinitcheck)]` - The function is able to be called before an initializer (if one exists)
17+
- `#[aztec(view)]` - Makes calls to the function static (see also [Static calls](../../../../protocol-specs/calls/static-calls))
18+
- `#[aztec(internal)]` - Function can only be called from within the contract
19+
20+
## Example
21+
22+
See [Private token contract](./../../../../tutorials/contract_tutorials/token_contract.md).
23+
24+
# Public, Private, and unconstrained types
25+
26+
For a deeper dive into how some of these functions work under the hood, check out the [Inner Workings](./inner_workings.md) page.
627

728
## `Public` Functions
829

docs/docs/aztec/concepts/smart_contracts/functions/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ There are also special oracle functions, which can get data from outside of the
2121
Explore this section to learn:
2222

2323
- [How function visibility works in Aztec](./visibility.md)
24-
- [Public, private, and unconstrained functions](./public_private_unconstrained.md), and how to write them
24+
- [Function types and Macros](./function_types_macros.md), and how to write them
2525
- How to write an [initializer function](../../../../guides/smart_contracts/writing_contracts/initializers.md)
2626
- [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
2727
- [Oracles](../oracles/index.md) and how Aztec smart contracts might use them

docs/docs/aztec/concepts/smart_contracts/functions/inner_workings.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
title: Inner Workings of Functions
3+
sidebar_position: 3
4+
tags: [functions]
35
---
46

57
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.

docs/docs/aztec/concepts/smart_contracts/functions/visibility.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
title: Visibility
3+
sidebar_position: 0
4+
tags: [functions]
35
---
46

57
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.

docs/docs/tutorials/contract_tutorials/token_contract.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ This specifies the interface of the `Token` contract. Don't worry if you get som
133133

134134
Before we through the interface and implement each function, let's review the functions to get a sense of what the contract does.
135135

136-
### Constructor interface
136+
### Initializer interface
137137

138-
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).
138+
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).
139139

140140
### Public functions
141141

noir/noir-repo/docs/docs/noir/concepts/functions.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,16 @@ See [Lambdas](./lambdas.md) for more details.
184184

185185
Attributes are metadata that can be applied to a function, using the following syntax: `#[attribute(value)]`.
186186

187-
Supported attributes include:
187+
A few supported attributes include:
188188

189189
- **builtin**: the function is implemented by the compiler, for efficiency purposes.
190190
- **deprecated**: mark the function as _deprecated_. Calling the function will generate a warning: `warning: use of deprecated function`
191191
- **field**: Used to enable conditional compilation of code depending on the field size. See below for more details
192192
- **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.
193193
- **test**: mark the function as unit tests. See [Tests](../../tooling/testing.md) for more details
194194

195+
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).
196+
195197
### Field Attribute
196198

197199
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.

0 commit comments

Comments
 (0)