diff --git a/yarn-project/aztec-nr/aztec/src/context.nr b/yarn-project/aztec-nr/aztec/src/context.nr index 13273da5a118..00f4892d0d9f 100644 --- a/yarn-project/aztec-nr/aztec/src/context.nr +++ b/yarn-project/aztec-nr/aztec/src/context.nr @@ -380,21 +380,7 @@ impl PrivateContext { let item = PublicCallStackItem { contract_address: AztecAddress::from_field(reader.read()), function_data: reader.read_struct(FunctionData::deserialize), - public_inputs: PublicCircuitPublicInputs { - call_context: reader.read_struct(CallContext::deserialize), - args_hash: reader.read(), - return_values: [0; RETURN_VALUES_LENGTH], - contract_storage_update_requests: [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL], - contract_storage_reads: [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL], - public_call_stack_hashes: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], - new_commitments: [SideEffect::empty(); MAX_NEW_COMMITMENTS_PER_CALL], - new_nullifiers: [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL], - new_l2_to_l1_msgs:[0; MAX_NEW_L2_TO_L1_MSGS_PER_CALL], - unencrypted_logs_hash:[0; NUM_FIELDS_PER_SHA256], - unencrypted_log_preimages_length: 0, - historical_header: Header::empty(), - prover_address: AztecAddress::zero(), - }, + public_inputs: reader.read_struct(PublicCircuitPublicInputs::deserialize), is_execution_request: true, }; reader.finish(); 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 03febadaa575..9995bee6a05b 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 @@ -107,9 +107,9 @@ impl Serialize for PrivateCircuitPublicInp impl Deserialize for PrivateCircuitPublicInputs { fn deserialize(serialized: [Field; PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH]) -> Self { - // TODO: This should accept a reader ^ to avoid copying data. + // TODO(#4390): This should accept a reader ^ to avoid copying data. let mut reader = Reader::new(serialized); - Self { + let inputs = Self { call_context: reader.read_struct(CallContext::deserialize), args_hash: reader.read(), return_values: reader.read_array([0; RETURN_VALUES_LENGTH]), @@ -129,7 +129,10 @@ impl Deserialize for PrivateCircuitPublicI contract_deployment_data: reader.read_struct(ContractDeploymentData::deserialize), chain_id: reader.read(), version: reader.read(), - } + }; + + reader.finish(); + inputs } } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/public_circuit_public_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/public_circuit_public_inputs.nr index 138a9d0e17d3..8d981d4ca12e 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/public_circuit_public_inputs.nr @@ -1,29 +1,34 @@ -use crate::constants::{ - MAX_NEW_L2_TO_L1_MSGS_PER_CALL, - MAX_NEW_NULLIFIERS_PER_CALL, - MAX_NEW_COMMITMENTS_PER_CALL, - MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, - MAX_PUBLIC_DATA_READS_PER_CALL, - MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, - NUM_FIELDS_PER_SHA256, - RETURN_VALUES_LENGTH, - GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS, - PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH, -}; use crate::{ abis::{ call_context::CallContext, side_effect::{SideEffect, SideEffectLinkedToNoteHash}, }, address::AztecAddress, + constants::{ + MAX_NEW_L2_TO_L1_MSGS_PER_CALL, + MAX_NEW_NULLIFIERS_PER_CALL, + MAX_NEW_COMMITMENTS_PER_CALL, + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, + MAX_PUBLIC_DATA_READS_PER_CALL, + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, + NUM_FIELDS_PER_SHA256, + RETURN_VALUES_LENGTH, + GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS, + PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH, + }, contrakt::{ storage_read::StorageRead, storage_update_request::StorageUpdateRequest, }, hash::pedersen_hash, header::Header, + traits::{ + Hash, + Serialize, + Deserialize, + }, + utils::reader::Reader, }; -use crate::traits::{Hash, Serialize, Deserialize}; struct PublicCircuitPublicInputs{ call_context: CallContext, @@ -82,6 +87,31 @@ impl Serialize for PublicCircuitPublicInput } } +impl Deserialize for PublicCircuitPublicInputs { + fn deserialize(serialized: [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH]) -> Self { + // TODO(#4390): This should accept a reader ^ to avoid copying data. + let mut reader = Reader::new(serialized); + let inputs = PublicCircuitPublicInputs { + call_context: reader.read_struct(CallContext::deserialize), + args_hash: reader.read(), + return_values: reader.read_array([0; RETURN_VALUES_LENGTH]), + contract_storage_update_requests: reader.read_struct_array(StorageUpdateRequest::deserialize, [StorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL]), + contract_storage_reads: reader.read_struct_array(StorageRead::deserialize, [StorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL]), + public_call_stack_hashes: reader.read_array([0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL]), + new_commitments: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_NEW_COMMITMENTS_PER_CALL]), + new_nullifiers: reader.read_struct_array(SideEffectLinkedToNoteHash::deserialize, [SideEffectLinkedToNoteHash::empty(); MAX_NEW_NULLIFIERS_PER_CALL]), + new_l2_to_l1_msgs: reader.read_array([0; MAX_NEW_L2_TO_L1_MSGS_PER_CALL]), + unencrypted_logs_hash: reader.read_array([0; NUM_FIELDS_PER_SHA256]), + unencrypted_log_preimages_length: reader.read(), + historical_header: reader.read_struct(Header::deserialize), + prover_address: reader.read_struct(AztecAddress::deserialize), + }; + + reader.finish(); + inputs + } +} + impl Hash for PublicCircuitPublicInputs { fn hash(self) -> Field { pedersen_hash(self.serialize(), GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS) diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/storage_read.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/storage_read.nr index ffc0cbe43c78..2921e23ab94e 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/storage_read.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/storage_read.nr @@ -4,14 +4,25 @@ use crate::{ GENERATOR_INDEX__PUBLIC_DATA_READ, }, hash::pedersen_hash, + traits::{ + Deserialize, + Hash, + Empty, + Serialize, + }, }; -use crate::traits::Empty; struct StorageRead { storage_slot: Field, current_value: Field, } +impl Eq for StorageRead { + fn eq(self, other: Self) -> bool { + (self.storage_slot == other.storage_slot) & (self.current_value == other.current_value) + } +} + impl Empty for StorageRead { fn empty() -> Self { Self { @@ -21,16 +32,28 @@ impl Empty for StorageRead { } } -impl StorageRead { +impl Hash for StorageRead { + fn hash(self) -> Field { + pedersen_hash(self.serialize(), GENERATOR_INDEX__PUBLIC_DATA_READ) + } +} - pub fn serialize(self) -> [Field; CONTRACT_STORAGE_READ_LENGTH] { +impl Serialize for StorageRead { + fn serialize(self) -> [Field; CONTRACT_STORAGE_READ_LENGTH] { [self.storage_slot, self.current_value] } +} - pub fn hash(self) -> Field { - pedersen_hash(self.serialize(), GENERATOR_INDEX__PUBLIC_DATA_READ) +impl Deserialize for StorageRead { + fn deserialize(serialized: [Field; CONTRACT_STORAGE_READ_LENGTH]) -> Self { + Self { + storage_slot: serialized[0], + current_value: serialized[1], + } } +} +impl StorageRead { pub fn is_empty(self) -> bool { self.storage_slot == 0 } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/storage_update_request.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/storage_update_request.nr index ecd535c96ff9..7c837dec53f3 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/storage_update_request.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/storage_update_request.nr @@ -4,9 +4,14 @@ use crate::{ GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST, }, hash::pedersen_hash, + traits::{ + Deserialize, + Hash, + Empty, + Serialize, + }, }; use dep::std::cmp::Eq; -use crate::traits::{Hash, Empty, Serialize}; struct StorageUpdateRequest{ storage_slot : Field, @@ -45,6 +50,16 @@ impl Serialize for StorageUpdateRequest } } +impl Deserialize for StorageUpdateRequest { + fn deserialize(serialized: [Field; CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH]) -> Self { + StorageUpdateRequest { + storage_slot: serialized[0], + old_value: serialized[1], + new_value: serialized[2], + } + } +} + impl StorageUpdateRequest { pub fn is_empty(self) -> bool { self.storage_slot == 0