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
BEGIN_COMMIT_OVERRIDE
fix(docs): update links in how_to_define_storage.md to include aztec
version (#17904)
chore(docs): Remove protocol specs from next (#17911)
END_COMMIT_OVERRIDE
Copy file name to clipboardExpand all lines: docs/docs/developers/docs/guides/smart_contracts/how_to_define_storage.md
+10-9Lines changed: 10 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,7 +98,7 @@ All private storage operates on note types rather than arbitrary data types. Lea
98
98
99
99
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. Updating the value means to destroy the current note, and to create a new one with the updated value.
100
100
101
-
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/smart-contracts/aztec/src/state_vars/private_mutable.nr).
101
+
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/#include_aztec_version/noir-projects/aztec-nr/aztec/src/state_vars/private_mutable.nr).
102
102
103
103
An example of `PrivateMutable` usage in contracts is keeping track of important values. The `PrivateMutable` is added to the `Storage` struct as follows:
104
104
@@ -116,17 +116,18 @@ Unlike public states, which have a default initial value of `0` (or many zeros,
116
116
117
117
#### `is_initialized`
118
118
119
-
An unconstrained method to check whether the PrivateMutable has been initialized or not. It takes an optional owner and returns a boolean. You can view the implementation [here (GitHub link)](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/smart-contracts/aztec/src/state_vars/private_mutable.nr).
119
+
An unconstrained method to check whether the PrivateMutable has been initialized or not. It takes an optional owner and returns a boolean. 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_mutable.nr).
120
120
121
121
```rust
122
122
letis_initialized=my_value.is_initialized();
123
123
```
124
-
s
124
+
125
125
#### `replace`
126
126
127
127
To update the value of a `PrivateMutable`, we can use the `replace` method. The method takes a function (or closure) that transforms the current note into a new one.
128
128
129
129
When called, the method will:
130
+
130
131
- Nullify the old note
131
132
- Apply the transform function to produce a new note
132
133
- Insert the new note into the data tree
@@ -168,7 +169,7 @@ Functionally similar to [`get_note`](#get_note), but executed in unconstrained f
168
169
169
170
### PrivateImmutable
170
171
171
-
`PrivateImmutable` represents a unique private state variable that, as the name suggests, is immutable. Once initialized, its value cannot be altered. You can view the implementation [here (GitHub link)](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/smart-contracts/aztec/src/state_vars/private_immutable.nr).
172
+
`PrivateImmutable` represents a unique private state variable that, as the name suggests, is immutable. Once initialized, its value cannot be altered. 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_immutable.nr).
172
173
173
174
#### `initialize`
174
175
@@ -198,7 +199,7 @@ Once initialized, an PrivateImmutable's value remains unchangeable. This method
198
199
199
200
#### `is_initialized`
200
201
201
-
An unconstrained method to check if the PrivateImmutable has been initialized. Takes an optional owner and returns a boolean. You can find the implementation [here (GitHub link)](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/smart-contracts/aztec/src/state_vars/private_immutable.nr).
202
+
An unconstrained method to check if the PrivateImmutable has been initialized. Takes an optional owner and returns a boolean. You can find the implementation [here (GitHub link)](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/aztec-nr/aztec/src/state_vars/private_immutable.nr).
202
203
203
204
#### `get_note`
204
205
@@ -284,7 +285,7 @@ let mut options = NoteViewerOptions::new();
There's also a limit on the maximum number of notes that can be returned in one go. To find the current limit, refer to [this file (GitHub link)](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/smart-contracts/aztec/src/note/constants.nr) and look for `MAX_NOTES_PER_PAGE`.
288
+
There's also a limit on the maximum number of notes that can be returned in one go. To find the current limit, refer to [this file (GitHub link)](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/aztec-nr/aztec/src/note/constants.nr) and look for `MAX_NOTES_PER_PAGE`.
288
289
289
290
The key distinction is that this method is unconstrained. It does not perform a check to verify if the notes actually exist, which is something the [`get_notes`](#get_notes) method does under the hood. Therefore, it should only be used in an unconstrained contract function.
290
291
@@ -304,7 +305,7 @@ Both types are generic over any serializable type `T`, allowing you to store sim
304
305
Store mutable public state using `PublicMutable<T>` for values that need to be updated throughout the contract's lifecycle.
305
306
306
307
:::info
307
-
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).
308
+
An example using a larger struct can be found in the [lending example](https://github.com/AztecProtocol/aztec-packages/tree/#include_aztec_version/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).
308
309
:::
309
310
310
311
For example, to add `config_value` public state variable into our storage struct, we can define it as:
@@ -346,7 +347,7 @@ Just like the `PublicMutable` it is generic over the variable type `T`. The type
You can find the details of `PublicImmutable` in the implementation [here (GitHub link)](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/smart-contracts/aztec/src/state_vars/public_immutable.nr).
350
+
You can find the details of `PublicImmutable` in the implementation [here (GitHub link)](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/aztec-nr/aztec/src/state_vars/public_immutable.nr).
350
351
351
352
#### `new`
352
353
@@ -405,7 +406,7 @@ Delayed Public Mutable state works around this by introducing **delays**:
405
406
406
407
- Instead, a value change is be scheduled ahead of time, and some minimum amount of time must pass between the scheduling and the new value taking effect.
407
408
- This means that we can privately prove that a historical public value cannot possibly change before some point in the future (due to the minimum delay), and therefore that our transaction will be valid **as long as it gets included before this future time**.
408
-
- In other words, we're saying "this value is public but can't change until ___".
409
+
- In other words, we're saying "this value is public but can't change until \_\_\_".
409
410
410
411
This results in the following key properties of `DelayedPublicMutable` state:
0 commit comments