Skip to content

Commit af855d1

Browse files
author
AztecBot
committed
Merge branch 'next' into merge-train/avm
2 parents 14f3ecd + 0eec8b7 commit af855d1

File tree

3 files changed

+36
-67
lines changed

3 files changed

+36
-67
lines changed

noir-projects/aztec-nr/aztec/src/context/calls.nr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ use crate::context::{gas::GasOpts, private_context::PrivateContext, public_conte
88
use crate::hash::{hash_args, hash_calldata_array};
99
use crate::oracle::execution_cache;
1010

11+
// Having T associated on the structs and then instantiating it with `std::mem::zeroed()` is ugly but we need to do it
12+
// like this to avoid forcing users to specify the return type when calling functions on the structs (that's the only
13+
// way how we can specify the type when we generate the call stubs. The return types are specified in
14+
// the `external_functions_stubs.nr` file.)
15+
1116
// PrivateCall
1217

1318
#[must_use = "Your private call needs to be passed into the `self.call(...)` method to be executed (e.g. `self.call(MyContract::at(address).my_private_function(...args))`"]

noir-projects/aztec-nr/aztec/src/contract_self.nr

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,7 @@ impl<Storage, CallSelf, EnqueueSelf, CallSelfStatic, EnqueueSelfStatic, CallInte
333333
///
334334
/// # Arguments
335335
/// * `call` - The interface representing the public function to enqueue.
336-
///
337-
/// TODO(F-131): We should drop T from here because it is strange as there
338-
/// is no return value. The PublicCall type seems to be defined
339-
/// incorrectly.
340-
pub fn enqueue<let M: u32, let N: u32, T>(&mut self, call: PublicCall<M, N, T>)
341-
where
342-
T: Deserialize,
343-
{
336+
pub fn enqueue<let M: u32, let N: u32, T>(&mut self, call: PublicCall<M, N, T>) {
344337
call.enqueue(self.context)
345338
}
346339

@@ -357,14 +350,7 @@ impl<Storage, CallSelf, EnqueueSelf, CallSelfStatic, EnqueueSelfStatic, CallInte
357350
/// ```noir
358351
/// self.enqueue_view(MyContract::at(address).assert_timestamp_less_than(timestamp));
359352
/// ```
360-
///
361-
/// TODO(F-131): We should drop T from here because it is strange as there
362-
/// is no return value. The PublicCall type seems to be defined
363-
/// incorrectly.
364-
pub fn enqueue_view<let M: u32, let N: u32, T>(&mut self, call: PublicStaticCall<M, N, T>)
365-
where
366-
T: Deserialize,
367-
{
353+
pub fn enqueue_view<let M: u32, let N: u32, T>(&mut self, call: PublicStaticCall<M, N, T>) {
368354
call.enqueue_view(self.context)
369355
}
370356

@@ -411,13 +397,7 @@ impl<Storage, CallSelf, EnqueueSelf, CallSelfStatic, EnqueueSelfStatic, CallInte
411397
/// aztec-nr will translate NULL_MSG_SENDER_CONTRACT_ADDRESS into
412398
/// `Option<AztecAddress>::none` for familiarity to devs.
413399
///
414-
/// TODO(F-131): We should drop T from here because it is strange as there
415-
/// is no return value. The PublicCall type seems to be defined
416-
/// incorrectly.
417-
pub fn enqueue_incognito<let M: u32, let N: u32, T>(&mut self, call: PublicCall<M, N, T>)
418-
where
419-
T: Deserialize,
420-
{
400+
pub fn enqueue_incognito<let M: u32, let N: u32, T>(&mut self, call: PublicCall<M, N, T>) {
421401
call.enqueue_incognito(self.context)
422402
}
423403

@@ -436,16 +416,10 @@ impl<Storage, CallSelf, EnqueueSelf, CallSelfStatic, EnqueueSelfStatic, CallInte
436416
/// self.enqueue_view_incognito(MyContract::at(address).assert_timestamp_less_than(timestamp));
437417
/// ```
438418
///
439-
/// TODO(F-131): We should drop T from here because it is strange as there
440-
/// is no return value. The PublicCall type seems to be defined
441-
/// incorrectly.
442419
pub fn enqueue_view_incognito<let M: u32, let N: u32, T>(
443420
&mut self,
444421
call: PublicStaticCall<M, N, T>,
445-
)
446-
where
447-
T: Deserialize,
448-
{
422+
) {
449423
call.enqueue_view_incognito(self.context)
450424
}
451425

@@ -478,13 +452,7 @@ impl<Storage, CallSelf, EnqueueSelf, CallSelfStatic, EnqueueSelfStatic, CallInte
478452
/// # Arguments
479453
/// * `call` - The object representing the public function to designate as teardown.
480454
///
481-
/// TODO(F-131): We should drop T from here because it is strange as there
482-
/// is no return value. The PublicCall type seems to be defined
483-
/// incorrectly.
484-
pub fn set_as_teardown<let M: u32, let N: u32, T>(&mut self, call: PublicCall<M, N, T>)
485-
where
486-
T: Deserialize,
487-
{
455+
pub fn set_as_teardown<let M: u32, let N: u32, T>(&mut self, call: PublicCall<M, N, T>) {
488456
call.set_as_teardown(self.context)
489457
}
490458

@@ -497,16 +465,10 @@ impl<Storage, CallSelf, EnqueueSelf, CallSelfStatic, EnqueueSelfStatic, CallInte
497465
///
498466
/// See `enqueue_incognito` for more details relating to hiding msg_sender.
499467
///
500-
/// TODO(F-131): We should drop T from here because it is strange as there
501-
/// is no return value. The PublicCall type seems to be defined
502-
/// incorrectly.
503468
pub fn set_as_teardown_incognito<let M: u32, let N: u32, T>(
504469
&mut self,
505470
call: PublicCall<M, N, T>,
506-
)
507-
where
508-
T: Deserialize,
509-
{
471+
) {
510472
call.set_as_teardown_incognito(self.context)
511473
}
512474
}

noir-projects/aztec-nr/aztec/src/macros/calls_generation/external_functions_stubs.nr

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,9 @@ pub(crate) comptime fn create_utility_stub(f: FunctionDefinition) -> Quoted {
153153
}
154154
}
155155

156-
// Self-call stub generation functions for CallSelf, CallSelfStatic, EnqueueSelf and EnqueueSelfStatic structs
157-
158-
// Note: Unlike for the call registry, the self-call registry stubs directly perform the call instead of returning a
159-
// call interface struct.
160-
// TODO(F-131): This ^ is confusing and should be reflected in the naming.
156+
// Self-call stub generation functions for CallSelf, CallSelfStatic, EnqueueSelf, and EnqueueSelfStatic structs.
157+
// Unlike the stubs above, the self-call stubs directly perform the call instead of returning a struct that can
158+
// be later used to perform the call.
161159

162160
/// Creates a stub for calling a private function (or static private function if `is_static` is true) from private
163161
/// context (for CallSelf<&mut PrivateContext> and CallSelfStatic<&mut PrivateContext>).
@@ -183,18 +181,15 @@ pub comptime fn create_private_self_call_stub(f: FunctionDefinition, is_static:
183181
}
184182
}
185183

186-
// TODO(F-131): Drop the use of the Call in the following 4 functions - it doesn't make sense to not not
187-
// perform the call directly using the context. I tried doing this already but it became a lot of pain due to the use of
188-
// slices and them being illegal to return from unconstrained functions. Makes sense to tackle this when cleaning up the
189-
// call interface code.
190-
// Note: Once we get rid of the structs we will be able to merge some of the static and non-static stub functions.
191-
192184
/// Creates a stub for calling a public function from public context (for CallSelf<PublicContext>)
193185
pub comptime fn create_public_self_call_stub(f: FunctionDefinition) -> Quoted {
194186
let (fn_name, fn_parameters_list, serialized_args_array_construction, serialized_args_array_name, _, fn_name_str, _, fn_selector) =
195187
create_stub_base(f);
196188
let fn_return_type = f.return_type();
197189

190+
// TODO: It makes sense to drop the use of PublicStaticCall struct here and just perform the call directly but
191+
// before doing that we need to drop the use of slices from return values because we cannot return slices from
192+
// an unconstrained function. This is not a priority right now.
198193
quote {
199194
pub fn $fn_name(self, $fn_parameters_list) -> $fn_return_type {
200195
$serialized_args_array_construction
@@ -217,6 +212,9 @@ pub comptime fn create_public_self_call_static_stub(f: FunctionDefinition) -> Qu
217212
create_stub_base(f);
218213
let fn_return_type = f.return_type();
219214

215+
// TODO: It makes sense to drop the use of PublicStaticCall struct here and just perform the call directly but
216+
// before doing that we need to drop the use of slices from return values because we cannot return slices from
217+
// an unconstrained function. This is not a priority right now.
220218
quote {
221219
pub fn $fn_name(self, $fn_parameters_list) -> $fn_return_type {
222220
$serialized_args_array_construction
@@ -235,40 +233,44 @@ pub comptime fn create_public_self_call_static_stub(f: FunctionDefinition) -> Qu
235233

236234
/// Creates a static stub for enqueuing a public view function from private context (for EnqueueSelfStatic<&mut PrivateContext>)
237235
pub comptime fn create_public_self_enqueue_static_stub(f: FunctionDefinition) -> Quoted {
238-
let (fn_name, fn_parameters_list, serialized_args_array_construction, serialized_args_array_name, serialized_args_array_len, fn_name_str, fn_name_len, fn_selector) =
236+
let (fn_name, fn_parameters_list, serialized_args_array_construction, serialized_args_array_name, _serialized_args_array_len, _fn_name_str, _fn_name_len, fn_selector) =
239237
create_stub_base(f);
240238

241239
quote {
242240
pub fn $fn_name(self, $fn_parameters_list) {
243241
$serialized_args_array_construction
244242
let selector = $FROM_FIELD($fn_selector);
245-
let interface: aztec::context::calls::PublicStaticCall<$fn_name_len, $serialized_args_array_len, ()> = aztec::context::calls::PublicStaticCall::new(
243+
let calldata = [aztec::protocol_types::traits::ToField::to_field(selector)].concat($serialized_args_array_name);
244+
let calldata_hash = aztec::hash::hash_calldata_array(calldata);
245+
aztec::oracle::execution_cache::store(calldata, calldata_hash);
246+
self.context.call_public_function_with_calldata_hash(
246247
self.address,
247-
selector,
248-
$fn_name_str,
249-
$serialized_args_array_name,
248+
calldata_hash,
249+
/*is_static_call=*/ true,
250+
/*hide_msg_sender=*/ false,
250251
);
251-
interface.enqueue_view(self.context);
252252
}
253253
}
254254
}
255255

256256
/// Creates a stub for enqueuing a public function from private context (for EnqueueSelf<&mut PrivateContext>)
257257
pub comptime fn create_public_self_enqueue_stub(f: FunctionDefinition) -> Quoted {
258-
let (fn_name, fn_parameters_list, serialized_args_array_construction, serialized_args_array_name, serialized_args_array_len, fn_name_str, fn_name_len, fn_selector) =
258+
let (fn_name, fn_parameters_list, serialized_args_array_construction, serialized_args_array_name, _serialized_args_array_len, _fn_name_str, _fn_name_len, fn_selector) =
259259
create_stub_base(f);
260260

261261
quote {
262262
pub fn $fn_name(self, $fn_parameters_list) {
263263
$serialized_args_array_construction
264264
let selector = $FROM_FIELD($fn_selector);
265-
let interface: aztec::context::calls::PublicCall<$fn_name_len, $serialized_args_array_len, ()> = aztec::context::calls::PublicCall::new(
265+
let calldata = [aztec::protocol_types::traits::ToField::to_field(selector)].concat($serialized_args_array_name);
266+
let calldata_hash = aztec::hash::hash_calldata_array(calldata);
267+
aztec::oracle::execution_cache::store(calldata, calldata_hash);
268+
self.context.call_public_function_with_calldata_hash(
266269
self.address,
267-
selector,
268-
$fn_name_str,
269-
$serialized_args_array_name,
270+
calldata_hash,
271+
/*is_static_call=*/ false,
272+
/*hide_msg_sender=*/ false,
270273
);
271-
interface.enqueue(self.context);
272274
}
273275
}
274276
}

0 commit comments

Comments
 (0)