diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr index f68934ddb32..f8185f89aed 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_context.nr @@ -21,27 +21,17 @@ struct CallContext { impl CallContext { fn assert_is_zero(self) { - // TODO(https://github.com/AztecProtocol/aztec-packages/issues/3595) - assert(self.msg_sender.to_field() == 0); - assert(self.storage_contract_address.to_field() == 0); - assert(self.portal_contract_address.to_field() == 0); - assert(self.function_selector.to_field() == 0); - assert(self.is_delegate_call == false); - assert(self.is_static_call == false); - assert(self.side_effect_counter == 0); + let serialized: [Field; CALL_CONTEXT_LENGTH] = self.serialize(); + + for i in 0..CALL_CONTEXT_LENGTH { + assert(serialized[i] == 0); + } } } impl Eq for CallContext { - fn eq(self, call_context: CallContext) -> bool { - // TODO(https://github.com/AztecProtocol/aztec-packages/issues/3595) - call_context.msg_sender.eq(self.msg_sender) - & call_context.storage_contract_address.eq(self.storage_contract_address) - & call_context.portal_contract_address.eq(self.portal_contract_address) - & call_context.function_selector.eq(self.function_selector) - & (call_context.is_delegate_call == self.is_delegate_call) - & (call_context.is_static_call == self.is_static_call) - & (call_context.side_effect_counter == self.side_effect_counter) + fn eq(self, other: CallContext) -> bool { + self.serialize() == other.serialize() } } @@ -80,13 +70,58 @@ impl Deserialize for CallContext { } #[test] -fn serialization_of_empty() { +fn serialize_deserialize_of_empty() { let context: CallContext = dep::std::unsafe::zeroed(); let serialized = context.serialize(); let deserialized = CallContext::deserialize(serialized); assert(context.eq(deserialized)); } +#[test] +fn assert_is_zero() { + let context: CallContext = dep::std::unsafe::zeroed(); + context.assert_is_zero(); +} + +#[test(should_fail)] +fn not_zero_assert_is_zero() { + let mut context: CallContext = dep::std::unsafe::zeroed(); + context.is_delegate_call = true; + context.assert_is_zero(); +} + +#[test] +fn test_eq() { + let mut context1: CallContext = dep::std::unsafe::zeroed(); + let mut context2: CallContext = dep::std::unsafe::zeroed(); + + context1.is_delegate_call = true; + context2.is_delegate_call = true; + + let address: AztecAddress = AztecAddress::from_field(69420); + context1.msg_sender = address; + context2.msg_sender = address; + + assert(context1.eq(context2)); +} + +#[test(should_fail)] +fn not_eq_test_eq() { + let mut context1: CallContext = dep::std::unsafe::zeroed(); + let mut context2: CallContext = dep::std::unsafe::zeroed(); + + context1.is_delegate_call = true; + context2.is_delegate_call = false; + + let address1: AztecAddress = AztecAddress::from_field(69420); + let address2: AztecAddress = AztecAddress::from_field(42069); + + context1.msg_sender = address1; + context2.msg_sender = address2; + + assert(context1.eq(context2)); +} + #[test] fn hash_smoke() { let context: CallContext = dep::std::unsafe::zeroed();