Skip to content

Commit 8284490

Browse files
authored
feat: merge-train/fairies (#23616)
BEGIN_COMMIT_OVERRIDE refactor(aztec-nr): use constructor methods for MessageDelivery variants (#23596) docs: update testing_contracts.md for two-crate aztec new layout (#23617) fix: drop usage of include and indexof on types that support equals (#23595) fix: unused ts expressions in tests (#23621) feat(aztec-nr): Get tagging index for constrained delivery (#23359) feat!: demote auth registry to non-protocol contract (#23106) feat(aztec-nr)!: embed BoundedVec max length in validation requests (#23622) fix: regenerate standard contract addresses after auth registry demotion (#23640) feat(aztec-nr): encrypt handshake log for indistinguishability (#23638) feat!: demote public_checks to non-protocol contract (#23217) fix: noir precommit re-staging inside worktrees (#23628) END_COMMIT_OVERRIDE
2 parents 4963d05 + d1ee5d5 commit 8284490

213 files changed

Lines changed: 2413 additions & 674 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

barretenberg/cpp/pil/vm2/constants_gen.pil

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ namespace constants;
1515
pol MAX_L2_TO_L1_MSGS_PER_TX = 8;
1616
pol MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 3000;
1717
pol MAX_PROTOCOL_CONTRACTS = 11;
18-
pol CANONICAL_AUTH_REGISTRY_ADDRESS = 1;
1918
pol CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS = 2;
2019
pol CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS = 3;
2120
pol MULTI_CALL_ENTRYPOINT_ADDRESS = 4;
2221
pol FEE_JUICE_ADDRESS = 5;
23-
pol PUBLIC_CHECKS_ADDRESS = 6;
2422
pol FEE_JUICE_BALANCES_SLOT = 1;
2523
pol UPDATED_CLASS_IDS_SLOT = 1;
2624
pol FLAT_PUBLIC_LOGS_HEADER_LENGTH = 1;

barretenberg/cpp/src/barretenberg/aztec/aztec_constants.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@
2121
#define GENESIS_ARCHIVE_ROOT "0x177a4955b31ecaafad999753938a44e526b54c5ba5d536688227f85f15cfbdf5"
2222
#define MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS 3000
2323
#define MAX_PROTOCOL_CONTRACTS 11
24-
#define CANONICAL_AUTH_REGISTRY_ADDRESS 1
2524
#define CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS 2
2625
#define CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS 3
2726
#define MULTI_CALL_ENTRYPOINT_ADDRESS 4
2827
#define FEE_JUICE_ADDRESS 5
29-
#define PUBLIC_CHECKS_ADDRESS 6
3028
#define FEE_JUICE_BALANCES_SLOT 1
3129
#define UPDATED_CLASS_IDS_SLOT 1
3230
#define FLAT_PUBLIC_LOGS_HEADER_LENGTH 1

boxes/boxes/react/src/contracts/src/main.nr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ contract BoxReact {
2121
let new_number = FieldNote { value: number };
2222

2323
self.storage.numbers.at(owner).initialize(new_number).deliver(
24-
MessageDelivery.ONCHAIN_CONSTRAINED,
24+
MessageDelivery::onchain_constrained(),
2525
);
2626
}
2727

2828
#[external("private")]
2929
fn setNumber(number: Field, owner: AztecAddress) {
3030
self.storage.numbers.at(owner).replace(|_old| FieldNote { value: number }).deliver(
31-
MessageDelivery.ONCHAIN_CONSTRAINED,
31+
MessageDelivery::onchain_constrained(),
3232
);
3333
}
3434

boxes/boxes/vite/src/contracts/src/main.nr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ contract BoxReact {
2121
let new_number = FieldNote { value: number };
2222

2323
self.storage.numbers.at(owner).initialize(new_number).deliver(
24-
MessageDelivery.ONCHAIN_CONSTRAINED,
24+
MessageDelivery::onchain_constrained(),
2525
);
2626
}
2727

2828
#[external("private")]
2929
fn setNumber(number: Field, owner: AztecAddress) {
3030
self.storage.numbers.at(owner).replace(|_old| FieldNote { value: number }).deliver(
31-
MessageDelivery.ONCHAIN_CONSTRAINED,
31+
MessageDelivery::onchain_constrained(),
3232
);
3333
}
3434

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn transfer(to: AztecAddress, amount: u128) {
4040

4141
self.emit(Transfer { from, to, amount }).deliver_to(
4242
to,
43-
MessageDelivery.ONCHAIN_UNCONSTRAINED,
43+
MessageDelivery::onchain_unconstrained(),
4444
);
4545
}
4646
```
@@ -55,15 +55,15 @@ You can deliver the same event to multiple recipients with different delivery mo
5555

5656
```rust
5757
let message = self.emit(Transfer { from, to, amount });
58-
message.deliver_to(from, MessageDelivery.OFFCHAIN);
59-
message.deliver_to(to, MessageDelivery.ONCHAIN_CONSTRAINED);
58+
message.deliver_to(from, MessageDelivery::offchain());
59+
message.deliver_to(to, MessageDelivery::onchain_constrained());
6060
```
6161

6262
The `MessageDelivery` options are:
6363

64-
- **`ONCHAIN_CONSTRAINED`** - Constrained encryption with onchain delivery. Slowest proving but provides cryptographic guarantees that recipients can decrypt messages.
65-
- **`ONCHAIN_UNCONSTRAINED`** - Unconstrained encryption with onchain delivery. Faster proving, but trusts the sender to encrypt correctly.
66-
- **`OFFCHAIN`** - Unconstrained encryption with offchain delivery. Lowest cost, but requires custom infrastructure to deliver messages to recipients.
64+
- **`onchain_constrained()`** - Constrained encryption with onchain delivery. Slowest proving but provides cryptographic guarantees that recipients can decrypt messages.
65+
- **`onchain_unconstrained()`** - Unconstrained encryption with onchain delivery. Faster proving, but trusts the sender to encrypt correctly.
66+
- **`offchain()`** - Unconstrained encryption with offchain delivery. Lowest cost, but requires custom infrastructure to deliver messages to recipients.
6767

6868
:::note
6969
Emitting private events is optional. Onchain delivery publishes encrypted data to Ethereum blobs, inheriting Ethereum's data availability guarantees. You can choose to share information offchain instead.

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub contract PrivateToken {
2828
fn mint(amount: u128, recipient: AztecAddress) {
2929
// Adding to the balance returns a MaybeNoteMessage
3030
self.storage.balances.at(recipient).add(amount)
31-
.deliver(MessageDelivery.ONCHAIN_CONSTRAINED);
31+
.deliver(MessageDelivery::onchain_constrained());
3232
}
3333
}
3434
```
@@ -37,7 +37,7 @@ pub contract PrivateToken {
3737

3838
Aztec provides three delivery modes that offer different tradeoffs between cost, proving time, and guarantees:
3939

40-
### `MessageDelivery.OFFCHAIN`
40+
### `MessageDelivery::offchain()`
4141

4242
**Fully offchain delivery with no guarantees.**
4343

@@ -76,7 +76,7 @@ This is expected to be the most common delivery method when you don't need const
7676
```rust
7777
// Change note - sender is motivated to deliver to themselves
7878
self.storage.balances.at(sender).add(change_amount)
79-
.deliver(MessageDelivery.OFFCHAIN);
79+
.deliver(MessageDelivery::offchain());
8080
```
8181

8282
:::info TODO
@@ -119,7 +119,7 @@ await contract.methods.process_message(ciphertext, messageContext.toNoirStruct()
119119

120120
See the [aztec.js documentation](../../aztec-js/index.md) for more details on accessing transaction effects.
121121

122-
### `MessageDelivery.ONCHAIN_UNCONSTRAINED`
122+
### `MessageDelivery::onchain_unconstrained()`
123123

124124
**Onchain delivery with no content guarantees.**
125125

@@ -133,10 +133,10 @@ This mode provides the same low proving time as `OFFCHAIN` while avoiding the ne
133133
```rust
134134
// Minting to an admin who controls the contract
135135
self.storage.balances.at(admin).add(amount)
136-
.deliver(MessageDelivery.ONCHAIN_UNCONSTRAINED);
136+
.deliver(MessageDelivery::onchain_unconstrained());
137137
```
138138

139-
### `MessageDelivery.ONCHAIN_CONSTRAINED`
139+
### `MessageDelivery::onchain_constrained()`
140140

141141
**Onchain delivery with guaranteed correct content.**
142142

@@ -150,7 +150,7 @@ self.storage.balances.at(admin).add(amount)
150150
```rust
151151
// Minting to an arbitrary recipient - must guarantee delivery
152152
self.storage.balances.at(recipient).add(amount)
153-
.deliver(MessageDelivery.ONCHAIN_CONSTRAINED);
153+
.deliver(MessageDelivery::onchain_constrained());
154154
```
155155

156156
## Choosing a Delivery Mode
@@ -199,7 +199,7 @@ You can deliver a note to an address other than the note's owner using `.deliver
199199
```rust
200200
// Create a note owned by `owner` but deliver it to `auditor`
201201
self.storage.balances.at(owner).add(amount)
202-
.deliver_to(auditor, MessageDelivery.ONCHAIN_CONSTRAINED);
202+
.deliver_to(auditor, MessageDelivery::onchain_constrained());
203203
```
204204

205205
**Important:** The recipient (e.g. an `auditor`) can see the note was created but **cannot use it** - only the owner can spend the note (this is authorized by the contract logic). The recipient also cannot see when/if the note is nullified.
@@ -219,12 +219,12 @@ fn transfer(amount: u128, sender: AztecAddress, recipient: AztecAddress) {
219219
// Subtract from sender - unconstrained since sender is the caller
220220
self.storage.balances.at(sender)
221221
.sub(amount)
222-
.deliver(MessageDelivery.ONCHAIN_UNCONSTRAINED);
222+
.deliver(MessageDelivery::onchain_unconstrained());
223223

224224
// Add to recipient - constrained delivery for untrusted sender
225225
self.storage.balances.at(recipient)
226226
.add(amount)
227-
.deliver(MessageDelivery.ONCHAIN_CONSTRAINED);
227+
.deliver(MessageDelivery::onchain_constrained());
228228
}
229229
```
230230

@@ -238,6 +238,6 @@ fn constructor(admin: AztecAddress) {
238238
// Use unconstrained delivery since we don't know if deployer is incentivized
239239
self.storage.admin
240240
.initialize(AddressNote { address: admin }, admin)
241-
.deliver(MessageDelivery.ONCHAIN_CONSTRAINED);
241+
.deliver(MessageDelivery::onchain_constrained());
242242
}
243243
```

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ When working with private state variables, many operations return a `NoteMessage
273273
#### Delivery Methods
274274

275275
Private notes need to be communicated to their recipients so they know the note exists and can use it. The [`NoteMessage`](pathname:///aztec-nr-api/#api_ref_version/noir_aztec/note/struct.NoteMessage) wrapper forces you to make an explicit choice about how this happens:
276-
- [`MessageDelivery.ONCHAIN_CONSTRAINED`](pathname:///aztec-nr-api/#api_ref_version/noir_aztec/messages/message_delivery/struct.MessageDeliveryEnum#structfield.ONCHAIN_CONSTRAINED): Verified in the circuit (most secure, but highest cost) - Use when the sender cannot be trusted to deliver correctly (e.g., protocol fees, multisig config updates). **Warning:** Currently [not fully constrained](https://github.com/AztecProtocol/aztec-packages/issues/14565) - the log's tag is unconstrained.
277-
- [`MessageDelivery.ONCHAIN_UNCONSTRAINED`](pathname:///aztec-nr-api/#api_ref_version/noir_aztec/messages/message_delivery/struct.MessageDeliveryEnum#structfield.ONCHAIN_UNCONSTRAINED): Message stored onchain but no guarantees on content - Use when the sender is incentivized to deliver correctly but may not have an offchain channel to the recipient.
278-
- [`MessageDelivery.OFFCHAIN`](pathname:///aztec-nr-api/#api_ref_version/noir_aztec/messages/message_delivery/struct.MessageDeliveryEnum#structfield.OFFCHAIN): Lowest cost, no onchain data - Use when the sender and recipient can communicate and the sender is incentivized to deliver correctly.
276+
- [`MessageDelivery::onchain_constrained()`](pathname:///aztec-nr-api/#api_ref_version/noir_aztec/messages/message_delivery/struct.MessageDelivery#method.onchain_constrained): Verified in the circuit (most secure, but highest cost) - Use when the sender cannot be trusted to deliver correctly (e.g., protocol fees, multisig config updates). **Warning:** Currently [not fully constrained](https://github.com/AztecProtocol/aztec-packages/issues/14565) - the log's tag is unconstrained.
277+
- [`MessageDelivery::onchain_unconstrained()`](pathname:///aztec-nr-api/#api_ref_version/noir_aztec/messages/message_delivery/struct.MessageDelivery#method.onchain_unconstrained): Message stored onchain but no guarantees on content - Use when the sender is incentivized to deliver correctly but may not have an offchain channel to the recipient.
278+
- [`MessageDelivery::offchain()`](pathname:///aztec-nr-api/#api_ref_version/noir_aztec/messages/message_delivery/struct.MessageDelivery#method.offchain): Lowest cost, no onchain data - Use when the sender and recipient can communicate and the sender is incentivized to deliver correctly.
279279

280280
#include_code note_delivery /noir-projects/noir-contracts/contracts/app/private_token_contract/src/main.nr rust
281281

@@ -324,7 +324,7 @@ fn perform_admin_action() {
324324
// value of the counter and can update it again in the future.
325325
self.storage.admin_call_count
326326
.replace(|current| UintNote{ value: current.value + 1 }) // wouldn't it be great if we didn't have to deal with this wrapping and unwrapping?
327-
.deliver(MessageDelivery.ONCHAIN_CONSTRAINED);
327+
.deliver(MessageDelivery::onchain_constrained());
328328

329329
// ...
330330
}
@@ -381,7 +381,7 @@ This function allows us to get the note of a `PrivateMutable`, essentially readi
381381
#[external("private")]
382382
fn read_settings() {
383383
let owner = self.msg_sender();
384-
self.storage.user_settings.at(owner).get_note().deliver(MessageDelivery.ONCHAIN_CONSTRAINED);
384+
self.storage.user_settings.at(owner).get_note().deliver(MessageDelivery::onchain_constrained());
385385
}
386386
```
387387

@@ -484,11 +484,11 @@ When initializing, you still pass an owner address, but this specifies who can d
484484

485485
```rust
486486
// owner_address determines who can see the note, not where it's stored
487-
self.storage.admin.initialize(note, owner_address).deliver(MessageDelivery.ONCHAIN_CONSTRAINED);
487+
self.storage.admin.initialize(note, owner_address).deliver(MessageDelivery::onchain_constrained());
488488
```
489489

490490
:::warning
491-
`SinglePrivateMutable` uses a nullify-and-recreate pattern when reading. Unless the caller is incentivized to deliver the note message correctly, you should use `MessageDelivery.ONCHAIN_CONSTRAINED` to prevent malicious actors from bricking the contract by failing to deliver the note.
491+
`SinglePrivateMutable` uses a nullify-and-recreate pattern when reading. Unless the caller is incentivized to deliver the note message correctly, you should use `MessageDelivery::onchain_constrained()` to prevent malicious actors from bricking the contract by failing to deliver the note.
492492
:::
493493

494494
## Containers
@@ -558,7 +558,7 @@ fn transfer(from: AztecAddress, to: AztecAddress, amount: u128) {
558558

559559
// Access the balance for the 'to' address
560560
let new_note = UintNote { value: amount };
561-
self.storage.balances.at(to).insert(new_note).deliver(MessageDelivery.ONCHAIN_UNCONSTRAINED);
561+
self.storage.balances.at(to).insert(new_note).deliver(MessageDelivery::onchain_unconstrained());
562562
}
563563
```
564564

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ A good example of this is writing to private state variables. These functions re
3030

3131
```rust
3232
storage.votes.insert(new_vote); // compiler error - unused NoteMessage return value
33-
storage.votes.insert(new_vote).deliver(MessageDelivery.ONCHAIN_CONSTRAINED); // deliver the note message onchain
33+
storage.votes.insert(new_vote).deliver(MessageDelivery::onchain_constrained()); // deliver the note message onchain
3434
```
3535

3636
## Contract Development

docs/docs-developers/docs/aztec-nr/standards/escrow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn _share_escrow(
7171
) {
7272
let event_struct = EscrowDetailsLogContent { escrow, master_secret_keys };
7373
emit_event_in_private(context, event_struct).deliver_to(
74-
account, MessageDelivery.ONCHAIN_CONSTRAINED,
74+
account, MessageDelivery::onchain_constrained(),
7575
);
7676
}
7777
```

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

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -46,69 +46,59 @@ Always use `aztec test` instead of `nargo test`. The `TestEnvironment` requires
4646

4747
## Basic test structure
4848

49-
Tests live in the same crate as your contract. `aztec new` creates a single-crate project, and the convention is to place `#[test]` functions in a `mod tests` block alongside the contract (or in submodules of the crate):
49+
`aztec new my_project` scaffolds a workspace with two crates: a `contract` crate that holds the contract code, and a separate `test` crate that holds your `#[test]` functions:
50+
51+
```text
52+
my_project/
53+
├── Nargo.toml # [workspace] members = ["my_project_contract", "my_project_test"]
54+
├── my_project_contract/
55+
│ ├── Nargo.toml # type = "contract"
56+
│ └── src/main.nr
57+
└── my_project_test/
58+
├── Nargo.toml # type = "lib", depends on my_project_contract
59+
└── src/lib.nr # #[test] functions go here
60+
```
5061

51-
```rust
52-
use aztec::macros::aztec;
62+
The motivation for the split of contract and tests into its own crates is **faster iteration**: editing a test does not invalidate the contract's compiled artifact, so `aztec test` skips contract recompilation when only test code changed.
5363

54-
#[aztec]
55-
pub contract MyContract {
56-
// ...contract functions...
57-
}
64+
`aztec compile` warns if it finds `#[test]` functions inside a contract crate.
5865

59-
mod tests {
60-
use super::MyContract;
61-
use aztec::test::helpers::test_environment::TestEnvironment;
66+
The generated test crate template imports the contract by package name and then initializes it:
6267

63-
#[test]
64-
unconstrained fn test_basic_flow() {
65-
// 1. Create test environment
66-
let mut env = TestEnvironment::new();
68+
```rust
69+
// my_project_test/src/lib.nr
70+
use aztec::test::helpers::test_environment::TestEnvironment;
71+
use my_project_contract::Main;
6772

68-
// 2. Create accounts
69-
let _owner = env.create_light_account();
70-
}
73+
#[test]
74+
unconstrained fn test_constructor() {
75+
let mut env = TestEnvironment::new();
76+
let deployer = env.create_light_account();
77+
78+
let _contract_address = env.deploy("@my_project_contract/Main")
79+
.with_private_initializer(deployer, Main::interface().constructor());
7180
}
7281
```
7382

83+
Because tests live in their own crate, we refer to the contract via its crate name using the `@crate_name/ContractName` syntax.
84+
7485
:::info Test execution notes
7586

7687
- Tests run in parallel by default
7788
- Use `unconstrained` functions for faster execution
7889
- See all `TestEnvironment` methods [here](pathname:///aztec-nr-api/#api_ref_version/noir_aztec/test/helpers/test_environment/struct.TestEnvironment)
79-
90+
- It is always necessary to deploy a contract in order to test it
8091
:::
8192

82-
:::tip Organizing test files
83-
For larger test suites, split tests into submodules of your crate rather than keeping them all inside `main.nr`:
84-
85-
- Create modules like `src/transfer_tests.nr`, `src/auth_tests.nr`
86-
- Declare them from `src/main.nr` with `mod transfer_tests;`, `mod auth_tests;`
87-
- Share setup functions in `src/test_utils.nr`
88-
89-
See the [aztec-standards token contract](https://github.com/defi-wonderland/aztec-standards/tree/dev/src/token_contract) for a worked example of this layout.
90-
:::
91-
92-
## Deploying contracts
93-
94-
In order to test you'll most likely want to deploy a contract in your testing environment. First, instantiate a deployer:
93+
If you'll add arguments to your contract's constructor you pass them directly to the constructor function in the test:
9594

9695
```rust
97-
let deployer = env.deploy("ContractName");
98-
99-
// If on a different crate:
100-
let deployer = env.deploy("../other_contract");
96+
let initializer = MyContract::interface().constructor(param1, param2);
10197
```
10298

103-
:::warning
104-
It is always necessary to deploy a contract in order to test it. `aztec test` automatically compiles contracts when changes are detected, but you can also manually compile with `aztec compile` to regenerate the bytecode and ABI.
105-
:::
106-
107-
You can then choose whatever you need to initialize by interfacing with your initializer and calling it:
99+
Since Aztec contracts can be initialized both in private and public or they can be interacted with without any kind of initialization (see [Contract creation](../foundational-topics/contract_creation.md) for how Aztec's deployment model differs from Ethereum's) there are 3 options on the deployer:
108100

109101
```rust
110-
let initializer = MyContract::interface().constructor(param1, param2);
111-
112102
let contract_address = deployer.with_private_initializer(owner, initializer);
113103
let contract_address = deployer.with_public_initializer(owner, initializer);
114104
let contract_address = deployer.without_initializer();
@@ -122,7 +112,7 @@ pub unconstrained fn setup(initial_value: Field) -> (TestEnvironment, AztecAddre
122112
let mut env = TestEnvironment::new();
123113
let owner = env.create_light_account();
124114
let initializer = MyContract::interface().constructor(initial_value, owner);
125-
let contract_address = env.deploy("MyContract").with_private_initializer(owner, initializer);
115+
let contract_address = env.deploy("@my_project_contract/MyContract").with_private_initializer(owner, initializer);
126116
(env, contract_address, owner)
127117
}
128118

0 commit comments

Comments
 (0)