diff --git a/yarn-project/aztec-nr/aztec/src/context/private_context.nr b/yarn-project/aztec-nr/aztec/src/context/private_context.nr index 07bc64240639..d9d1a232c07f 100644 --- a/yarn-project/aztec-nr/aztec/src/context/private_context.nr +++ b/yarn-project/aztec-nr/aztec/src/context/private_context.nr @@ -1,10 +1,7 @@ use crate::{ context::inputs::PrivateContextInputs, key::nullifier_key::validate_nullifier_key_against_address, - messaging::{ - process_l1_to_l2_message, - l2_to_l1_message::L2ToL1Message, - }, + messaging::process_l1_to_l2_message, oracle::{ arguments, call_private_function::call_private_function_internal, @@ -50,6 +47,7 @@ use dep::protocol_types::{ grumpkin_private_key::GrumpkinPrivateKey, hash::hash_args, header::Header, + messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader, }; use dep::std::option::Option; diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr index f7eafd6503eb..44ed670877ce 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr @@ -117,7 +117,9 @@ impl Serialize for PrivateCircuitPublicInp } fields.extend_from_array(self.private_call_stack_hashes); fields.extend_from_array(self.public_call_stack_hashes); - fields.extend_from_array(self.new_l2_to_l1_msgs); + for i in 0..MAX_NEW_L2_TO_L1_MSGS_PER_CALL { + fields.extend_from_array(self.new_l2_to_l1_msgs[i].serialize()); + } fields.push(self.end_side_effect_counter as Field); fields.extend_from_array(self.encrypted_logs_hash); fields.extend_from_array(self.unencrypted_logs_hash); @@ -149,7 +151,7 @@ impl Deserialize for PrivateCircuitPublicI new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL]), private_call_stack_hashes: reader.read_array([0; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL]), public_call_stack_hashes: reader.read_array([0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL]), - new_l2_to_l1_msgs: reader.read_array([0; MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), + new_l2_to_l1_msgs: reader.read_struct_array(L2ToL1Message::deserialize, [L2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), end_side_effect_counter: reader.read() as u32, encrypted_logs_hash: reader.read_array([0; NUM_FIELDS_PER_SHA256]), unencrypted_logs_hash: reader.read_array([0; NUM_FIELDS_PER_SHA256]), diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/messaging/l2_to_l1_message.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/messaging/l2_to_l1_message.nr index 40302bc9a9d1..d7b2c6046a8d 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/messaging/l2_to_l1_message.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/messaging/l2_to_l1_message.nr @@ -1,8 +1,10 @@ use crate::{ address::EthAddress, - traits::Empty, + traits::{Deserialize, Empty, Serialize}, }; +global L2_TO_L1_MESSAGE_LENGTH: Field = 2; + struct L2ToL1Message { recipient: EthAddress, content: Field, @@ -22,3 +24,18 @@ impl Eq for L2ToL1Message { (self.recipient == other.recipient) & (self.content == other.content) } } + +impl Serialize for L2ToL1Message { + fn serialize(self) -> [Field; L2_TO_L1_MESSAGE_LENGTH] { + [self.recipient.to_field(), self.content] + } +} + +impl Deserialize for L2ToL1Message { + fn deserialize(values: [Field; L2_TO_L1_MESSAGE_LENGTH]) -> Self { + Self { + recipient: EthAddress::from_field(values[0]), + content: values[1], + } + } +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_circuit_public_inputs_builder.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_circuit_public_inputs_builder.nr index 11c7c39842f2..d60c838d95ba 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_circuit_public_inputs_builder.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_circuit_public_inputs_builder.nr @@ -9,6 +9,7 @@ use crate::{ contrakt::deployment_data::ContractDeploymentData, hash::{compute_constructor_hash, hash_args}, header::Header, + messaging::l2_to_l1_message::L2ToL1Message, tests::{ fixtures, testing_harness::build_contract_deployment_data, @@ -42,7 +43,7 @@ struct PrivateCircuitPublicInputsBuilder { private_call_stack_hashes: BoundedVec, public_call_stack_hashes: BoundedVec, - new_l2_to_l1_msgs: BoundedVec, + new_l2_to_l1_msgs: BoundedVec, encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256], unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256],