Skip to content

Commit

Permalink
refactor: continuation of note naming update (#3137)
Browse files Browse the repository at this point in the history
[PR 3051](AztecProtocol/aztec-packages#3051) was
getting too big so I decided to do the naming changes in noir contracts
in a separate PR. This is the PR.
  • Loading branch information
benesjan authored and AztecBot committed Nov 7, 2023
1 parent f08cdb6 commit d54caed
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions address-note/src/address_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ impl AddressNote {
[self.address, self.owner, self.randomness]
}

pub fn deserialize(preimage: [Field; ADDRESS_NOTE_LEN]) -> Self {
pub fn deserialize(serialized_note: [Field; ADDRESS_NOTE_LEN]) -> Self {
AddressNote {
address: preimage[0],
owner: preimage[1],
randomness: preimage[2],
address: serialized_note[0],
owner: serialized_note[1],
randomness: serialized_note[2],
header: NoteHeader::empty(),
}
}
Expand Down Expand Up @@ -85,8 +85,8 @@ impl AddressNote {
}
}

fn deserialize(preimage: [Field; ADDRESS_NOTE_LEN]) -> AddressNote {
AddressNote::deserialize(preimage)
fn deserialize(serialized_note: [Field; ADDRESS_NOTE_LEN]) -> AddressNote {
AddressNote::deserialize(serialized_note)
}

fn serialize(note: AddressNote) -> [Field; ADDRESS_NOTE_LEN]{
Expand Down
4 changes: 2 additions & 2 deletions aztec/src/note/lifecycle.nr
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pub fn create_note<Note, N>(
let inner_note_hash = compute_inner_note_hash(note_interface, *note);

let serialize = note_interface.serialize;
let preimage = serialize(*note);
assert(notify_created_note(storage_slot, preimage, inner_note_hash) == 0);
let serialized_note = serialize(*note);
assert(notify_created_note(storage_slot, serialized_note, inner_note_hash) == 0);

context.push_new_note_hash(inner_note_hash);

Expand Down
4 changes: 2 additions & 2 deletions aztec/src/note/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ pub fn compute_note_hash_for_read_or_nullify<Note, N>(
pub fn compute_note_hash_and_nullifier<Note, N, S>(
note_interface: NoteInterface<Note, N>,
note_header: NoteHeader,
preimage: [Field; S],
serialized_note: [Field; S],
) -> [Field; 4] {
let deserialize = note_interface.deserialize;
let set_header = note_interface.set_header;
let mut note = deserialize(arr_copy_slice(preimage, [0; N], 0));
let mut note = deserialize(arr_copy_slice(serialized_note, [0; N], 0));
set_header(&mut note, note_header);

let compute_note_hash = note_interface.compute_note_hash;
Expand Down
10 changes: 5 additions & 5 deletions aztec/src/oracle/notes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ use crate::utils::arr_copy_slice;
#[oracle(notifyCreatedNote)]
fn notify_created_note_oracle<N>(
_storage_slot: Field,
_preimage: [Field; N],
_serialized_note: [Field; N],
_inner_note_hash: Field,
) -> Field {}

unconstrained pub fn notify_created_note<N>(
storage_slot: Field,
preimage: [Field; N],
serialized_note: [Field; N],
inner_note_hash: Field,
) -> Field {
notify_created_note_oracle(storage_slot, preimage, inner_note_hash)
notify_created_note_oracle(storage_slot, serialized_note, inner_note_hash)
}

#[oracle(notifyNullifiedNote)]
Expand Down Expand Up @@ -89,8 +89,8 @@ unconstrained pub fn get_notes<Note, N, M, S, NS>(
let nonce = fields[read_offset];
let is_transient = fields[read_offset + 1] as bool;
let header = NoteHeader { contract_address, nonce, storage_slot, is_transient };
let preimage = arr_copy_slice(fields, [0; N], read_offset + 2);
let mut note = deserialize(preimage);
let serialized_note = arr_copy_slice(fields, [0; N], read_offset + 2);
let mut note = deserialize(serialized_note);
set_header(&mut note, header);
placeholder_opt_notes[i] = Option::some(note);
};
Expand Down
10 changes: 5 additions & 5 deletions field-note/src/field_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use dep::aztec::{
global FIELD_NOTE_LEN: Field = 1;

// A note which stores a field and is expected to be passed around using the `addNote` function.
// WARNING: This Note is not private as it does not contain randomness and hence it can be easy to perform preimage
// WARNING: This Note is not private as it does not contain randomness and hence it can be easy to perform serialized_note
// attack on it.
struct FieldNote {
value: Field,
Expand All @@ -29,9 +29,9 @@ impl FieldNote {
[self.value]
}

pub fn deserialize(preimage: [Field; FIELD_NOTE_LEN]) -> Self {
pub fn deserialize(serialized_note: [Field; FIELD_NOTE_LEN]) -> Self {
FieldNote {
value: preimage[0],
value: serialized_note[0],
header: NoteHeader::empty(),
}
}
Expand All @@ -51,8 +51,8 @@ impl FieldNote {
}
}

fn deserialize(preimage: [Field; FIELD_NOTE_LEN]) -> FieldNote {
FieldNote::deserialize(preimage)
fn deserialize(serialized_note: [Field; FIELD_NOTE_LEN]) -> FieldNote {
FieldNote::deserialize(serialized_note)
}

fn serialize(note: FieldNote) -> [Field; FIELD_NOTE_LEN]{
Expand Down
12 changes: 6 additions & 6 deletions value-note/src/value_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ impl ValueNote {
[self.value, self.owner, self.randomness]
}

pub fn deserialize(preimage: [Field; VALUE_NOTE_LEN]) -> Self {
pub fn deserialize(serialized_note: [Field; VALUE_NOTE_LEN]) -> Self {
ValueNote {
value: preimage[0],
owner: preimage[1],
randomness: preimage[2],
value: serialized_note[0],
owner: serialized_note[1],
randomness: serialized_note[2],
header: NoteHeader::empty(),
}
}
Expand Down Expand Up @@ -87,8 +87,8 @@ impl ValueNote {
}
}

fn deserialize(preimage: [Field; VALUE_NOTE_LEN]) -> ValueNote {
ValueNote::deserialize(preimage)
fn deserialize(serialized_note: [Field; VALUE_NOTE_LEN]) -> ValueNote {
ValueNote::deserialize(serialized_note)
}

fn serialize(note: ValueNote) -> [Field; VALUE_NOTE_LEN] {
Expand Down

0 comments on commit d54caed

Please sign in to comment.