Skip to content

Commit 88feaab

Browse files
iAmMichaelConnorludamad
authored andcommitted
chore: move a migration note (#17739)
1 parent 1b1500b commit 88feaab

File tree

2 files changed

+95
-90
lines changed

2 files changed

+95
-90
lines changed

docs/docs/developers/migration_notes.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,101 @@ Aztec is in full-speed development. Literally every version breaks compatibility
99

1010
## TBD
1111

12+
### `msg_sender` is now an `Option<AztecAddress>` type.
13+
14+
Because Aztec has native account abstraction, the very first function call of a tx has no `msg_sender`. (Recall, the first function call of an Aztec transaction is always a _private_ function call).
15+
16+
Previously (before this change) we'd been silently setting this first `msg_sender` to be `AztecAddress::from_field(-1);`, and enforcing this value in the protocol's kernel circuits. Now we're passing explicitness to smart contract developers by wrapping `msg_sender` in an `Option` type. We'll explain the syntax shortly.
17+
18+
We've also added a new protocol feature. Previously (before this change) whenever a public function call was enqueued by a private function (a so-called private->public call), the called public function (and hence the whole world) would be able to see `msg_sender`. For some use cases, visibility of `msg_sender` is important, to ensure the caller executed certain checks in private-land. For `#[internal]` public functions, visibility of `msg_sender` is unavoidable (the caller of an internal function must be the same contract address by definition). But for _some_ use cases, a visible `msg_sender` is an unnecessary privacy leakage.
19+
We therefore have added a feature where `msg_sender` can be optionally set to `Option<AztecAddress>::none()` for enqueued public function calls (aka private->public calls). We've been colloquially referring to this as "setting msg_sender to null".
20+
21+
#### Aztec.nr diffs
22+
23+
> Note: we'll be doing another pass at this aztec.nr syntax in the near future.
24+
25+
Given the above, the syntax for accessing `msg_sender` in Aztec.nr is slightly different:
26+
27+
For most public and private functions, to adjust to this change, you can make this change to your code:
28+
29+
```diff
30+
- let sender: AztecAddress = context.msg_sender();
31+
+ let sender: AztecAddress = context.msg_sender().unwrap();
32+
```
33+
34+
Recall that `Option::unwrap()` will throw if the Option is "none".
35+
36+
Indeed, most smart contract functions will require access to a proper contract address (instead of a "null" value), in order to do bookkeeping (allocation of state variables against user addresses), and so in such cases throwing is sensible behaviour.
37+
38+
If you want to output a useful error message when unwrapping fails, you can use `Option::expect`:
39+
40+
```diff
41+
- let sender: AztecAddress = context.msg_sender();
42+
+ let sender: AztecAddress = context.msg_sender().expect(f"Sender must not be none!");
43+
```
44+
45+
For a minority of functions, a "null" msg_sender will be acceptable:
46+
47+
- A private entrypoint function.
48+
- A public function which doesn't seek to do bookkeeping against `msg_sender`.
49+
50+
Some apps might even want to _assert_ that the `msg_sender` is "null" to force their users into strong privacy practices:
51+
52+
```rust
53+
let sender: Option<AztecAddress> = context.msg_sender();
54+
assert(sender.is_none());
55+
```
56+
57+
##### Enqueueing public function calls
58+
59+
###### Auto-generated contract interfaces
60+
61+
When you use the `#[aztec]` macro, it will generate a noir contract interface for your contract, behind the scenes.
62+
63+
This provides pretty syntax when you come to call functions of that contract. E.g.:
64+
65+
```rust
66+
Token::at(context.this_address())._increase_public_balance(to, amount).enqueue(&mut context);
67+
```
68+
69+
In keeping with this new feature of being able to enqueue public function calls with a hidden `msg_sender`, there are some new methods that can be chained instead of `.enqueue(...)`:
70+
71+
- `enqueue_incognito` -- akin to `enqueue`, but `msg_sender` is set "null".
72+
- `enqueue_view_incognito` -- akin to `enqueue_view`, but `msg_sender` is "null".
73+
- `set_as_teardown_incognito` -- akin to `set_as_teardown`, but `msg_sender` is "null".
74+
75+
> The name "incognito" has been chosen to imply "msg_sender will not be visible to observers".
76+
77+
These new functions enable the _calling_ contract to specify that it wants its address to not be visible to the called public function. This is worth re-iterating: it is the _caller's_ choice. A smart contract developer who uses these functions must be sure that the target public function will accept a "null" `msg_sender`. It would not be good (for example) if the called public function did `context.msg_sender().unwrap()`, because then a public function that is called via `enqueue_incognito` would _always fail_! Hopefully smart contract developers will write sufficient tests to catch such problems during development!
78+
79+
###### Making lower-level public function calls from the private context
80+
81+
This is discouraged vs using the auto-generated contract interfaces described directly above.
82+
83+
If you do use any of these low-level methods of the `PrivateContext` in your contract:
84+
85+
- `call_public_function`
86+
- `static_call_public_function`
87+
- `call_public_function_no_args`
88+
- `static_call_public_function_no_args`
89+
- `call_public_function_with_calldata_hash`
90+
- `set_public_teardown_function`
91+
- `set_public_teardown_function_with_calldata_hash`
92+
93+
... there is a new `hide_msg_sender: bool` parameter that you will need to specify.
94+
95+
#### Aztec.js diffs
96+
97+
> Note: we'll be doing another pass at this aztec.js syntax in the near future.
98+
99+
When lining up a new tx, the `FunctionCall` struct has been extended to include a `hide_msg_sender: bool` field.
100+
101+
- `is_public & hide_msg_sender` -- will make a public call with `msg_sender` set to "null".
102+
- `is_public & !hide_msg_sender` -- will make a public call with a visible `msg_sender`, as was the case before this new feature.
103+
- `!is_public & hide_msg_sender` -- Incompatible flags.
104+
- `!is_public & !hide_msg_sender` -- will make a private call with a visible `msg_sender` (noting that since it's a private function call, the `msg_sender` will only be visible to the called private function, but not to the rest of the world).
105+
106+
12107
## [cli-wallet]
13108

14109
The `deploy-account` command now requires the address (or alias) of the account to deploy as an argument, not a parameter

docs/versioned_docs/version-v2.0.2/developers/migration_notes.md

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -9,96 +9,6 @@ Aztec is in full-speed development. Literally every version breaks compatibility
99

1010
## 2.0.2
1111

12-
### `msg_sender` is now an `Option<AztecAddress>` type.
13-
14-
Because Aztec has native account abstraction, the very first function call of a tx has no `msg_sender`. (Recall, the first function call of an Aztec transaction is always a _private_ function call).
15-
16-
Previously (before this change) we'd been silently setting this first `msg_sender` to be `AztecAddress::from_field(-1);`, and enforcing this value in the protocol's kernel circuits. Now we're passing explicitness to smart contract developers by wrapping `msg_sender` in an `Option` type. We'll explain the syntax shortly.
17-
18-
We've also added a new protocol feature. Previously (before this change) whenever a public function call was enqueued by a private function (a so-called private->public call), the called public function (and hence the whole world) would be able to see `msg_sender`. For some use cases, visibility of `msg_sender` is important, to ensure the caller executed certain checks in private-land. For `#[internal]` public functions, visibility of `msg_sender` is unavoidable (the caller of an internal function must be the same contract address by definition). But for _some_ use cases, a visible `msg_sender` is an unnecessary privacy leakage.
19-
We therefore have added a feature where `msg_sender` can be optionally set to `Option<AztecAddress>::none()` for enqueued public function calls (aka private->public calls). We've been colloquially referring to this as "setting msg_sender to null".
20-
21-
#### Aztec.nr diffs
22-
23-
Given the above, the syntax for accessing `msg_sender` in Aztec.nr is slightly different:
24-
25-
For most public and private functions, to adjust to this change, you can make this change to your code:
26-
27-
```diff
28-
- let sender: AztecAddress = context.msg_sender();
29-
+ let sender: AztecAddress = context.msg_sender().unwrap();
30-
```
31-
32-
Recall that `Option::unwrap()` will throw if the Option is "none".
33-
34-
Indeed, most smart contract functions will require access to a proper contract address (instead of a "null" value), in order to do bookkeeping (allocation of state variables against user addresses), and so in such cases throwing is sensible behaviour.
35-
36-
If you want to output a useful error message when unwrapping fails, you can use `Option::expect`:
37-
38-
```diff
39-
- let sender: AztecAddress = context.msg_sender();
40-
+ let sender: AztecAddress = context.msg_sender().expect(f"Sender must not be none!");
41-
```
42-
43-
For a minority of functions, a "null" msg_sender will be acceptable:
44-
45-
- A private entrypoint function.
46-
- A public function which doesn't seek to do bookkeeping against `msg_sender`.
47-
48-
Some apps might even want to _assert_ that the `msg_sender` is "null" to force their users into strong privacy practices:
49-
50-
```rust
51-
let sender: Option<AztecAddress> = context.msg_sender();
52-
assert(sender.is_none());
53-
```
54-
55-
##### Enqueueing public function calls
56-
57-
###### Auto-generated contract interfaces
58-
59-
When you use the `#[aztec]` macro, it will generate a noir contract interface for your contract, behind the scenes.
60-
61-
This provides pretty syntax when you come to call functions of that contract. E.g.:
62-
63-
```rust
64-
Token::at(context.this_address())._increase_public_balance(to, amount).enqueue(&mut context);
65-
```
66-
67-
In keeping with this new feature of being able to enqueue public function calls with a hidden `msg_sender`, there are some new methods that can be chained instead of `.enqueue(...)`:
68-
69-
- `enqueue_incognito` -- akin to `enqueue`, but `msg_sender` is set "null".
70-
- `enqueue_view_incognito` -- akin to `enqueue_view`, but `msg_sender` is "null".
71-
- `set_as_teardown_incognito` -- akin to `set_as_teardown`, but `msg_sender` is "null".
72-
73-
> The name "incognito" has been chosen to imply "msg_sender will not be visible to observers".
74-
75-
These new functions enable the _calling_ contract to specify that it wants its address to not be visible to the called public function. This is worth re-iterating: it is the _caller's_ choice. A smart contract developer who uses these functions must be sure that the target public function will accept a "null" `msg_sender`. It would not be good (for example) if the called public function did `context.msg_sender().unwrap()`, because then a public function that is called via `enqueue_incognito` would _always fail_! Hopefully smart contract developers will write sufficient tests to catch such problems during development!
76-
77-
###### Making lower-level public function calls from the private context
78-
79-
This is discouraged vs using the auto-generated contract interfaces described directly above.
80-
81-
If you do use any of these low-level methods of the `PrivateContext` in your contract:
82-
83-
- `call_public_function`
84-
- `static_call_public_function`
85-
- `call_public_function_no_args`
86-
- `static_call_public_function_no_args`
87-
- `call_public_function_with_calldata_hash`
88-
- `set_public_teardown_function`
89-
- `set_public_teardown_function_with_calldata_hash`
90-
91-
... there is a new `hide_msg_sender: bool` parameter that you will need to specify.
92-
93-
#### Aztec.js diffs
94-
95-
When lining up a new tx, the `FunctionCall` struct has been extended to include a `hide_msg_sender: bool` field.
96-
97-
- `is_public & hide_msg_sender` -- will make a public call with `msg_sender` set to "null".
98-
- `is_public & !hide_msg_sender` -- will make a public call with a visible `msg_sender`, as was the case before this new feature.
99-
- `!is_public & hide_msg_sender` -- Incompatible flags.
100-
- `!is_public & !hide_msg_sender` -- will make a private call with a visible `msg_sender` (noting that since it's a private function call, the `msg_sender` will only be visible to the called private function, but not to the rest of the world).
101-
10212
## [Aztec Tools]
10313

10414
### Contract compilation now requires two steps

0 commit comments

Comments
 (0)