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

refactor: renaming Note generic as NOTE #12282

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,19 @@ fn assert_note_exists<let N: u32>(context: PrivateContext, note_hash_counter: u3
/// note_id and the storage_slot) to be converted into bytes, because the aes function
/// operates on bytes; not fields.
/// NB: The extra `+ 64` bytes is for the note_id and the storage_slot of the note:
fn compute_note_plaintext_for_this_strategy<Note, let N: u32>(
note: Note,
fn compute_note_plaintext_for_this_strategy<NOTE, let N: u32>(
note: NOTE,
storage_slot: Field,
) -> [u8; N * 32 + 64]
where
Note: NoteType + Packable<N>,
NOTE: NoteType + Packable<N>,
{
let packed_note = note.pack();

let storage_slot_bytes: [u8; 32] = storage_slot.to_be_bytes();

// TODO(#10952): The following can be reduced to 7 bits
let note_type_id_bytes: [u8; 32] = Note::get_id().to_be_bytes();
let note_type_id_bytes: [u8; 32] = NOTE::get_id().to_be_bytes();

// We combine all the bytes into plaintext_bytes:
let mut plaintext_bytes: [u8; N * 32 + 64] = [0; N * 32 + 64];
Expand All @@ -244,15 +244,15 @@ where
plaintext_bytes
}

fn compute_log<Note, let N: u32>(
fn compute_log<NOTE, let N: u32>(
context: PrivateContext,
note: Note,
note: NOTE,
storage_slot: Field,
recipient: AztecAddress,
sender: AztecAddress,
) -> [Field; PRIVATE_LOG_SIZE_IN_FIELDS]
where
Note: NoteType + Packable<N>,
NOTE: NoteType + Packable<N>,
{
// *****************************************************************************
// Compute the shared secret
Expand Down Expand Up @@ -408,32 +408,32 @@ where
final_log
}

unconstrained fn compute_log_unconstrained<Note, let N: u32>(
unconstrained fn compute_log_unconstrained<NOTE, let N: u32>(
context: PrivateContext,
note: Note,
note: NOTE,
storage_slot: Field,
recipient: AztecAddress,
sender: AztecAddress,
) -> [Field; PRIVATE_LOG_SIZE_IN_FIELDS]
where
Note: NoteType + Packable<N>,
NOTE: NoteType + Packable<N>,
{
compute_log(context, note, storage_slot, recipient, sender)
}

// This function seems to be affected by the following Noir bug:
// https://github.com/noir-lang/noir/issues/5771
// If you get weird behavior it might be because of it.
pub fn encode_and_encrypt_note<Note, let N: u32>(
pub fn encode_and_encrypt_note<NOTE, let N: u32>(
context: &mut PrivateContext,
recipient: AztecAddress,
// We need this because to compute a tagging secret, we require a sender:
sender: AztecAddress,
) -> fn[(&mut PrivateContext, AztecAddress, AztecAddress)](NoteEmission<Note>) -> ()
) -> fn[(&mut PrivateContext, AztecAddress, AztecAddress)](NoteEmission<NOTE>) -> ()
where
Note: NoteType + Packable<N>,
NOTE: NoteType + Packable<N>,
{
|e: NoteEmission<Note>| {
|e: NoteEmission<NOTE>| {
let note = e.note;
let storage_slot = e.storage_slot;
let note_hash_counter = e.note_hash_counter;
Expand All @@ -447,16 +447,16 @@ where
// Important note: this function -- although called "unconstrained" -- the
// function is not labelled as `unconstrained`, because we pass a reference to the
// context.
pub fn encode_and_encrypt_note_unconstrained<Note, let N: u32>(
pub fn encode_and_encrypt_note_unconstrained<NOTE, let N: u32>(
context: &mut PrivateContext,
recipient: AztecAddress,
// We need this because to compute a tagging secret, we require a sender:
sender: AztecAddress,
) -> fn[(&mut PrivateContext, AztecAddress, AztecAddress)](NoteEmission<Note>) -> ()
) -> fn[(&mut PrivateContext, AztecAddress, AztecAddress)](NoteEmission<NOTE>) -> ()
where
Note: NoteType + Packable<N>,
NOTE: NoteType + Packable<N>,
{
|e: NoteEmission<Note>| {
|e: NoteEmission<NOTE>| {
let note = e.note;
let storage_slot = e.storage_slot;
let note_hash_counter = e.note_hash_counter;
Expand Down
10 changes: 5 additions & 5 deletions noir-projects/aztec-nr/aztec/src/history/note_inclusion.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ use crate::{
};

trait ProveNoteInclusion {
fn prove_note_inclusion<Note>(
fn prove_note_inclusion<NOTE>(
header: BlockHeader,
retrieved_note: RetrievedNote<Note>,
retrieved_note: RetrievedNote<NOTE>,
storage_slot: Field,
)
where
Note: NoteHash;
NOTE: NoteHash;
}

impl ProveNoteInclusion for BlockHeader {
fn prove_note_inclusion<Note>(self, retrieved_note: RetrievedNote<Note>, storage_slot: Field)
fn prove_note_inclusion<NOTE>(self, retrieved_note: RetrievedNote<NOTE>, storage_slot: Field)
where
Note: NoteHash,
NOTE: NoteHash,
{
let note_hash = compute_note_hash_for_nullify(retrieved_note, storage_slot);

Expand Down
12 changes: 6 additions & 6 deletions noir-projects/aztec-nr/aztec/src/history/note_validity.nr
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ use crate::{
use dep::protocol_types::block_header::BlockHeader;

trait ProveNoteValidity {
fn prove_note_validity<Note>(
fn prove_note_validity<NOTE>(
header: BlockHeader,
retrieved_note: RetrievedNote<Note>,
retrieved_note: RetrievedNote<NOTE>,
storage_slot: Field,
context: &mut PrivateContext,
)
where
Note: NoteHash;
NOTE: NoteHash;
}

impl ProveNoteValidity for BlockHeader {
fn prove_note_validity<Note>(
fn prove_note_validity<NOTE>(
self,
retrieved_note: RetrievedNote<Note>,
retrieved_note: RetrievedNote<NOTE>,
storage_slot: Field,
context: &mut PrivateContext,
)
where
Note: NoteHash,
NOTE: NoteHash,
{
self.prove_note_inclusion(retrieved_note, storage_slot);
self.prove_note_not_nullified(retrieved_note, storage_slot, context);
Expand Down
12 changes: 6 additions & 6 deletions noir-projects/aztec-nr/aztec/src/history/nullifier_inclusion.nr
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,26 @@ impl ProveNullifierInclusion for BlockHeader {
}

trait ProveNoteIsNullified {
fn prove_note_is_nullified<Note>(
fn prove_note_is_nullified<NOTE>(
header: BlockHeader,
retrieved_note: RetrievedNote<Note>,
retrieved_note: RetrievedNote<NOTE>,
storage_slot: Field,
context: &mut PrivateContext,
)
where
Note: NoteHash;
NOTE: NoteHash;
}

impl ProveNoteIsNullified for BlockHeader {
// docs:start:prove_note_is_nullified
fn prove_note_is_nullified<Note>(
fn prove_note_is_nullified<NOTE>(
self,
retrieved_note: RetrievedNote<Note>,
retrieved_note: RetrievedNote<NOTE>,
storage_slot: Field,
context: &mut PrivateContext,
)
where
Note: NoteHash,
NOTE: NoteHash,
{
let nullifier = compute_siloed_note_nullifier(retrieved_note, storage_slot, context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,26 @@ impl ProveNullifierNonInclusion for BlockHeader {
}

trait ProveNoteNotNullified {
fn prove_note_not_nullified<Note>(
fn prove_note_not_nullified<NOTE>(
header: BlockHeader,
retrieved_note: RetrievedNote<Note>,
retrieved_note: RetrievedNote<NOTE>,
storage_slot: Field,
context: &mut PrivateContext,
)
where
Note: NoteHash;
NOTE: NoteHash;
}

impl ProveNoteNotNullified for BlockHeader {
// docs:start:prove_note_not_nullified
fn prove_note_not_nullified<Note>(
fn prove_note_not_nullified<NOTE>(
self,
retrieved_note: RetrievedNote<Note>,
retrieved_note: RetrievedNote<NOTE>,
storage_slot: Field,
context: &mut PrivateContext,
)
where
Note: NoteHash,
NOTE: NoteHash,
{
let nullifier = compute_siloed_note_nullifier(retrieved_note, storage_slot, context);

Expand Down
24 changes: 12 additions & 12 deletions noir-projects/aztec-nr/aztec/src/note/lifecycle.nr
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ use crate::note::{
use crate::oracle::notes::notify_created_note;
use protocol_types::traits::Packable;

pub fn create_note<Note, let N: u32>(
pub fn create_note<NOTE, let N: u32>(
context: &mut PrivateContext,
storage_slot: Field,
note: Note,
) -> NoteEmission<Note>
note: NOTE,
) -> NoteEmission<NOTE>
where
Note: NoteType + NoteHash + Packable<N>,
NOTE: NoteType + NoteHash + Packable<N>,
{
let note_hash_counter = context.side_effect_counter;

let note_hash = note.compute_note_hash(storage_slot);

let packed_note = Note::pack(note);
let packed_note = NOTE::pack(note);
notify_created_note(
storage_slot,
Note::get_id(),
NOTE::get_id(),
packed_note,
note_hash,
note_hash_counter,
Expand All @@ -35,27 +35,27 @@ where
}

// Note: This function is currently totally unused.
pub fn destroy_note<Note>(
pub fn destroy_note<NOTE>(
context: &mut PrivateContext,
retrieved_note: RetrievedNote<Note>,
retrieved_note: RetrievedNote<NOTE>,
storage_slot: Field,
)
where
Note: NoteHash,
NOTE: NoteHash,
{
let note_hash_for_read_request =
compute_note_hash_for_read_request(retrieved_note, storage_slot);

destroy_note_unsafe(context, retrieved_note, note_hash_for_read_request)
}

pub fn destroy_note_unsafe<Note>(
pub fn destroy_note_unsafe<NOTE>(
context: &mut PrivateContext,
retrieved_note: RetrievedNote<Note>,
retrieved_note: RetrievedNote<NOTE>,
note_hash_for_read_request: Field,
)
where
Note: NoteHash,
NOTE: NoteHash,
{
let note_hash_for_nullify =
compute_note_hash_for_nullify_from_read_request(retrieved_note, note_hash_for_read_request);
Expand Down
18 changes: 9 additions & 9 deletions noir-projects/aztec-nr/aztec/src/note/note_emission.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* A note emission struct containing the information required for emitting a note.
* The exact `emit` logic is passed in by the application code
*/
pub struct NoteEmission<Note> {
pub note: Note,
pub struct NoteEmission<NOTE> {
pub note: NOTE,
pub storage_slot: Field,
pub note_hash_counter: u32, // a note_hash_counter of 0 means settled
}

impl<Note> NoteEmission<Note> {
pub fn new(note: Note, storage_slot: Field, note_hash_counter: u32) -> Self {
impl<NOTE> NoteEmission<NOTE> {
pub fn new(note: NOTE, storage_slot: Field, note_hash_counter: u32) -> Self {
Self { note, storage_slot, note_hash_counter }
}

Expand All @@ -28,16 +28,16 @@ impl<Note> NoteEmission<Note> {
* and this allows us to keep the same API for emission in both cases (e.g. inserting
* a change note in a token's transfer function only when there is "change" left).
*/
pub struct OuterNoteEmission<Note> {
emission: Option<NoteEmission<Note>>,
pub struct OuterNoteEmission<NOTE> {
emission: Option<NoteEmission<NOTE>>,
}

impl<Note> OuterNoteEmission<Note> {
pub fn new(emission: Option<NoteEmission<Note>>) -> Self {
impl<NOTE> OuterNoteEmission<NOTE> {
pub fn new(emission: Option<NoteEmission<NOTE>>) -> Self {
Self { emission }
}

pub fn emit<Env>(self, _emit: fn[Env](NoteEmission<Note>) -> ()) {
pub fn emit<Env>(self, _emit: fn[Env](NoteEmission<NOTE>) -> ()) {
if self.emission.is_some() {
_emit(self.emission.unwrap());
}
Expand Down
Loading
Loading