From ebedb6a3f86d8f90a60142694f67d48a00daf2d1 Mon Sep 17 00:00:00 2001 From: Nicolas Chamo Date: Wed, 11 Mar 2026 10:22:36 -0300 Subject: [PATCH 1/3] cherry-pick: fix(aztec-nr): return Option from decode functions and fix event commitment capacity (#21264) Cherry-pick of 7a485d139a with conflicts preserved for review. --- .../aztec/src/event/event_interface.nr | 9 +- .../src/messages/discovery/partial_notes.nr | 43 ++++++-- .../src/messages/discovery/private_events.nr | 35 +++--- .../src/messages/discovery/private_notes.nr | 43 +++++--- .../src/messages/discovery/process_message.nr | 69 +++++++++++- .../aztec-nr/aztec/src/messages/encoding.nr | 102 +++++++++++------- .../aztec-nr/aztec/src/messages/logs/event.nr | 59 ++++++---- .../aztec-nr/aztec/src/messages/logs/note.nr | 65 ++++++----- .../aztec/src/messages/logs/partial_note.nr | 70 ++++++++++-- 9 files changed, 362 insertions(+), 133 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/event/event_interface.nr b/noir-projects/aztec-nr/aztec/src/event/event_interface.nr index 38ba43d6e471..2c5ccd0d40ed 100644 --- a/noir-projects/aztec-nr/aztec/src/event/event_interface.nr +++ b/noir-projects/aztec-nr/aztec/src/event/event_interface.nr @@ -36,7 +36,7 @@ pub unconstrained fn compute_private_serialized_event_commitment( event_type_id: Field, ) -> Field { let mut commitment_preimage = - BoundedVec::<_, 1 + MAX_EVENT_SERIALIZED_LEN>::from_array([randomness, event_type_id]); + BoundedVec::<_, 2 + MAX_EVENT_SERIALIZED_LEN>::from_array([randomness, event_type_id]); commitment_preimage.extend_from_bounded_vec(serialized_event); poseidon2_hash_with_separator_bounded_vec(commitment_preimage, DOM_SEP__EVENT_COMMITMENT) @@ -46,12 +46,19 @@ mod test { use crate::event::event_interface::{ compute_private_event_commitment, compute_private_serialized_event_commitment, EventInterface, }; + use crate::messages::logs::event::MAX_EVENT_SERIALIZED_LEN; use crate::protocol::traits::{Serialize, ToField}; use crate::test::mocks::mock_event::MockEvent; global VALUE: Field = 7; global RANDOMNESS: Field = 10; + #[test] + unconstrained fn max_size_serialized_event_commitment() { + let serialized_event = BoundedVec::from_array([0; MAX_EVENT_SERIALIZED_LEN]); + let _ = compute_private_serialized_event_commitment(serialized_event, 0, 0); + } + #[test] unconstrained fn event_commitment_equivalence() { let event = MockEvent::new(VALUE).build_event(); diff --git a/noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr b/noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr index df29197a0020..8c8fa4cb5acf 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr @@ -12,12 +12,17 @@ use crate::{ utils::array, }; +<<<<<<< HEAD use crate::protocol::{ address::AztecAddress, hash::sha256_to_field, logging::debug_log_format, traits::{Deserialize, Serialize}, }; +======= +use crate::logging::{aztecnr_debug_log_format, aztecnr_warn_log_format}; +use crate::protocol::{address::AztecAddress, hash::sha256_to_field, traits::{Deserialize, Serialize}}; +>>>>>>> 7a485d139a (fix(aztec-nr): return Option from decode functions and fix event commitment capacity (#21264)) /// The slot in the PXE capsules where we store a `CapsuleArray` of `DeliveredPendingPartialNote`. pub global DELIVERED_PENDING_PARTIAL_NOTE_ARRAY_LENGTH_CAPSULES_SLOT: Field = sha256_to_field( @@ -42,7 +47,9 @@ pub unconstrained fn process_partial_note_private_msg( recipient: AztecAddress, msg_metadata: u64, msg_content: BoundedVec, + tx_hash: Field, ) { +<<<<<<< HEAD // 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) = @@ -57,12 +64,36 @@ pub unconstrained fn process_partial_note_private_msg( packed_private_note_content, recipient, }; - - CapsuleArray::at( - contract_address, - DELIVERED_PENDING_PARTIAL_NOTE_ARRAY_LENGTH_CAPSULES_SLOT, - ) - .push(pending); +======= + let decoded = decode_partial_note_private_message(msg_metadata, msg_content); + + if decoded.is_some() { + // 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, randomness, note_completion_log_tag, note_type_id, packed_private_note_content) = decoded.unwrap(); +>>>>>>> 7a485d139a (fix(aztec-nr): return Option from decode functions and fix event commitment capacity (#21264)) + + let pending = DeliveredPendingPartialNote { + owner, + randomness, + note_completion_log_tag, + note_type_id, + packed_private_note_content, + recipient, + }; + + CapsuleArray::at( + contract_address, + DELIVERED_PENDING_PARTIAL_NOTE_ARRAY_LENGTH_CAPSULES_SLOT, + ) + .push(pending); + } else { + aztecnr_warn_log_format!( + "Could not decode partial note private message from tx {0}, ignoring", + )( + [tx_hash], + ); + } } /// Searches for logs that would result in the completion of pending partial notes, ultimately resulting in the notes diff --git a/noir-projects/aztec-nr/aztec/src/messages/discovery/private_events.nr b/noir-projects/aztec-nr/aztec/src/messages/discovery/private_events.nr index 697761f7c959..914ec423b424 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/discovery/private_events.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/discovery/private_events.nr @@ -1,5 +1,6 @@ use crate::{ event::event_interface::compute_private_serialized_event_commitment, + logging::aztecnr_warn_log_format, messages::{ encoding::MAX_MESSAGE_CONTENT_LEN, logs::event::decode_private_event_message, processing::enqueue_event_for_validation, @@ -14,18 +15,28 @@ pub unconstrained fn process_private_event_msg( msg_content: BoundedVec, tx_hash: Field, ) { - let (event_type_id, randomness, serialized_event) = decode_private_event_message(msg_metadata, msg_content); + let decoded = decode_private_event_message(msg_metadata, msg_content); - let event_commitment = - compute_private_serialized_event_commitment(serialized_event, randomness, event_type_id.to_field()); + if decoded.is_some() { + let (event_type_id, randomness, serialized_event) = decoded.unwrap(); - enqueue_event_for_validation( - contract_address, - event_type_id, - randomness, - serialized_event, - event_commitment, - tx_hash, - recipient, - ); + let event_commitment = + compute_private_serialized_event_commitment(serialized_event, randomness, event_type_id.to_field()); + + enqueue_event_for_validation( + contract_address, + event_type_id, + randomness, + serialized_event, + event_commitment, + tx_hash, + recipient, + ); + } else { + aztecnr_warn_log_format!( + "Could not decode private event message from tx {0}, ignoring", + )( + [tx_hash], + ); + } } diff --git a/noir-projects/aztec-nr/aztec/src/messages/discovery/private_notes.nr b/noir-projects/aztec-nr/aztec/src/messages/discovery/private_notes.nr index 6366ec9a5543..7f8ed776a648 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/discovery/private_notes.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/discovery/private_notes.nr @@ -1,3 +1,7 @@ +<<<<<<< HEAD +======= +use crate::logging::{aztecnr_debug_log_format, aztecnr_warn_log_format}; +>>>>>>> 7a485d139a (fix(aztec-nr): return Option from decode functions and fix event commitment capacity (#21264)) use crate::messages::{ discovery::{ComputeNoteHashAndNullifier, nonce_discovery::attempt_note_nonce_discovery}, encoding::MAX_MESSAGE_CONTENT_LEN, @@ -16,22 +20,31 @@ pub unconstrained fn process_private_note_msg( msg_metadata: u64, msg_content: BoundedVec, ) { - let (note_type_id, owner, storage_slot, randomness, packed_note) = - decode_private_note_message(msg_metadata, msg_content); + let decoded = decode_private_note_message(msg_metadata, msg_content); - attempt_note_discovery( - contract_address, - tx_hash, - unique_note_hashes_in_tx, - first_nullifier_in_tx, - recipient, - compute_note_hash_and_nullifier, - owner, - storage_slot, - randomness, - note_type_id, - packed_note, - ); + if decoded.is_some() { + let (note_type_id, owner, storage_slot, randomness, packed_note) = decoded.unwrap(); + + attempt_note_discovery( + contract_address, + tx_hash, + unique_note_hashes_in_tx, + first_nullifier_in_tx, + recipient, + compute_note_hash_and_nullifier, + owner, + storage_slot, + randomness, + note_type_id, + packed_note, + ); + } else { + aztecnr_warn_log_format!( + "Could not decode private note message from tx {0}, ignoring", + )( + [tx_hash], + ); + } } /// Attempts discovery of a note given information about its contents and the transaction in which it is suspected the diff --git a/noir-projects/aztec-nr/aztec/src/messages/discovery/process_message.nr b/noir-projects/aztec-nr/aztec/src/messages/discovery/process_message.nr index 965d7224c8a5..bedb1c44671c 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/discovery/process_message.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/discovery/process_message.nr @@ -56,8 +56,9 @@ pub unconstrained fn process_message_plaintext( // have 3 message types: private notes, partial notes and events. // We decode the message to obtain the message type id, metadata and content. - let (msg_type_id, msg_metadata, msg_content) = decode_message(message_plaintext); + let decoded = decode_message(message_plaintext); +<<<<<<< HEAD if msg_type_id == PRIVATE_NOTE_MSG_TYPE_ID { debug_log("Processing private note msg"); @@ -92,5 +93,71 @@ pub unconstrained fn process_message_plaintext( ); } else { debug_log_format("Unknown msg type id {0}", [msg_type_id as Field]); +======= + if decoded.is_some() { + let (msg_type_id, msg_metadata, msg_content) = decoded.unwrap(); + + if msg_type_id == PRIVATE_NOTE_MSG_TYPE_ID { + aztecnr_debug_log!("Processing private note msg"); + + process_private_note_msg( + contract_address, + message_context.tx_hash, + message_context.unique_note_hashes_in_tx, + message_context.first_nullifier_in_tx, + message_context.recipient, + compute_note_hash_and_nullifier, + msg_metadata, + msg_content, + ); + } else if msg_type_id == PARTIAL_NOTE_PRIVATE_MSG_TYPE_ID { + aztecnr_debug_log!("Processing partial note private msg"); + + process_partial_note_private_msg( + contract_address, + message_context.recipient, + msg_metadata, + msg_content, + message_context.tx_hash, + ); + } else if msg_type_id == PRIVATE_EVENT_MSG_TYPE_ID { + aztecnr_debug_log!("Processing private event msg"); + + process_private_event_msg( + contract_address, + message_context.recipient, + msg_metadata, + msg_content, + message_context.tx_hash, + ); + } else if msg_type_id < MIN_CUSTOM_MSG_TYPE_ID { + // The message type ID falls in the range reserved for aztec.nr built-in types but wasn't matched above. + // This most likely means the message is malformed or a custom message was incorrectly assigned a reserved + // ID. Custom message types must use IDs allocated via `custom_msg_type_id`. + aztecnr_warn_log_format!( + "Message type ID {0} is in the reserved range but is not recognized, ignoring. See https://docs.aztec.network/errors/3", + )( + [msg_type_id as Field], + ); + } else if process_custom_message.is_some() { + process_custom_message.unwrap()( + contract_address, + msg_type_id, + msg_metadata, + msg_content, + message_context, + ); + } else { + // A custom message was received but no handler is configured. This likely means the contract emits custom + // messages but forgot to register a handler via `AztecConfig::custom_message_handler`. + aztecnr_warn_log_format!( + "Received custom message with type id {0} but no handler is configured, ignoring. See https://docs.aztec.network/errors/2", + )( + [msg_type_id as Field], + ); + } + } else { + aztecnr_warn_log_format!("Could not decode message plaintext from tx {0}, ignoring")([message_context.tx_hash]); +>>>>>>> 7a485d139a (fix(aztec-nr): return Option from decode functions and fix event commitment capacity (#21264)) } } diff --git a/noir-projects/aztec-nr/aztec/src/messages/encoding.nr b/noir-projects/aztec-nr/aztec/src/messages/encoding.nr index dc484086cf8a..322d5dd78103 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/encoding.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/encoding.nr @@ -90,29 +90,34 @@ pub fn encode_message( /// Decodes a standard aztec-nr message, i.e. one created via `encode_message`, returning the original encoded values. /// +/// Returns `None` if the message is empty or has invalid (>128 bit) expanded metadata. +/// /// Note that `encode_message` returns a fixed size array while this function takes a `BoundedVec`: this is because /// prior to decoding the message type is unknown, and consequentially not known at compile time. If working with /// fixed-size messages, consider using `BoundedVec::from_array` to convert them. pub unconstrained fn decode_message( message: BoundedVec, -) -> (u64, u64, BoundedVec) { - assert( - message.len() >= MESSAGE_EXPANDED_METADATA_LEN, - f"Invalid message: it must have at least {MESSAGE_EXPANDED_METADATA_LEN} fields", - ); - - // If MESSAGE_EXPANDED_METADATA_LEN is changed, causing the assertion below to fail, then the destructuring of the - // message encoding below must be updated as well. - std::static_assert( - MESSAGE_EXPANDED_METADATA_LEN == 1, - "unexpected value for MESSAGE_EXPANDED_METADATA_LEN", - ); - - let msg_expanded_metadata = message.get(0); - let (msg_type_id, msg_metadata) = from_expanded_metadata(msg_expanded_metadata); - let msg_content = array::subbvec(message, MESSAGE_EXPANDED_METADATA_LEN); - - (msg_type_id, msg_metadata, msg_content) +) -> Option<(u64, u64, BoundedVec)> { + Option::some(message) + .and_then(|message| { + // If MESSAGE_EXPANDED_METADATA_LEN is changed, causing the assertion below to fail, then the destructuring + // of the + // message encoding below must be updated as well. + std::static_assert( + MESSAGE_EXPANDED_METADATA_LEN == 1, + "unexpected value for MESSAGE_EXPANDED_METADATA_LEN", + ); + if message.len() < MESSAGE_EXPANDED_METADATA_LEN { + Option::none() + } else { + Option::some(message.get(0)) + } + }) + .and_then(|msg_expanded_metadata| from_expanded_metadata(msg_expanded_metadata)) + .map(|(msg_type_id, msg_metadata)| { + let msg_content = array::subbvec(message, MESSAGE_EXPANDED_METADATA_LEN); + (msg_type_id, msg_metadata, msg_content) + }) } global U64_SHIFT_MULTIPLIER: Field = 2.pow_32(64); @@ -126,17 +131,26 @@ fn to_expanded_metadata(msg_type: u64, msg_metadata: u64) -> Field { type_field + msg_metadata_field } -fn from_expanded_metadata(input: Field) -> (u64, u64) { - input.assert_max_bit_size::<128>(); - let msg_metadata = (input as u64); - let msg_type = ((input - (msg_metadata as Field)) / U64_SHIFT_MULTIPLIER) as u64; - // Use division instead of bit shift since bit shifts are expensive in circuits - (msg_type, msg_metadata) +global TWO_POW_128: Field = 2.pow_32(128); + +/// Unpacks expanded metadata into (msg_type, msg_metadata). Returns `None` if `input >= 2^128`. +fn from_expanded_metadata(input: Field) -> Option<(u64, u64)> { + if input.lt(TWO_POW_128) { + let msg_metadata = (input as u64); + let msg_type = ((input - (msg_metadata as Field)) / U64_SHIFT_MULTIPLIER) as u64; + // Use division instead of bit shift since bit shifts are expensive in circuits + Option::some((msg_type, msg_metadata)) + } else { + Option::none() + } } mod tests { use crate::utils::array::subarray::subarray; - use super::{decode_message, encode_message, from_expanded_metadata, MAX_MESSAGE_CONTENT_LEN, to_expanded_metadata}; + use super::{ + decode_message, encode_message, from_expanded_metadata, MAX_MESSAGE_CONTENT_LEN, to_expanded_metadata, + TWO_POW_128, + }; global U64_MAX: u64 = (2.pow_32(64) - 1) as u64; global U128_MAX: Field = (2.pow_32(128) - 1); @@ -145,7 +159,7 @@ mod tests { unconstrained fn encode_decode_empty_message(msg_type: u64, msg_metadata: u64) { let encoded = encode_message(msg_type, msg_metadata, []); let (decoded_msg_type, decoded_msg_metadata, decoded_msg_content) = - decode_message(BoundedVec::from_array(encoded)); + decode_message(BoundedVec::from_array(encoded)).unwrap(); assert_eq(decoded_msg_type, msg_type); assert_eq(decoded_msg_metadata, msg_metadata); @@ -160,7 +174,7 @@ mod tests { ) { let encoded = encode_message(msg_type, msg_metadata, msg_content); let (decoded_msg_type, decoded_msg_metadata, decoded_msg_content) = - decode_message(BoundedVec::from_array(encoded)); + decode_message(BoundedVec::from_array(encoded)).unwrap(); assert_eq(decoded_msg_type, msg_type); assert_eq(decoded_msg_metadata, msg_metadata); @@ -176,7 +190,7 @@ mod tests { ) { let encoded = encode_message(msg_type, msg_metadata, msg_content); let (decoded_msg_type, decoded_msg_metadata, decoded_msg_content) = - decode_message(BoundedVec::from_array(encoded)); + decode_message(BoundedVec::from_array(encoded)).unwrap(); assert_eq(decoded_msg_type, msg_type); assert_eq(decoded_msg_metadata, msg_metadata); @@ -188,25 +202,25 @@ mod tests { unconstrained fn to_expanded_metadata_packing() { // Test case 1: All bits set let packed = to_expanded_metadata(U64_MAX, U64_MAX); - let (msg_type, msg_metadata) = from_expanded_metadata(packed); + let (msg_type, msg_metadata) = from_expanded_metadata(packed).unwrap(); assert_eq(msg_type, U64_MAX); assert_eq(msg_metadata, U64_MAX); // Test case 2: Only log type bits set let packed = to_expanded_metadata(U64_MAX, 0); - let (msg_type, msg_metadata) = from_expanded_metadata(packed); + let (msg_type, msg_metadata) = from_expanded_metadata(packed).unwrap(); assert_eq(msg_type, U64_MAX); assert_eq(msg_metadata, 0); // Test case 3: Only msg_metadata bits set let packed = to_expanded_metadata(0, U64_MAX); - let (msg_type, msg_metadata) = from_expanded_metadata(packed); + let (msg_type, msg_metadata) = from_expanded_metadata(packed).unwrap(); assert_eq(msg_type, 0); assert_eq(msg_metadata, U64_MAX); // Test case 4: No bits set let packed = to_expanded_metadata(0, 0); - let (msg_type, msg_metadata) = from_expanded_metadata(packed); + let (msg_type, msg_metadata) = from_expanded_metadata(packed).unwrap(); assert_eq(msg_type, 0); assert_eq(msg_metadata, 0); } @@ -215,25 +229,25 @@ mod tests { unconstrained fn from_expanded_metadata_packing() { // Test case 1: All bits set let input = U128_MAX as Field; - let (msg_type, msg_metadata) = from_expanded_metadata(input); + let (msg_type, msg_metadata) = from_expanded_metadata(input).unwrap(); assert_eq(msg_type, U64_MAX); assert_eq(msg_metadata, U64_MAX); // Test case 2: Only log type bits set let input = (U128_MAX - U64_MAX as Field); - let (msg_type, msg_metadata) = from_expanded_metadata(input); + let (msg_type, msg_metadata) = from_expanded_metadata(input).unwrap(); assert_eq(msg_type, U64_MAX); assert_eq(msg_metadata, 0); // Test case 3: Only msg_metadata bits set let input = U64_MAX as Field; - let (msg_type, msg_metadata) = from_expanded_metadata(input); + let (msg_type, msg_metadata) = from_expanded_metadata(input).unwrap(); assert_eq(msg_type, 0); assert_eq(msg_metadata, U64_MAX); // Test case 4: No bits set let input = 0; - let (msg_type, msg_metadata) = from_expanded_metadata(input); + let (msg_type, msg_metadata) = from_expanded_metadata(input).unwrap(); assert_eq(msg_type, 0); assert_eq(msg_metadata, 0); } @@ -241,7 +255,7 @@ mod tests { #[test] unconstrained fn to_from_expanded_metadata(original_msg_type: u64, original_msg_metadata: u64) { let packed = to_expanded_metadata(original_msg_type, original_msg_metadata); - let (unpacked_msg_type, unpacked_msg_metadata) = from_expanded_metadata(packed); + let (unpacked_msg_type, unpacked_msg_metadata) = from_expanded_metadata(packed).unwrap(); assert_eq(original_msg_type, unpacked_msg_type); assert_eq(original_msg_metadata, unpacked_msg_metadata); @@ -257,7 +271,8 @@ mod tests { } let encoded = encode_message(msg_type_id, msg_metadata, msg_content); - let (decoded_type_id, decoded_metadata, decoded_content) = decode_message(BoundedVec::from_array(encoded)); + let (decoded_type_id, decoded_metadata, decoded_content) = + decode_message(BoundedVec::from_array(encoded)).unwrap(); assert_eq(decoded_type_id, msg_type_id); assert_eq(decoded_metadata, msg_metadata); @@ -269,4 +284,15 @@ mod tests { let msg_content = [0; MAX_MESSAGE_CONTENT_LEN + 1]; let _ = encode_message(0, 0, msg_content); } + + #[test] + unconstrained fn decode_empty_message_returns_none() { + assert(decode_message(BoundedVec::new()).is_none()); + } + + #[test] + unconstrained fn decode_message_with_oversized_metadata_returns_none() { + let message = BoundedVec::from_array([TWO_POW_128]); + assert(decode_message(message).is_none()); + } } diff --git a/noir-projects/aztec-nr/aztec/src/messages/logs/event.nr b/noir-projects/aztec-nr/aztec/src/messages/logs/event.nr index fbe759248efa..101bff9a3f68 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/logs/event.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/logs/event.nr @@ -57,7 +57,8 @@ where /// Decodes the plaintext from a private event message (i.e. one of type [`PRIVATE_EVENT_MSG_TYPE_ID`]). /// -/// This plaintext is meant to have originated from [`encode_private_event_message`]. +/// Returns `None` if `msg_content` has too few fields. This plaintext is meant to have originated +/// from [`encode_private_event_message`]. /// /// Note that while [`encode_private_event_message`] returns a fixed-size array, this function takes a [`BoundedVec`] /// instead. This is because when decoding we're typically processing runtime-sized plaintexts, more specifically, @@ -65,26 +66,24 @@ where pub(crate) unconstrained fn decode_private_event_message( msg_metadata: u64, msg_content: BoundedVec, -) -> (EventSelector, Field, BoundedVec) { - // Private event messages contain the event type id in the metadata - let event_type_id = EventSelector::from_field(msg_metadata as Field); - - assert( - msg_content.len() > PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN, - f"Invalid private event message: all private event messages must have at least {PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN} fields", - ); - - // If PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN is changed, causing the assertion below to fail, then the - // destructuring of the private event message encoding below must be updated as well. - std::static_assert( - PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN == 1, - "unexpected value for PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN", - ); - - let randomness = msg_content.get(PRIVATE_EVENT_MSG_PLAINTEXT_RANDOMNESS_INDEX); - let serialized_event = array::subbvec(msg_content, PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN); - - (event_type_id, randomness, serialized_event) +) -> Option<(EventSelector, Field, BoundedVec)> { + if msg_content.len() <= PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN { + Option::none() + } else { + let event_type_id = EventSelector::from_field(msg_metadata as Field); + + // If PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN is changed, causing the assertion below to fail, then the + // destructuring of the private event message encoding below must be updated as well. + std::static_assert( + PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN == 1, + "unexpected value for PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN", + ); + + let randomness = msg_content.get(PRIVATE_EVENT_MSG_PLAINTEXT_RANDOMNESS_INDEX); + let serialized_event = array::subbvec(msg_content, PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN); + + Option::some((event_type_id, randomness, serialized_event)) + } } mod test { @@ -108,14 +107,28 @@ mod test { let message_plaintext = encode_private_event_message(event, RANDOMNESS); - let (msg_type_id, msg_metadata, msg_content) = decode_message(BoundedVec::from_array(message_plaintext)); + let (msg_type_id, msg_metadata, msg_content) = + decode_message(BoundedVec::from_array(message_plaintext)).unwrap(); assert_eq(msg_type_id, PRIVATE_EVENT_MSG_TYPE_ID); - let (event_type_id, randomness, serialized_event) = decode_private_event_message(msg_metadata, msg_content); + let (event_type_id, randomness, serialized_event) = + decode_private_event_message(msg_metadata, msg_content).unwrap(); assert_eq(event_type_id, MockEvent::get_event_type_id()); assert_eq(randomness, RANDOMNESS); assert_eq(serialized_event, BoundedVec::from_array(event.serialize())); } + + #[test] + unconstrained fn decode_empty_content_returns_none() { + let empty = BoundedVec::new(); + assert(decode_private_event_message(0, empty).is_none()); + } + + #[test] + unconstrained fn decode_with_only_reserved_fields_returns_none() { + let content = BoundedVec::from_array([0]); + assert(decode_private_event_message(0, content).is_none()); + } } diff --git a/noir-projects/aztec-nr/aztec/src/messages/logs/note.nr b/noir-projects/aztec-nr/aztec/src/messages/logs/note.nr index 84a72a48e534..b78a17b09102 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/logs/note.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/logs/note.nr @@ -54,7 +54,8 @@ where /// Decodes the plaintext from a private note message (i.e. one of type [`PRIVATE_NOTE_MSG_TYPE_ID`]). /// -/// This plaintext is meant to have originated from [`encode_private_note_message`]. +/// Returns `None` if `msg_content` has too few fields. This plaintext is meant to have originated +/// from [`encode_private_note_message`]. /// /// Note that while [`encode_private_note_message`] returns a fixed-size array, this function takes a [`BoundedVec`] /// instead. This is because when decoding we're typically processing runtime-sized plaintexts, more specifically, @@ -62,27 +63,26 @@ where pub(crate) unconstrained fn decode_private_note_message( msg_metadata: u64, msg_content: BoundedVec, -) -> (Field, AztecAddress, Field, Field, BoundedVec) { - let note_type_id = msg_metadata as Field; // TODO: make note type id not be a full field - - assert( - msg_content.len() > PRIVATE_NOTE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN, - f"Invalid private note message: all private note messages must have at least {PRIVATE_NOTE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN} fields", - ); - - // If PRIVATE_NOTE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN is changed, causing the assertion below to fail, then the - // decoding below must be updated as well. - std::static_assert( - PRIVATE_NOTE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN == 3, - "unexpected value for PRIVATE_NOTE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN", - ); - - let owner = AztecAddress::from_field(msg_content.get(PRIVATE_NOTE_MSG_PLAINTEXT_OWNER_INDEX)); - let storage_slot = msg_content.get(PRIVATE_NOTE_MSG_PLAINTEXT_STORAGE_SLOT_INDEX); - let randomness = msg_content.get(PRIVATE_NOTE_MSG_PLAINTEXT_RANDOMNESS_INDEX); - let packed_note = array::subbvec(msg_content, PRIVATE_NOTE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN); - - (note_type_id, owner, storage_slot, randomness, packed_note) +) -> Option<(Field, AztecAddress, Field, Field, BoundedVec)> { + if msg_content.len() <= PRIVATE_NOTE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN { + Option::none() + } else { + let note_type_id = msg_metadata as Field; // TODO: make note type id not be a full field + + // If PRIVATE_NOTE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN is changed, causing the assertion below to fail, then the + // decoding below must be updated as well. + std::static_assert( + PRIVATE_NOTE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN == 3, + "unexpected value for PRIVATE_NOTE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN", + ); + + let owner = AztecAddress::from_field(msg_content.get(PRIVATE_NOTE_MSG_PLAINTEXT_OWNER_INDEX)); + let storage_slot = msg_content.get(PRIVATE_NOTE_MSG_PLAINTEXT_STORAGE_SLOT_INDEX); + let randomness = msg_content.get(PRIVATE_NOTE_MSG_PLAINTEXT_RANDOMNESS_INDEX); + let packed_note = array::subbvec(msg_content, PRIVATE_NOTE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN); + + Option::some((note_type_id, owner, storage_slot, randomness, packed_note)) + } } mod test { @@ -108,12 +108,13 @@ mod test { let message_plaintext = encode_private_note_message(note, OWNER, STORAGE_SLOT, RANDOMNESS); - let (msg_type_id, msg_metadata, msg_content) = decode_message(BoundedVec::from_array(message_plaintext)); + let (msg_type_id, msg_metadata, msg_content) = + decode_message(BoundedVec::from_array(message_plaintext)).unwrap(); assert_eq(msg_type_id, PRIVATE_NOTE_MSG_TYPE_ID); let (note_type_id, owner, storage_slot, randomness, packed_note) = - decode_private_note_message(msg_metadata, msg_content); + decode_private_note_message(msg_metadata, msg_content).unwrap(); assert_eq(note_type_id, MockNote::get_id()); assert_eq(owner, OWNER); @@ -142,12 +143,12 @@ mod test { let note = MaxSizeNote { data }; let encoded = encode_private_note_message(note, OWNER, STORAGE_SLOT, RANDOMNESS); - let (msg_type_id, msg_metadata, msg_content) = decode_message(BoundedVec::from_array(encoded)); + let (msg_type_id, msg_metadata, msg_content) = decode_message(BoundedVec::from_array(encoded)).unwrap(); assert_eq(msg_type_id, PRIVATE_NOTE_MSG_TYPE_ID); let (note_type_id, owner, storage_slot, randomness, packed_note) = - decode_private_note_message(msg_metadata, msg_content); + decode_private_note_message(msg_metadata, msg_content).unwrap(); assert_eq(note_type_id, MaxSizeNote::get_id()); assert_eq(owner, OWNER); @@ -172,4 +173,16 @@ mod test { let note = OversizedNote { data: [0; MAX_NOTE_PACKED_LEN + 1] }; let _ = encode_private_note_message(note, OWNER, STORAGE_SLOT, RANDOMNESS); } + + #[test] + unconstrained fn decode_empty_content_returns_none() { + let empty = BoundedVec::new(); + assert(decode_private_note_message(0, empty).is_none()); + } + + #[test] + unconstrained fn decode_with_only_reserved_fields_returns_none() { + let content = BoundedVec::from_array([0, 0, 0]); + assert(decode_private_note_message(0, content).is_none()); + } } diff --git a/noir-projects/aztec-nr/aztec/src/messages/logs/partial_note.nr b/noir-projects/aztec-nr/aztec/src/messages/logs/partial_note.nr index b39e0a809fbc..d0c8005ce184 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/logs/partial_note.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/logs/partial_note.nr @@ -91,9 +91,11 @@ where ) } -/// Decodes the plaintext from a private note message (i.e. one of type [`PARTIAL_NOTE_PRIVATE_MSG_TYPE_ID`]). +/// Decodes the plaintext from a partial note private message (i.e. one of type +/// [`PARTIAL_NOTE_PRIVATE_MSG_TYPE_ID`]). /// -/// This plaintext is meant to have originated from [`encode_partial_note_private_message`]. +/// Returns `None` if `msg_content` has too few fields. This plaintext is meant to have originated +/// from [`encode_partial_note_private_message`]. /// /// Note that while [`encode_partial_note_private_message`] returns a fixed-size array, this function takes a /// [`BoundedVec`] instead. This is because when decoding we're typically processing runtime-sized plaintexts, more @@ -102,17 +104,25 @@ where pub(crate) unconstrained fn decode_partial_note_private_message( msg_metadata: u64, msg_content: BoundedVec, +<<<<<<< HEAD ) -> (AztecAddress, Field, Field, Field, Field, BoundedVec) { let note_type_id = msg_metadata as Field; // TODO: make note type id not be a full field +======= +) -> Option<(AztecAddress, Field, Field, Field, BoundedVec)> { + if msg_content.len() < PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN { + Option::none() + } else { + let note_type_id: Field = msg_metadata as Field; // TODO: make note type id not be a full field +>>>>>>> 7a485d139a (fix(aztec-nr): return Option from decode functions and fix event commitment capacity (#21264)) + + // 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 == 3, + "unexpected value for PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_NON_NOTE_FIELDS_LEN", + ); - // The following ensures that the message content contains at least the minimum number of fields required for a - // valid partial note private message. (Refer to the description of - // PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_NON_NOTE_FIELDS_LEN for more information about these fields.) - assert( - msg_content.len() >= PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN, - f"Invalid private note message: all partial note private messages must have at least {PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN} fields", - ); - +<<<<<<< HEAD // 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( @@ -135,6 +145,25 @@ pub(crate) unconstrained fn decode_partial_note_private_message( ); (owner, storage_slot, randomness, note_completion_log_tag, note_type_id, packed_private_note_content) +======= + // 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 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); + + let packed_private_note_content: BoundedVec = array::subbvec( + msg_content, + PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN, + ); + + Option::some( + (owner, randomness, note_completion_log_tag, note_type_id, packed_private_note_content), + ) + } +>>>>>>> 7a485d139a (fix(aztec-nr): return Option from decode functions and fix event commitment capacity (#21264)) } mod test { @@ -168,12 +197,18 @@ mod test { NOTE_COMPLETION_LOG_TAG, ); - let (msg_type_id, msg_metadata, msg_content) = decode_message(BoundedVec::from_array(message_plaintext)); + let (msg_type_id, msg_metadata, msg_content) = + decode_message(BoundedVec::from_array(message_plaintext)).unwrap(); assert_eq(msg_type_id, PARTIAL_NOTE_PRIVATE_MSG_TYPE_ID); +<<<<<<< HEAD let (owner, storage_slot, randomness, note_completion_log_tag, note_type_id, packed_note) = decode_partial_note_private_message(msg_metadata, msg_content); +======= + let (owner, randomness, note_completion_log_tag, note_type_id, packed_note) = + decode_partial_note_private_message(msg_metadata, msg_content).unwrap(); +>>>>>>> 7a485d139a (fix(aztec-nr): return Option from decode functions and fix event commitment capacity (#21264)) assert_eq(note_type_id, MockNote::get_id()); assert_eq(owner, OWNER); @@ -182,4 +217,17 @@ mod test { assert_eq(note_completion_log_tag, NOTE_COMPLETION_LOG_TAG); assert_eq(packed_note, BoundedVec::from_array(note.pack())); } + + #[test] + unconstrained fn decode_empty_content_returns_none() { + let empty = BoundedVec::new(); + assert(decode_partial_note_private_message(0, empty).is_none()); + } + + #[test] + unconstrained fn decode_succeeds_with_only_reserved_fields() { + let content = BoundedVec::from_array([0, 0, 0]); + let (_, _, _, _, packed_note) = decode_partial_note_private_message(0, content).unwrap(); + assert_eq(packed_note.len(), 0); + } } From 57ea78cd40bb8b42770110b81b7d11678231706d Mon Sep 17 00:00:00 2001 From: AztecBot Date: Sat, 14 Mar 2026 14:39:48 +0000 Subject: [PATCH 2/3] fix: resolve cherry-pick conflicts Adapted PR #21264 changes for backport-to-v4-staging: - Keep storage_slot in partial note decode (4 reserved fields vs 3 on next) - Use debug_log_format instead of aztecnr_warn_log_format (not available on v4) - Keep v4's simpler process_message without custom message handling - Fix private_events.nr auto-merged import of unavailable aztecnr_warn_log_format --- .../src/messages/discovery/partial_notes.nr | 28 +------- .../src/messages/discovery/private_events.nr | 6 +- .../src/messages/discovery/private_notes.nr | 7 +- .../src/messages/discovery/process_message.nr | 70 ++----------------- .../aztec/src/messages/logs/partial_note.nr | 50 +++---------- 5 files changed, 19 insertions(+), 142 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr b/noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr index 8c8fa4cb5acf..e0ab92a2d2c9 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr @@ -12,17 +12,12 @@ use crate::{ utils::array, }; -<<<<<<< HEAD use crate::protocol::{ address::AztecAddress, hash::sha256_to_field, logging::debug_log_format, traits::{Deserialize, Serialize}, }; -======= -use crate::logging::{aztecnr_debug_log_format, aztecnr_warn_log_format}; -use crate::protocol::{address::AztecAddress, hash::sha256_to_field, traits::{Deserialize, Serialize}}; ->>>>>>> 7a485d139a (fix(aztec-nr): return Option from decode functions and fix event commitment capacity (#21264)) /// The slot in the PXE capsules where we store a `CapsuleArray` of `DeliveredPendingPartialNote`. pub global DELIVERED_PENDING_PARTIAL_NOTE_ARRAY_LENGTH_CAPSULES_SLOT: Field = sha256_to_field( @@ -49,32 +44,16 @@ pub unconstrained fn process_partial_note_private_msg( msg_content: BoundedVec, tx_hash: Field, ) { -<<<<<<< HEAD - // 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) = - decode_partial_note_private_message(msg_metadata, msg_content); - - let pending = DeliveredPendingPartialNote { - owner, - storage_slot, - randomness, - note_completion_log_tag, - note_type_id, - packed_private_note_content, - recipient, - }; -======= let decoded = decode_partial_note_private_message(msg_metadata, msg_content); if decoded.is_some() { // 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, randomness, note_completion_log_tag, note_type_id, packed_private_note_content) = decoded.unwrap(); ->>>>>>> 7a485d139a (fix(aztec-nr): return Option from decode functions and fix event commitment capacity (#21264)) + let (owner, storage_slot, randomness, note_completion_log_tag, note_type_id, packed_private_note_content) = decoded.unwrap(); let pending = DeliveredPendingPartialNote { owner, + storage_slot, randomness, note_completion_log_tag, note_type_id, @@ -88,9 +67,8 @@ pub unconstrained fn process_partial_note_private_msg( ) .push(pending); } else { - aztecnr_warn_log_format!( + debug_log_format( "Could not decode partial note private message from tx {0}, ignoring", - )( [tx_hash], ); } diff --git a/noir-projects/aztec-nr/aztec/src/messages/discovery/private_events.nr b/noir-projects/aztec-nr/aztec/src/messages/discovery/private_events.nr index 914ec423b424..4ead09f40119 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/discovery/private_events.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/discovery/private_events.nr @@ -1,12 +1,11 @@ use crate::{ event::event_interface::compute_private_serialized_event_commitment, - logging::aztecnr_warn_log_format, messages::{ encoding::MAX_MESSAGE_CONTENT_LEN, logs::event::decode_private_event_message, processing::enqueue_event_for_validation, }, }; -use crate::protocol::{address::AztecAddress, traits::ToField}; +use crate::protocol::{address::AztecAddress, logging::debug_log_format, traits::ToField}; pub unconstrained fn process_private_event_msg( contract_address: AztecAddress, @@ -33,9 +32,8 @@ pub unconstrained fn process_private_event_msg( recipient, ); } else { - aztecnr_warn_log_format!( + debug_log_format( "Could not decode private event message from tx {0}, ignoring", - )( [tx_hash], ); } diff --git a/noir-projects/aztec-nr/aztec/src/messages/discovery/private_notes.nr b/noir-projects/aztec-nr/aztec/src/messages/discovery/private_notes.nr index 7f8ed776a648..3ad8567170de 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/discovery/private_notes.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/discovery/private_notes.nr @@ -1,7 +1,3 @@ -<<<<<<< HEAD -======= -use crate::logging::{aztecnr_debug_log_format, aztecnr_warn_log_format}; ->>>>>>> 7a485d139a (fix(aztec-nr): return Option from decode functions and fix event commitment capacity (#21264)) use crate::messages::{ discovery::{ComputeNoteHashAndNullifier, nonce_discovery::attempt_note_nonce_discovery}, encoding::MAX_MESSAGE_CONTENT_LEN, @@ -39,9 +35,8 @@ pub unconstrained fn process_private_note_msg( packed_note, ); } else { - aztecnr_warn_log_format!( + debug_log_format( "Could not decode private note message from tx {0}, ignoring", - )( [tx_hash], ); } diff --git a/noir-projects/aztec-nr/aztec/src/messages/discovery/process_message.nr b/noir-projects/aztec-nr/aztec/src/messages/discovery/process_message.nr index bedb1c44671c..a140d0485f18 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/discovery/process_message.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/discovery/process_message.nr @@ -58,47 +58,11 @@ pub unconstrained fn process_message_plaintext( // We decode the message to obtain the message type id, metadata and content. let decoded = decode_message(message_plaintext); -<<<<<<< HEAD - if msg_type_id == PRIVATE_NOTE_MSG_TYPE_ID { - debug_log("Processing private note msg"); - - process_private_note_msg( - contract_address, - message_context.tx_hash, - message_context.unique_note_hashes_in_tx, - message_context.first_nullifier_in_tx, - message_context.recipient, - compute_note_hash_and_nullifier, - msg_metadata, - msg_content, - ); - } else if msg_type_id == PARTIAL_NOTE_PRIVATE_MSG_TYPE_ID { - debug_log("Processing partial note private msg"); - - process_partial_note_private_msg( - contract_address, - message_context.recipient, - msg_metadata, - msg_content, - ); - } else if msg_type_id == PRIVATE_EVENT_MSG_TYPE_ID { - debug_log("Processing private event msg"); - - process_private_event_msg( - contract_address, - message_context.recipient, - msg_metadata, - msg_content, - message_context.tx_hash, - ); - } else { - debug_log_format("Unknown msg type id {0}", [msg_type_id as Field]); -======= if decoded.is_some() { let (msg_type_id, msg_metadata, msg_content) = decoded.unwrap(); if msg_type_id == PRIVATE_NOTE_MSG_TYPE_ID { - aztecnr_debug_log!("Processing private note msg"); + debug_log("Processing private note msg"); process_private_note_msg( contract_address, @@ -111,7 +75,7 @@ pub unconstrained fn process_message_plaintext( msg_content, ); } else if msg_type_id == PARTIAL_NOTE_PRIVATE_MSG_TYPE_ID { - aztecnr_debug_log!("Processing partial note private msg"); + debug_log("Processing partial note private msg"); process_partial_note_private_msg( contract_address, @@ -121,7 +85,7 @@ pub unconstrained fn process_message_plaintext( message_context.tx_hash, ); } else if msg_type_id == PRIVATE_EVENT_MSG_TYPE_ID { - aztecnr_debug_log!("Processing private event msg"); + debug_log("Processing private event msg"); process_private_event_msg( contract_address, @@ -130,34 +94,10 @@ pub unconstrained fn process_message_plaintext( msg_content, message_context.tx_hash, ); - } else if msg_type_id < MIN_CUSTOM_MSG_TYPE_ID { - // The message type ID falls in the range reserved for aztec.nr built-in types but wasn't matched above. - // This most likely means the message is malformed or a custom message was incorrectly assigned a reserved - // ID. Custom message types must use IDs allocated via `custom_msg_type_id`. - aztecnr_warn_log_format!( - "Message type ID {0} is in the reserved range but is not recognized, ignoring. See https://docs.aztec.network/errors/3", - )( - [msg_type_id as Field], - ); - } else if process_custom_message.is_some() { - process_custom_message.unwrap()( - contract_address, - msg_type_id, - msg_metadata, - msg_content, - message_context, - ); } else { - // A custom message was received but no handler is configured. This likely means the contract emits custom - // messages but forgot to register a handler via `AztecConfig::custom_message_handler`. - aztecnr_warn_log_format!( - "Received custom message with type id {0} but no handler is configured, ignoring. See https://docs.aztec.network/errors/2", - )( - [msg_type_id as Field], - ); + debug_log_format("Unknown msg type id {0}", [msg_type_id as Field]); } } else { - aztecnr_warn_log_format!("Could not decode message plaintext from tx {0}, ignoring")([message_context.tx_hash]); ->>>>>>> 7a485d139a (fix(aztec-nr): return Option from decode functions and fix event commitment capacity (#21264)) + debug_log_format("Could not decode message plaintext from tx {0}, ignoring", [message_context.tx_hash]); } } diff --git a/noir-projects/aztec-nr/aztec/src/messages/logs/partial_note.nr b/noir-projects/aztec-nr/aztec/src/messages/logs/partial_note.nr index d0c8005ce184..2741ba08d333 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/logs/partial_note.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/logs/partial_note.nr @@ -104,53 +104,25 @@ where pub(crate) unconstrained fn decode_partial_note_private_message( msg_metadata: u64, msg_content: BoundedVec, -<<<<<<< HEAD -) -> (AztecAddress, Field, Field, Field, Field, BoundedVec) { - let note_type_id = msg_metadata as Field; // TODO: make note type id not be a full field -======= -) -> Option<(AztecAddress, Field, Field, Field, BoundedVec)> { +) -> Option<(AztecAddress, Field, Field, Field, Field, BoundedVec)> { if msg_content.len() < PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN { Option::none() } else { let note_type_id: Field = msg_metadata as Field; // TODO: make note type id not be a full field ->>>>>>> 7a485d139a (fix(aztec-nr): return Option from decode functions and fix event commitment capacity (#21264)) // 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 == 3, + PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN == 4, "unexpected value for PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_NON_NOTE_FIELDS_LEN", ); -<<<<<<< HEAD - // 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, - "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. - 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); - - let packed_private_note_content: BoundedVec = array::subbvec( - msg_content, - PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN, - ); - - (owner, storage_slot, randomness, note_completion_log_tag, note_type_id, packed_private_note_content) -======= - // 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. + // 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. 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); @@ -160,10 +132,9 @@ pub(crate) unconstrained fn decode_partial_note_private_message( ); Option::some( - (owner, randomness, note_completion_log_tag, note_type_id, packed_private_note_content), + (owner, storage_slot, randomness, note_completion_log_tag, note_type_id, packed_private_note_content), ) } ->>>>>>> 7a485d139a (fix(aztec-nr): return Option from decode functions and fix event commitment capacity (#21264)) } mod test { @@ -202,13 +173,8 @@ mod test { assert_eq(msg_type_id, PARTIAL_NOTE_PRIVATE_MSG_TYPE_ID); -<<<<<<< HEAD let (owner, storage_slot, randomness, note_completion_log_tag, note_type_id, packed_note) = - decode_partial_note_private_message(msg_metadata, msg_content); -======= - let (owner, randomness, note_completion_log_tag, note_type_id, packed_note) = decode_partial_note_private_message(msg_metadata, msg_content).unwrap(); ->>>>>>> 7a485d139a (fix(aztec-nr): return Option from decode functions and fix event commitment capacity (#21264)) assert_eq(note_type_id, MockNote::get_id()); assert_eq(owner, OWNER); @@ -226,8 +192,8 @@ mod test { #[test] unconstrained fn decode_succeeds_with_only_reserved_fields() { - let content = BoundedVec::from_array([0, 0, 0]); - let (_, _, _, _, packed_note) = decode_partial_note_private_message(0, content).unwrap(); + let content = BoundedVec::from_array([0, 0, 0, 0]); + let (_, _, _, _, _, packed_note) = decode_partial_note_private_message(0, content).unwrap(); assert_eq(packed_note.len(), 0); } } From 07aac7c34c182f641facca93c85f17b6ab13806e Mon Sep 17 00:00:00 2001 From: AztecBot Date: Sat, 14 Mar 2026 14:57:20 +0000 Subject: [PATCH 3/3] fix: apply nargo formatting fixes --- .../aztec-nr/aztec/src/messages/discovery/partial_notes.nr | 3 ++- .../aztec/src/messages/discovery/process_message.nr | 5 ++++- .../aztec-nr/aztec/src/messages/logs/partial_note.nr | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr b/noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr index e0ab92a2d2c9..77af6845e427 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr @@ -49,7 +49,8 @@ pub unconstrained fn process_partial_note_private_msg( if decoded.is_some() { // 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) = decoded.unwrap(); + let (owner, storage_slot, randomness, note_completion_log_tag, note_type_id, packed_private_note_content) = + decoded.unwrap(); let pending = DeliveredPendingPartialNote { owner, diff --git a/noir-projects/aztec-nr/aztec/src/messages/discovery/process_message.nr b/noir-projects/aztec-nr/aztec/src/messages/discovery/process_message.nr index a140d0485f18..2ac488d053cd 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/discovery/process_message.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/discovery/process_message.nr @@ -98,6 +98,9 @@ pub unconstrained fn process_message_plaintext( debug_log_format("Unknown msg type id {0}", [msg_type_id as Field]); } } else { - debug_log_format("Could not decode message plaintext from tx {0}, ignoring", [message_context.tx_hash]); + debug_log_format( + "Could not decode message plaintext from tx {0}, ignoring", + [message_context.tx_hash], + ); } } diff --git a/noir-projects/aztec-nr/aztec/src/messages/logs/partial_note.nr b/noir-projects/aztec-nr/aztec/src/messages/logs/partial_note.nr index 2741ba08d333..63a19ee0cd15 100644 --- a/noir-projects/aztec-nr/aztec/src/messages/logs/partial_note.nr +++ b/noir-projects/aztec-nr/aztec/src/messages/logs/partial_note.nr @@ -131,9 +131,9 @@ pub(crate) unconstrained fn decode_partial_note_private_message( PARTIAL_NOTE_PRIVATE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN, ); - Option::some( - (owner, storage_slot, randomness, note_completion_log_tag, note_type_id, packed_private_note_content), - ) + Option::some(( + owner, storage_slot, randomness, note_completion_log_tag, note_type_id, packed_private_note_content, + )) } }