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
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use crate::{
encoding::MAX_MESSAGE_CONTENT_LEN,
logs::partial_note::{decode_partial_note_private_message, MAX_PARTIAL_NOTE_PRIVATE_PACKED_LEN},
processing::{
enqueue_note_for_validation, get_pending_partial_notes_completion_logs,
log_retrieval_response::LogRetrievalResponse,
enqueue_note_for_validation,
get_pending_partial_notes_completion_logs,
log_retrieval_response::{LogRetrievalResponse, MAX_LOG_CONTENT_LEN},
},
},
utils::array,
Expand All @@ -25,7 +26,6 @@ pub(crate) global DELIVERED_PENDING_PARTIAL_NOTE_ARRAY_LENGTH_CAPSULES_SLOT: Fie
#[derive(Serialize, Deserialize)]
pub(crate) struct DeliveredPendingPartialNote {
pub(crate) owner: AztecAddress,
pub(crate) storage_slot: Field,
pub(crate) randomness: Field,
pub(crate) note_completion_log_tag: Field,
pub(crate) note_type_id: Field,
Expand All @@ -41,12 +41,11 @@ pub(crate) unconstrained fn process_partial_note_private_msg(
) {
// We store the information of the partial note we found in a persistent capsule in PXE, so that we can later
// search for the public log that will complete it.
let (owner, storage_slot, randomness, note_completion_log_tag, note_type_id, packed_private_note_content) =
let (owner, randomness, note_completion_log_tag, note_type_id, packed_private_note_content) =
decode_partial_note_private_message(msg_metadata, msg_content);

let pending = DeliveredPendingPartialNote {
owner,
storage_slot,
randomness,
note_completion_log_tag,
note_type_id,
Expand Down Expand Up @@ -105,12 +104,17 @@ pub(crate) unconstrained fn fetch_and_process_partial_note_completion_logs<Env>(
]);
let log = maybe_log.unwrap();

// Public fields are assumed to all be placed at the end of the packed representation, so we combine the
// private and public packed fields (i.e. the contents of the private message and public log plaintext to
// get the complete packed content.
// The first field in the completion log payload is the storage slot, followed by the public note
// content fields.
let storage_slot = log.log_payload.get(0);
let public_note_content: BoundedVec<Field, MAX_LOG_CONTENT_LEN - 1> = array::subbvec(log.log_payload, 1);

// Public fields are assumed to all be placed at the end of the packed representation, so we combine
// the private and public packed fields (i.e. the contents of the private message and public log
// plaintext) to get the complete packed content.
let complete_packed_note = array::append(
pending_partial_note.packed_private_note_content,
log.log_payload,
public_note_content,
);

let discovered_notes = attempt_note_nonce_discovery(
Expand All @@ -119,7 +123,7 @@ pub(crate) unconstrained fn fetch_and_process_partial_note_completion_logs<Env>(
compute_note_hash_and_nullifier,
contract_address,
pending_partial_note.owner,
pending_partial_note.storage_slot,
storage_slot,
pending_partial_note.randomness,
pending_partial_note.note_type_id,
complete_packed_note,
Expand All @@ -142,7 +146,7 @@ pub(crate) unconstrained fn fetch_and_process_partial_note_completion_logs<Env>(
enqueue_note_for_validation(
contract_address,
pending_partial_note.owner,
pending_partial_note.storage_slot,
storage_slot,
pending_partial_note.randomness,
discovered_note.note_nonce,
complete_packed_note,
Expand Down
36 changes: 11 additions & 25 deletions noir-projects/aztec-nr/aztec/src/messages/logs/partial_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ use crate::protocol::{
};

/// The number of fields in a private note message content that are not the note's packed representation.
pub(crate) global PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN: u32 = 4;
pub(crate) global PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN: u32 = 3;
pub(crate) global PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_OWNER_INDEX: u32 = 0;
pub(crate) global PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_STORAGE_SLOT_INDEX: u32 = 1;
pub(crate) global PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RANDOMNESS_INDEX: u32 = 2;
pub(crate) global PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_NOTE_COMPLETION_LOG_TAG_INDEX: u32 = 3;
pub(crate) global PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RANDOMNESS_INDEX: u32 = 1;
pub(crate) global PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_NOTE_COMPLETION_LOG_TAG_INDEX: u32 = 2;

/// Partial notes have a maximum packed length of their private fields bound by extra content in their private message
/// (e.g. the storage slot, note completion log tag, etc.).
Expand All @@ -30,7 +29,6 @@ pub global MAX_PARTIAL_NOTE_PRIVATE_PACKED_LEN: u32 =
pub fn compute_partial_note_private_content_log<PartialNotePrivateContent>(
partial_note_private_content: PartialNotePrivateContent,
owner: AztecAddress,
storage_slot: Field,
randomness: Field,
recipient: AztecAddress,
note_completion_log_tag: Field,
Expand All @@ -41,7 +39,6 @@ where
let message_plaintext = encode_partial_note_private_message(
partial_note_private_content,
owner,
storage_slot,
randomness,
note_completion_log_tag,
);
Expand All @@ -56,7 +53,6 @@ where
pub fn encode_partial_note_private_message<PartialNotePrivateContent>(
partial_note_private_content: PartialNotePrivateContent,
owner: AztecAddress,
storage_slot: Field,
randomness: Field,
note_completion_log_tag: Field,
) -> [Field; PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN + <PartialNotePrivateContent as Packable>::N + MESSAGE_EXPANDED_METADATA_LEN]
Expand All @@ -68,14 +64,13 @@ where
// If PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_NON_NOTE_FIELDS_LEN is changed, causing the assertion below to fail, then
// the encoding below must be updated as well.
std::static_assert(
PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN == 4,
PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN == 3,
"unexpected value for PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_NON_NOTE_FIELDS_LEN",
);

let mut msg_content =
[0; PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN + <PartialNotePrivateContent as Packable>::N];
msg_content[PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_OWNER_INDEX] = owner.to_field();
msg_content[PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_STORAGE_SLOT_INDEX] = storage_slot;
msg_content[PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RANDOMNESS_INDEX] = randomness;
msg_content[PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_NOTE_COMPLETION_LOG_TAG_INDEX] = note_completion_log_tag;

Expand All @@ -102,7 +97,7 @@ where
pub(crate) unconstrained fn decode_partial_note_private_message(
msg_metadata: u64,
msg_content: BoundedVec<Field, MAX_MESSAGE_CONTENT_LEN>,
) -> (AztecAddress, Field, Field, Field, Field, BoundedVec<Field, MAX_PARTIAL_NOTE_PRIVATE_PACKED_LEN>) {
) -> (AztecAddress, Field, Field, Field, BoundedVec<Field, MAX_PARTIAL_NOTE_PRIVATE_PACKED_LEN>) {
let note_type_id = msg_metadata as Field; // TODO: make note type id not be a full field

// The following ensures that the message content contains at least the minimum number of fields required for a
Expand All @@ -116,16 +111,15 @@ pub(crate) unconstrained fn decode_partial_note_private_message(
// If PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_NON_NOTE_FIELDS_LEN is changed, causing the assertion below to fail, then
// the destructuring of the partial note private message encoding below must be updated as well.
std::static_assert(
PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN == 4,
PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN == 3,
"unexpected value for PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_NON_NOTE_FIELDS_LEN",
);

// We currently have four fields that are not the partial note's packed representation, which are the owner, the
// storage slot, the randomness, and the note completion log tag.
// We currently have three fields that are not the partial note's packed representation, which are the owner, the
// randomness, and the note completion log tag.
let owner = AztecAddress::from_field(
msg_content.get(PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_OWNER_INDEX),
);
let storage_slot = msg_content.get(PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_STORAGE_SLOT_INDEX);
let randomness = msg_content.get(PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RANDOMNESS_INDEX);
let note_completion_log_tag = msg_content.get(PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_NOTE_COMPLETION_LOG_TAG_INDEX);

Expand All @@ -134,7 +128,7 @@ pub(crate) unconstrained fn decode_partial_note_private_message(
PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN,
);

(owner, storage_slot, randomness, note_completion_log_tag, note_type_id, packed_private_note_content)
(owner, randomness, note_completion_log_tag, note_type_id, packed_private_note_content)
}

mod test {
Expand All @@ -151,7 +145,6 @@ mod test {

global VALUE: Field = 7;
global OWNER: AztecAddress = AztecAddress::from_field(8);
global STORAGE_SLOT: Field = 9;
global RANDOMNESS: Field = 10;
global NOTE_COMPLETION_LOG_TAG: Field = 11;

Expand All @@ -160,24 +153,17 @@ mod test {
// Note that here we use MockNote as the private fields of a partial note
let note = MockNote::new(VALUE).build_note();

let message_plaintext = encode_partial_note_private_message(
note,
OWNER,
STORAGE_SLOT,
RANDOMNESS,
NOTE_COMPLETION_LOG_TAG,
);
let message_plaintext = encode_partial_note_private_message(note, OWNER, RANDOMNESS, NOTE_COMPLETION_LOG_TAG);

let (msg_type_id, msg_metadata, msg_content) = decode_message(BoundedVec::from_array(message_plaintext));

assert_eq(msg_type_id, PARTIAL_NOTE_PRIVATE_MSG_TYPE_ID);

let (owner, storage_slot, randomness, note_completion_log_tag, note_type_id, packed_note) =
let (owner, randomness, note_completion_log_tag, note_type_id, packed_note) =
decode_partial_note_private_message(msg_metadata, msg_content);

assert_eq(note_type_id, MockNote::get_id());
assert_eq(owner, OWNER);
assert_eq(storage_slot, STORAGE_SLOT);
assert_eq(randomness, RANDOMNESS);
assert_eq(note_completion_log_tag, NOTE_COMPLETION_LOG_TAG);
assert_eq(packed_note, BoundedVec::from_array(note.pack()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::protocol::{constants::{MAX_NOTE_HASHES_PER_TX, PRIVATE_LOG_CIPHERTEXT

pub global MAX_PUBLIC_LOG_LEN_FOR_NOTE_COMPLETION: u32 = MAX_NOTE_PACKED_LEN;

global MAX_LOG_CONTENT_LEN: u32 = std::cmp::max(
pub(crate) global MAX_LOG_CONTENT_LEN: u32 = std::cmp::max(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to expose this because it's now used by fetch_and_process_partial_note_completion_logs when separating the public note content from the storage slot.

MAX_PUBLIC_LOG_LEN_FOR_NOTE_COMPLETION,
PRIVATE_LOG_CIPHERTEXT_LEN,
);
Expand Down
Loading
Loading