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
chore!: noir contracts, notes and note abstractions cleanup (#18782)
Fixes#15959
Partially addresses
#15966
There was a lot of mess lying around the codebase which had a real cost
when it comes to maintenance. In this PR I:
- moved `BalanceSet` from token contract to a separate `balance_set`
crate,
- drop the copies of `balance_set.nr` and use the one shared crate,
- drop `BalancesMap` from token blacklist and use there `BalanceSet`,
- drop `EasyPrivateUint` and use `BalanceSet` instead,
- drop the ugly utils from `ValueNote` and either use `BalanceSet`
instead or I copy the utils to the test contracts where they were used
(those test contracts are an ugly mess already so hiding it there seems
fine),
- renamed `ValueNote` as `FieldNote`,
- dropped stale `DocsExample` contract and pointed readers to run `nargo
expand` instead.
Now I can live in peace.
Copy file name to clipboardExpand all lines: docs/docs/developers/docs/aztec-nr/framework-description/functions/attributes.md
+13-25Lines changed: 13 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,53 +21,42 @@ A private function operates on private information, and is executed by the user
21
21
22
22
`#[external("private")]` is just syntactic sugar. At compile time, the Aztec.nr framework inserts code that allows the function to interact with the [kernel](../../../foundational-topics/advanced/circuits/kernels/private_kernel.md).
23
23
24
-
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.
24
+
If you are interested in what exactly the macros are doing we encourage you to run `nargo expand` on your contract.
25
+
This will display your contract's code after the transformations are performed.
(If you are using VSCode you can display the expanded code by pressing `CMD + Shift + P` and typing `nargo expand` and selecting `Noir: nargo expand on current package.)
33
28
34
29
#### The expansion broken down
35
30
36
31
Viewing the expanded Aztec contract uncovers a lot about how Aztec contracts interact with the kernel. To aid with developing intuition, we will break down each inserted line.
Private function calls are able to interact with each other through orchestration from within the kernel circuits. The kernel circuit forwards information to each contract function (recall each contract function is a circuit). This information then becomes part of the private context.
42
-
For example, within each private function we can access some global variables. To access them we can call on the `context`, e.g. `context.chain_id()`. The value of the chain ID comes from the values passed into the circuit from the kernel.
36
+
For example, within each private function we can access some global variables. To access them we can call on the `self.context`, e.g. `self.context.chain_id()`. The value of the chain ID comes from the values passed into the circuit from the kernel.
43
37
44
38
The kernel checks that all of the values passed to each circuit in a function call are the same.
The contract function must return information about the execution back to the kernel. This is done through a rigid structure we call the `PrivateCircuitPublicInputs`.
50
-
51
-
> _Why is it called the `PrivateCircuitPublicInputs`?_
52
-
> When verifying zk programs, return values are not computed at verification runtime, rather expected return values are provided as inputs and checked for correctness. Hence, the return values are considered public inputs.
53
-
54
-
This structure contains a host of information about the executed program. It will contain any newly created nullifiers, any messages to be sent to l2 and most importantly it will contain the return values of the function.
Each Aztec function has access to a `self` object. Upon creation it accepts storage and context. Context is initialized from the inputs provided by the kernel, and a hash of the function's inputs.
We use the kernel to pass information between circuits. This means that the return values of functions must also be passed to the kernel (where they can be later passed on to another function).
65
45
We achieve this by pushing return values to the execution context, which we then pass to the kernel.
66
46
67
47
**Hashing the function inputs.**
68
48
69
49
Inside the kernel circuits, the inputs to functions are reduced to a single value; the inputs hash. This prevents the need for multiple different kernel circuits; each supporting differing numbers of inputs. Hashing the inputs allows to reduce all of the inputs to a single value.
70
50
51
+
**Returning the context to the kernel.**
52
+
53
+
The contract function must return information about the execution back to the kernel. This is done through a rigid structure we call the `PrivateCircuitPublicInputs`.
54
+
55
+
> _Why is it called the `PrivateCircuitPublicInputs`?_
56
+
> When verifying zk programs, return values are not computed at verification runtime, rather expected return values are provided as inputs and checked for correctness. Hence, the return values are considered public inputs.
57
+
58
+
This structure contains a host of information about the executed program. It will contain any newly created nullifiers, any messages to be sent to l2 and most importantly it will contain the return values of the function.
59
+
71
60
**Making the contract's storage available**
72
61
73
62
Each `self` has a `storage` variable exposed on it.
@@ -78,7 +67,6 @@ If Storage is note defined `self.storage` contains only a placeholder value.
78
67
Any state variables declared in the `Storage` struct can now be accessed as normal struct members.
This function takes the application context, and converts it into the `PrivateCircuitPublicInputs` structure. This structure is then passed to the kernel circuit.
Copy file name to clipboardExpand all lines: docs/docs/developers/docs/resources/migration_notes.md
+62Lines changed: 62 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,68 @@ Aztec is in full-speed development. Literally every version breaks compatibility
9
9
10
10
## TBD
11
11
12
+
### [Aztec.nr]`ValueNote` renamed to `FieldNote` and `value-note` crate renamed to `field-note`
13
+
14
+
The `ValueNote` struct has been renamed to `FieldNote` to better reflect that it stores a `Field` value. The crate has also been renamed from `value-note` to `field-note`.
### [Aztec.nr] New `balance-set` library for managing token balances
24
+
25
+
A new `balance-set` library has been created that provides `BalanceSet<Context>` for managing u128 token balances with `UintNote`. This consolidates balance management functionality that was previously duplicated across contracts.
26
+
27
+
**Features:**
28
+
29
+
-`add(amount: u128)` - Add to balance
30
+
-`sub(amount: u128)` - Subtract from balance (with change note)
31
+
-`try_sub(amount: u128, max_notes: u32)` - Attempt to subtract with configurable note limit
32
+
-`balance_of()` - Get total balance (unconstrained)
-`get_value(owner)` → `at(owner).balance_of()` (returns `u128` instead of `Field`)
65
+
66
+
### [Aztec.nr]`balance_utils` removed from `value-note` (now `field-note`)
67
+
68
+
The `balance_utils` module has been removed from the `field-note` crate (formerly `value-note`). If you need similar functionality, implement it locally in your contract or use `BalanceSet` for u128 balances.
69
+
70
+
### [Aztec.nr]`filter_notes_min_sum` removed from `value-note` (now `field-note`)
71
+
72
+
The `filter_notes_min_sum` function has been removed from the `field-note` crate (formerly in `value-note`). If you need this functionality, copy it to your contract locally. This function was only used in specific test contracts and doesn't belong in the general-purpose note library.
0 commit comments