Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 27, 2025
1 parent 294298f commit e9a4768
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
10 changes: 5 additions & 5 deletions docs/docs/aztec/smart_contracts/functions/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ When a struct is annotated with `#[note]`, the Aztec macro applies a series of t

1. **NoteInterface Implementation**: The macro automatically implements most methods of the `NoteInterface` trait for the annotated struct. This includes:

- `serialize_content` and `deserialize_content`
- `pack_content` and `unpack_content`
- `get_header` and `set_header`
- `get_note_type_id`
- `compute_note_hiding_point`
Expand Down Expand Up @@ -219,14 +219,14 @@ struct CustomNote {

```rust
impl CustomNote {
fn serialize_content(self: CustomNote) -> [Field; NOTE_SERIALIZED_LEN] {
fn pack_content(self: CustomNote) -> [Field; PACKED_NOTE_CONTENT_LEN] {
[self.data, self.owner.to_field()]
}

fn deserialize_content(serialized_note: [Field; NOTE_SERIALIZED_LEN]) -> Self {
fn unpack_content(packed_content: [Field; PACKED_NOTE_CONTENT_LEN]) -> Self {
CustomNote {
data: serialized_note[0] as Field,
owner: Address::from_field(serialized_note[1]),
data: packed_content[0] as Field,
owner: Address::from_field(packed_content[1]),
header: NoteHeader::empty()
}
}
Expand Down
14 changes: 7 additions & 7 deletions docs/docs/aztec/smart_contracts/functions/function_transforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ For private functions, the context creation involves hashing all input parameter

```rust
let mut args_hasher = ArgsHasher::new();
// Hash each parameter
// Hash each parameter
args_hasher.add(param1);
args_hasher.add(param2);
// add all parameters
Expand Down Expand Up @@ -71,8 +71,8 @@ The context provides methods to call other contracts:
```rust
let token_contract = TokenContract::at(token);
```
Under the hood, this creates a new instance of the contract interface with the specified address.

Under the hood, this creates a new instance of the contract interface with the specified address.

## Private and public input injection

Expand Down Expand Up @@ -102,7 +102,7 @@ This makes these inputs available to be consumed within private annotated functi

## Return value handling

Return values in Aztec contracts are processed differently from traditional smart contracts when using private functions.
Return values in Aztec contracts are processed differently from traditional smart contracts when using private functions.

### Private functions

Expand Down Expand Up @@ -156,10 +156,10 @@ The function is automatically generated based on the note types defined in the c
```rust
if (note_type_id == NoteType::get_note_type_id()) {
aztec::note::utils::compute_note_hash_and_optionally_a_nullifier(
NoteType::deserialize_content,
NoteType::unpack_content,
note_header,
compute_nullifier,
serialized_note
packed_note_content
)
}
```
Expand Down Expand Up @@ -206,7 +206,7 @@ The computed function signatures are integrated into the contract interface like
- The function's parameters are extracted
- The signature hash is computed using `compute_fn_signature_hash`
- The placeholder in the contract interface is replaced with the computed hash

This process ensures that each function in the contract has a unique, deterministic signature based on its name and parameter types. They are inspired by Solidity's function selector mechanism.

## Contract artifacts
Expand Down
21 changes: 21 additions & 0 deletions docs/docs/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ impl Packable<U128_PACKED_LEN> for U128 {
}
```

### [Aztec.nr] Packing notes resulting in changes in `NoteInterface`
Note interface implementation generated by our macros now packs note content instead of serializing it
With this change notes are being less costly DA-wise to emit when some of the note struct members implements the `Packable` trait (this is typically the `UintNote` which represents `value` as `U128` that gets serialized as 2 fields but packed as 1).
This results in the following changes in the `NoteInterface`:

```diff
pub trait NoteInterface<let N: u32> {
- fn serialize_content(self) -> [Field; N];
+ fn pack_content(self) -> [Field; N];

- fn deserialize_content(fields: [Field; N]) -> Self;
+ fn unpack_content(fields: [Field; N]) -> Self;

fn get_header(self) -> NoteHeader;
fn set_header(&mut self, header: NoteHeader) -> ();
fn get_note_type_id() -> Field;
fn to_be_bytes(self, storage_slot: Field) -> [u8; N * 32 + 64];
fn compute_note_hash(self) -> Field;
}
```

## 0.72.0
### Some functions in `aztec.js` and `@aztec/accounts` are now async
In our efforts to make libraries more browser-friendly and providing with more bundling options for `bb.js` (like a non top-level-await version), some functions are being made async, in particular those that access our cryptographic functions.
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ comptime fn generate_note_interface(
let (unpacked_content, _) = generate_deserialize_from_fields(
quote {},
typ,
quote { packed_content }, // "packed_content" is argument of NoteInterface::deserialize_content
quote { packed_content }, // "packed_content" is argument of NoteInterface::unpack_content
0,
quote {header},
quote { aztec::note::note_header::NoteHeader::empty() },
Expand Down

0 comments on commit e9a4768

Please sign in to comment.