Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: aztec_macros are dead, long live aztec::macros #8438

Merged
merged 103 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
a10676c
wip
Thunkar Sep 4, 2024
8f49fd4
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Sep 5, 2024
b73cd7e
derive serialize, contract interfaces, full private, lfg
Thunkar Sep 6, 2024
53f0e8f
almost finished storage
Thunkar Sep 6, 2024
e5a9ca1
more things working
Thunkar Sep 6, 2024
0b1c482
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Sep 12, 2024
f7d11eb
align with noir
Thunkar Sep 12, 2024
687fd85
more stuff
Thunkar Sep 12, 2024
3305098
separated note interface + arithmetic generics
Thunkar Sep 12, 2024
09ff34e
the witch is dead
Thunkar Sep 13, 2024
4e81f4d
towards token_contract
Thunkar Sep 13, 2024
b23d25c
fixes
Thunkar Sep 16, 2024
aac230d
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Sep 16, 2024
14a2fd1
heck yeah
Thunkar Sep 16, 2024
bc3c873
almost there
Thunkar Sep 16, 2024
e55f2cd
removed dumb helper
Thunkar Sep 16, 2024
1b7e294
first pass at all contracts
Thunkar Sep 16, 2024
0087534
contract fixin'
Thunkar Sep 16, 2024
f033fcc
more fixin
Thunkar Sep 17, 2024
e0853f7
we have liftoff
Thunkar Sep 17, 2024
b8e5d80
fmt
Thunkar Sep 17, 2024
a300679
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Sep 17, 2024
5cff536
removed log line
Thunkar Sep 17, 2024
8424bfb
macro intensifies
Thunkar Sep 17, 2024
450bb83
bootstrapin
Thunkar Sep 17, 2024
a7d74b0
unhack
Thunkar Sep 17, 2024
393449a
woooooo
Thunkar Sep 17, 2024
817f09f
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Sep 17, 2024
35dfdb2
fix transpiler
Thunkar Sep 17, 2024
fb0ca20
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Sep 17, 2024
b73b94b
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Sep 18, 2024
e0ed976
removed hacks
Thunkar Sep 18, 2024
7d385e8
revert
Thunkar Sep 18, 2024
10df443
one step to go
Thunkar Sep 18, 2024
13e016f
more fixing and updating aztec.nr
Thunkar Sep 18, 2024
03e6b09
final fixes
Thunkar Sep 18, 2024
5a292b3
more generic numerics
Thunkar Sep 18, 2024
ebda8a0
fix: address a bunch of issues with generics
TomAFrench Sep 18, 2024
fcb39b3
chore: add safety check for converting u32 to u8
TomAFrench Sep 18, 2024
ae87091
remove .quoted_contents() as much as possible
Thunkar Sep 18, 2024
75dbb7e
.
TomAFrench Sep 18, 2024
6d071a7
.
TomAFrench Sep 18, 2024
279a22e
.
TomAFrench Sep 18, 2024
75238c3
.
TomAFrench Sep 18, 2024
34144d6
indexed note fields
Thunkar Sep 18, 2024
fab5112
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Sep 18, 2024
432a8bf
Merge branch 'tf/fix-bad-generics' of github.com:AztecProtocol/aztec-…
Thunkar Sep 18, 2024
ebd3817
uint note
Thunkar Sep 18, 2024
86ae957
more u32
Thunkar Sep 18, 2024
a596821
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Sep 18, 2024
5a2d6c7
fixes
Thunkar Sep 18, 2024
1d1f7c4
Merge branch 'master' into gj/metaprogramming_experiments
TomAFrench Sep 19, 2024
b0f7034
.
TomAFrench Sep 19, 2024
461574b
Merge branch 'master' into gj/metaprogramming_experiments
TomAFrench Sep 19, 2024
ae31dfa
migration notes
benesjan Sep 19, 2024
57b980f
Merge branch 'master' into gj/metaprogramming_experiments
TomAFrench Sep 19, 2024
e5e2990
Minor migration doc adjustments
nventuro Sep 19, 2024
cd9df60
Fix nargo fmt crash
nventuro Sep 19, 2024
8810631
Add comments and misc improvements to utils
nventuro Sep 19, 2024
0324653
Add comments to storage
nventuro Sep 19, 2024
585deed
Merge branch 'master' into gj/metaprogramming_experiments
TomAFrench Sep 20, 2024
f50815b
Let type always be a slice
asterite Sep 20, 2024
6c73e62
nargo fmt
asterite Sep 20, 2024
c59d739
Merge branch 'master' into gj/metaprogramming_experiments
asterite Sep 20, 2024
4d7795d
More nargo fmt
asterite Sep 20, 2024
8784eef
Merge branch 'gj/metaprogramming_experiments' of github.com:AztecProt…
asterite Sep 20, 2024
9cd31eb
Don't run the old macros anymore
asterite Sep 20, 2024
d8a14ee
nargo fmt
asterite Sep 20, 2024
e4e041b
Fix build
nventuro Sep 20, 2024
ab5f219
Fix docs
nventuro Sep 20, 2024
64f5936
Make rs macros not do nothing but compile
nventuro Sep 20, 2024
5295b7e
Fix rust linter
nventuro Sep 20, 2024
09e457a
Merge branch 'master' into gj/metaprogramming_experiments
nventuro Sep 20, 2024
b822c30
Add some notes to function macros
nventuro Sep 20, 2024
6e9cd8a
Restore nullifier
nventuro Sep 20, 2024
cad19e5
Minor comments on aztec macr
nventuro Sep 20, 2024
89e8bd8
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Sep 23, 2024
d4693bf
updated constants and boxes
Thunkar Sep 23, 2024
976c6d4
comment
Thunkar Sep 23, 2024
173356b
remake constants again
Thunkar Sep 23, 2024
4b16d8a
added missing condition to init check
Thunkar Sep 23, 2024
6059703
fixed note type computation
Thunkar Sep 23, 2024
c4b15ce
unused imports
Thunkar Sep 23, 2024
8d68266
correctly generate compute_note_hash_and_nullifier
Thunkar Sep 23, 2024
ec5a41d
e2e fixes
Thunkar Sep 23, 2024
c7ef24e
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Sep 23, 2024
f938346
fixes
Thunkar Sep 23, 2024
15ef260
Update noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr
Thunkar Sep 23, 2024
bd3f54c
comment
Thunkar Sep 23, 2024
4218cfa
Merge branch 'gj/metaprogramming_experiments' of github.com:AztecProt…
Thunkar Sep 23, 2024
2f81b78
added more generators
Thunkar Sep 23, 2024
db80913
fmt
Thunkar Sep 23, 2024
469abb8
fixed logs
Thunkar Sep 23, 2024
06dae6f
fixed partial notes
Thunkar Sep 23, 2024
b07e6d8
Merge branch 'master' into gj/metaprogramming_experiments
Thunkar Sep 23, 2024
b2fb913
final fixes
Thunkar Sep 23, 2024
43edd62
Merge branch 'master' into gj/metaprogramming_experiments
Thunkar Sep 23, 2024
df1f1ef
Use panic instead of assert(false)
nventuro Sep 23, 2024
fd67160
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Sep 24, 2024
af652f3
better approach for note hiding point
Thunkar Sep 24, 2024
e59d315
Merge branch 'gj/metaprogramming_experiments' of github.com:AztecProt…
Thunkar Sep 24, 2024
08fb04e
fixed test
Thunkar Sep 24, 2024
ecac29d
final fixes?
Thunkar Sep 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion avm-transpiler/src/transpile_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl From<CompiledAcirContractArtifact> for TranspiledContractArtifact {

for function in contract.functions {
// TODO(4269): once functions are tagged for transpilation to AVM, check tag
if function.custom_attributes.contains(&"aztec(public)".to_string()) {
if function.custom_attributes.contains(&"public".to_string()) {
info!("Transpiling AVM function {} on contract {}", function.name, contract.name);
// Extract Brillig Opcodes from acir
let acir_program = function.bytecode;
Expand Down
20 changes: 12 additions & 8 deletions boxes/boxes/react/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
use dep::aztec::macros::aztec;

#[aztec]
contract BoxReact {
use dep::aztec::{
keys::public_keys::{IvpkM, OvpkM},
prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader, Point},
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note_with_keys
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note_with_keys,
macros::{storage::storage, functions::{private, public, initializer}}
};
use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};
use dep::value_note::value_note::ValueNote;

#[aztec(storage)]
struct Storage {
numbers: Map<AztecAddress, PrivateMutable<ValueNote>>,
#[storage]
struct Storage<Context> {
numbers: Map<AztecAddress, PrivateMutable<ValueNote, Context>, Context>,
}

#[aztec(private)]
#[aztec(initializer)]
#[private]
#[initializer]
fn constructor(
number: Field,
owner: AztecAddress,
Expand All @@ -25,7 +29,7 @@ contract BoxReact {
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note_with_keys(&mut context, owner_ovpk_m, owner_ivpk_m, owner));
}

#[aztec(private)]
#[private]
fn setNumber(
number: Field,
owner: AztecAddress,
Expand Down
18 changes: 11 additions & 7 deletions boxes/boxes/vanilla/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
use dep::aztec::macros::aztec;

#[aztec]
contract Vanilla {
use dep::aztec::{
keys::public_keys::{IvpkM, OvpkM},
prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader, Point},
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note_with_keys
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note_with_keys,
macros::{storage::storage, functions::{private, public, initializer}}
};
use dep::value_note::value_note::{ValueNote, VALUE_NOTE_LEN};

#[aztec(storage)]
struct Storage {
numbers: Map<AztecAddress, PrivateMutable<ValueNote>>,
#[storage]
struct Storage<Context> {
numbers: Map<AztecAddress, PrivateMutable<ValueNote, Context>, Context>,
}

#[aztec(private)]
#[aztec(initializer)]
#[private]
#[initializer]
fn constructor(
number: Field,
owner: AztecAddress,
Expand All @@ -25,7 +29,7 @@ contract Vanilla {
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note_with_keys(&mut context, owner_ovpk_m, owner_ivpk_m, owner));
}

#[aztec(private)]
#[private]
fn setNumber(
number: Field,
owner: AztecAddress,
Expand Down
7 changes: 5 additions & 2 deletions boxes/init/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

use dep::aztec::macros::aztec;

#[aztec]
contract Main {
#[aztec(private)]
#[aztec(initializer)]
#[private]
#[initializer]
fn constructor() { }
}
4 changes: 2 additions & 2 deletions docs/docs/aztec/concepts/storage/partial_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ Then we just emit `P_a.x` and `P_b.x` as a note hashes, and we're done!

[`NoteInterface.nr`](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/aztec-nr/aztec/src/note/note_interface.nr) implements `compute_note_hiding_point`, which takes a note and computes the point "hides" it.

This is implemented in the example token contract:
This is implemented by applying the `partial_note` attribute:

#include_code compute_note_hiding_point noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr rust
#include_code TokenNote noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr rust

Those `G_x` are generators that generated [here](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/noir-projects/aztec-nr/aztec/src/generators.nr). Anyone can use them for separating different fields in a "partial note".

Expand Down
81 changes: 81 additions & 0 deletions docs/docs/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,87 @@ The `select` function in both `NoteGetterOptions` and `NoteViewerOptions` no lon
+ options.select(ValueNote::properties().value, Comparator.EQ, amount)
```

### [Aztec.nr] Changes to contract definition

We've migrated the Aztec macros to use the newly introduce meta programming Noir feature. Due to being Noir-based, the new macros are less obscure and can be more easily modified.

As part of this transition, some changes need to be applied to Aztec contracts:

- The top level `contract` block needs to have the `#[aztec]` macro applied to it.
- All `#[aztec(name)]` macros are renamed to `#[name]`.
- The storage struct (the one that gets the `#[storage]` macro applied) but be generic over a `Context` type, and all state variables receive this type as their last generic type parameter.

```diff
+ use dep::aztec::macros::aztec;

#[aztec]
contract Token {
+ use dep::aztec::macros::{storage::storage, events::event, functions::{initializer, private, view, public}};

- #[aztec(storage)]
- struct Storage {
+ #[storage]
+ struct Storage<Context> {
- admin: PublicMutable<AztecAddress>,
+ admin: PublicMutable<AztecAddress, Context>,
- minters: Map<AztecAddress, PublicMutable<bool>>,
+ minters: Map<AztecAddress, PublicMutable<bool, Context>, Context>,
}

- #[aztec(public)]
- #[aztec(initializer)]
+ #[public]
+ #[initializer]
fn constructor(admin: AztecAddress, name: str<31>, symbol: str<31>, decimals: u8) {
...
}

- #[aztec(public)]
- #[aztec(view)]
- fn public_get_name() -> FieldCompressedString {
+ #[public]
+ #[view]
fn public_get_name() -> FieldCompressedString {
...
}
```

### [Aztec.nr] Changes to `NoteInterface`

The new macro model prevents partial trait auto-implementation: they either implement the entire trait or none of it. This means users can no longer implement part of `NoteInterface` and have the rest be auto-implemented.

For this reason we've separated the methods which are auto-implemented and those which needs to be implemented manually into two separate traits: the auto-implemented ones stay in the `NoteInterface` trace and the manually implemented ones were moved to `NullifiableNote` (name likely to change):

```diff
-#[aztec(note)]
+#[note]
struct AddressNote {
...
}

-impl NoteInterface<ADDRESS_NOTE_LEN, ADDRESS_NOTE_BYTES_LEN> for AddressNote {
+impl NullifiableNote for AddressNote {
fn compute_nullifier(self, context: &mut PrivateContext, note_hash_for_nullify: Field) -> Field {
...
}

fn compute_nullifier_without_context(self) -> Field {
...
}
}
```

### [Aztec.nr] Changes to contract interface

The `Contract::storage()` static method has been renamed to `Contract::storage_layout()`.

```diff
- let fee_payer_balances_slot = derive_storage_slot_in_map(Token::storage().balances.slot, fee_payer);
- let user_balances_slot = derive_storage_slot_in_map(Token::storage().balances.slot, user);
+ let fee_payer_balances_slot = derive_storage_slot_in_map(Token::storage_layout().balances.slot, fee_payer);
+ let user_balances_slot = derive_storage_slot_in_map(Token::storage_layout().balances.slot, user);
```

## 0.53.0

### [Aztec.nr] Remove `OwnedNote` and create `UintNote`
Expand Down
18 changes: 6 additions & 12 deletions noir-projects/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
use dep::aztec::{
protocol_types::{
address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER,
hash::poseidon2_hash_with_separator
},
note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_nullify},
oracle::unsafe_rand::unsafe_rand, keys::getters::get_nsk_app, context::PrivateContext
protocol_types::{address::AztecAddress, constants::GENERATOR_INDEX__NOTE_NULLIFIER, hash::poseidon2_hash_with_separator},
note::{note_header::NoteHeader, note_interface::NullifiableNote, utils::compute_note_hash_for_nullify},
oracle::unsafe_rand::unsafe_rand, keys::getters::get_nsk_app, context::PrivateContext,
macros::notes::note
};

global ADDRESS_NOTE_LEN: u32 = 3;
// ADDRESS_NOTE_LEN * 32 + 32(storage_slot as bytes) + 32(note_type_id as bytes)
global ADDRESS_NOTE_BYTES_LEN: u32 = 3 * 32 + 64;

// docs:start:address_note_def
// docs:start:address_note_struct
// Stores an address
#[aztec(note)]
#[note]
struct AddressNote {
address: AztecAddress,
// The nullifying public key hash is used with the nsk_app to ensure that the note can be privately spent.
Expand All @@ -23,7 +17,7 @@ struct AddressNote {
}
// docs:end:address_note_struct

impl NoteInterface<ADDRESS_NOTE_LEN, ADDRESS_NOTE_BYTES_LEN> for AddressNote {
impl NullifiableNote for AddressNote {

fn compute_nullifier(self, context: &mut PrivateContext, note_hash_for_nullify: Field) -> Field {
let secret = context.request_nsk_app(self.npk_m_hash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use dep::protocol_types::{
};

// When finished, one can call .finish() to convert back to the abi
struct PrivateContext {
pub struct PrivateContext {
// docs:start:private-context
inputs: PrivateContextInputs,
side_effect_counter: u32,
Expand Down
Loading
Loading