diff --git a/cspell.json b/cspell.json index 5ab5fc6366f8..7f3370d64d03 100644 --- a/cspell.json +++ b/cspell.json @@ -152,7 +152,9 @@ "mktemp", "unshielding", "workdir", - "leveldb" + "leveldb", + "persistable", + "siloes" ], "ignorePaths": [ "node_modules/", diff --git a/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr b/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr index bc15b4dec4a3..47b0db923c15 100644 --- a/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr +++ b/yarn-project/aztec-nr/aztec/src/note/lifecycle.nr @@ -9,14 +9,36 @@ use crate::note::{ note_interface::NoteInterface, utils::compute_inner_note_hash, }; -use crate::oracle::notes::{notify_created_note, notify_nullified_note}; +use crate::oracle::{ + notes::{notify_created_note, notify_nullified_note}, + get_public_key::get_public_key, +} use crate::constants_gen::EMPTY_NULLIFIED_COMMITMENT; +use crate::log::emit_encrypted_log; pub fn create_note( context: &mut PrivateContext, storage_slot: Field, note: &mut Note, note_interface: NoteInterface, + owner: Field, // TODO: add owner() to NoteInterface and remove this arg? +) { + create_note_no_broadcast(context, storage_slot, note, note_interface); + let owner_key = get_public_key(owner); + emit_encrypted_log( + context, + (*context).this_address(), + storage_slot, + owner_key, + note.serialize(), + ); +} + +pub fn create_note_no_broadcast( + context: &mut PrivateContext, + storage_slot: Field, + note: &mut Note, + note_interface: NoteInterface, ) { let contract_address = (*context).this_address(); @@ -65,7 +87,7 @@ pub fn destroy_note( // the nullifier corresponds to so they can be matched and both squashed/deleted. // nonzero nonce implies "persistable" nullifier (nullifies a persistent/in-tree // commitment) in which case `nullified_commitment` is not used since the kernel - // just siloes and forwards the nullier to its output. + // just siloes and forwards the nullifier to its output. if (header.is_transient) { // TODO(1718): Can we reuse the note commitment computed in `compute_nullifier`? nullified_commitment = compute_inner_note_hash(note_interface, note); diff --git a/yarn-project/aztec-nr/aztec/src/state_vars/set.nr b/yarn-project/aztec-nr/aztec/src/state_vars/set.nr index 68fe16dd3b6f..812367eee82f 100644 --- a/yarn-project/aztec-nr/aztec/src/state_vars/set.nr +++ b/yarn-project/aztec-nr/aztec/src/state_vars/set.nr @@ -3,7 +3,7 @@ use crate::abi::PublicContextInputs; use crate::constants_gen::{MAX_NOTES_PER_PAGE, MAX_READ_REQUESTS_PER_CALL}; use crate::context::{PrivateContext, PublicContext, Context}; use crate::note::{ - lifecycle::{create_note, create_note_hash_from_public, destroy_note}, + lifecycle::{create_note, create_note_no_broadcast, create_note_hash_from_public, destroy_note}, note_getter::{get_notes, view_notes}, note_getter_options::NoteGetterOptions, note_header::NoteHeader, @@ -37,16 +37,29 @@ impl Set { // docs:end:new // docs:start:insert - pub fn insert(self, note: &mut Note) { + pub fn insert(self, + note: &mut Note, + owner: Field, // TODO: add owner() to NoteInterface and remove this arg? + ) { create_note( self.context.private.unwrap(), self.storage_slot, note, self.note_interface, + owner, ); } // docs:end:insert + pub fn insert_no_broadcast(self, note: &mut Note) { + create_note_no_broadcast( + self.context.private.unwrap(), + self.storage_slot, + note, + self.note_interface, + ); + } + // docs:start:insert_from_public pub fn insert_from_public(self, note: &mut Note) { create_note_hash_from_public( diff --git a/yarn-project/boxes/token/src/contracts/src/types/balance_set.nr b/yarn-project/boxes/token/src/contracts/src/types/balance_set.nr index 240b8a3a8c47..79d63aaf0424 100644 --- a/yarn-project/boxes/token/src/contracts/src/types/balance_set.nr +++ b/yarn-project/boxes/token/src/contracts/src/types/balance_set.nr @@ -4,7 +4,6 @@ use dep::aztec::{ context::Context, constants_gen::MAX_READ_REQUESTS_PER_CALL, state_vars::set::Set, - log::emit_encrypted_log, types::address::AztecAddress, }; use dep::aztec::note::{ @@ -12,16 +11,6 @@ use dep::aztec::note::{ note_getter_options::{NoteGetterOptions, SortOrder}, note_viewer_options::NoteViewerOptions }; -use dep::aztec::note::{ - note_header::NoteHeader, - note_interface::NoteInterface, - utils::compute_note_hash_for_read_or_nullify, -}; -use dep::aztec::oracle::{ - rand::rand, - get_secret_key::get_secret_key, - get_public_key::get_public_key, -}; use crate::types::token_note::{TokenNote, TOKEN_NOTE_LEN, TokenNoteMethods}; @@ -77,13 +66,8 @@ impl BalanceSet { let mut addend_note = TokenNote::new(addend, self.owner); // docs:start:insert - self.set.insert(&mut addend_note); + self.set.insert(&mut addend_note, self.owner); // docs:end:insert - - addend_note.emit_encrypted( - self.context.private.unwrap(), - self.set.storage_slot - ); } pub fn sub(self: Self, subtrahend: SafeU120) { diff --git a/yarn-project/boxes/token/src/contracts/src/types/token_note.nr b/yarn-project/boxes/token/src/contracts/src/types/token_note.nr index fdc147adf1a7..8e0a224eb9bb 100644 --- a/yarn-project/boxes/token/src/contracts/src/types/token_note.nr +++ b/yarn-project/boxes/token/src/contracts/src/types/token_note.nr @@ -84,31 +84,6 @@ impl TokenNote { self.header = header; } - - pub fn emit_encrypted( - self: &mut Self, - context: &mut PrivateContext, - storage_slot: Field, - ) { - // We only bother inserting the note if non-empty to save funds on gas. - if !self.amount.is_zero() { - // docs:start:encrypted - let application_contract_address = (*context).this_address(); - let encryption_pub_key = get_public_key(self.owner.address); - let encrypted_data = (*self).serialize(); - - emit_encrypted_log( - context, - application_contract_address, - storage_slot, - encryption_pub_key, - encrypted_data, - ); - // docs:end:encrypted - } - } -} - fn deserialize(preimage: [Field; TOKEN_NOTE_LEN]) -> TokenNote { TokenNote::deserialize(preimage) } diff --git a/yarn-project/noir-contracts/src/contracts/card_game_contract/src/cards.nr b/yarn-project/noir-contracts/src/contracts/card_game_contract/src/cards.nr index 58005615eca2..ffe3177484bc 100644 --- a/yarn-project/noir-contracts/src/contracts/card_game_contract/src/cards.nr +++ b/yarn-project/noir-contracts/src/contracts/card_game_contract/src/cards.nr @@ -1,16 +1,12 @@ use dep::aztec::{ context::{PrivateContext, PublicContext, Context}, constants_gen::{MAX_NOTES_PER_PAGE, MAX_READ_REQUESTS_PER_CALL}, - log::emit_encrypted_log, note::{ note_getter_options::NoteGetterOptions, note_viewer_options::NoteViewerOptions, note_getter::view_notes, }, - oracle::{ - get_public_key::get_public_key, - get_secret_key::get_secret_key, - }, + oracle::get_secret_key::get_secret_key, state_vars::set::Set, types::point::Point, }; @@ -133,20 +129,12 @@ impl Deck { } pub fn add_cards(&mut self, cards: [Card; N], owner: Field) -> [CardNote]{ - let owner_key = get_public_key(owner); let context = self.set.context.private.unwrap(); let mut inserted_cards = []; for card in cards { let mut card_note = CardNote::from_card(card, owner); - self.set.insert(&mut card_note.note); - emit_encrypted_log( - context, - (*context).this_address(), - self.set.storage_slot, - owner_key, - card_note.note.serialize(), - ); + self.set.insert(&mut card_note.note, owner); inserted_cards = inserted_cards.push_back(card_note); } diff --git a/yarn-project/noir-contracts/src/contracts/token_contract/src/types/balance_set.nr b/yarn-project/noir-contracts/src/contracts/token_contract/src/types/balance_set.nr index 240b8a3a8c47..79d63aaf0424 100644 --- a/yarn-project/noir-contracts/src/contracts/token_contract/src/types/balance_set.nr +++ b/yarn-project/noir-contracts/src/contracts/token_contract/src/types/balance_set.nr @@ -4,7 +4,6 @@ use dep::aztec::{ context::Context, constants_gen::MAX_READ_REQUESTS_PER_CALL, state_vars::set::Set, - log::emit_encrypted_log, types::address::AztecAddress, }; use dep::aztec::note::{ @@ -12,16 +11,6 @@ use dep::aztec::note::{ note_getter_options::{NoteGetterOptions, SortOrder}, note_viewer_options::NoteViewerOptions }; -use dep::aztec::note::{ - note_header::NoteHeader, - note_interface::NoteInterface, - utils::compute_note_hash_for_read_or_nullify, -}; -use dep::aztec::oracle::{ - rand::rand, - get_secret_key::get_secret_key, - get_public_key::get_public_key, -}; use crate::types::token_note::{TokenNote, TOKEN_NOTE_LEN, TokenNoteMethods}; @@ -77,13 +66,8 @@ impl BalanceSet { let mut addend_note = TokenNote::new(addend, self.owner); // docs:start:insert - self.set.insert(&mut addend_note); + self.set.insert(&mut addend_note, self.owner); // docs:end:insert - - addend_note.emit_encrypted( - self.context.private.unwrap(), - self.set.storage_slot - ); } pub fn sub(self: Self, subtrahend: SafeU120) { diff --git a/yarn-project/noir-contracts/src/contracts/token_contract/src/types/token_note.nr b/yarn-project/noir-contracts/src/contracts/token_contract/src/types/token_note.nr index fdc147adf1a7..168b97f2608a 100644 --- a/yarn-project/noir-contracts/src/contracts/token_contract/src/types/token_note.nr +++ b/yarn-project/noir-contracts/src/contracts/token_contract/src/types/token_note.nr @@ -7,13 +7,11 @@ use dep::aztec::{ context::PrivateContext, constants_gen::MAX_READ_REQUESTS_PER_CALL, state_vars::set::Set, - log::emit_encrypted_log }; use dep::aztec::types::address::AztecAddress; use dep::aztec::oracle::{ rand::rand, get_secret_key::get_secret_key, - get_public_key::get_public_key, }; use dep::safe_math::SafeU120; @@ -83,30 +81,6 @@ impl TokenNote { pub fn set_header(&mut self, header: NoteHeader) { self.header = header; } - - - pub fn emit_encrypted( - self: &mut Self, - context: &mut PrivateContext, - storage_slot: Field, - ) { - // We only bother inserting the note if non-empty to save funds on gas. - if !self.amount.is_zero() { - // docs:start:encrypted - let application_contract_address = (*context).this_address(); - let encryption_pub_key = get_public_key(self.owner.address); - let encrypted_data = (*self).serialize(); - - emit_encrypted_log( - context, - application_contract_address, - storage_slot, - encryption_pub_key, - encrypted_data, - ); - // docs:end:encrypted - } - } } fn deserialize(preimage: [Field; TOKEN_NOTE_LEN]) -> TokenNote {