Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Sync from aztec-packages #5432

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10076d9663dcf40ac712df69e3a71a1bb54866e2
c7b1ae40593c24530723f344111459a51ad5f0e5
99 changes: 41 additions & 58 deletions aztec_macros/src/transforms/contract_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
// }
// }
//
Expand Down Expand Up @@ -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<{},{} {{
Expand Down
37 changes: 12 additions & 25 deletions aztec_macros/src/utils/hir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,28 +269,19 @@
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,
) -> Option<Vec<String>> {
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()])
Expand All @@ -299,20 +290,16 @@
}
})
.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
}
})
})
}

Expand Down Expand Up @@ -360,7 +347,7 @@
}
}

pub fn get_global_numberic_const(

Check warning on line 350 in aztec_macros/src/utils/hir_utils.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (numberic)
context: &HirContext,
const_name: &str,
) -> Result<u128, MacroError> {
Expand Down
Loading