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!: automatic NoteInterface and NoteGetterOptions auto select #4508

Merged
merged 57 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
155ee0d
squash refactor changes
Thunkar Mar 11, 2024
4049d99
noteinterface transformer and fieldselectors
Thunkar Mar 11, 2024
f05a3b7
merge changes
Thunkar Mar 11, 2024
7f8d093
fixed merge conflicts
Thunkar Mar 11, 2024
f102ee6
Merge branch 'master' into gj/aztec-macros-refactor
Thunkar Mar 11, 2024
fe98e06
Merge branch 'gj/aztec-macros-refactor' into gj/notegetteroptions_aut…
Thunkar Mar 11, 2024
f7648b5
renaming
Thunkar Mar 11, 2024
f97a471
removed whitespace
Thunkar Mar 11, 2024
eae0d5a
Merge branch 'master' into gj/aztec-macros-refactor
Thunkar Mar 11, 2024
82665d6
Merge branch 'gj/aztec-macros-refactor' of github.com:AztecProtocol/a…
Thunkar Mar 11, 2024
087ba80
better error handling
Thunkar Mar 11, 2024
077a621
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 11, 2024
4d2d4a3
removed unused dep
Thunkar Mar 11, 2024
18a1517
PR comments
Thunkar Mar 11, 2024
b37562c
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 11, 2024
3f62725
Merge branch 'gj/aztec-macros-refactor' of github.com:AztecProtocol/a…
Thunkar Mar 11, 2024
410b603
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 11, 2024
82ca27d
better error handling
Thunkar Mar 12, 2024
ce28515
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 12, 2024
cf4015c
better error handling, added spans almost everywhere
Thunkar Mar 12, 2024
84a0c03
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 13, 2024
88a9f34
automatic header field
Thunkar Mar 14, 2024
cc8c879
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 14, 2024
0406724
clippy run
Thunkar Mar 14, 2024
efa4ee5
docs and fixes
Thunkar Mar 14, 2024
1ee26bd
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 14, 2024
e07344b
Merge branch 'master' into gj/notegetteroptions_auto_select
Thunkar Mar 14, 2024
307e117
Merge branch 'master' into gj/notegetteroptions_auto_select
Thunkar Mar 15, 2024
18569d0
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 15, 2024
8d58dbd
Merge branch 'gj/notegetteroptions_auto_select' of github.com:AztecPr…
Thunkar Mar 15, 2024
82c9d8c
removed autogenerated methods
Thunkar Mar 15, 2024
6a77c9d
Merge branch 'master' into gj/notegetteroptions_auto_select
Thunkar Mar 15, 2024
b9265ea
Merge branch 'master' into gj/notegetteroptions_auto_select
Thunkar Mar 15, 2024
ec4331c
Merge branch 'master' into gj/notegetteroptions_auto_select
Thunkar Mar 15, 2024
ad9970f
Merge branch 'master' into gj/notegetteroptions_auto_select
Thunkar Mar 15, 2024
316062b
PR review
Thunkar Mar 15, 2024
4c110cf
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 15, 2024
98cc21e
Merge branch 'gj/notegetteroptions_auto_select' of github.com:AztecPr…
Thunkar Mar 15, 2024
3004dc0
more reviews
Thunkar Mar 15, 2024
003b040
more PR comments
Thunkar Mar 15, 2024
41a9221
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 15, 2024
bc47a64
workaround to the workaround
Thunkar Mar 15, 2024
6c2cd4f
Merge branch 'master' into gj/notegetteroptions_auto_select
Thunkar Mar 15, 2024
7f63326
Merge branch 'master' into gj/notegetteroptions_auto_select
Thunkar Mar 15, 2024
af5e67f
Merge branch 'master' into gj/notegetteroptions_auto_select
Thunkar Mar 18, 2024
817bf2f
better sort, docs
Thunkar Mar 18, 2024
adc4463
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 18, 2024
221e86c
Merge branch 'master' into gj/notegetteroptions_auto_select
Thunkar Mar 18, 2024
9214f7e
applied more feedback
Thunkar Mar 18, 2024
4fddfb1
Merge branch 'gj/notegetteroptions_auto_select' of github.com:AztecPr…
Thunkar Mar 18, 2024
83d8445
more renaming
Thunkar Mar 18, 2024
989663b
typo
Thunkar Mar 18, 2024
dd22c18
Merge branch 'master' into gj/notegetteroptions_auto_select
Thunkar Mar 18, 2024
ed5d0ce
Merge branch 'master' into gj/notegetteroptions_auto_select
Thunkar Mar 18, 2024
247682b
better header handling
Thunkar Mar 19, 2024
d804e95
Merge branch 'master' of github.com:AztecProtocol/aztec-packages into…
Thunkar Mar 19, 2024
424a790
Merge branch 'gj/notegetteroptions_auto_select' of github.com:AztecPr…
Thunkar Mar 19, 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
1 change: 1 addition & 0 deletions avm-transpiler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ You can view the implementation [here](https://github.com/AztecProtocol/aztec-pa

### `selects: BoundedVec<Option<Select>, N>`

`selects` is a collection of filtering criteria, specified by `Select { field_index: u8, value: Field, comparator: u3 }` structs. It instructs the data oracle to find notes whose (`field_index`)th field matches the provided `value`, according to the `comparator`.
`selects` is a collection of filtering criteria, specified by `Select { property_selector: PropertySelector, value: Field, comparator: u3 }` structs. It instructs the data oracle to find notes whose serialized field (as specified by the PropertySelector) matches the provided `value`, according to the `comparator`. The PropertySelector is in turn specified as having an `index` (nth position of the selected field in the serialized note), an `offset` (byte offset inside the selected serialized field) and `length` (bytes to read of the field from the offset)

### `sorts: BoundedVec<Option<Sort>, N>`

`sorts` is a set of sorting instructions defined by `Sort { field_index: u8, order: u2 }` structs. This directs the data oracle to sort the matching notes based on the value of the specified field index and in the indicated order. The value of order is **1** for _DESCENDING_ and **2** for _ASCENDING_.
`sorts` is a set of sorting instructions defined by `Sort { property_selector: PropertySelector, order: u2 }` structs. This directs the data oracle to sort the matching notes based on the value of the specified PropertySelector and in the indicated order. The value of order is **1** for _DESCENDING_ and **2** for _ASCENDING_.

### `limit: u32`

Expand Down
153 changes: 153 additions & 0 deletions docs/docs/misc/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,159 @@ keywords: [sandbox, cli, aztec, notes, migration, updating, upgrading]

Aztec is in full-speed development. Literally every version breaks compatibility with the previous ones. This page attempts to target errors and difficulties you might encounter when upgrading, and how to resolve them.

## 0.28.0

### Automatic NoteInterface implementation and selector changes

Implementing a note required a fair amount of boilerplate code, which has been substituted by the `#[aztec(note)]` attribute.
Thunkar marked this conversation as resolved.
Show resolved Hide resolved

Before:

```rust
struct AddressNote {
address: AztecAddress,
owner: AztecAddress,
randomness: Field,
header: NoteHeader
}

impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {
fn serialize_content(self) -> [Field; ADDRESS_NOTE_LEN]{
[self.address.to_field(), self.owner.to_field(), self.randomness]
}

fn deserialize_content(serialized_note: [Field; ADDRESS_NOTE_LEN]) -> Self {
AddressNote {
address: AztecAddress::from_field(serialized_note[0]),
owner: AztecAddress::from_field(serialized_note[1]),
randomness: serialized_note[2],
header: NoteHeader::empty(),
}
}

fn compute_note_content_hash(self) -> Field {
pedersen_hash(self.serialize_content(), 0)
}

fn compute_nullifier(self, context: &mut PrivateContext) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = context.request_nullifier_secret_key(self.owner);
pedersen_hash([
note_hash_for_nullify,
secret.low,
secret.high,
],0)
}

fn compute_nullifier_without_context(self) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_nullifier_secret_key(self.owner);
pedersen_hash([
note_hash_for_nullify,
secret.low,
secret.high,
],0)
}

fn set_header(&mut self, header: NoteHeader) {
self.header = header;
}

fn get_header(note: Self) -> NoteHeader {
note.header
}

fn broadcast(self, context: &mut PrivateContext, slot: Field) {
let encryption_pub_key = get_public_key(self.owner);
emit_encrypted_log(
context,
(*context).this_address(),
slot,
Self::get_note_type_id(),
encryption_pub_key,
self.serialize_content(),
);
}

fn get_note_type_id() -> Field {
6510010011410111511578111116101
}
}

```

After:

```rust
#[aztec(note)]
struct AddressNote {
address: AztecAddress,
owner: AztecAddress,
randomness: Field,
}

impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {
fn compute_nullifier(self, context: &mut PrivateContext) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = context.request_nullifier_secret_key(self.owner);
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([
note_hash_for_nullify,
secret.low,
secret.high,
],0)
}

fn compute_nullifier_without_context(self) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_nullifier_secret_key(self.owner);
pedersen_hash([
note_hash_for_nullify,
secret.low,
secret.high,
],0)
}

fn broadcast(self, context: &mut PrivateContext, slot: Field) {
let encryption_pub_key = get_public_key(self.owner);
emit_encrypted_log(
context,
(*context).this_address(),
slot,
Self::get_note_type_id(),
encryption_pub_key,
self.serialize_content(),
);
}
}
```

Automatic note (de)serialization implementation also means it is now easier to filter notes using `NoteGetterOptions.select` via the `::properties()` helper:

Before:

```rust
let options = NoteGetterOptions::new().select(0, amount, Option::none()).select(1, owner.to_field(), Option::none()).set_limit(1);
```

After:

```rust
let options = NoteGetterOptions::new().select(ValueNote::properties().value, amount, Option::none()).select(ValueNote::properties().owner, owner.to_field(), Option::none()).set_limit(1);
```

The helper returns a metadata struct that looks like this (if autogenerated)

```rust
ValueNoteProperties {
value: PropertySelector { index: 0, offset: 0, length: 32 },
owner: PropertySelector { index: 1, offset: 0, length: 32 },
randomness: PropertySelector { index: 2, offset: 0, length: 32 },
}
```

It can also be used for the `.sort` method.

## 0.27.0

### `initializer` macro replaces `constructor`
Expand Down
33 changes: 1 addition & 32 deletions noir-projects/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,14 @@ global ADDRESS_NOTE_LEN: Field = 3;

// docs:start:address_note_def
// Stores an address
#[aztec(note)]
struct AddressNote {
address: AztecAddress,
owner: AztecAddress,
randomness: Field,
header: NoteHeader,
}

impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {
fn serialize_content(self) -> [Field; ADDRESS_NOTE_LEN]{
[self.address.to_field(), self.owner.to_field(), self.randomness]
}

fn deserialize_content(serialized_note: [Field; ADDRESS_NOTE_LEN]) -> Self {
AddressNote {
address: AztecAddress::from_field(serialized_note[0]),
owner: AztecAddress::from_field(serialized_note[1]),
randomness: serialized_note[2],
header: NoteHeader::empty(),
}
}

fn compute_note_content_hash(self) -> Field {
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash(self.serialize_content(), 0)
}

fn compute_nullifier(self, context: &mut PrivateContext) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
Expand All @@ -60,14 +43,6 @@ impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {
],0)
}

fn set_header(&mut self, header: NoteHeader) {
self.header = header;
}

fn get_header(note: Self) -> NoteHeader {
note.header
}

// Broadcasts the note as an encrypted log on L1.
fn broadcast(self, context: &mut PrivateContext, slot: Field) {
let encryption_pub_key = get_public_key(self.owner);
Expand All @@ -82,12 +57,6 @@ impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {
);
// docs:end:encrypted
}

fn get_note_type_id() -> Field {
// TODO(#4519): autogenerate
// python -c "print(int(''.join(str(ord(c)) for c in 'AddressNote')))"
6510010011410111511578111116101
}
}

impl AddressNote {
Expand Down
Loading