Skip to content

Commit

Permalink
docs: aztec macros (#6935)
Browse files Browse the repository at this point in the history
Closes AztecProtocol/dev-rel#189

---------

Co-authored-by: josh crites <[email protected]>
  • Loading branch information
jzaki and critesjosh authored Jun 7, 2024
1 parent b70bc98 commit 57078d4
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/docs/aztec/concepts/smart_contracts/functions/context.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
title: Understanding Function Context
sidebar_position: 1
tags: [functions, context]
---

## What is the context
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/tutorials/contract_tutorials/token_contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion noir/noir-repo/docs/docs/noir/concepts/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,16 @@ 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`
- **field**: Used to enable conditional compilation of code depending on the field size. See below for more details
- **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.
Expand Down

0 comments on commit 57078d4

Please sign in to comment.