Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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 @@
9be0ad6b41a69c35ad9737d60da7a16300b87642
ed815a3713fc311056a8bd0a616945f12d9be2a8
12 changes: 3 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ rand = "0.8.5"
proptest = "1.2.0"
proptest-derive = "0.4.0"


im = { version = "15.1", features = ["serde"] }
tracing = "0.1.40"
tracing-web = "0.1.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fn generate_compute_note_hash_and_optionally_a_nullifier_source(
format!(
"
unconstrained fn compute_note_hash_and_optionally_a_nullifier(
contract_address: aztec::protocol_types::address::AztecAddress,
contract_address: dep::aztec::protocol_types::address::AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
Expand All @@ -194,7 +194,7 @@ fn generate_compute_note_hash_and_optionally_a_nullifier_source(

let if_statements: Vec<String> = note_types.iter().map(|note_type| format!(
"if (note_type_id == {0}::get_note_type_id()) {{
aztec::note::utils::compute_note_hash_and_optionally_a_nullifier({0}::deserialize_content, note_header, compute_nullifier, serialized_note)
dep::aztec::note::utils::compute_note_hash_and_optionally_a_nullifier({0}::deserialize_content, note_header, compute_nullifier, serialized_note)
}}"
, note_type)).collect();

Expand All @@ -208,14 +208,14 @@ fn generate_compute_note_hash_and_optionally_a_nullifier_source(
format!(
"
unconstrained fn compute_note_hash_and_optionally_a_nullifier(
contract_address: aztec::protocol_types::address::AztecAddress,
contract_address: dep::aztec::protocol_types::address::AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
compute_nullifier: bool,
serialized_note: [Field; {}],
) -> pub [Field; 4] {{
let note_header = aztec::prelude::NoteHeader::new(contract_address, nonce, storage_slot);
let note_header = dep::aztec::prelude::NoteHeader::new(contract_address, nonce, storage_slot);

{}
}}",
Expand Down
16 changes: 8 additions & 8 deletions aztec_macros/src/transforms/contract_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use crate::utils::{
// for i in 0..third_arg.len() {
// args_acc = args_acc.append(third_arg[i].serialize().as_slice());
// }
// let args_hash = aztec::hash::hash_args(args_acc);
// assert(args_hash == aztec::oracle::arguments::pack_arguments(args_acc));
// let args_hash = dep::aztec::hash::hash_args(args_acc);
// assert(args_hash == dep::aztec::oracle::arguments::pack_arguments(args_acc));
// PublicCallInterface {
// target_contract: self.target_contract,
// selector: FunctionSelector::from_signature("SELECTOR_PLACEHOLDER"),
Expand All @@ -57,7 +57,7 @@ pub fn stub_function(aztec_visibility: &str, func: &NoirFunction, is_static_call
let fn_return_type: noirc_frontend::ast::UnresolvedType = func.return_type();

let fn_selector = format!(
"aztec::protocol_types::abis::function_selector::FunctionSelector::from_signature(\"{}\")",
"dep::aztec::protocol_types::abis::function_selector::FunctionSelector::from_signature(\"{}\")",
SELECTOR_PLACEHOLDER
);

Expand Down Expand Up @@ -137,8 +137,8 @@ pub fn stub_function(aztec_visibility: &str, func: &NoirFunction, is_static_call
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));",
let args_hash = dep::aztec::hash::hash_args(args_acc);
assert(args_hash == dep::aztec::oracle::arguments::pack_arguments(args_acc));",
call_args
)
} else {
Expand Down Expand Up @@ -234,14 +234,14 @@ pub fn generate_contract_interface(
let contract_interface = format!(
"
struct {0} {{
target_contract: aztec::protocol_types::address::AztecAddress
target_contract: dep::aztec::protocol_types::address::AztecAddress
}}

impl {0} {{
{1}

pub fn at(
target_contract: aztec::protocol_types::address::AztecAddress
target_contract: dep::aztec::protocol_types::address::AztecAddress
) -> Self {{
Self {{ target_contract }}
}}
Expand All @@ -255,7 +255,7 @@ pub fn generate_contract_interface(

#[contract_library_method]
pub fn at(
target_contract: aztec::protocol_types::address::AztecAddress
target_contract: dep::aztec::protocol_types::address::AztecAddress
) -> {0} {{
{0} {{ target_contract }}
}}
Expand Down
18 changes: 11 additions & 7 deletions aztec_macros/src/transforms/note_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ fn generate_note_get_header(
) -> Result<NoirFunction, AztecMacroError> {
let function_source = format!(
"
fn get_header(note: {}) -> aztec::note::note_header::NoteHeader {{
fn get_header(note: {}) -> dep::aztec::note::note_header::NoteHeader {{
note.{}
}}
",
Expand Down Expand Up @@ -303,7 +303,7 @@ fn generate_note_set_header(
) -> Result<NoirFunction, AztecMacroError> {
let function_source = format!(
"
fn set_header(self: &mut {}, header: aztec::note::note_header::NoteHeader) {{
fn set_header(self: &mut {}, header: dep::aztec::note::note_header::NoteHeader) {{
self.{} = header;
}}
",
Expand Down Expand Up @@ -493,7 +493,7 @@ fn generate_note_properties_fn(

// Automatically generate the method to compute the note's content hash as:
// fn compute_note_content_hash(self: NoteType) -> Field {
// aztec::hash::pedersen_hash(self.serialize_content(), aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH)
// dep::aztec::hash::pedersen_hash(self.serialize_content(), dep::aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH)
// }
//
fn generate_compute_note_content_hash(
Expand All @@ -503,7 +503,7 @@ fn generate_compute_note_content_hash(
let function_source = format!(
"
fn compute_note_content_hash(self: {}) -> Field {{
aztec::hash::pedersen_hash(self.serialize_content(), aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH)
dep::aztec::hash::pedersen_hash(self.serialize_content(), dep::aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH)
}}
",
note_type
Expand Down Expand Up @@ -562,7 +562,9 @@ fn generate_note_properties_struct_source(
.iter()
.filter_map(|(field_name, _)| {
if field_name != note_header_field_name {
Some(format!("{}: aztec::note::note_getter_options::PropertySelector", field_name))
Some(format!(
"{field_name}: dep::aztec::note::note_getter_options::PropertySelector"
))
} else {
None
}
Expand Down Expand Up @@ -590,7 +592,7 @@ fn generate_note_properties_fn_source(
.filter_map(|(index, (field_name, _))| {
if field_name != note_header_field_name {
Some(format!(
"{}: aztec::note::note_getter_options::PropertySelector {{ index: {}, offset: 0, length: 32 }}",
"{}: dep::aztec::note::note_getter_options::PropertySelector {{ index: {}, offset: 0, length: 32 }}",
field_name,
index
))
Expand Down Expand Up @@ -667,7 +669,9 @@ fn generate_note_deserialize_content_source(
)
}
} else {
format!("{}: aztec::note::note_header::NoteHeader::empty()", note_header_field_name)
format!(
"{note_header_field_name}: dep::aztec::note::note_header::NoteHeader::empty()"
)
}
})
.collect::<Vec<String>>()
Expand Down
2 changes: 1 addition & 1 deletion aztec_macros/src/utils/ast_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ macro_rules! chained_dep {
( $base:expr $(, $tail:expr)* ) => {
{
let mut base_path = ident_path($base);
base_path.kind = PathKind::Plain;
base_path.kind = PathKind::Dep;
$(
base_path.segments.push(ident($tail));
)*
Expand Down
52 changes: 7 additions & 45 deletions compiler/noirc_frontend/src/hir/resolution/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,12 @@ pub fn resolve_import(
import_directive: &ImportDirective,
def_maps: &BTreeMap<CrateId, CrateDefMap>,
) -> Result<ResolvedImport, PathResolutionError> {
let allow_contracts =
allow_referencing_contracts(def_maps, crate_id, import_directive.module_id);

let module_scope = import_directive.module_id;
let NamespaceResolution {
module_id: resolved_module,
namespace: resolved_namespace,
mut error,
} = resolve_path_to_ns(import_directive, crate_id, crate_id, def_maps, allow_contracts)?;
} = resolve_path_to_ns(import_directive, crate_id, crate_id, def_maps)?;

let name = resolve_path_name(import_directive);

Expand Down Expand Up @@ -129,34 +126,19 @@ pub fn resolve_import(
})
}

fn allow_referencing_contracts(
def_maps: &BTreeMap<CrateId, CrateDefMap>,
krate: CrateId,
local_id: LocalModuleId,
) -> bool {
ModuleId { krate, local_id }.module(def_maps).is_contract
}

fn resolve_path_to_ns(
import_directive: &ImportDirective,
crate_id: CrateId,
importing_crate: CrateId,
def_maps: &BTreeMap<CrateId, CrateDefMap>,
allow_contracts: bool,
) -> NamespaceResolutionResult {
let import_path = &import_directive.path.segments;
let def_map = &def_maps[&crate_id];

match import_directive.path.kind {
crate::ast::PathKind::Crate => {
// Resolve from the root of the crate
resolve_path_from_crate_root(
crate_id,
importing_crate,
import_path,
def_maps,
allow_contracts,
)
resolve_path_from_crate_root(crate_id, importing_crate, import_path, def_maps)
}
crate::ast::PathKind::Plain => {
// There is a possibility that the import path is empty
Expand All @@ -168,7 +150,6 @@ fn resolve_path_to_ns(
import_path,
import_directive.module_id,
def_maps,
allow_contracts,
);
}

Expand All @@ -177,13 +158,7 @@ fn resolve_path_to_ns(
let first_segment = import_path.first().expect("ice: could not fetch first segment");
if current_mod.find_name(first_segment).is_none() {
// Resolve externally when first segment is unresolved
return resolve_external_dep(
def_map,
import_directive,
def_maps,
allow_contracts,
importing_crate,
);
return resolve_external_dep(def_map, import_directive, def_maps, importing_crate);
}

resolve_name_in_module(
Expand All @@ -192,17 +167,12 @@ fn resolve_path_to_ns(
import_path,
import_directive.module_id,
def_maps,
allow_contracts,
)
}

crate::ast::PathKind::Dep => resolve_external_dep(
def_map,
import_directive,
def_maps,
allow_contracts,
importing_crate,
),
crate::ast::PathKind::Dep => {
resolve_external_dep(def_map, import_directive, def_maps, importing_crate)
}
}
}

Expand All @@ -212,15 +182,13 @@ fn resolve_path_from_crate_root(

import_path: &[Ident],
def_maps: &BTreeMap<CrateId, CrateDefMap>,
allow_contracts: bool,
) -> NamespaceResolutionResult {
resolve_name_in_module(
crate_id,
importing_crate,
import_path,
def_maps[&crate_id].root,
def_maps,
allow_contracts,
)
}

Expand All @@ -230,7 +198,6 @@ fn resolve_name_in_module(
import_path: &[Ident],
starting_mod: LocalModuleId,
def_maps: &BTreeMap<CrateId, CrateDefMap>,
allow_contracts: bool,
) -> NamespaceResolutionResult {
let def_map = &def_maps[&krate];
let mut current_mod_id = ModuleId { krate, local_id: starting_mod };
Expand Down Expand Up @@ -293,10 +260,6 @@ fn resolve_name_in_module(
return Err(PathResolutionError::Unresolved(current_segment.clone()));
}

// Check if it is a contract and we're calling from a non-contract context
if current_mod.is_contract && !allow_contracts {
return Err(PathResolutionError::ExternalContractUsed(current_segment.clone()));
}
current_ns = found_ns;
}

Expand All @@ -314,7 +277,6 @@ fn resolve_external_dep(
current_def_map: &CrateDefMap,
directive: &ImportDirective,
def_maps: &BTreeMap<CrateId, CrateDefMap>,
allow_contracts: bool,
importing_crate: CrateId,
) -> NamespaceResolutionResult {
// Use extern_prelude to get the dep
Expand Down Expand Up @@ -344,7 +306,7 @@ fn resolve_external_dep(
is_prelude: false,
};

resolve_path_to_ns(&dep_directive, dep_module.krate, importing_crate, def_maps, allow_contracts)
resolve_path_to_ns(&dep_directive, dep_module.krate, importing_crate, def_maps)
}

// Issue an error if the given private function is being called from a non-child module, or
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/how_to/how-to-oracles.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ server.addMethod("resolve_function_call", async (params) => {
if params.function !== "getSqrt" {
throw Error("Unexpected foreign call")
};
const values = params.inputs[0].Array.map((field) => {
const values = params.inputs[0].map((field) => {
return `${Math.sqrt(parseInt(field, 16))}`;
});
return { values: [{ Array: values }] };
return { values };
});
```

Expand Down Expand Up @@ -236,9 +236,9 @@ const foreignCallHandler = async (name, input) => {
// notice that the "inputs" parameter contains *all* the inputs
// in this case we to make the RPC request with the first parameter "numbers", which would be input[0]
const oracleReturn = await client.request(name, [
{ Array: input[0].map((i) => i.toString("hex")) },
input[0].map((i) => i.toString("hex")),
]);
return [oracleReturn.values[0].Array];
return { values: oracleReturn };
};

// the rest of your NoirJS code
Expand Down
2 changes: 1 addition & 1 deletion test_programs/benchmarks/bench_eddsa_poseidon/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ fn main(
s: Field
) -> pub bool {
eddsa_poseidon_verify(pub_key_x, pub_key_y, s, r8_x, r8_y, msg)
}
}
Loading