Skip to content
Merged
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
15 changes: 8 additions & 7 deletions noir-projects/aztec-nr/aztec/src/discovery/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub global MAX_NOTE_PACKED_LEN: u32 =
pub struct NoteHashAndNullifier {
/// The result of NoteHash::compute_note_hash
pub note_hash: Field,
/// The result of NoteHash::compute_nullifier_unconstrained (since all of note discovery is unconstrained)
/// The result of NoteHash::compute_nullifier_unconstrained (since all of message discovery is unconstrained)
pub inner_nullifier: Field,
}

Expand Down Expand Up @@ -59,16 +59,17 @@ pub struct NoteHashAndNullifier {
/// ```
type ComputeNoteHashAndNullifier<Env> = unconstrained fn[Env](/* packed_note_content */BoundedVec<Field, MAX_NOTE_PACKED_LEN>, /* storage_slot */ Field, /* note_type_id */ Field, /* contract_address */ AztecAddress, /* nonce */ Field) -> Option<NoteHashAndNullifier>;

/// Performs the note discovery process, in which private and public logs are downloaded and inspected to find private
/// notes, partial notes, and their completion. This is the mechanism via which PXE learns of new notes.
/// Performs the message discovery process, in which private are downloaded and inspected to find new private notes,
/// partial notes and events, etc., and pending partial notes are processed to search for their completion logs.
/// This is the mechanism via which a contract updates its knowldge of its private state.
///
/// Receives the address of the contract on which discovery is performed (i.e. the contract that emitted the notes)
/// along with its `compute_note_hash_and_nullifier` function.
pub unconstrained fn discover_new_notes<Env>(
/// Receives the address of the contract on which discovery is performed along with its
/// `compute_note_hash_and_nullifier` function.
pub unconstrained fn discover_new_messages<Env>(
contract_address: AztecAddress,
compute_note_hash_and_nullifier: ComputeNoteHashAndNullifier<Env>,
) {
debug_log("Performing note discovery");
debug_log("Performing message discovery");

private_logs::fetch_and_process_private_tagged_logs(
contract_address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub unconstrained fn attempt_note_nonce_discovery<Env>(
let discovered_notes = &mut BoundedVec::new();

debug_log_format(
"Attempting note discovery on {0} potential notes on contract {1} for storage slot {2}",
"Attempting nonce discovery on {0} potential notes on contract {1} for storage slot {2}",
[unique_note_hashes_in_tx.len() as Field, contract_address.to_field(), storage_slot],
);

Expand Down
6 changes: 3 additions & 3 deletions noir-projects/aztec-nr/aztec/src/discovery/partial_notes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
nonce_discovery::{attempt_note_nonce_discovery, DiscoveredNoteInfo},
private_logs::MAX_PARTIAL_NOTE_PRIVATE_PACKED_LEN,
},
oracle::note_discovery::{deliver_note, get_log_by_tag},
oracle::message_discovery::{deliver_note, get_log_by_tag},
utils::array,
};

Expand Down Expand Up @@ -72,8 +72,8 @@ pub unconstrained fn fetch_and_process_public_partial_note_completion_logs<Env>(
);
*i += 1 as u32;
// Note that we're not removing the pending partial note from the PXE DB, so we will continue searching
// for this tagged log when performing note discovery in the future until we either find it or the entry
// is somehow removed from the PXE DB.
// for this tagged log when performing message discovery in the future until we either find it or the
// entry is somehow removed from the PXE DB.
} else {
debug_log_format(
"Completion log found for partial note with tag {}",
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/discovery/private_logs.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::static_assert;

use crate::{
capsules::CapsuleArray,
oracle::note_discovery::{deliver_note, sync_notes},
oracle::message_discovery::{deliver_note, sync_notes},
utils::array,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub global PRIVATE_LOG_PLAINTEXT_SIZE_IN_FIELDS: u32 = PRIVATE_LOG_PLAINTEXT_SIZ
/// The resulting log has the following format:
/// ```text
/// [
/// tag: Field, // Tag for note discovery, derived from sender/recipient
/// tag: Field, // Tag for message discovery, derived from sender/recipient
/// epk_x: Field, // X coordinate of ephemeral public key
/// log_bytes: [Field], // Encrypted data converted from bytes to fields, containing:
/// [
Expand Down
31 changes: 16 additions & 15 deletions noir-projects/aztec-nr/aztec/src/macros/functions/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ pub(crate) comptime fn transform_private(f: FunctionDefinition) -> Quoted {
quote {}
};

// All private functions perform note discovery, since they may need to access notes. This is slightly inefficient
// and could be improved by only doing it once we actually attempt to read any.
let note_discovery_call = if NOTES.len() > 0 {
create_note_discovery_call()
// All private functions perform message discovery, since they may need to access notes. This is slightly
// inefficient and could be improved by only doing it once we actually attempt to read any.
let message_discovery_call = if NOTES.len() > 0 {
create_message_discovery_call()
} else {
quote {}
};
Expand Down Expand Up @@ -156,7 +156,7 @@ pub(crate) comptime fn transform_private(f: FunctionDefinition) -> Quoted {
$internal_check
$view_check
$storage_init
$note_discovery_call
$message_discovery_call
};

let to_append = quote {
Expand Down Expand Up @@ -324,18 +324,19 @@ pub(crate) comptime fn transform_top_level_unconstrained(f: FunctionDefinition)
quote {}
};

// All unconstrained functions perform note discovery, since they may need to access notes. This is slightly
// inefficient and could be improved by only doing it once we actually attempt to read any.
let note_discovery_call = if NOTES.len() > 0 {
create_note_discovery_call()
// All unconstrained functions perform message discovery, since they may need to access private notes that would be
// found during this process. This is slightly inefficient and could be improved by only doing it once we actually
// attempt to read any.
let message_discovery_call = if NOTES.len() > 0 {
create_message_discovery_call()
} else {
quote {}
};

let to_prepend = quote {
$context_creation
$storage_init
$note_discovery_call
$message_discovery_call
};
let body = f.body().as_block().unwrap();
let modified_body = modify_fn_body(body, to_prepend, quote {});
Expand Down Expand Up @@ -379,14 +380,14 @@ comptime fn create_init_check(f: FunctionDefinition) -> Quoted {
.quoted_contents()
}

/// Injects a call to `aztec::discovery::discover_new_notes`, causing for new notes to be added to PXE and made
/// Injects a call to `aztec::discovery::discover_new_messages`, causing for new notes to be added to PXE and made
/// available for the current execution.
pub(crate) comptime fn create_note_discovery_call() -> Quoted {
pub(crate) comptime fn create_message_discovery_call() -> Quoted {
quote {
/// Safety: note discovery returns nothing and is performed solely for its side-effects. It is therefore always
/// safe to call.
/// Safety: message discovery returns nothing and is performed solely for its side-effects. It is therefore
/// always safe to call.
unsafe {
dep::aztec::discovery::discover_new_notes(
dep::aztec::discovery::discover_new_messages(
context.this_address(),
_compute_note_hash_and_nullifier,
);
Expand Down
20 changes: 10 additions & 10 deletions noir-projects/aztec-nr/aztec/src/macros/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod events;

use functions::{
stub_registry,
utils::{create_note_discovery_call, find_and_transform_top_level_unconstrained_fns},
utils::{create_message_discovery_call, find_and_transform_top_level_unconstrained_fns},
};
use notes::{generate_note_export, NOTES};
use storage::STORAGE_LAYOUT_NAME;
Expand Down Expand Up @@ -189,7 +189,7 @@ comptime fn generate_contract_library_method_compute_note_hash_and_nullifier() -

let note_hash = $compute_note_hash(note, storage_slot);

// The note discovery process finds settled notes, that is, notes that were created in prior
// The message discovery process finds settled notes, that is, notes that were created in prior
// transactions and are therefore already part of the note hash tree. We therefore compute the
// nullification note hash by treating the note as a settled note with the provided nonce.
let note_hash_for_nullify = aztec::note::utils::compute_note_hash_for_nullify(
Expand Down Expand Up @@ -221,8 +221,8 @@ comptime fn generate_contract_library_method_compute_note_hash_and_nullifier() -
/// tree with `nonce`.
///
/// The signature of this function notably matches the `aztec::discovery::ComputeNoteHashAndNullifier` type,
/// and so it can be used to call functions from that module such as `discover_new_notes`, `do_process_log`
/// and `attempt_note_discovery`.
/// and so it can be used to call functions from that module such as `discover_new_messages`,
/// `do_process_log` and `attempt_note_discovery`.
///
/// This function is automatically injected by the `#[aztec]` macro.
#[contract_library_method]
Expand Down Expand Up @@ -263,7 +263,7 @@ comptime fn generate_contract_library_method_compute_note_hash_and_nullifier() -

comptime fn generate_process_log() -> Quoted {
// This mandatory function processes a log emitted by the contract. This is currently used to process private logs
// and perform note discovery of either private notes or partial notes.
// and perform message discovery, resulting in new private notes, partial notes and events.
// The bulk of the work of this function is done by aztec::discovery::do_process_log, so all we need to do is call
// that function.

Expand All @@ -279,9 +279,9 @@ comptime fn generate_process_log() -> Quoted {
first_nullifier_in_tx: Field,
recipient: aztec::protocol_types::address::AztecAddress,
) {
// Because this unconstrained function is injected after the contract is processed by the macros, it'll not
// be modified by the macros that alter unconstrained functions. As such, we need to manually inject the
// unconstrained execution context since it will not be available otherwise.
// Because this unconstrained function is injected after the contract is processed by the macros, it'll
// not be modified by the macros that alter unconstrained functions. As such, we need to manually inject
// the unconstrained execution context since it will not be available otherwise.
let context = dep::aztec::context::unconstrained_context::UnconstrainedContext::new();

// TODO(#10727): allow other contracts to process logs and deliver notes
Expand Down Expand Up @@ -327,15 +327,15 @@ comptime fn generate_note_exports() -> Quoted {
}

comptime fn generate_sync_notes() -> Quoted {
let note_discovery_call = create_note_discovery_call();
let message_discovery_call = create_message_discovery_call();
quote {
unconstrained fn sync_notes() {
// Because this unconstrained function is injected after the contract is processed by the macros, it'll not
// be modified by the macros that alter unconstrained functions. As such, we need to manually inject the
// unconstrained execution context since it will not be available otherwise.
let context = dep::aztec::context::unconstrained_context::UnconstrainedContext::new();

$note_discovery_call
$message_discovery_call
}
}
}
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub mod get_membership_witness;
pub mod keys;
pub mod key_validation_request;
pub mod logs;
pub mod note_discovery;
pub mod message_discovery;
pub mod notes;
pub mod random;
pub mod shared_secret;
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/stdlib/src/logs/log_with_tx_data.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MAX_NOTE_HASHES_PER_TX, PUBLIC_LOG_DATA_SIZE_IN_FIELDS } from '@aztec/constants';
import { Fr } from '@aztec/foundation/fields';

// TypeScript representation of the Noir aztec::oracle::note_discovery::LogWithTxData struct. This is used as a response
// for PXE's custom getLogByTag oracle.
// TypeScript representation of the Noir aztec::oracle::message_discovery::LogWithTxData struct. This is used as a
// response for PXE's custom getLogByTag oracle.
export class LogWithTxData {
constructor(
public logContent: Fr[],
Expand Down