Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 8 additions & 1 deletion noir-projects/aztec-nr/aztec/src/event/event_interface.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,36 @@ pub unconstrained fn process_partial_note_private_msg(
recipient: AztecAddress,
msg_metadata: u64,
msg_content: BoundedVec<Field, MAX_MESSAGE_CONTENT_LEN>,
tx_hash: Field,
) {
// 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,
};

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, 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,
packed_private_note_content,
recipient,
};

CapsuleArray::at(
contract_address,
DELIVERED_PENDING_PARTIAL_NOTE_ARRAY_LENGTH_CAPSULES_SLOT,
)
.push(pending);
} else {
debug_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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
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,
Expand All @@ -14,18 +14,27 @@ pub unconstrained fn process_private_event_msg(
msg_content: BoundedVec<Field, MAX_MESSAGE_CONTENT_LEN>,
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 {
debug_log_format(
"Could not decode private event message from tx {0}, ignoring",
[tx_hash],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,30 @@ pub unconstrained fn process_private_note_msg<Env>(
msg_metadata: u64,
msg_content: BoundedVec<Field, MAX_MESSAGE_CONTENT_LEN>,
) {
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 {
debug_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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,41 +56,48 @@ pub unconstrained fn process_message_plaintext<Env>(
// 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);

if msg_type_id == PRIVATE_NOTE_MSG_TYPE_ID {
debug_log("Processing private note msg");
if decoded.is_some() {
let (msg_type_id, msg_metadata, msg_content) = decoded.unwrap();

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");
if msg_type_id == PRIVATE_NOTE_MSG_TYPE_ID {
debug_log("Processing private note 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_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_private_event_msg(
contract_address,
message_context.recipient,
msg_metadata,
msg_content,
message_context.tx_hash,
);
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 {
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]);
}
} else {
debug_log_format("Unknown msg type id {0}", [msg_type_id as Field]);
debug_log_format("Could not decode message plaintext from tx {0}, ignoring", [message_context.tx_hash]);
}
}
Loading
Loading