Skip to content

Commit

Permalink
fix: Allow importing notes from other contracts and inject them in th…
Browse files Browse the repository at this point in the history
…e macros (#7349)

Removes an overzealous check that prevented pulling note structs from
imported contract dependencies. Since we make sure we only import the
same struct once from the "closest" source to the root crate, it should
be ok to pull notes from them (at least to generate
`compute_note_hash_and_optionally_a_nullifier`. God I hate that name)
  • Loading branch information
Thunkar authored Jul 5, 2024
1 parent 783d9b6 commit 586c0b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
2 changes: 1 addition & 1 deletion noir-projects/noir-contracts/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ members = [
"contracts/uniswap_contract",
"contracts/multi_call_entrypoint_contract",
"contracts/static_child_contract",
"contracts/static_parent_contract"
"contracts/static_parent_contract",
]
37 changes: 12 additions & 25 deletions noir/noir-repo/aztec_macros/src/utils/hir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,28 +269,19 @@ 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,
) -> 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 @@ 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
}
})
})
}

Expand Down

0 comments on commit 586c0b0

Please sign in to comment.