diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/call_context.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/call_context.nr index 42e516226552..e6c3189b4872 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/call_context.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/call_context.nr @@ -12,7 +12,6 @@ use crate::{ Serialize, }, }; -use dep::std::cmp::Eq; // docs:start:call-context struct CallContext { @@ -95,9 +94,11 @@ impl Deserialize for CallContext { } #[test] -fn serialization_smoke() { +fn serialization_of_empty() { let context: CallContext = dep::std::unsafe::zeroed(); - let _serialized = context.serialize(); + let serialized = context.serialize(); + let deserialized = CallContext::deserialize(serialized); + assert(context.eq(deserialized)); } #[test] diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/function_data.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/function_data.nr index 86a31e334609..29c193a47dca 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/function_data.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/function_data.nr @@ -21,6 +21,15 @@ struct FunctionData { is_constructor : bool, } +impl Eq for FunctionData { + fn eq(self, other: Self) -> bool { + self.selector.eq(other.selector) & + self.is_internal == other.is_internal & + self.is_private == other.is_private & + self.is_constructor == other.is_constructor + } +} + impl Serialize for FunctionData { // A field is ~256 bits // TODO(https://github.com/AztecProtocol/aztec-packages/issues/3057): Since, function data can fit into a Field, @@ -53,9 +62,11 @@ impl Hash for FunctionData { } #[test] -fn serialization_smoke() { +fn serialization_of_empty() { let data: FunctionData = dep::std::unsafe::zeroed(); - let _serialized = data.serialize(); + let serialized = data.serialize(); + let deserialized = FunctionData::deserialize(serialized); + assert(data.eq(deserialized)); } #[test] diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/global_variables.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/global_variables.nr index 42358630586b..d84fccb7417b 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/global_variables.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/global_variables.nr @@ -62,7 +62,7 @@ impl Empty for GlobalVariables { } #[test] -fn serialization_deserialization_smoke() { +fn serialization_of_empty() { let vars: GlobalVariables = dep::std::unsafe::zeroed(); let _serialized = vars.serialize(); let _deserialized = GlobalVariables::deserialize(_serialized); diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_call_stack_item.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_call_stack_item.nr index a885a17f0e26..73e5fa0e9c13 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_call_stack_item.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_call_stack_item.nr @@ -30,6 +30,15 @@ struct PrivateCallStackItem { is_execution_request: bool, } +impl Eq for PrivateCallStackItem { + fn eq(self, other: Self) -> bool { + self.contract_address.eq(other.contract_address) & + self.function_data.eq(other.function_data) & + self.public_inputs.eq(other.public_inputs) & + self.is_execution_request == other.is_execution_request + } +} + impl Serialize for PrivateCallStackItem { fn serialize(self) -> [Field; PRIVATE_CALL_STACK_ITEM_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(0); @@ -69,9 +78,11 @@ impl Hash for PrivateCallStackItem { } #[test] -fn serialization_smoke() { +fn serialization_of_empty() { let item: PrivateCallStackItem = dep::std::unsafe::zeroed(); - let _serialized = item.serialize(); + let serialized = item.serialize(); + let deserialized = PrivateCallStackItem::deserialize(serialized); + assert(item.eq(deserialized)); } #[test] 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 68f2d4c20882..45eb76d7c413 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 @@ -67,6 +67,30 @@ struct PrivateCircuitPublicInputs { version: Field, } +impl Eq for PrivateCircuitPublicInputs { + fn eq(self, other: Self) -> bool { + self.call_context.eq(other.call_context) & + self.args_hash.eq(other.args_hash) & + (self.return_values == other.return_values) & + (self.read_requests == other.read_requests) & + (self.nullifier_key_validation_requests == other.nullifier_key_validation_requests) & + (self.new_commitments == other.new_commitments) & + (self.new_nullifiers == other.new_nullifiers) & + (self.private_call_stack_hashes == other.private_call_stack_hashes) & + (self.public_call_stack_hashes == other.public_call_stack_hashes) & + (self.new_l2_to_l1_msgs == other.new_l2_to_l1_msgs) & + (self.end_side_effect_counter == other.end_side_effect_counter) & + (self.encrypted_logs_hash == other.encrypted_logs_hash) & + (self.unencrypted_logs_hash == other.unencrypted_logs_hash) & + (self.encrypted_log_preimages_length == other.encrypted_log_preimages_length) & + (self.unencrypted_log_preimages_length == other.unencrypted_log_preimages_length) & + self.historical_header.eq(other.historical_header) & + self.contract_deployment_data.eq(other.contract_deployment_data) & + self.chain_id.eq(other.chain_id) & + self.version.eq(other.version) + } +} + impl Serialize for PrivateCircuitPublicInputs { fn serialize(self) -> [Field; PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(0); @@ -143,9 +167,11 @@ impl Hash for PrivateCircuitPublicInputs { } #[test] -fn serialization_smoke() { +fn serialization_of_empty() { let pcpi: PrivateCircuitPublicInputs = dep::std::unsafe::zeroed(); - let _serialized = pcpi.serialize(); + let serialized = pcpi.serialize(); + let deserialized = PrivateCircuitPublicInputs::deserialize(serialized); + assert(pcpi.eq(deserialized)); } #[test] 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 8d981d4ca12e..372aefde0168 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 @@ -58,6 +58,12 @@ struct PublicCircuitPublicInputs{ prover_address: AztecAddress, } +impl Eq for PublicCircuitPublicInputs { + fn eq(self, other: Self) -> bool { + self.serialize() == other.serialize() + } +} + impl Serialize for PublicCircuitPublicInputs { fn serialize(self) -> [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(0); @@ -119,9 +125,11 @@ impl Hash for PublicCircuitPublicInputs { } #[test] -fn serialization_smoke() { +fn serialization_of_empty() { let pcpi: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); - let _serialized = pcpi.serialize(); + let serialized = pcpi.serialize(); + let deserialized = PublicCircuitPublicInputs::deserialize(serialized); + assert(pcpi.eq(deserialized)); } #[test] diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/deployment_data.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/deployment_data.nr index c7637c795bbb..668234a88325 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/deployment_data.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/deployment_data.nr @@ -24,6 +24,16 @@ struct ContractDeploymentData { } // docs:end:contract-deployment-data +impl Eq for ContractDeploymentData { + fn eq(self, other: Self) -> bool { + self.public_key.eq(other.public_key) & + self.initialization_hash.eq(other.initialization_hash) & + self.contract_class_id.eq(other.contract_class_id) & + self.contract_address_salt.eq(other.contract_address_salt) & + self.portal_contract_address.eq(other.portal_contract_address) + } +} + impl Hash for ContractDeploymentData { fn hash(self) -> Field { pedersen_hash(self.serialize(), GENERATOR_INDEX__CONTRACT_DEPLOYMENT_DATA) @@ -67,3 +77,11 @@ impl ContractDeploymentData { self.portal_contract_address.assert_is_zero(); } } + +#[test] +fn serialization_of_empty() { + let data: ContractDeploymentData = dep::std::unsafe::zeroed(); + let serialized = data.serialize(); + let deserialized = ContractDeploymentData::deserialize(serialized); + assert(data.eq(deserialized)); +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/header.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/header.nr index c67a3c03e38b..f5f38bceb4c0 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/header.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/header.nr @@ -37,6 +37,15 @@ struct Header { } // docs:end:header +impl Eq for Header { + fn eq(self, other: Self) -> bool { + self.last_archive.eq(other.last_archive) & + (self.body_hash == other.body_hash) & + self.state.eq(other.state) & + self.global_variables.eq(other.global_variables) + } +} + impl Serialize for Header { fn serialize(self) -> [Field; HEADER_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(0); @@ -92,10 +101,11 @@ impl Hash for Header { } #[test] -fn serialization_deserialization_smoke() { +fn serialization_of_empty() { let header: Header = dep::std::unsafe::zeroed(); - let _serialized = header.serialize(); - let _deserialized = Header::deserialize(_serialized); + let serialized = header.serialize(); + let deserialized = Header::deserialize(serialized); + assert(header.eq(deserialized)); } #[test] diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/partial_state_reference.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/partial_state_reference.nr index 7240ffed93d9..7e22fd8bee0a 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/partial_state_reference.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/partial_state_reference.nr @@ -76,7 +76,7 @@ impl Empty for PartialStateReference { } #[test] -fn serialization_deserialization_smoke() { +fn serialization_of_empty() { let partial: PartialStateReference = dep::std::unsafe::zeroed(); let _serialized = partial.serialize(); let _deserialized = PartialStateReference::deserialize(_serialized); diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/state_reference.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/state_reference.nr index 1a064bd681ba..99aa8a52d74f 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/state_reference.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/state_reference.nr @@ -68,7 +68,7 @@ impl Empty for StateReference { } #[test] -fn serialization_deserialization_smoke() { +fn serialization_of_empty() { let state: StateReference = dep::std::unsafe::zeroed(); let _serialized = state.serialize(); let _deserialized = StateReference::deserialize(_serialized);