You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/aztec/concepts/accounts/keys.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,7 +106,7 @@ When it comes to storing the signing key in a private note, there are several de
106
106
107
107
#### Using Delayed Public Mutable state
108
108
109
-
By [Delayed Public Mutable](../../../developers/guides/smart_contracts/data_types.md#delayed-public-mutable) we mean privately readable publicly mutable state.
109
+
By [Delayed Public Mutable](../../../developers/guides/smart_contracts/storage_types.md#delayed-public-mutable) we mean privately readable publicly mutable state.
110
110
111
111
To make public state accessible privately, there is a delay window in public state updates. One needs this window to be able to generate proofs client-side. This approach would not generate additional nullifiers and commitments for each transaction while allowing the user to rotate their key. However, this causes every transaction to now have a time-to-live determined by the frequency of the delayed mutable state, as well as imposing restrictions on how fast keys can be rotated due to minimum delays.
Even with the router contract achieving good privacy is hard.
151
151
For example, if the value being checked against is unique and stored in the contract's public storage, it's then simple to find private transactions that are using that value in the enqueued public reads, and therefore link them to this contract.
152
-
For this reason it is encouraged to try to avoid public function calls and instead privately read [Shared State](../../developers/guides/smart_contracts/data_types.md#delayed-public-mutable) when possible.
152
+
For this reason it is encouraged to try to avoid public function calls and instead privately read [Shared State](../../developers/guides/smart_contracts/storage_types.md#delayed-public-mutable) when possible.
Copy file name to clipboardExpand all lines: docs/docs/developers/guides/smart_contracts/common_patterns.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ Note - you could also create a note and send it to the user. The problem is ther
39
39
40
40
### Reading public storage in private
41
41
42
-
You can read public storage in private domain by leveraging the private getters of `PublicImmutable` (for values that never change) and `DelayedPublicMutable` (for values that change infrequently, see [delayed public mutable state](./data_types.md#delayed-public-mutable) for details) state variables.
42
+
You can read public storage in private domain by leveraging the private getters of `PublicImmutable` (for values that never change) and `DelayedPublicMutable` (for values that change infrequently, see [delayed public mutable state](./storage_types.md#delayed-public-mutable) for details) state variables.
43
43
Values that change frequently (`PublicMutable`) cannot be read in private as for those we need access to the tip of the chain and only a sequencer has access to that (and sequencer executes only public functions).
Copy file name to clipboardExpand all lines: docs/docs/developers/guides/smart_contracts/note_types.md
+12-5Lines changed: 12 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
---
2
-
title: Custom Types
2
+
title: Note Types
3
3
tags: [contracts, notes]
4
4
sidebar_position: 3
5
5
keywords: [implementing note, note]
6
-
description: Learn how to implement custom note types in your Aztec smart contracts.
6
+
description: Learn about note types and how to implement custom note types in your Aztec smart contracts.
7
7
---
8
8
9
9
Notes are the fundamental data structure in Aztec when working with private state. Using Aztec.nr, developers can define note types which allow flexibility in how notes are stored and nullified.
@@ -14,9 +14,7 @@ For example, if you are developing a card game, you may want to store multiple p
14
14
15
15
If you want to work with values, addresses or integers, you can check out [ValueNote](#valuenote), or [AddressNote](#addressnote).
16
16
17
-
## Define a note type
18
-
19
-
You will likely want to define your note in a new file and import it into your contract.
17
+
## Standard Note Type
20
18
21
19
A note type can be defined with the macro `#[note]` used on a struct:
22
20
@@ -38,6 +36,7 @@ This would work since the nullifier would be unique and only the note recipient
38
36
However, if we did this, the sender could also derive the nullifier off-chain and monitor the nullifier tree for its inclusion, allowing them to determine when a note has been spent.
39
37
This would leak privacy.
40
38
39
+
41
40
## Examples
42
41
43
42
Address notes hold one main property of the type `AztecAddress`. It also holds `owner` and `randomness`, similar to other note types.
@@ -124,6 +123,14 @@ For example:
124
123
125
124
The `decrement` function works similarly except the `amount` is the number that the value will be decremented by, and it will fail if the sum of the selected notes is less than the amount.
126
125
126
+
### Custom Note Type
127
+
128
+
Using the `#[custom_note]` macro allows you to define your own note hash and nullifier schemes for your notes, rather than using the default poseidon2 hash of the note to generate the note hash or using the note owners nullifier key to generate a nullifier.
129
+
130
+
The TransparentNote in an example token contract demonstrates how you can generate a custom note hash and nullifiers.
-[What is `#[note]` actually doing? + functions such as serialize() and deserialize()](../../../aztec/smart_contracts/functions/attributes.md#implementing-notes)
Copy file name to clipboardExpand all lines: docs/docs/developers/guides/smart_contracts/storage_types.md
+30-24Lines changed: 30 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,12 @@
1
1
---
2
-
title: Data Types
2
+
title: Storage Types
3
3
sidebar_position: 2
4
4
tags: [data-types, smart-contracts]
5
-
description: Learn about the data types available in Aztec.nr.
5
+
description: Learn about how data is stored in Aztec contracts.
6
6
---
7
7
8
+
Interacting with the protocol in a reliable, private manner is simplified by using the storage types described below, provided by the Aztec.nr library for writing contracts.
9
+
8
10
## Map
9
11
10
12
A `map` is a state variable that "maps" a key to a value. It can be used with private or public storage variables.
@@ -57,15 +59,15 @@ To simplify the experience of writing private state, Aztec.nr provides three dif
57
59
58
60
These three structs abstract-away many of Aztec's protocol complexities, by providing intuitive methods to modify notes in the utxo tree in a privacy-preserving way.
59
61
60
-
Unlike public state variables, which can be arbitrary types, private state variables operate on `NoteType`. See [custom types](./custom_types.md) for more information about how to define your own note types.
62
+
Unlike public state variables, which can be arbitrary types, private state variables operate on `NoteType`. See [Note Types](./note_types.md) for more information about how to define your own note types.
61
63
62
64
Notes are the fundamental elements of private state.
63
65
64
66
### PrivateMutable
65
67
66
68
PrivateMutable is a private state variable that is unique in a way. When a PrivateMutable is initialized, a note is created to represent its value. And the way to update the value is to destroy the current note, and create a new one with the updated value.
67
69
68
-
Like for public state, we define the struct to have context and a storage slot. You can view the implementation [here (GitHub link)](https://github.com/AztecProtocol/aztec-packages/blob/master/noir-projects/aztec-nr/aztec/src/state_vars/private_mutable.nr).
70
+
Like for public state, we define the struct to have context and a storage slot. You can view the implementation [here](https://github.com/AztecProtocol/aztec-packages/blob/master/noir-projects/aztec-nr/aztec/src/state_vars/private_mutable.nr).
69
71
70
72
An example of `PrivateMutable` usage in the account contracts is keeping track of public keys. The `PrivateMutable` is added to the `Storage` struct as follows:
71
73
@@ -103,12 +105,18 @@ An unconstrained method to check whether the PrivateMutable has been initialized
103
105
104
106
#### `replace`
105
107
106
-
To update the value of a `PrivateMutable`, we can use the `replace` method. The method takes a new note as input, and replaces the current note with the new one. It emits a nullifier for the old value, and inserts the new note into the data tree.
108
+
To update the value of a `PrivateMutable`, we can use the `replace` method. The method takes a new note as input and replaces the current note with the new one. It emits a nullifier for the old value, and inserts the new note into the data tree.
107
109
108
110
An example of this is seen in a example card game, where we create a new note (a `CardNote`) containing some new data, and replace the current note with it:
Calling `emit(encode_and_encrypt_note())` on the `replace` method will encrypt the new note and post it to the data availability layer so that the note information is retrievable by the recipient.
117
+
118
+
:::
119
+
112
120
If two people are trying to modify the PrivateMutable at the same time, only one will succeed as we don't allow duplicate nullifiers! Developers should put in place appropriate access controls to avoid race conditions (unless a race is intended!).
113
121
114
122
#### `get_note`
@@ -151,6 +159,12 @@ Set the value of an PrivateImmutable by calling the `initialize` method:
Calling `emit(encode_and_encrypt_note())` on `initialize` will encrypt the new note and post it to the data availability layer so that the note information is retrievable by the recipient.
165
+
166
+
:::
167
+
154
168
Once initialized, an PrivateImmutable's value remains unchangeable. This method can only be called once.
155
169
156
170
#### `is_initialized`
@@ -175,21 +189,11 @@ Functionally similar to `get_note`, but executed unconstrained and can be used b
175
189
176
190
### PrivateSet
177
191
178
-
`PrivateSet` is used for managing a collection of notes. All notes in a `PrivateSet` are of the same `NoteType`. But whether these notes all belong to one entity, or are accessible and editable by different entities, is up to the developer. The set is a collection of notes inserted into the data-tree, but notes are never removed from the tree itself, they are only nullified.
179
-
180
-
You can view the implementation [here (GitHub link)](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr).
181
-
182
-
And can be added to the `Storage` struct as follows. Here adding a set for a custom note.
192
+
`PrivateSet` is used for managing a collection of notes. All notes in a `PrivateSet` are of the same `NoteType`. But whether these notes all belong to one entity, or are accessible and editable by different entities, is up to the developer.
Calling `emit(encode_and_encrypt_note())` on `insert` will encrypt the new note and post it to the data availability layer so that the note information is retrievable by the recipient.
209
+
210
+
:::
211
+
202
212
#### `insert_from_public`
203
213
204
214
The `insert_from_public` allow public function to insert notes into private storage. This is very useful when we want to support private function calls that have been initiated in public.
@@ -243,20 +253,16 @@ This function requires a `NoteViewerOptions`. The `NoteViewerOptions` is essenti
243
253
244
254
### PublicMutable
245
255
246
-
The `PublicMutable`(formerly known as `PublicState`) struct is generic over the variable type `T`.
256
+
The `PublicMutable` struct is generic over the variable type `T`.
247
257
248
258
The struct contains a `storage_slot` which, similar to Ethereum, is used to figure out _where_ in storage the variable is located.
249
259
250
260
For a version of `PublicMutable` that can also be read in private, head to [`DelayedPublicMutable`](#delayed-public-mutable).
251
261
252
262
:::info
253
-
An example using a larger struct can be found in the [lending example (GitHub link)](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-contracts/contracts/app/lending_contract)'s use of an [`Asset` (GitHub link)](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/noir-projects/noir-contracts/contracts/app/lending_contract/src/asset.nr).
263
+
An example using a larger struct can be found in the [lending example](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-contracts/contracts/app/lending_contract)'s use of an [`Asset`](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/noir-projects/noir-contracts/contracts/app/lending_contract/src/asset.nr).
254
264
:::
255
265
256
-
#### `new`
257
-
258
-
When declaring the storage for `T` as a persistent public storage variable, we use the `PublicMutable::new()` constructor. As seen below, this takes the `storage_slot` and the `serialization_methods` as arguments along with the `Context`, which in this case is used to share interface with other structures. You can view the implementation [here (GitHub link)](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/aztec-nr/aztec/src/state_vars/public_mutable.nr).
259
-
260
266
##### Single value example
261
267
262
268
To add `admin` public state variable into our storage struct, we can define it as:
Copy file name to clipboardExpand all lines: docs/docs/developers/tutorials/contract_tutorials/nft_contract.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -174,7 +174,7 @@ Below the dependencies, paste the following Storage struct:
174
174
175
175
## Custom Notes
176
176
177
-
The contract storage uses a [custom note](../../../guides/smart_contracts/custom_types.md) implementation. Custom notes are useful for defining your own data types. You can think of a custom note as a "chunk" of private data, the entire thing is added, updated or nullified (deleted) together. This NFT note is very simple and stores only the owner and the `token_id` and uses `randomness` to hide its contents.
177
+
The contract storage uses a [custom note](../../../guides/smart_contracts/note_types.md) implementation. Custom notes are useful for defining your own data types. You can think of a custom note as a "chunk" of private data, the entire thing is added, updated or nullified (deleted) together. This NFT note is very simple and stores only the owner and the `token_id` and uses `randomness` to hide its contents.
178
178
179
179
Randomness is required because notes are stored as commitments (hashes) in the note hash tree. Without randomness, the contents of a note may be derived through brute force (e.g. without randomness, if you know my Aztec address, you may be able to figure out which note hash in the tree is mine by hashing my address with many potential `token_id`s).
0 commit comments