From 633a3a0686d3b4811ae37482ffcb544f01e27624 Mon Sep 17 00:00:00 2001 From: Gregorio Juliana Date: Wed, 25 Sep 2024 16:48:02 +0200 Subject: [PATCH] chore: cleanup call interfaces and calldata_copy warnings (#8777) Almost ready to compile with warnings, pending https://github.com/noir-lang/noir/pull/6149 --- .../aztec/src/context/call_interfaces.nr | 80 +++++++++++++++---- .../aztec/src/context/public_context.nr | 2 +- .../aztec/src/macros/functions/interfaces.nr | 14 +++- 3 files changed, 76 insertions(+), 20 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/context/call_interfaces.nr b/noir-projects/aztec-nr/aztec/src/context/call_interfaces.nr index a540488b158..49d5a424ac0 100644 --- a/noir-projects/aztec-nr/aztec/src/context/call_interfaces.nr +++ b/noir-projects/aztec-nr/aztec/src/context/call_interfaces.nr @@ -53,7 +53,10 @@ pub struct PrivateCallInterface { impl PrivateCallInterface { pub fn call(self, context: &mut PrivateContext) -> T where T: Deserialize { - assert(self.args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(self.args_hash == packed_args_hash); let returns = context.call_private_function_with_packed_args( self.target_contract, self.selector, @@ -66,13 +69,19 @@ impl PrivateCallInterface { } pub fn view(self, context: &mut PrivateContext) -> T where T: Deserialize { - assert(self.args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(self.args_hash == packed_args_hash); let returns = context.call_private_function_with_packed_args(self.target_contract, self.selector, self.args_hash, true, false); returns.unpack_into() } pub fn delegate_call(self, context: &mut PrivateContext) -> T where T: Deserialize { - assert(self.args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(self.args_hash == packed_args_hash); let returns = context.call_private_function_with_packed_args(self.target_contract, self.selector, self.args_hash, false, true); returns.unpack_into() } @@ -96,7 +105,10 @@ pub struct PrivateVoidCallInterface { impl PrivateVoidCallInterface { pub fn call(self, context: &mut PrivateContext) { - assert(self.args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(self.args_hash == packed_args_hash); context.call_private_function_with_packed_args( self.target_contract, self.selector, @@ -107,12 +119,18 @@ impl PrivateVoidCallInterface { } pub fn view(self, context: &mut PrivateContext) { - assert(self.args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(self.args_hash == packed_args_hash); context.call_private_function_with_packed_args(self.target_contract, self.selector, self.args_hash, true, false).assert_empty(); } pub fn delegate_call(self, context: &mut PrivateContext) { - assert(self.args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(self.args_hash == packed_args_hash); context.call_private_function_with_packed_args(self.target_contract, self.selector, self.args_hash, false, true).assert_empty(); } } @@ -135,7 +153,10 @@ pub struct PrivateStaticCallInterface { impl PrivateStaticCallInterface { pub fn view(self, context: &mut PrivateContext) -> T where T: Deserialize { - assert(self.args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(self.args_hash == packed_args_hash); let returns = context.call_private_function_with_packed_args(self.target_contract, self.selector, self.args_hash, true, false); returns.unpack_into() } @@ -159,7 +180,10 @@ pub struct PrivateStaticVoidCallInterface { impl PrivateStaticVoidCallInterface { pub fn view(self, context: &mut PrivateContext) { - assert(self.args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(self.args_hash == packed_args_hash); context.call_private_function_with_packed_args(self.target_contract, self.selector, self.args_hash, true, false).assert_empty(); } } @@ -203,7 +227,10 @@ impl PublicCallInterface { pub fn enqueue(self, context: &mut PrivateContext) { let args_hash = hash_args(self.args); - assert(args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(args_hash == packed_args_hash); context.call_public_function_with_packed_args( self.target_contract, self.selector, @@ -215,7 +242,10 @@ impl PublicCallInterface { pub fn enqueue_view(self, context: &mut PrivateContext) { let args_hash = hash_args(self.args); - assert(args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(args_hash == packed_args_hash); context.call_public_function_with_packed_args( self.target_contract, self.selector, @@ -227,7 +257,10 @@ impl PublicCallInterface { pub fn delegate_enqueue(self, context: &mut PrivateContext) { let args_hash = hash_args(self.args); - assert(args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(args_hash == packed_args_hash); context.call_public_function_with_packed_args( self.target_contract, self.selector, @@ -277,7 +310,10 @@ impl PublicVoidCallInterface { pub fn enqueue(self, context: &mut PrivateContext) { let args_hash = hash_args(self.args); - assert(args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(args_hash == packed_args_hash); context.call_public_function_with_packed_args( self.target_contract, self.selector, @@ -289,7 +325,10 @@ impl PublicVoidCallInterface { pub fn enqueue_view(self, context: &mut PrivateContext) { let args_hash = hash_args(self.args); - assert(args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(args_hash == packed_args_hash); context.call_public_function_with_packed_args( self.target_contract, self.selector, @@ -301,7 +340,10 @@ impl PublicVoidCallInterface { pub fn delegate_enqueue(self, context: &mut PrivateContext) { let args_hash = hash_args(self.args); - assert(args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(args_hash == packed_args_hash); context.call_public_function_with_packed_args( self.target_contract, self.selector, @@ -342,7 +384,10 @@ impl PublicStaticCallInterface { pub fn enqueue_view(self, context: &mut PrivateContext) { let args_hash = hash_args(self.args); - assert(args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(args_hash == packed_args_hash); context.call_public_function_with_packed_args( self.target_contract, self.selector, @@ -382,7 +427,10 @@ impl PublicStaticVoidCallInterface { pub fn enqueue_view(self, context: &mut PrivateContext) { let args_hash = hash_args(self.args); - assert(args_hash == pack_arguments(self.args)); + let packed_args_hash = unsafe { + pack_arguments(self.args) + }; + assert(args_hash == packed_args_hash); context.call_public_function_with_packed_args( self.target_contract, self.selector, diff --git a/noir-projects/aztec-nr/aztec/src/context/public_context.nr b/noir-projects/aztec-nr/aztec/src/context/public_context.nr index fa32f86967f..0a3da729960 100644 --- a/noir-projects/aztec-nr/aztec/src/context/public_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/public_context.nr @@ -288,7 +288,7 @@ unconstrained fn call_static( call_static_opcode(gas, address, args, function_selector) } -unconstrained fn calldata_copy(cdoffset: u32, copy_size: u32) -> [Field; N] { +unconstrained pub fn calldata_copy(cdoffset: u32, copy_size: u32) -> [Field; N] { calldata_copy_opcode(cdoffset, copy_size) } diff --git a/noir-projects/aztec-nr/aztec/src/macros/functions/interfaces.nr b/noir-projects/aztec-nr/aztec/src/macros/functions/interfaces.nr index ecd4fe1fe41..25486c1d07a 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/functions/interfaces.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/functions/interfaces.nr @@ -146,9 +146,17 @@ pub comptime fn stub_fn(f: FunctionDefinition) -> Quoted { } else { parameter_names_list.join(quote {,}) }; - let original = quote { - | inputs: $input_type | -> $return_type_hint { - $fn_name($parameter_names) + let original = if is_fn_private(f) { + quote { + | inputs: $input_type | -> $return_type_hint { + $fn_name($parameter_names) + } + } + } else { + quote { + | _: $input_type | -> $return_type_hint { + unsafe { $fn_name($parameter_names) } + } } };