diff --git a/.aztec-sync-commit b/.aztec-sync-commit index b28ae5a3b99..34501cf4146 100644 --- a/.aztec-sync-commit +++ b/.aztec-sync-commit @@ -1 +1 @@ -10076d9663dcf40ac712df69e3a71a1bb54866e2 +c7b1ae40593c24530723f344111459a51ad5f0e5 diff --git a/aztec_macros/src/transforms/contract_interface.rs b/aztec_macros/src/transforms/contract_interface.rs index b9323644379..e79cee66407 100644 --- a/aztec_macros/src/transforms/contract_interface.rs +++ b/aztec_macros/src/transforms/contract_interface.rs @@ -35,7 +35,15 @@ use crate::utils::{ // PublicCallInterface { // target_contract: self.target_contract, // selector: FunctionSelector::from_signature("SELECTOR_PLACEHOLDER"), -// args_hash +// args_hash, +// name: "a_function", +// args_hash, +// args: args_acc, +// original: | inputs: dep::aztec::context::inputs::PublicContextInputs | -> Field { +// a_function(inputs, first_arg, second_arg, third_arg) +// }, +// is_static: false, +// gas_opts: dep::aztec::context::gas::GasOpts::default() // } // } // @@ -132,73 +140,48 @@ pub fn stub_function(aztec_visibility: &str, func: &NoirFunction, is_static_call format!("{}, {}>", return_type_hint, arg_types) }; - let fn_body = if aztec_visibility != "Public" { - let args_hash = if !parameters.is_empty() { - format!( - "let mut args_acc: [Field] = &[]; - {} - let args_hash = aztec::hash::hash_args(args_acc); - assert(args_hash == aztec::oracle::arguments::pack_arguments(args_acc));", - call_args - ) + let args = format!( + "let mut args_acc: [Field] = &[]; + {} + {}", + call_args, + if aztec_visibility == "Private" { + "let args_hash = aztec::hash::hash_args(args_acc);" } else { - " - let mut args_acc: [Field] = &[]; - let args_hash = 0; - " - .to_string() - }; - - format!( - "{} - let selector = {}; - dep::aztec::context::{}{}{}CallInterface {{ - target_contract: self.target_contract, - selector, - name: \"{}\", - args_hash, - args: args_acc, - original: {}, - is_static: {} - }}", - args_hash, - fn_selector, - aztec_visibility, - is_static, - is_void, - fn_name, - original, - is_static_call - ) + "" + } + ); + + let gas_opts = if aztec_visibility == "Public" { + "gas_opts: dep::aztec::context::gas::GasOpts::default()" } else { - let args = format!( - "let mut args_acc: [Field] = &[]; - {} - ", - call_args - ); - format!( - "{} + "" + }; + + let fn_body = format!( + "{} let selector = {}; dep::aztec::context::{}{}{}CallInterface {{ target_contract: self.target_contract, selector, name: \"{}\", + {} args: args_acc, - gas_opts: dep::aztec::context::gas::GasOpts::default(), original: {}, - is_static: {} + is_static: {}, + {} }}", - args, - fn_selector, - aztec_visibility, - is_static, - is_void, - fn_name, - original, - is_static_call - ) - }; + args, + fn_selector, + aztec_visibility, + is_static, + is_void, + fn_name, + if aztec_visibility == "Private" { "args_hash," } else { "" }, + original, + is_static_call, + gas_opts + ); format!( "pub fn {}(self, {}) -> dep::aztec::context::{}{}{}CallInterface<{},{} {{ diff --git a/aztec_macros/src/utils/hir_utils.rs b/aztec_macros/src/utils/hir_utils.rs index 3f47fe5ca25..7198ed5bd3d 100644 --- a/aztec_macros/src/utils/hir_utils.rs +++ b/aztec_macros/src/utils/hir_utils.rs @@ -269,20 +269,12 @@ pub fn fully_qualified_note_path(context: &HirContext, note_id: StructId) -> Opt if &module_id.krate == context.root_crate_id() { Some(module_path) } else { - find_non_contract_dependencies_bfs(context, context.root_crate_id(), &module_id.krate) + find_dependencies_bfs(context, context.root_crate_id(), &module_id.krate) .map(|crates| crates.join("::") + "::" + &module_path) } } -fn filter_contract_modules(context: &HirContext, crate_id: &CrateId) -> bool { - if let Some(def_map) = context.def_map(crate_id) { - !def_map.modules().iter().any(|(_, module)| module.is_contract) - } else { - true - } -} - -fn find_non_contract_dependencies_bfs( +fn find_dependencies_bfs( context: &HirContext, crate_id: &CrateId, target_crate_id: &CrateId, @@ -290,7 +282,6 @@ fn find_non_contract_dependencies_bfs( context.crate_graph[crate_id] .dependencies .iter() - .filter(|dep| filter_contract_modules(context, &dep.crate_id)) .find_map(|dep| { if &dep.crate_id == target_crate_id { Some(vec![dep.name.to_string()]) @@ -299,20 +290,16 @@ fn find_non_contract_dependencies_bfs( } }) .or_else(|| { - context.crate_graph[crate_id] - .dependencies - .iter() - .filter(|dep| filter_contract_modules(context, &dep.crate_id)) - .find_map(|dep| { - if let Some(mut path) = - find_non_contract_dependencies_bfs(context, &dep.crate_id, target_crate_id) - { - path.insert(0, dep.name.to_string()); - Some(path) - } else { - None - } - }) + context.crate_graph[crate_id].dependencies.iter().find_map(|dep| { + if let Some(mut path) = + find_dependencies_bfs(context, &dep.crate_id, target_crate_id) + { + path.insert(0, dep.name.to_string()); + Some(path) + } else { + None + } + }) }) }