Skip to content

Commit ef7cd86

Browse files
authored
feat!: rename sharedimmutable methods (#10164)
We used to have to do this because we only knew the context at runtime, but since #6442 we no longer need this. I'm also doing this for some other state vars, but chose do to so in separate PRs as some of those changes are a bit messier.
1 parent 12b1daa commit ef7cd86

File tree

14 files changed

+90
-73
lines changed

14 files changed

+90
-73
lines changed

docs/docs/guides/developer_guides/smart_contracts/how_to_compile_contract.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ contract FPC {
466466

467467
#[private]
468468
fn fee_entrypoint_private(amount: Field, asset: AztecAddress, secret_hash: Field, nonce: Field) {
469-
assert(asset == storage.other_asset.read_private());
469+
assert(asset == storage.other_asset.read());
470470
Token::at(asset).transfer_to_public(context.msg_sender(), context.this_address(), amount, nonce).call(&mut context);
471471
FPC::at(context.this_address()).pay_fee_with_shielded_rebate(amount, asset, secret_hash).enqueue(&mut context);
472472
}

docs/docs/migration_notes.md

+27-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ Aztec is in full-speed development. Literally every version breaks compatibility
88

99
## TBD
1010

11+
### [aztec.nr] SharedImmutable renamings
12+
13+
`SharedImmutable::read_private` and `SharedImmutable::read_public` were renamed to simply `read`, since only one of these versions is ever available depending on the current context.
14+
15+
```diff
16+
// In private
17+
- let value = storage.my_var.read_private();
18+
+ let value = storage.my_var.read();
19+
20+
// In public
21+
- let value = storage.my_var.read_public();
22+
+ let value = storage.my_var.read();
23+
```
24+
1125
### [aztec.nr] SharedMutable renamings
1226

1327
`SharedMutable` getters (`get_current_value_in_public`, etc.) were renamed by dropping the `_in<public|private|unconstrained>` suffix, since only one of these versions is ever available depending on the current context.
@@ -27,10 +41,11 @@ Aztec is in full-speed development. Literally every version breaks compatibility
2741
The `AztecAddress.random()` function now returns valid addresses, i.e. addresses that can receive encrypted messages and therefore have notes be sent to them. `AztecAddress.isValid()` was also added to check for validity of an address.
2842

2943
## 0.63.0
44+
3045
### [PXE] Note tagging and discovery
3146

3247
PXE's trial decryption of notes has been replaced in favor of a tagging and discovery approach. It is much more efficient and should scale a lot better as the network size increases, since
33-
notes can now be discovered on-demand. For the time being, this means that accounts residing *on different PXE instances* should add senders to their contact list, so notes can be discovered
48+
notes can now be discovered on-demand. For the time being, this means that accounts residing _on different PXE instances_ should add senders to their contact list, so notes can be discovered
3449
(accounts created on the same PXE instance will be added as senders for each other by default)
3550

3651
```diff
@@ -51,12 +66,14 @@ const receipt = await inclusionsProofsContract.methods.create_note(owner, 5n).se
5166
```
5267

5368
### [Token contract] Partial notes related refactor
69+
5470
We've decided to replace the old "shield" flow with one leveraging partial notes.
5571
This led to a removal of `shield` and `redeem_shield` functions and an introduction of `transfer_to_private`.
5672
An advantage of the new approach is that only 1 tx is required and the API of partial notes is generally nicer.
5773
For more information on partial notes refer to docs.
5874

5975
### [Token contract] Function naming changes
76+
6077
There have been a few naming changes done for improved consistency.
6178
These are the renamings:
6279
`transfer_public` --> `transfer_in_public`
@@ -65,7 +82,9 @@ These are the renamings:
6582
`burn` --> `burn_private`
6683

6784
## 0.62.0
85+
6886
### [TXE] Single execution environment
87+
6988
Thanks to recent advancements in Brillig TXE performs every single call as if it was a nested call, spawning a new ACVM or AVM simulator without performance loss.
7089
This ensures every single test runs in a consistent environment and allows for clearer test syntax:
7190

@@ -74,6 +93,7 @@ This ensures every single test runs in a consistent environment and allows for c
7493
-env.call_private(my_contract_interface)
7594
+MyContract::at(address).my_function(args).call(&mut env.private());
7695
```
96+
7797
This implies every contract has to be deployed before it can be tested (via `env.deploy` or `env.deploy_self`) and of course it has to be recompiled if its code was changed before TXE can use the modified bytecode.
7898

7999
### Uniqueness of L1 to L2 messages
@@ -115,18 +135,22 @@ The address now serves as someone's public key to encrypt incoming notes. An add
115135
Because of removing key rotation, we can now store addresses as the owner of a note. Because of this and the above change, we can and have removed the process of registering a recipient, because now we do not need any keys of the recipient.
116136

117137
example_note.nr
138+
118139
```diff
119140
-npk_m_hash: Field
120141
+owner: AztecAddress
121142
```
122143

123144
PXE Interface
145+
124146
```diff
125147
-registerRecipient(completeAddress: CompleteAddress)
126148
```
127149

128150
## 0.58.0
151+
129152
### [l1-contracts] Inbox's MessageSent event emits global tree index
153+
130154
Earlier `MessageSent` event in Inbox emitted a subtree index (index of the message in the subtree of the l2Block). But the nodes and Aztec.nr expects the index in the global L1_TO_L2_MESSAGES_TREE. So to make it easier to parse this, Inbox now emits this global index.
131155

132156
## 0.57.0
@@ -135,8 +159,8 @@ Earlier `MessageSent` event in Inbox emitted a subtree index (index of the messa
135159

136160
PXE APIs have been refactored to better reflect the lifecycle of a Tx (`execute private -> simulate kernels -> simulate public (estimate gas) -> prove -> send`)
137161

138-
* `.simulateTx`: Now returns a `TxSimulationResult`, containing the output of private execution, kernel simulation and public simulation (optional).
139-
* `.proveTx`: Now accepts the result of executing the private part of a transaction, so simulation doesn't have to happen again.
162+
- `.simulateTx`: Now returns a `TxSimulationResult`, containing the output of private execution, kernel simulation and public simulation (optional).
163+
- `.proveTx`: Now accepts the result of executing the private part of a transaction, so simulation doesn't have to happen again.
140164

141165
Thanks to this refactor, `ContractFunctionInteraction` has been updated to remove its internal cache and avoid bugs due to its mutable nature. As a result our type-safe interfaces now have to be used as follows:
142166

@@ -153,7 +177,6 @@ It's still possible to use `.send()` as before, which will perform proving under
153177

154178
More changes are coming to these APIs to better support gas estimation mechanisms and advanced features.
155179

156-
157180
### Changes to public calling convention
158181

159182
Contracts that include public functions (that is, marked with `#[public]`), are required to have a function `public_dispatch(selector: Field)` which acts as an entry point. This will be soon the only public function registered/deployed in contracts. The calling convention is updated so that external calls are made to this function.

docs/docs/reference/developer_references/smart_contract_reference/storage/shared_state.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,10 @@ This function sets the immutable value. It must only be called once during contr
118118
A `SharedImmutable`'s storage **must** only be set once via `initialize`. Attempting to override this by manually accessing the underlying storage slots breaks all properties of the data structure, rendering it useless.
119119
:::
120120

121-
### `read_public`
121+
### `read`
122122

123-
Returns the stored immutable value in a public execution context.
123+
Returns the stored immutable value. This function is available in public, private and unconstrained contexts.
124124

125-
#include_code read_decimals_public /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust
125+
#include_code read_shared_immutable_public /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust
126126

127-
### `read_private`
128-
129-
Returns the stored immutable value in a private execution context.
130-
131-
#include_code read_decimals_private /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust
127+
#include_code read_shared_immutable_private /noir-projects/noir-contracts/contracts/token_contract/src/main.nr rust

noir-projects/aztec-nr/aztec/src/state_vars/shared_immutable.nr

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ where
4545
self.context.storage_write(self.storage_slot, value);
4646
}
4747

48-
pub fn read_public(self) -> T {
48+
pub fn read(self) -> T {
4949
self.context.storage_read(self.storage_slot)
5050
}
5151
}
@@ -54,7 +54,7 @@ impl<T, let T_SERIALIZED_LEN: u32> SharedImmutable<T, UnconstrainedContext>
5454
where
5555
T: Serialize<T_SERIALIZED_LEN> + Deserialize<T_SERIALIZED_LEN>,
5656
{
57-
pub unconstrained fn read_public(self) -> T {
57+
pub unconstrained fn read(self) -> T {
5858
self.context.storage_read(self.storage_slot)
5959
}
6060
}
@@ -63,7 +63,7 @@ impl<T, let T_SERIALIZED_LEN: u32> SharedImmutable<T, &mut PrivateContext>
6363
where
6464
T: Serialize<T_SERIALIZED_LEN> + Deserialize<T_SERIALIZED_LEN>,
6565
{
66-
pub fn read_private(self) -> T {
66+
pub fn read(self) -> T {
6767
let header = self.context.get_header();
6868
let mut fields = [0; T_SERIALIZED_LEN];
6969

noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ contract AppSubscription {
5959
context.set_as_fee_payer();
6060

6161
// TODO(palla/gas) Assert fee_juice_limit_per_tx is less than this tx gas_limit
62-
let _gas_limit = storage.fee_juice_limit_per_tx.read_private();
62+
let _gas_limit = storage.fee_juice_limit_per_tx.read();
6363

6464
context.end_setup();
6565

6666
// We check that the note is not expired. We do that via the router contract to conceal which contract
6767
// is performing the check.
6868
privately_check_block_number(Comparator.LT, note.expiry_block_number, &mut context);
6969

70-
payload.execute_calls(&mut context, storage.target_address.read_private());
70+
payload.execute_calls(&mut context, storage.target_address.read());
7171
}
7272

7373
#[public]
@@ -95,11 +95,11 @@ contract AppSubscription {
9595
) {
9696
assert(tx_count as u64 <= SUBSCRIPTION_TXS as u64);
9797

98-
Token::at(storage.subscription_token_address.read_private())
98+
Token::at(storage.subscription_token_address.read())
9999
.transfer_in_private(
100100
context.msg_sender(),
101-
storage.subscription_recipient_address.read_private(),
102-
storage.subscription_price.read_private(),
101+
storage.subscription_recipient_address.read(),
102+
storage.subscription_price.read(),
103103
nonce,
104104
)
105105
.call(&mut context);

noir-projects/noir-contracts/contracts/claim_contract/src/main.nr

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ contract Claim {
2929
#[private]
3030
fn claim(proof_note: ValueNote, recipient: AztecAddress) {
3131
// 1) Check that the note corresponds to the target contract and belongs to the sender
32-
let target_address = storage.target_contract.read_private();
32+
let target_address = storage.target_contract.read();
3333
assert(
3434
target_address == proof_note.header.contract_address,
3535
"Note does not correspond to the target contract",
@@ -51,8 +51,8 @@ contract Claim {
5151
context.push_nullifier(nullifier);
5252

5353
// 4) Finally we mint the reward token to the sender of the transaction
54-
Token::at(storage.reward_token.read_private())
55-
.mint_to_public(recipient, proof_note.value)
56-
.enqueue(&mut context);
54+
Token::at(storage.reward_token.read()).mint_to_public(recipient, proof_note.value).enqueue(
55+
&mut context,
56+
);
5757
}
5858
}

noir-projects/noir-contracts/contracts/crowdfunding_contract/src/main.nr

+6-6
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ contract Crowdfunding {
7070
// 1) Check that the deadline has not passed --> we do that via the router contract to conceal which contract
7171
// is performing the check.
7272
// docs:start:call-check-deadline
73-
let deadline = storage.deadline.read_private();
73+
let deadline = storage.deadline.read();
7474
privately_check_timestamp(Comparator.LT, deadline, &mut context);
7575
// docs:end:call-check-deadline
7676
// docs:start:do-transfer
7777
// 2) Transfer the donation tokens from donor to this contract
7878
let donor = context.msg_sender();
79-
Token::at(storage.donation_token.read_private())
79+
Token::at(storage.donation_token.read())
8080
.transfer_in_private(donor, context.this_address(), amount as Field, 0)
8181
.call(&mut context);
8282
// docs:end:do-transfer
@@ -101,13 +101,13 @@ contract Crowdfunding {
101101
#[private]
102102
fn withdraw(amount: u64) {
103103
// 1) Check that msg_sender() is the operator
104-
let operator_address = storage.operator.read_private();
104+
let operator_address = storage.operator.read();
105105
assert(context.msg_sender() == operator_address, "Not an operator");
106106

107107
// 2) Transfer the donation tokens from this contract to the operator
108-
Token::at(storage.donation_token.read_private())
109-
.transfer(operator_address, amount as Field)
110-
.call(&mut context);
108+
Token::at(storage.donation_token.read()).transfer(operator_address, amount as Field).call(
109+
&mut context,
110+
);
111111
// 3) Emit an unencrypted event so that anyone can audit how much the operator has withdrawn
112112
Crowdfunding::at(context.this_address())
113113
._publish_donation_receipts(amount, operator_address)

noir-projects/noir-contracts/contracts/docs_example_contract/src/main.nr

+6-6
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ contract DocsExample {
103103
#[private]
104104
fn match_shared_immutable(account: AztecAddress, points: u8) {
105105
let expected = Leader { account, points };
106-
let read = storage.shared_immutable.read_private();
106+
let read = storage.shared_immutable.read();
107107

108108
assert(read.account == expected.account, "Invalid account");
109109
assert(read.points == expected.points, "Invalid points");
@@ -138,23 +138,23 @@ contract DocsExample {
138138
#[public]
139139
#[view]
140140
fn get_shared_immutable_constrained_public() -> Leader {
141-
storage.shared_immutable.read_public()
141+
storage.shared_immutable.read()
142142
}
143143

144144
#[public]
145145
fn get_shared_immutable_constrained_public_multiple() -> [Leader; 5] {
146-
let a = storage.shared_immutable.read_public();
146+
let a = storage.shared_immutable.read();
147147
[a, a, a, a, a]
148148
}
149149

150150
#[private]
151151
#[view]
152152
fn get_shared_immutable_constrained_private() -> Leader {
153-
storage.shared_immutable.read_private()
153+
storage.shared_immutable.read()
154154
}
155155

156156
unconstrained fn get_shared_immutable() -> Leader {
157-
storage.shared_immutable.read_public()
157+
storage.shared_immutable.read()
158158
}
159159

160160
#[public]
@@ -165,8 +165,8 @@ contract DocsExample {
165165
// docs:end:initialize_public_immutable
166166
}
167167

168+
// docs:start:read_public_immutable
168169
unconstrained fn get_public_immutable() -> Leader {
169-
// docs:start:read_public_immutable
170170
storage.public_immutable.read()
171171
// docs:end:read_public_immutable
172172
}

noir-projects/noir-contracts/contracts/fee_juice_contract/src/main.nr

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ contract FeeJuice {
4343
// is a hardcoded constant in the rollup circuits.
4444
#[public]
4545
fn set_portal(portal_address: EthAddress) {
46-
assert(storage.portal_address.read_public().is_zero());
46+
assert(storage.portal_address.read().is_zero());
4747
storage.portal_address.initialize(portal_address);
4848
}
4949

5050
#[private]
5151
fn claim(to: AztecAddress, amount: Field, secret: Field, message_leaf_index: Field) {
5252
let content_hash = get_bridge_gas_msg_hash(to, amount);
53-
let portal_address = storage.portal_address.read_private();
53+
let portal_address = storage.portal_address.read();
5454
assert(!portal_address.is_zero());
5555

5656
// Consume message and emit nullifier

noir-projects/noir-contracts/contracts/fpc_contract/src/main.nr

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ contract FPC {
2929
#[private]
3030
fn fee_entrypoint_private(amount: Field, asset: AztecAddress, nonce: Field) {
3131
// TODO(PR #8022): Once SharedImmutable performs only 1 merkle proof here, we'll save ~4k gates
32-
let settings = storage.settings.read_private();
32+
let settings = storage.settings.read();
3333

3434
assert(asset == settings.other_asset);
3535

noir-projects/noir-contracts/contracts/nft_contract/src/main.nr

+4-4
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,25 @@ contract NFT {
9696
#[public]
9797
#[view]
9898
fn public_get_name() -> pub FieldCompressedString {
99-
storage.name.read_public()
99+
storage.name.read()
100100
}
101101

102102
#[private]
103103
#[view]
104104
fn private_get_name() -> pub FieldCompressedString {
105-
storage.name.read_private()
105+
storage.name.read()
106106
}
107107

108108
#[public]
109109
#[view]
110110
fn public_get_symbol() -> pub FieldCompressedString {
111-
storage.symbol.read_public()
111+
storage.symbol.read()
112112
}
113113

114114
#[private]
115115
#[view]
116116
fn private_get_symbol() -> pub FieldCompressedString {
117-
storage.symbol.read_private()
117+
storage.symbol.read()
118118
}
119119

120120
#[public]

0 commit comments

Comments
 (0)