Skip to content

Commit

Permalink
naming fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 23, 2025
1 parent 5a4e6d0 commit e37bf82
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 51 deletions.
12 changes: 6 additions & 6 deletions noir-projects/aztec-nr/aztec/src/macros/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ comptime fn generate_contract_interface(m: Module) -> Quoted {
}

comptime fn generate_compute_note_hash_and_optionally_a_nullifier() -> Quoted {
let mut max_note_length: u32 = 0;
let mut max_note_content_length: u32 = 0;
let notes = NOTES.entries();
let body = if notes.len() > 0 {
max_note_length = notes.fold(
max_note_content_length = notes.fold(
0,
|acc, (_, (_, len, _, _)): (Type, (StructDefinition, u32, Field, [(Quoted, u32, bool)]))| {
if len > acc {
Expand All @@ -138,7 +138,7 @@ comptime fn generate_compute_note_hash_and_optionally_a_nullifier() -> Quoted {
if_statements_list = if_statements_list.push_back(
quote {
$if_or_else_if note_type_id == $typ::get_note_type_id() {
aztec::note::utils::compute_note_hash_and_optionally_a_nullifier($typ::unpack_content, note_header, compute_nullifier, serialized_note)
aztec::note::utils::compute_note_hash_and_optionally_a_nullifier($typ::unpack_content, note_header, compute_nullifier, packed_note_content)
}
},
);
Expand Down Expand Up @@ -166,7 +166,7 @@ comptime fn generate_compute_note_hash_and_optionally_a_nullifier() -> Quoted {
storage_slot: Field,
note_type_id: Field,
compute_nullifier: bool,
serialized_note: [Field; $max_note_length],
packed_note_content: [Field; $max_note_content_length],
) -> pub [Field; 4] {
$body
}
Expand Down Expand Up @@ -213,7 +213,7 @@ comptime fn generate_process_log() -> Quoted {

let mut if_note_type_id_match_statements_list = &[];
for i in 0..notes.len() {
let (typ, (_, serialized_note_length, _, _)) = notes[i];
let (typ, (_, packed_note_content_length, _, _)) = notes[i];

let if_or_else_if = if i == 0 {
quote { if }
Expand All @@ -227,7 +227,7 @@ comptime fn generate_process_log() -> Quoted {
// As an extra safety check we make sure that the packed_note_content bounded vec has the
// expected length, to avoid scenarios in which compute_note_hash_and_optionally_a_nullifier
// silently trims the end if the log were to be longer.
let expected_len = $serialized_note_length;
let expected_len = $packed_note_content_length;
let actual_len = packed_note_content.len();
assert(
actual_len == expected_len,
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ comptime global NOTE_HEADER_TYPE: Type = type_of(NoteHeader::empty());

/// A map from note type to (note_struct_definition, note_packed_len, note_type_id, fields).
/// `fields` is an array of tuples where each tuple contains the name of the field/struct member (e.g. `amount`
/// in `TokenNote`), the index of where the serialized member starts in the serialized note and a flag indicating
/// in `TokenNote`), the index of where the packed member starts in the packed note and a flag indicating
/// whether the field is nullable or not.
pub comptime mut global NOTES: UHashMap<Type, (StructDefinition, u32, Field, [(Quoted, u32, bool)]), BuildHasherDefault<Poseidon2Hasher>> =
UHashMap::default();
Expand All @@ -35,7 +35,7 @@ comptime fn get_next_note_type_id() -> Field {
}

/// Generates default `NoteInterface` implementation for a given note struct `s` and returns it as quote along with
/// the length of the serialized note.
/// the length of the packed note.
///
/// impl NoteInterface<N> for NoteStruct {
/// fn to_be_bytes(self, storage_slot: Field) -> [u8; N * 32 + 64] {
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/note/lifecycle.nr
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ where
note.set_header(header);
let note_hash = note.compute_note_hash();

let serialized_note = Note::pack_content(*note);
let packed_note_content = Note::pack_content(*note);
notify_created_note(
storage_slot,
Note::get_note_type_id(),
serialized_note,
packed_note_content,
note_hash,
note_hash_counter,
);
Expand Down
12 changes: 6 additions & 6 deletions noir-projects/aztec-nr/aztec/src/note/note_getter/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ pub use crate::note::constants::MAX_NOTES_PER_PAGE;
mod test;

fn extract_property_value_from_selector<let N: u32>(
serialized_note: [Field; N],
packed_note_content: [Field; N],
selector: PropertySelector,
) -> Field {
// Selectors use PropertySelectors in order to locate note properties inside the serialized note.
// This allows easier packing and custom (de)serialization schemas. A note property is located
// inside the serialized note using the index inside the array, a byte offset and a length.
let value: [u8; 32] = serialized_note[selector.index].to_be_bytes();
let value: [u8; 32] = packed_note_content[selector.index].to_be_bytes();
let offset = selector.offset;
let length = selector.length;
let mut value_field = 0 as Field;
Expand All @@ -47,14 +47,14 @@ where
assert(header.storage_slot == storage_slot, "Mismatch note header storage slot.");
}

fn check_note_fields<let N: u32>(
serialized_note: [Field; N],
fn check_note_content<let N: u32>(
packed_note_content: [Field; N],
selects: BoundedVec<Option<Select>, N>,
) {
for i in 0..selects.len() {
let select = selects.get_unchecked(i).unwrap_unchecked();
let value_field =
extract_property_value_from_selector(serialized_note, select.property_selector);
extract_property_value_from_selector(packed_note_content, select.property_selector);

assert(
compare(value_field, select.comparator, select.value.to_field()),
Expand Down Expand Up @@ -156,7 +156,7 @@ where
let note = notes.get_unchecked(i);
let fields = note.pack_content();
check_note_header(*context, storage_slot, note);
check_note_fields(fields, options.selects);
check_note_content(fields, options.selects);
if i != 0 {
check_notes_order(prev_fields, fields, options.sorts);
}
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/note/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ pub unconstrained fn compute_note_hash_and_optionally_a_nullifier<T, let N: u32,
unpack_content: fn([Field; N]) -> T,
note_header: NoteHeader,
compute_nullifier: bool,
serialized_note: [Field; S],
packed_note_content: [Field; S],
) -> [Field; 4]
where
T: NoteInterface<N> + NullifiableNote,
{
let mut note = unpack_content(array::subarray(serialized_note, 0));
let mut note = unpack_content(array::subarray(packed_note_content, 0));
note.set_header(note_header);

let note_hash = note.compute_note_hash();
Expand Down
10 changes: 5 additions & 5 deletions noir-projects/aztec-nr/aztec/src/oracle/notes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use dep::protocol_types::{
pub fn notify_created_note<let N: u32>(
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; N],
packed_note_content: [Field; N],
note_hash: Field,
counter: u32,
) {
Expand All @@ -20,7 +20,7 @@ pub fn notify_created_note<let N: u32>(
notify_created_note_oracle_wrapper(
storage_slot,
note_type_id,
serialized_note,
packed_note_content,
note_hash,
counter,
)
Expand All @@ -45,14 +45,14 @@ pub fn notify_created_nullifier(nullifier: Field) {
unconstrained fn notify_created_note_oracle_wrapper<let N: u32>(
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; N],
packed_note_content: [Field; N],
note_hash: Field,
counter: u32,
) {
let _ = notify_created_note_oracle(
storage_slot,
note_type_id,
serialized_note,
packed_note_content,
note_hash,
counter,
);
Expand All @@ -62,7 +62,7 @@ unconstrained fn notify_created_note_oracle_wrapper<let N: u32>(
unconstrained fn notify_created_note_oracle<let N: u32>(
_storage_slot: Field,
_note_type_id: Field,
_serialized_note: [Field; N],
_packed_note_content: [Field; N],
_note_hash: Field,
_counter: u32,
) -> Field {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ impl TestEnvironment {
let header = NoteHeader { contract_address, storage_slot, nonce: 0, note_hash_counter };
note.set_header(header);
let note_hash = note.compute_note_hash();
let serialized_note = Note::pack_content(*note);
let packed_content = Note::pack_content(*note);
notify_created_note(
storage_slot,
Note::get_note_type_id(),
serialized_note,
packed_content,
note_hash,
note_hash_counter,
);
Expand Down
6 changes: 3 additions & 3 deletions noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl NoteInterface<MOCK_NOTE_LENGTH> for MockNote {
}

fn to_be_bytes(self, storage_slot: Field) -> [u8; MOCK_NOTE_LENGTH * 32 + 64] {
let serialized_note = self.pack_content();
let packed_content = self.pack_content();

let mut buffer: [u8; MOCK_NOTE_LENGTH * 32 + 64] = [0; MOCK_NOTE_LENGTH * 32 + 64];

Expand All @@ -81,8 +81,8 @@ impl NoteInterface<MOCK_NOTE_LENGTH> for MockNote {
buffer[32 + i] = note_type_id_bytes[i];
}

for i in 0..serialized_note.len() {
let bytes: [u8; 32] = serialized_note[i].to_be_bytes();
for i in 0..packed_content.len() {
let bytes: [u8; 32] = packed_content[i].to_be_bytes();
for j in 0..32 {
buffer[64 + i * 32 + j] = bytes[j];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct EcdsaPublicKeyNote {
}

impl NoteInterface<ECDSA_PUBLIC_KEY_NOTE_LEN> for EcdsaPublicKeyNote {
// Cannot use the automatic serialization since x and y don't fit. Serialize the note as 5 fields where:
// Cannot use the automatic packing since x and y don't fit. Serialize the note as 5 fields where:
// [0] = x[0..31] (upper bound excluded)
// [1] = x[31]
// [2] = y[0..31]
Expand All @@ -46,28 +46,28 @@ impl NoteInterface<ECDSA_PUBLIC_KEY_NOTE_LEN> for EcdsaPublicKeyNote {
[x, last_x, y, last_y, self.owner.to_field()]
}

// Cannot use the automatic deserialization for the aforementioned reasons
fn unpack_content(serialized_note: [Field; ECDSA_PUBLIC_KEY_NOTE_LEN]) -> EcdsaPublicKeyNote {
// Cannot use the automatic unpacking for the aforementioned reasons
fn unpack_content(packed_content: [Field; ECDSA_PUBLIC_KEY_NOTE_LEN]) -> EcdsaPublicKeyNote {
let mut x: [u8; 32] = [0; 32];
let mut y: [u8; 32] = [0; 32];

let part_x:[u8; 32] = serialized_note[0].to_be_bytes();
let part_x:[u8; 32] = packed_content[0].to_be_bytes();
for i in 0..31 {
x[i] = part_x[i + 1];
}
x[31] = serialized_note[1].to_be_bytes::<32>()[31];
x[31] = packed_content[1].to_be_bytes::<32>()[31];

let part_y:[u8; 32] = serialized_note[2].to_be_bytes();
let part_y:[u8; 32] = packed_content[2].to_be_bytes();
for i in 0..31 {
y[i] = part_y[i + 1];
}
y[31] = serialized_note[3].to_be_bytes::<32>()[31];
y[31] = packed_content[3].to_be_bytes::<32>()[31];

EcdsaPublicKeyNote { x, y, owner: AztecAddress::from_field(serialized_note[4]), header: NoteHeader::empty() }
EcdsaPublicKeyNote { x, y, owner: AztecAddress::from_field(packed_content[4]), header: NoteHeader::empty() }
}

fn to_be_bytes(self, storage_slot: Field) -> [u8; ECDSA_PUBLIC_KEY_NOTE_LEN * 32 + 64] {
let serialized_note = self.pack_content();
let packed_content = self.pack_content();

let mut buffer: [u8; ECDSA_PUBLIC_KEY_NOTE_LEN * 32 + 64] = [0; ECDSA_PUBLIC_KEY_NOTE_LEN * 32 + 64];

Expand All @@ -79,8 +79,8 @@ impl NoteInterface<ECDSA_PUBLIC_KEY_NOTE_LEN> for EcdsaPublicKeyNote {
buffer[32 + i] = note_type_id_bytes[i];
}

for i in 0..serialized_note.len() {
let bytes: [u8; 32] = serialized_note[i].to_be_bytes();
for i in 0..packed_content.len() {
let bytes: [u8; 32] = packed_content[i].to_be_bytes();
for j in 0..32 {
buffer[64 + i * 32 + j] = bytes[j];
}
Expand All @@ -102,15 +102,15 @@ impl NoteInterface<ECDSA_PUBLIC_KEY_NOTE_LEN> for EcdsaPublicKeyNote {
}

fn compute_note_hash(self) -> Field {
let serialized = self.pack_content();
let packed_content = self.pack_content();
std::embedded_curve_ops::multi_scalar_mul(
[Gx_1, Gx_2, Gy_1, Gy_2, G_owner, G_slot],
[
from_field_unsafe(serialized[0]),
from_field_unsafe(serialized[1]),
from_field_unsafe(serialized[2]),
from_field_unsafe(serialized[3]),
from_field_unsafe(serialized[4]),
from_field_unsafe(packed_content[0]),
from_field_unsafe(packed_content[1]),
from_field_unsafe(packed_content[2]),
from_field_unsafe(packed_content[3]),
from_field_unsafe(packed_content[4]),
from_field_unsafe(self.get_header().storage_slot)
]
).x
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/pxe/src/database/note_dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
import { type NoteData } from '@aztec/simulator/client';

/**
* A Note Data Access Object, representing a note that was comitted to the note hash tree, holding all of the
* A Note Data Access Object, representing a note that was committed to the note hash tree, holding all of the
* information required to use it during execution and manage its state.
*/
export class NoteDao implements NoteData {
constructor(
// Note information

/** The serialized content of the note, as will be returned in the getNotes oracle. */
/** The packed content of the note, as will be returned in the getNotes oracle. */
public note: Note,
/** The address of the contract that created the note (i.e. the address used by the kernel during siloing). */
public contractAddress: AztecAddress,
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/simulator/src/client/pick_notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ interface ContainsNote {
note: Note;
}

const selectPropertyFromSerializedNote = (noteData: Fr[], selector: PropertySelector): Fr => {
const selectPropertyFromPackedNoteContent = (noteData: Fr[], selector: PropertySelector): Fr => {
const noteValueBuffer = noteData[selector.index].toBuffer();
const noteValue = noteValueBuffer.subarray(selector.offset, selector.offset + selector.length);
return Fr.fromBuffer(noteValue);
Expand All @@ -93,7 +93,7 @@ const selectPropertyFromSerializedNote = (noteData: Fr[], selector: PropertySele
const selectNotes = <T extends ContainsNote>(noteDatas: T[], selects: Select[]): T[] =>
noteDatas.filter(noteData =>
selects.every(({ selector, value, comparator }) => {
const noteValueFr = selectPropertyFromSerializedNote(noteData.note.items, selector);
const noteValueFr = selectPropertyFromPackedNoteContent(noteData.note.items, selector);
const comparatorSelector = {
[Comparator.EQ]: () => noteValueFr.equals(value),
[Comparator.NEQ]: () => !noteValueFr.equals(value),
Expand All @@ -117,8 +117,8 @@ const sortNotes = (a: Fr[], b: Fr[], sorts: Sort[], level = 0): number => {
return 0;
}

const aValue = selectPropertyFromSerializedNote(a, selector);
const bValue = selectPropertyFromSerializedNote(b, selector);
const aValue = selectPropertyFromPackedNoteContent(a, selector);
const bValue = selectPropertyFromPackedNoteContent(b, selector);

const dir = order === 1 ? [-1, 1] : [1, -1];
return aValue.toBigInt() === bValue.toBigInt()
Expand Down

0 comments on commit e37bf82

Please sign in to comment.