Skip to content

Commit 936f4e9

Browse files
authored
docs: fix aztec-nr v4.2.0 documentation issues from audit (backport #22166) (#22227)
## Summary Backport of #22166 to v4-next. Fixes 52 documentation issues across aztec-nr doc pages (deprecated import paths, missing API parameters, incorrect method names, wrong dependency URLs, etc.). ## Conflict resolution All 20 conflicts were modify/delete in `docs/developer_versioned_docs/version-v4.2.0-aztecnr-rc.2/` — this versioned docs directory does not exist on v4-next, so the deletions were accepted. The 18 `docs-developers/` source files merged cleanly. ## Commits 1. Cherry-pick with conflicts (original attempt) 2. Conflict resolution (remove versioned docs that don't exist on v4-next) 3. No build fixes needed (docs-only change) ClaudeBox log: https://claudebox.work/s/78234c172376f4ce?run=1
2 parents a84b8da + cac6bff commit 936f4e9

18 files changed

Lines changed: 76 additions & 63 deletions

docs/docs-developers/docs/aztec-nr/compiling_contracts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Use generated interfaces instead of manual function calls:
3333

3434
```rust
3535
contract MyContract {
36-
use dep::token::Token;
36+
use token::Token;
3737

3838
#[external("private")]
3939
fn transfer_tokens(token_address: AztecAddress, recipient: AztecAddress, amount: u128) {

docs/docs-developers/docs/aztec-nr/debugging.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ tags: [debugging, errors, logging, local_network, aztec.nr]
55
description: This guide shows you how to debug issues in your Aztec contracts.
66
---
77

8-
<!-- need to move some into aztec.js -->
9-
108
This guide shows you how to debug issues in your Aztec development environment.
119

1210
## Prerequisites
@@ -160,7 +158,7 @@ link.click();
160158

161159
## Interpret error messages
162160

163-
### Kernel circuit errors (2xxx)
161+
### Circuit and protocol errors
164162

165163
- **Private kernel errors (2xxx)**: Issues with private function execution
166164
- **Public kernel errors (3xxx)**: Issues with public function execution
@@ -218,7 +216,7 @@ await wallet.getContractMetadata(myContractInstance.address);
218216

219217
### Decode L1 errors
220218

221-
Check hex errors against [Errors.sol](https://github.com/AztecProtocol/aztec-packages/blob/master/l1-contracts/src/core/libraries/Errors.sol)
219+
Check hex errors against [Errors.sol](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/l1-contracts/src/core/libraries/Errors.sol)
222220

223221
## Tips
224222

docs/docs-developers/docs/aztec-nr/framework-description/advanced/how_to_use_capsules.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,26 @@ Capsules provide per-contract non-volatile storage in the PXE. Data is stored lo
1212
```rust
1313
use aztec::oracle::capsules;
1414

15-
// Inside a contract function, use self.address for contract_address
16-
let contract_address: AztecAddress = self.address;
15+
// Capsule operations are unconstrained, so these values are typically
16+
// passed in as parameters from the calling context.
17+
let contract_address: AztecAddress = /* self.address */;
1718
let slot: Field = 1;
19+
// scope is an AztecAddress used for capsule isolation, allowing multiple
20+
// independent namespaces within the same contract.
21+
let scope: AztecAddress = /* e.g. the account address */;
1822

1923
// Store data at a slot (overwrites existing data)
20-
capsules::store(contract_address, slot, value);
24+
capsules::store(contract_address, slot, value, scope);
2125

2226
// Load data (returns Option<T>)
23-
let result: Option<MyStruct> = capsules::load(contract_address, slot);
27+
let result: Option<MyStruct> = capsules::load(contract_address, slot, scope);
2428

2529
// Delete data at a slot
26-
capsules::delete(contract_address, slot);
30+
capsules::delete(contract_address, slot, scope);
2731

2832
// Copy contiguous slots (supports overlapping regions)
29-
// copy(contract_address, src_slot, dst_slot, num_entries: u32)
30-
capsules::copy(contract_address, src_slot, dst_slot, 3);
33+
// copy(contract_address, src_slot, dst_slot, num_entries: u32, scope)
34+
capsules::copy(contract_address, src_slot, dst_slot, 3, scope);
3135
```
3236

3337
Types must implement `Serialize` and `Deserialize` traits.
@@ -42,12 +46,12 @@ All capsule operations are `unconstrained`. Data loaded from capsules should be
4246

4347
```rust
4448
use aztec::capsules::CapsuleArray;
45-
use protocol::hash::sha256_to_field;
49+
use aztec::protocol::hash::sha256_to_field;
4650

4751
// Use a hash for base_slot to avoid collisions with other storage
4852
global BASE_SLOT: Field = sha256_to_field("MY_CONTRACT::MY_ARRAY".as_bytes());
4953

50-
let array: CapsuleArray<Field> = CapsuleArray::at(contract_address, BASE_SLOT);
54+
let array: CapsuleArray<Field> = CapsuleArray::at(contract_address, BASE_SLOT, scope);
5155

5256
array.push(value); // Append to end
5357
let value = array.get(index); // Read at index (throws if out of bounds)

docs/docs-developers/docs/aztec-nr/framework-description/advanced/partial_notes.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Let's say, for example, we have a `UintNote`:
1818

1919
The `UintNote` struct itself only contains the `value` field. Additional fields including `owner`, `randomness`, and `storage_slot` are passed as parameters during note hash computation.
2020

21-
When creating the note locally during private execution, the `owner` and `storage_slot` are known, but the `value` potentially is not (e.g., it depends on some onchain dynamic variable). First, a **partial note** can be created during private execution that commits to the `owner`, `randomness`, and `storage_slot`, and then the note is *"completed"* to create a full note by later adding the `value` field, usually during public execution.
21+
When creating the note locally during private execution, the `owner` and `storage_slot` are known, but the `value` potentially is not (e.g., it depends on some onchain dynamic variable). First, a **partial note** can be created during private execution that commits to the `owner` and `randomness`, and then the note is *"completed"* to create a full note by later adding the `storage_slot` and `value` fields, usually during public execution.
2222

2323
<Image img={require("@site/static/img/partial-notes.png")} />
2424

@@ -44,14 +44,14 @@ The `UintNote` struct contains only the `value` field:
4444

4545
**Phase 1: Partial Commitment (Private Execution)**
4646

47-
The private fields (`owner`, `randomness`, and `storage_slot`) are committed during local, private execution:
47+
The private fields (`owner` and `randomness`) are committed during local, private execution:
4848

4949
#include_code compute_partial_commitment /noir-projects/aztec-nr/uint-note/src/uint_note.nr rust
5050

5151
This creates a partial note commitment:
5252

5353
```
54-
partial_commitment = H(owner, storage_slot, randomness)
54+
partial_commitment = H(owner, randomness)
5555
```
5656

5757
**Phase 2: Note Completion (Public Execution)**
@@ -63,8 +63,8 @@ The note is completed by hashing the partial commitment with the public value:
6363
The resulting structure is a nested commitment:
6464

6565
```
66-
note_hash = H(H(owner, storage_slot, randomness), value)
67-
= H(partial_commitment, value)
66+
note_hash = H(H(owner, randomness), storage_slot, value)
67+
= H(partial_commitment, storage_slot, value)
6868
```
6969

7070
## Universal Note Format
@@ -73,14 +73,13 @@ All notes in Aztec use the partial note format internally, even when all data is
7373

7474
When a note is created with all fields known (including `owner`, `storage_slot`, `randomness`, and `value`):
7575

76-
1. A partial commitment is computed from the private fields (`owner`, `storage_slot`, `randomness`)
77-
2. The partial commitment is immediately completed with the `value` field
76+
1. A partial commitment is computed from the private fields (`owner`, `randomness`)
77+
2. The partial commitment is immediately completed with the `storage_slot` and `value` fields
7878

7979
#include_code compute_note_hash /noir-projects/aztec-nr/uint-note/src/uint_note.nr rust
8080

8181
This two-step process ensures that notes with identical field values produce identical note hashes, regardless of whether they were created as partial notes or complete notes.
8282

83-
<Image img={require("@site/static/img/shrek.jpeg")} />
8483

8584
## Partial Notes in Practice
8685

docs/docs-developers/docs/aztec-nr/framework-description/advanced/writing_efficient_contracts.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ To get a sense of things, here is a table of gate counts for common operations:
9595
| ~75 | Hashing 3 fields with Poseidon2 |
9696
| 3500 | Reading a value from a tree (public data tree, note hash tree, nullifier tree) |
9797
| 4000 | Reading a delayed public mutable read |
98-
| X000 | Calculating sha256 |
99-
| X000 | Constrained encryption of a log of Y fields |
100-
| X000 | Constrained encryption and tag a log of Y fields |
98+
| ~5,000 | Calculating sha256 (varies by input size) |
99+
| Varies | Constrained encryption of a private log (depends on field count) |
100+
| Varies | Constrained encryption and tagging of a private log (depends on field count) |
101101

102102
### Optimization: use arithmetic instead of non-arithmetic operations
103103

@@ -106,7 +106,7 @@ Because the underlying equation in the proving backend makes use of multiplicati
106106
For example:
107107

108108
```rust
109-
comptime global TWO_POW_32: Field = 2.pow_32(16);
109+
comptime global TWO_POW_16: Field = 2.pow_32(16);
110110
// ...
111111
{
112112
#[external("private")]
@@ -116,7 +116,7 @@ comptime global TWO_POW_32: Field = 2.pow_32(16);
116116

117117
#[external("private")]
118118
fn mul_efficient(number: Field) -> u128 {
119-
(number * TWO_POW_32) as u128
119+
(number * TWO_POW_16) as u128
120120
} // 5184 gates (60 gates less)
121121
}
122122
```
@@ -153,7 +153,7 @@ For example, use boolean equality effectively instead of `>=`:
153153
}
154154
}
155155
sum
156-
} // 45068 gates (751 gates less)
156+
} // 45068 gates (751 gates more due to the boolean operations, but the pattern demonstrates how to avoid range checks)
157157
}
158158
```
159159

@@ -279,9 +279,12 @@ Like with sqrt, we have the inefficient function that does the sort with constra
279279
// Safety: calculate in unconstrained function, then constrain the result
280280
let sorted_array = unsafe { super::sort_array(array) };
281281
// constrain that sorted_array elements are sorted
282-
for i in 0..super::ARRAY_SIZE as u32 {
282+
for i in 0..super::ARRAY_SIZE as u32 - 1 {
283283
assert(sorted_array[i] <= sorted_array[i + 1], "array should be sorted");
284284
}
285+
// Note: A production implementation should also verify that sorted_array is a
286+
// permutation of the input array to prevent a malicious prover from returning
287+
// arbitrary sorted values.
285288
sorted_array
286289
} // 5870 gates (953 gates less) for 10 elements, 12582 gates for 100 elements (115198 gates less)
287290
}
@@ -309,7 +312,7 @@ Note: The stdlib provides a highly optimized version of sort on arrays, `array.s
309312
```rust
310313
#[external("private")]
311314
fn sort_stdlib(array: [u32; super::ARRAY_SIZE]) -> [u32; super::ARRAY_SIZE] {
312-
array.sort();
315+
array.sort()
313316
} // 5943 gates (880 gates less) for 10 elements, 13308 gates for 100 elements (114472 gates less)
314317
```
315318

docs/docs-developers/docs/aztec-nr/framework-description/contract_structure.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,16 @@ use aztec::macros::aztec;
9898
pub contract MyContract {
9999
use aztec::{
100100
macros::storage,
101-
state_vars::{PrivateMutable, PublicMutable}
101+
state_vars::{Owned, PrivateMutable, PublicMutable}
102102
};
103+
use uint_note::UintNote;
103104

104105
// The storage struct can have any name, but is typically called `Storage`. It must have the `#[storage]` macro applied to it.
105106
// This struct must also have a generic type called C or Context.
106107
#[storage]
107108
struct Storage<Context> {
108109
// A private numeric value which can change over time. This value will be hidden, and only those with the secret can know its current value.
109-
my_private_state_variable: Owned<PrivateMutable<NoteType, Context>>,
110+
my_private_state_variable: Owned<PrivateMutable<UintNote, Context>, Context>,
110111
// A public numeric value which can change over time. This value will be known to everyone and is equivalent to the Solidity example above.
111112
my_public_state_variable: PublicMutable<u128, Context>,
112113
}
@@ -142,6 +143,7 @@ use aztec::macros::aztec;
142143
#[aztec]
143144
contract MyContract {
144145
use aztec::macros::functions::external;
146+
use aztec::protocol::address::AztecAddress;
145147

146148
#[external("private")]
147149
fn my_private_function(parameter_a: u128, parameter_b: AztecAddress) {
@@ -154,7 +156,7 @@ contract MyContract {
154156
}
155157

156158
#[external("utility")]
157-
fn my_utility_function(parameter_a: u128, parameter_b: AztecAddress) {
159+
unconstrained fn my_utility_function(parameter_a: u128, parameter_b: AztecAddress) {
158160
// ...
159161
}
160162
}

docs/docs-developers/docs/aztec-nr/framework-description/contract_upgrades.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ fn update_to(new_class_id: ContractClassId) {
4141
}
4242
```
4343

44+
:::info
45+
To use the `ContractInstanceRegistry`, add this dependency to your `Nargo.toml`:
46+
```toml
47+
contract_instance_registry = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/noir-contracts/contracts/protocol_interface/contract_instance_registry_interface" }
48+
```
49+
:::
50+
4451
The `update` function in the registry is a public function, so you can enqueue it from a private function (as shown above) or call it directly from a public function.
4552

4653
:::warning[Access Control]

docs/docs-developers/docs/aztec-nr/framework-description/custom_notes.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ Aztec.nr provides pre-built note types for common use cases:
2929

3030
```toml
3131
# In Nargo.toml
32-
uint_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/aztec-nr/uint-note" }
32+
uint_note = { git="https://github.com/AztecProtocol/aztec-nr", tag="#include_aztec_version", directory="uint-note" }
3333
```
3434

3535
**FieldNote** - For storing single Field values:
3636

3737
```toml
3838
# In Nargo.toml
39-
field_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/aztec-nr/field-note" }
39+
field_note = { git="https://github.com/AztecProtocol/aztec-nr", tag="#include_aztec_version", directory="field-note" }
4040
```
4141

4242
**AddressNote** - For storing Aztec addresses:
4343

4444
```toml
4545
# In Nargo.toml
46-
address_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/aztec-nr/address-note" }
46+
address_note = { git="https://github.com/AztecProtocol/aztec-nr", tag="#include_aztec_version", directory="address-note" }
4747
```
4848

4949
:::

docs/docs-developers/docs/aztec-nr/framework-description/events_and_logs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use aztec::messages::message_delivery::MessageDelivery;
3434

3535
#[external("private")]
3636
fn transfer(to: AztecAddress, amount: u128) {
37-
let from = self.msg_sender().unwrap();
37+
let from = self.msg_sender();
3838

3939
// ... transfer logic ...
4040

docs/docs-developers/docs/aztec-nr/framework-description/functions/attributes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ It is also useful in private functions when dealing with tasks of an unknown siz
126126
This macro inserts a check at the beginning of the function to ensure that the caller is the contract itself. This is done by adding the following assertion:
127127

128128
```rust
129-
assert(self.msg_sender().unwrap() == self.address, "Function can only be called internally");
129+
assert(self.msg_sender() == self.address, "Function can only be called internally");
130130
```
131131

132132
## #[allow_phase_change]

0 commit comments

Comments
 (0)