-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
182 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ mod header; | |
mod incoming_body; | ||
mod outgoing_body; | ||
mod payload; | ||
mod encrypted_note_emission; |
56 changes: 56 additions & 0 deletions
56
noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use crate::{ | ||
context::PrivateContext, note::{note_emission::NoteEmission, note_interface::NoteInterface}, | ||
encrypted_logs::payload::compute_encrypted_note_log | ||
}; | ||
use dep::protocol_types::{ | ||
address::AztecAddress, grumpkin_point::GrumpkinPoint, abis::note_hash::NoteHash, | ||
constants::MAX_NEW_NOTE_HASHES_PER_CALL, utils::arrays::find_index | ||
}; | ||
|
||
fn emit_with_keys<Note, N, NB, M>( | ||
context: &mut PrivateContext, | ||
storage_slot: Field, | ||
note: Note, | ||
ovpk: GrumpkinPoint, | ||
ivpk: GrumpkinPoint | ||
) where Note: NoteInterface<N, NB> { | ||
let note_hash_counter = note.get_header().note_hash_counter; | ||
|
||
let note_exists_index = find_index( | ||
context.new_note_hashes.storage, | ||
|n: NoteHash| n.counter == note_hash_counter | ||
); | ||
assert( | ||
note_exists_index as u32 != MAX_NEW_NOTE_HASHES_PER_CALL, "Can only emit a note log for an existing note." | ||
); | ||
|
||
let contract_address: AztecAddress = context.this_address(); | ||
let ovsk_app: Field = context.request_ovsk_app(ovpk.hash()); | ||
|
||
let encrypted_log: [u8; M] = compute_encrypted_note_log(contract_address, storage_slot, ovsk_app, ovpk, ivpk, note); | ||
|
||
context.emit_raw_note_log(note_hash_counter, encrypted_log); | ||
} | ||
|
||
pub fn with_az_enc<Note, N, NB>( | ||
context: &mut PrivateContext, | ||
ov: AztecAddress, | ||
iv: AztecAddress | ||
) -> fn[(&mut PrivateContext, AztecAddress, AztecAddress)](NoteEmission<Note>) -> () where Note: NoteInterface<N, NB> { | ||
| e: NoteEmission<Note> | { | ||
let header = context.get_header(); | ||
let ovpk = header.get_ovpk_m(context, ov); | ||
let ivpk = header.get_ivpk_m(context, iv); | ||
emit_with_keys(context, e.storage_slot, e.note, ovpk, ivpk); | ||
} | ||
} | ||
|
||
pub fn with_az_enc_with_keys<Note, N, NB>( | ||
context: &mut PrivateContext, | ||
ovpk: GrumpkinPoint, | ||
ivpk: GrumpkinPoint | ||
) -> fn[(&mut PrivateContext, GrumpkinPoint, GrumpkinPoint)](NoteEmission<Note>) -> () where Note: NoteInterface<N, NB> { | ||
| e: NoteEmission<Note> | { | ||
emit_with_keys(context, e.storage_slot, e.note, ovpk, ivpk); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ mod note_header; | |
mod note_interface; | ||
mod note_viewer_options; | ||
mod utils; | ||
mod note_emission; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
struct NoteEmission<Note> { | ||
storage_slot: Field, | ||
note: Note | ||
} | ||
|
||
impl<Note> NoteEmission<Note> { | ||
pub fn new(storage_slot: Field, note: Note) -> Self { | ||
Self { storage_slot, note } | ||
} | ||
|
||
pub fn emit<Env>(self, _emit: fn[Env](Self) -> ()) { | ||
_emit(self) | ||
} | ||
|
||
pub fn discard(self) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.