Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): document noir macros #2016

Merged
merged 36 commits into from
Sep 19, 2023
Merged

feat(docs): document noir macros #2016

merged 36 commits into from
Sep 19, 2023

Conversation

Maddiaa0
Copy link
Member

@Maddiaa0 Maddiaa0 commented Sep 5, 2023

Documents how the macros work and what they do.

Also adds some information about the context objects, they are required to understand the macros abstraction.

closes: #2063

@Maddiaa0 Maddiaa0 requested a review from LHerskind September 6, 2023 14:19
@Maddiaa0 Maddiaa0 marked this pull request as ready for review September 6, 2023 14:20
@Maddiaa0 Maddiaa0 changed the title feat(docs): document noir macros WIP feat(docs): document noir macros Sep 6, 2023
Copy link
Contributor

@LHerskind LHerskind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The renders generally get really funky indention @iAmMichaelConnor might have an idea there?

docs/docs/dev_docs/contracts/context.md Outdated Show resolved Hide resolved
docs/docs/dev_docs/contracts/context.md Outdated Show resolved Hide resolved
Behind the scenes, Aztec noir will pass data the kernel needs to and from a circuit, this is abstracted away from the developer. In an developer's eyes; the context is a useful structure that allows access and mutate the state of the `Aztec` blockchain.

## Two context's one API
The `Aztec` blockchain contains two execution environments (ADD REFERENCE).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ADD REFERENCE should either be fixed or have an issue or something.

docs/docs/dev_docs/contracts/context.md Outdated Show resolved Hide resolved
docs/docs/dev_docs/contracts/context.md Outdated Show resolved Hide resolved

When calling the `consume_l1_to_l2_message` function on a contract; a number of actions are performed by `Aztec.nr`.

1. The `msgKey` value (passed to the consume message function) is used to look up the contents of the l1 message.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea time, should we have this as an oracle instead to get it out of the input parameters here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would leave the node with alot of extra indexing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? You don't need the oracle to index it, you just use the oracle to pass in the value 🤷, that could happen similarly to the auth witnesses, but it allow us to update with an index down the line if useful.


Each Aztec function has access to a [context](./context.md) object. This object although ergonomically a global variable, is local. It is initialized from the inputs provided by the kernel, and a hash of the function's inputs.

#include_code context-example-context-return /yarn-project/noir-contracts/src/contracts/docs_example_contract/src/main.nr rust
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a small header here as well?

...
}
```
#include_code send_to_portal /yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/main.nr rust
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be updated along with #2177. Adding a comment here for reference.

DataStructures.L1Actor recipient;
bytes32 content;
}
<!-- TODO: the rest of these docs should have code snippets updates -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an issue, or should it be fixed in this pr?

Copy link
Member Author

@Maddiaa0 Maddiaa0 Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did it in this pr, will revert in this one

aztec = { git="https://github.com/AztecProtocol/aztec-packages", tag="master", directory="yarn-project/noir-libs/noir-aztec" }
```

Note: currently the dependency name ***MUST*** be `aztec`. The framework expects this namespace to be available when compiling into contracts. This limitation may be removed in the future.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would probably be better to make this a larger note os one of the info boxes.

@iAmMichaelConnor
Copy link
Contributor

The renders generally get really funky indention @iAmMichaelConnor might have an idea there?

Funky indentation? Of code snippets, you mean? I opened an issue earlier about weird code snippet indentation #2189

@Maddiaa0 Maddiaa0 requested a review from LHerskind September 18, 2023 16:50
@Maddiaa0 Maddiaa0 enabled auto-merge (squash) September 18, 2023 16:51
Copy link
Contributor

@LHerskind LHerskind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nits.

@@ -97,7 +98,7 @@ Aztec.nr uses an attribute system to annotate a function's type. Annotating a fu

However; `#aztec(private)` is just syntactic sugar. At compile time, the framework inserts code that allows the function to interact with the [kernel](../../concepts/advanced/circuits/kernels/private_kernel.md).

To help illustrate how this interacts with the internals of Aztec and its kernel circuits, we can take an example private function, and explore what it looks like after Aztec.nr's macro expansion.
To help illustrate how this interacts with the internals of #public-contextAztec and its kernel circuits, we can take an example private function, and explore what it looks like after Aztec.nr's macro expansion.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats going on with the # in here? Seems off.


When calling the `consume_l1_to_l2_message` function on a contract; a number of actions are performed by `Aztec.nr`.

1. The `msgKey` value (passed to the consume message function) is used to look up the contents of the l1 message.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? You don't need the oracle to index it, you just use the oracle to pass in the value 🤷, that could happen similarly to the auth witnesses, but it allow us to update with an index down the line if useful.

1. Msg Sender
- The message sender is the account (Aztec Contract) that sent the message to the current context. In the first call of the kernel circuit (often the account contract call), this value will be empty. For all subsequent calls the value will be the previous call.

( TODO: INCLUDE A DIAGRAM HERE SHOWING HOW IT GETS UPDATED ON CONTRACT CALLS )
> The graphic below illustrates how the message sender changes throughout the kernel circuit iterations.
<Image img={require("/img/context/sender_context_change.png")} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gud drawing.

- A constructor doesn't have a name, because its purpose is clear: to initialise state.
- In Aztec terminology, a constructor is always a 'private function' (i.e. it cannot be an `open` function).
- A constructor doesn't have a name, because its purpose is clear: to initialise contract state.
- In Aztec terminology, a constructor is always a '`private` function' (i.e. it cannot be a `public` function).
- A constructor behaves almost identically to any other function. It's just important for Aztec to be able to identify this function as special: it may only be called once, and will not be deployed as part of the contract.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably add a comment that it also cannot call any public functions.

@@ -5,7 +5,7 @@
"scripts": {
"docusaurus": "docusaurus",
"start": "docusaurus start",
"start:dev": "concurrently \"yarn preprocess:dev\" \"docusaurus start --host 0.0.0.0\"",
"start:dev": "concurrently \"yarn preprocess:dev\" \"docusaurus start --host 0.0.0.0 --port 3001\"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???

Copy link
Contributor

@LHerskind LHerskind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes lgtm. When you get it building feel free to merge.

@Maddiaa0 Maddiaa0 merged commit 1f1a17f into master Sep 19, 2023
@Maddiaa0 Maddiaa0 deleted the md/document-macros branch September 19, 2023 14:22
PhilWindle pushed a commit that referenced this pull request Sep 20, 2023
🤖 I have created a release *beep* *boop*
---


<details><summary>aztec-packages: 0.7.10</summary>

##
[0.7.10](aztec-packages-v0.7.9...aztec-packages-v0.7.10)
(2023-09-20)


### Features

* Aztec-cli unbox "really empty box"
([#2388](#2388))
([b57182d](b57182d))
* **docs:** Document noir macros
([#2016](#2016))
([1f1a17f](1f1a17f))
* **docs:** Include aztec rpc interface typedoc output in docs
([#2255](#2255))
([62c9e9b](62c9e9b))
* **token portal standard:** Create a token portal standard
([#2351](#2351))
([426a3ea](426a3ea))


### Bug Fixes

* **build:** Fix build system post deployment tests
([#2420](#2420))
([d509dc3](d509dc3))
* CLI encoding for arrays and structs
([#2407](#2407))
([85283bd](85283bd))
* Correct sandbox addresses in up-quick-start test
([#2412](#2412))
([974d859](974d859))
* **docs:** Revert include aztec rpc interface typedoc output in docs
([#2255](#2255))
([f852432](f852432))
* Handle falsy bigints in json-rpc
([#2403](#2403))
([d100650](d100650)),
closes
[#2402](#2402)
* **nargo_check.sh:** UNIX standard grep
([#2396](#2396))
([02e788a](02e788a))


### Miscellaneous

* **docs:** Note getter options
([#2411](#2411))
([8a95d8c](8a95d8c))
* Update docs url in config
([#2386](#2386))
([e44066d](e44066d))
</details>

<details><summary>barretenberg.js: 0.7.10</summary>

##
[0.7.10](barretenberg.js-v0.7.9...barretenberg.js-v0.7.10)
(2023-09-20)


### Miscellaneous

* **barretenberg.js:** Synchronize aztec-packages versions
</details>

<details><summary>barretenberg: 0.7.10</summary>

##
[0.7.10](barretenberg-v0.7.9...barretenberg-v0.7.10)
(2023-09-20)


### Miscellaneous

* **barretenberg:** Synchronize aztec-packages versions
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

docs/dev-docs/contracts/context
3 participants