Skip to content

Commit 32a917e

Browse files
committed
more flattening, rearranging
1 parent eb8fea5 commit 32a917e

File tree

28 files changed

+280
-358
lines changed

28 files changed

+280
-358
lines changed

docs/docs/aztec/concepts/storage/notes.md

Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,145 @@ When using the Aztec protocol, users may not be aware of the specific notes that
4343

4444
This is accomplished through the smart contract library, Aztec.nr, which abstracts notes by allowing developers to specify custom note types. This means they can specify how notes are interacted with, nullified, transferred, and displayed. Aztec.nr also helps users discover all of the notes that have been encrypted to their account and posted to the chain, known as [note discovery](../advanced/storage/note_discovery.md).
4545

46-
To understand note abstraction in Aztec.nr, you can read the [Build section](../../../developers/guides/smart_contracts/notes/index.md).
46+
## Technical details
47+
48+
### Some context
49+
50+
- Public functions and storage work much like other blockchains in terms of having dedicated storage slots and being publicly visible
51+
- Private functions are executed locally with proofs generated for sound execution, and commitments to private variable updates are stored using append-only trees
52+
- "Note" types are part of Aztec.nr, a framework that facilitates use of Aztec's different storage trees to achieve things such as private variables
53+
54+
This page will focus on how private variables are implemented with Notes and storage trees.
55+
56+
#### Side-note about execution
57+
58+
Under the hood, the Aztec protocol handles some important details around public and private function calls. Calls between them are asynchronous due to different execution contexts (local execution vs. node execution).
59+
A detailed explanation of the transaction lifecycle can be found [here](../transactions.md#simple-example-of-the-private-transaction-lifecycle).
60+
61+
## Private state variables in Aztec
62+
63+
State variables in an Aztec contract are defined inside a struct specifically named `Storage`, and must satisfy the [Note Interface (GitHub link)](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/noir-projects/aztec-nr/aztec/src/note/note_interface.nr) and contain a [Note header (GitHub link)](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/noir-projects/aztec-nr/aztec/src/note/note_header.nr).
64+
65+
The Note header struct contains the contract address which the value is effectively siloed to, a nonce to ensure unique Note hashes, and a storage "slot" (or ID) to associate multiple notes.
66+
67+
A couple of things to unpack here:
68+
69+
#### Storage "slot"
70+
71+
Storage slots are more literal for public storage, a place where a value is stored. For private storage, a storage slot is logical (more [here](../advanced/storage/storage_slots.md)).
72+
73+
#### Silos
74+
75+
The address of the contract is included in a Note's data to ensure that different contracts don't arrive at the same hash with an identical variable. This is handled in the protocol's execution.
76+
77+
### Note types
78+
79+
There is more than one Note type, such as the `PrivateSet` type is used for private variables. There are also `PrivateMutable` and `PrivateImmutable` types.
80+
81+
Furthermore, notes can be completely custom types, storing any value or set of values that are desired by an application.
82+
83+
### Initialization
84+
85+
Private state variables are stored locally when the contract is created. Depending on the application, values may be privately shared by the creator with others via encrypted logs onchain.
86+
A hash of a note is stored in the append-only note hash tree on the network so as to prove existence of the current state of the note in a privacy preserving way.
87+
88+
#### Note Hash Tree
89+
90+
By virtue of being append only, notes are not edited. If two transactions amend a private value, multiple notes will be inserted into the tree to the note hash tree and the nullifier tree. The header will contain the same logical storage slot.
91+
92+
### Reading Notes
93+
94+
:::info
95+
96+
Only those with appropriate keys/information will be able to successfully read private values that they have permission to. Notes can be read outside of a transaction or "off-chain" with no changes to data structures on-chain.
97+
98+
:::
99+
100+
When a note is read in a transaction, a subsequent read from another transaction of the same note would reveal a link between the two. So to preserve privacy, notes that are read in a transaction are said to be "consumed" (defined below), and new note(s) are then created with a unique hash.
101+
102+
With type `PrviateSet`, a private variable's value is interpreted as the sum of values of notes with the same logical storage slot.
103+
104+
Consuming, deleting, or otherwise "nullifying" a note is NOT done by deleting the Note hash; this would leak information. Rather a nullifier is created deterministically linked to the value. This nullifier is inserted into another the nullifier storage tree.
105+
106+
When reading a value, the local private execution checks that its notes (of the corresponding storage slot/ID) have not been nullified.
107+
108+
### Updating
109+
110+
:::note
111+
Only those with appropriate keys/information will be able to successfully nullify a value that they have permission to.
112+
:::
113+
114+
To update a value, its previous note hash(es) are nullified. The new note value is updated in the user's private execution environment (PXE), and the updated note hash inserted into the note hash tree.
115+
116+
## Supplementary components
117+
118+
Some optional background resources on notes can be found here:
119+
120+
- [High level network architecture](../../index.md), specifically the Private Execution Environment
121+
- [Transaction lifecycle (simple diagram)](../transactions.md#simple-example-of-the-private-transaction-lifecycle)
122+
- [Public and Private state](./state_model.md)
123+
124+
Notes touch several core components of the protocol, but we will focus on a the essentials first.
125+
126+
### Some code context
127+
128+
The way Aztec benefits from the Noir language is via three important components:
129+
130+
- `Aztec.nr` - a Noir framework enabling contracts on Aztec, written in Noir. Includes useful Note implementations
131+
- `noir contracts` - example Aztec contracts
132+
- `noir-protocol-circuits` - a crate containing essential circuits for the protocol (public circuits and private wrappers)
133+
134+
A lot of what we will look at will be in [aztec-nr/aztec/src/note (GitHub link)](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/noir-projects/aztec-nr/aztec/src/note), specifically the lifecycle and note interface.
135+
136+
Looking at the noir circuits in these components, you will see references to the distinction between public/private execution and state.
137+
138+
### Lifecycle functions
139+
140+
Inside the [lifecycle (GitHub link)](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/noir-projects/aztec-nr/aztec/src/note/lifecycle.nr) circuits we see the functions to create and destroy a note, implemented as insertions of note hashes and nullifiers respectively. This is helpful for regular private variables.
141+
142+
We also see a function to create a note hash from the public context, a way of creating a private variable from a public call (run in the sequencer). This could be used in application contracts to give private digital assets to users.
143+
144+
### Note Interface functions
145+
146+
To see a [note_interface (GitHub link)](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/noir-projects/aztec-nr/aztec/src/note/note_interface.nr) implementation, we will look at a simple [ValueNote GitHub link](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/noir-projects/aztec-nr/value-note/src/value_note.nr).
147+
148+
The interface is required to work within an Aztec contract's storage, and a ValueNote is a specific type of note to hold a number (as a `Field`).
149+
150+
#### Computing hashes and nullifiers
151+
152+
A few key functions in the note interface are around computing the note hash and nullifier, with logic to get/use secret keys from the private context.
153+
154+
In the ValueNote implementation you'll notice that it uses the `pedersen_hash` function. This is currently required by the protocol, but may be updated to another hashing function, like poseidon.
155+
156+
As a convenience, the outer [note/utils.nr (GitHub link)](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/noir-projects/aztec-nr/aztec/src/note/utils.nr) contains implementations of functions that may be needed in Aztec contracts, for example computing note hashes.
157+
158+
#### Serialization and deserialization
159+
160+
Serialization/deserialization of content is used to convert between the Note's variables and a generic array of Field elements. The Field type is understood and used by lower level crypographic libraries.
161+
This is analogous to the encoding/decoding between variables and bytes in solidity.
162+
163+
For example in ValueNote, the `serialize_content` function simply returns: the value, nullifying public key hash (as a field) and the note randomness; as an array of Field elements.
164+
165+
### Value as a sum of Notes
166+
167+
We recall that multiple notes are associated with a "slot" (or ID), and so the value of a numerical note (like ValueNote) is the sum of each note's value.
168+
The helper function in [balance_utils (GitHub link)](https://github.com/AztecProtocol/aztec-packages/blob/#include_/noir-projects/aztec-nr/value-note/src/balance_utils.nr) implements this logic taking a `PrivateSet` of `ValueNotes`.
169+
170+
A couple of things worth clarifying:
171+
172+
- A `PrivateSet` takes a Generic type, specified here as `ValueNote`, but can be any `Note` type (for all notes in the set)
173+
- A `PrivateSet` of notes also specifies _the_ slot of all Notes that it holds
174+
175+
### Example - Notes in action
176+
177+
The Aztec.nr framework includes examples of high-level states [easy_private_uint (GitHub link)](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr) for use in contracts.
178+
179+
The struct (`EasyPrivateUint`) contains a Context, Set of ValueNotes, and storage_slot (used when setting the Set).
180+
181+
Notice how the `add` function shows the simplicity of appending a new note to all existing ones. On the other hand, `sub` (subtraction), needs to first add up all existing values (consuming them in the process), and then insert a single new value of the difference between the sum and parameter.
182+
183+
---
184+
185+
### References
186+
187+
- ["Stable" state variable (GitHub link)](https://github.com/AztecProtocol/aztec-packages/issues/4130)

docs/docs/developers/guides/getting_started_on_testnet.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Setting up for Testnet
3-
sidebar_position: 1
3+
sidebar_position: 3
44
tags: [testnet]
55
description: Guide for developers to get started with the Aztec testnet, including account creation and contract deployment.
66
---
@@ -14,6 +14,7 @@ This guide explains the differences between sandbox and testnet, how to migrate
1414
Before diving into the setup, it's important to understand the differences between sandbox and testnet:
1515

1616
### Sandbox (Local Development)
17+
1718
- Runs locally on your machine
1819
- No proving by default (faster development)
1920
- No fees
@@ -22,6 +23,7 @@ Before diving into the setup, it's important to understand the differences betwe
2223
- Ideal for rapid development and testing
2324

2425
### Testnet (Remote Network)
26+
2527
- Remote environment with network of sequencers
2628
- Always has proving enabled (longer transaction times)
2729
- Always has fees enabled (need to pay or sponsor fees)
@@ -128,7 +130,6 @@ aztec-wallet send mint_to_private \
128130
--args accounts:my-wallet 10
129131
```
130132

131-
132133
## Migrating from Sandbox to Testnet
133134

134135
If you have an existing app running on sandbox, here's how to migrate it to testnet:
@@ -152,11 +153,13 @@ aztec-wallet create-account -a main --register-only --node-url $NODE_URL
152153
You can connect to testnet directly from your app using AztecJS:
153154

154155
In the browser:
156+
155157
```javascript
156158
import { createPXEService } from "@aztec/pxe/client/lazy";
157159
```
158160

159161
In Node.js:
162+
160163
```javascript
161164
import { createPXEService } from "@aztec/pxe/server";
162165
```
@@ -219,8 +222,8 @@ Testnet transactions take longer than sandbox. Handle timeouts gracefully:
219222
try {
220223
const receipt = await tx.wait();
221224
} catch (error) {
222-
if (error.message.includes('Timeout awaiting isMined')) {
223-
console.log('Transaction sent but still being mined');
225+
if (error.message.includes("Timeout awaiting isMined")) {
226+
console.log("Transaction sent but still being mined");
224227
// Check block explorer for status
225228
}
226229
}
@@ -231,8 +234,8 @@ try {
231234
Detect which environment your code is running against:
232235

233236
```javascript
234-
const isTestnet = process.env.NODE_URL?.includes('testnet');
235-
const nodeUrl = process.env.NODE_URL || 'http://localhost:8080';
237+
const isTestnet = process.env.NODE_URL?.includes("testnet");
238+
const nodeUrl = process.env.NODE_URL || "http://localhost:8080";
236239
```
237240
238241
## Next Steps
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"position": 3,
3-
"collapsible": true,
4-
"collapsed": true,
5-
"label": "How to Use Aztec in JS"
2+
"position": 2,
3+
"collapsible": true,
4+
"collapsed": true,
5+
"label": "How to Use Aztec in JS"
66
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"position": 4,
3-
"collapsible": true,
4-
"collapsed": true,
5-
"label": "Developing Smart Contracts"
2+
"position": 1,
3+
"collapsible": true,
4+
"collapsed": true,
5+
"label": "Developing Smart Contracts"
66
}

docs/docs/developers/guides/smart_contracts/authwit.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
2-
title: Authentication Witness
3-
description: Developer Documentation to use Authentication Witness for authentication actions on Aztec.
2+
title: Permit Contract Actions
3+
description: Developer Documentation to use Authentication Witness for authorizing actions by other contracts.
44
tags: [accounts, authwit]
5+
sidebar_position: 7
56
---
67

78
This page introduces the authwit library and how you can use it in your Aztec.nr smart contracts. [Skip to the usage](#usage).

docs/docs/developers/guides/smart_contracts/call_contracts.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: Calling Other Contracts
3-
sidebar_position: 4
4-
tags: [functions, contracts]
2+
title: Contract Composability
3+
sidebar_position: 6
4+
tags: [functions, contracts, composability]
55
description: Learn how to call other contracts from your Aztec smart contracts.
66
---
77

0 commit comments

Comments
 (0)