Skip to content

Commit

Permalink
feat: Sync from aztec-packages (noir-lang#5377)
Browse files Browse the repository at this point in the history
Automated pull of Noir development from
[aztec-packages](https://github.com/AztecProtocol/aztec-packages).
BEGIN_COMMIT_OVERRIDE
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <[email protected]>
Co-authored-by: Tom French <[email protected]>
  • Loading branch information
3 people authored Jul 1, 2024
1 parent 076fe0a commit 7b77bbf
Show file tree
Hide file tree
Showing 51 changed files with 76 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ed815a3713fc311056a8bd0a616945f12d9be2a8
eb9e9f6f2b3952760822faaacb7e851e936e0800
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: dep::aztec::protocol_types::address::AztecAddress,
contract_address: 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()) {{
dep::aztec::note::utils::compute_note_hash_and_optionally_a_nullifier({0}::deserialize_content, note_header, compute_nullifier, serialized_note)
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: dep::aztec::protocol_types::address::AztecAddress,
contract_address: 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 = dep::aztec::prelude::NoteHeader::new(contract_address, nonce, storage_slot);
let note_header = aztec::prelude::NoteHeader::new(contract_address, nonce, storage_slot);
{}
}}",
Expand Down
14 changes: 7 additions & 7 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 = dep::aztec::hash::hash_args(args_acc);
// assert(args_hash == dep::aztec::oracle::arguments::pack_arguments(args_acc));
// let args_hash = aztec::hash::hash_args(args_acc);
// assert(args_hash == aztec::oracle::arguments::pack_arguments(args_acc));
// PublicCallInterface {
// target_contract: self.target_contract,
// 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 = dep::aztec::hash::hash_args(args_acc);
assert(args_hash == dep::aztec::oracle::arguments::pack_arguments(args_acc));",
let args_hash = aztec::hash::hash_args(args_acc);
assert(args_hash == 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: dep::aztec::protocol_types::address::AztecAddress
target_contract: aztec::protocol_types::address::AztecAddress
}}
impl {0} {{
{1}
pub fn at(
target_contract: dep::aztec::protocol_types::address::AztecAddress
target_contract: 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: dep::aztec::protocol_types::address::AztecAddress
target_contract: aztec::protocol_types::address::AztecAddress
) -> {0} {{
{0} {{ target_contract }}
}}
Expand Down
10 changes: 5 additions & 5 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: {}) -> dep::aztec::note::note_header::NoteHeader {{
fn get_header(note: {}) -> 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: dep::aztec::note::note_header::NoteHeader) {{
fn set_header(self: &mut {}, header: 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 {
// dep::aztec::hash::pedersen_hash(self.serialize_content(), dep::aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH)
// aztec::hash::pedersen_hash(self.serialize_content(), 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 {{
dep::aztec::hash::pedersen_hash(self.serialize_content(), dep::aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH)
aztec::hash::pedersen_hash(self.serialize_content(), aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH)
}}
",
note_type
Expand Down Expand Up @@ -592,7 +592,7 @@ fn generate_note_properties_fn_source(
.filter_map(|(index, (field_name, _))| {
if field_name != note_header_field_name {
Some(format!(
"{}: dep::aztec::note::note_getter_options::PropertySelector {{ index: {}, offset: 0, length: 32 }}",
"{}: aztec::note::note_getter_options::PropertySelector {{ index: {}, offset: 0, length: 32 }}",
field_name,
index
))
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::Dep;
base_path.kind = PathKind::Plain;
$(
base_path.segments.push(ident($tail));
)*
Expand Down
7 changes: 0 additions & 7 deletions compiler/noirc_frontend/src/hir/resolution/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ pub(crate) type PathResolutionResult = Result<PathResolution, PathResolutionErro
pub enum PathResolutionError {
#[error("Could not resolve '{0}' in path")]
Unresolved(Ident),
#[error("Contract variable '{0}' referenced from outside the contract")]
ExternalContractUsed(Ident),
#[error("{0} is private and not visible from the current module")]
Private(Ident),
}
Expand Down Expand Up @@ -68,11 +66,6 @@ impl<'a> From<&'a PathResolutionError> for CustomDiagnostic {
PathResolutionError::Unresolved(ident) => {
CustomDiagnostic::simple_error(error.to_string(), String::new(), ident.span())
}
PathResolutionError::ExternalContractUsed(ident) => CustomDiagnostic::simple_error(
error.to_string(),
"Contracts may only be referenced from within a contract".to_string(),
ident.span(),
),
// This will be upgraded to an error in future versions
PathResolutionError::Private(ident) => CustomDiagnostic::simple_warning(
error.to_string(),
Expand Down
6 changes: 2 additions & 4 deletions compiler/noirc_frontend/src/hir/resolution/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ pub(crate) fn resolve_traits(
traits: BTreeMap<TraitId, UnresolvedTrait>,
crate_id: CrateId,
) -> Vec<(CompilationError, FileId)> {
for (trait_id, unresolved_trait) in &traits {
context.def_interner.push_empty_trait(*trait_id, unresolved_trait, vec![]);
}
let mut all_errors = Vec::new();

for (trait_id, unresolved_trait) in traits {
Expand All @@ -49,6 +46,8 @@ pub(crate) fn resolve_traits(
);
let generic_type_vars = generics.iter().map(|generic| generic.type_var.clone()).collect();

context.def_interner.push_empty_trait(trait_id, &unresolved_trait, generics);

// Resolve order
// 1. Trait Types ( Trait constants can have a trait type, therefore types before constants)
let _ = resolve_trait_types(context, crate_id, &unresolved_trait);
Expand All @@ -67,7 +66,6 @@ pub(crate) fn resolve_traits(

context.def_interner.update_trait(trait_id, |trait_def| {
trait_def.set_methods(methods);
trait_def.generics = generics;
});

// This check needs to be after the trait's methods are set since
Expand Down
4 changes: 3 additions & 1 deletion compiler/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ impl<'interner> Monomorphizer<'interner> {
Definition::Oracle(opcode.to_string())
}
FunctionKind::Recursive => {
unreachable!("Only main can be specified as recursive, which should already be checked");
let id =
self.queue_function(id, expr_id, typ, turbofish_generics, trait_method);
Definition::Function(id)
}
}
}
Expand Down
4 changes: 2 additions & 2 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].map((field) => {
const values = params.inputs[0].Array.map((field) => {
return `${Math.sqrt(parseInt(field, 16))}`;
});
return { values };
return { values: [{ Array: values }] };
});
```

Expand Down
1 change: 0 additions & 1 deletion noir_stdlib/src/hash/mimc.nr
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ global MIMC_BN254_CONSTANTS: [Field; MIMC_BN254_ROUNDS] = [

//mimc implementation with hardcoded parameters for BN254 curve.
#[field(bn254)]
#[no_predicates]
pub fn mimc_bn254<let N: u32>(array: [Field; N]) -> Field {
let exponent = 7;
let mut r = 0;
Expand Down
17 changes: 0 additions & 17 deletions noir_stdlib/src/hash/poseidon/bn254.nr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ use crate::hash::poseidon::{PoseidonConfig, absorb};

// Variable-length Poseidon-128 sponge as suggested in second bullet point of §3 of https://eprint.iacr.org/2019/458.pdf
#[field(bn254)]
#[no_predicates]
pub fn sponge<let N: u32>(msg: [Field; N]) -> Field {
absorb(consts::x5_5_config(), [0; 5], 4, 1, msg)[1]
}

// Various instances of the Poseidon hash function
// Consistent with Circom's implementation
#[no_predicates]
pub fn hash_1(input: [Field; 1]) -> Field {
let mut state = [0; 2];
for i in 0..input.len() {
Expand All @@ -23,7 +21,6 @@ pub fn hash_1(input: [Field; 1]) -> Field {
perm::x5_2(state)[0]
}

#[no_predicates]
pub fn hash_2(input: [Field; 2]) -> Field {
let mut state = [0; 3];
for i in 0..input.len() {
Expand All @@ -33,7 +30,6 @@ pub fn hash_2(input: [Field; 2]) -> Field {
perm::x5_3(state)[0]
}

#[no_predicates]
pub fn hash_3(input: [Field; 3]) -> Field {
let mut state = [0; 4];
for i in 0..input.len() {
Expand All @@ -43,7 +39,6 @@ pub fn hash_3(input: [Field; 3]) -> Field {
perm::x5_4(state)[0]
}

#[no_predicates]
pub fn hash_4(input: [Field; 4]) -> Field {
let mut state = [0; 5];
for i in 0..input.len() {
Expand All @@ -53,7 +48,6 @@ pub fn hash_4(input: [Field; 4]) -> Field {
perm::x5_5(state)[0]
}

#[no_predicates]
pub fn hash_5(input: [Field; 5]) -> Field {
let mut state = [0; 6];
for i in 0..input.len() {
Expand All @@ -63,7 +57,6 @@ pub fn hash_5(input: [Field; 5]) -> Field {
perm::x5_6(state)[0]
}

#[no_predicates]
pub fn hash_6(input: [Field; 6]) -> Field {
let mut state = [0; 7];
for i in 0..input.len() {
Expand All @@ -73,7 +66,6 @@ pub fn hash_6(input: [Field; 6]) -> Field {
perm::x5_7(state)[0]
}

#[no_predicates]
pub fn hash_7(input: [Field; 7]) -> Field {
let mut state = [0; 8];
for i in 0..input.len() {
Expand All @@ -83,7 +75,6 @@ pub fn hash_7(input: [Field; 7]) -> Field {
perm::x5_8(state)[0]
}

#[no_predicates]
pub fn hash_8(input: [Field; 8]) -> Field {
let mut state = [0; 9];
for i in 0..input.len() {
Expand All @@ -93,7 +84,6 @@ pub fn hash_8(input: [Field; 8]) -> Field {
perm::x5_9(state)[0]
}

#[no_predicates]
pub fn hash_9(input: [Field; 9]) -> Field {
let mut state = [0; 10];
for i in 0..input.len() {
Expand All @@ -103,7 +93,6 @@ pub fn hash_9(input: [Field; 9]) -> Field {
perm::x5_10(state)[0]
}

#[no_predicates]
pub fn hash_10(input: [Field; 10]) -> Field {
let mut state = [0; 11];
for i in 0..input.len() {
Expand All @@ -113,7 +102,6 @@ pub fn hash_10(input: [Field; 10]) -> Field {
perm::x5_11(state)[0]
}

#[no_predicates]
pub fn hash_11(input: [Field; 11]) -> Field {
let mut state = [0; 12];
for i in 0..input.len() {
Expand All @@ -123,7 +111,6 @@ pub fn hash_11(input: [Field; 11]) -> Field {
perm::x5_12(state)[0]
}

#[no_predicates]
pub fn hash_12(input: [Field; 12]) -> Field {
let mut state = [0; 13];
for i in 0..input.len() {
Expand All @@ -133,7 +120,6 @@ pub fn hash_12(input: [Field; 12]) -> Field {
perm::x5_13(state)[0]
}

#[no_predicates]
pub fn hash_13(input: [Field; 13]) -> Field {
let mut state = [0; 14];
for i in 0..input.len() {
Expand All @@ -143,7 +129,6 @@ pub fn hash_13(input: [Field; 13]) -> Field {
perm::x5_14(state)[0]
}

#[no_predicates]
pub fn hash_14(input: [Field; 14]) -> Field {
let mut state = [0; 15];
for i in 0..input.len() {
Expand All @@ -153,7 +138,6 @@ pub fn hash_14(input: [Field; 14]) -> Field {
perm::x5_15(state)[0]
}

#[no_predicates]
pub fn hash_15(input: [Field; 15]) -> Field {
let mut state = [0; 16];
for i in 0..input.len() {
Expand All @@ -163,7 +147,6 @@ pub fn hash_15(input: [Field; 15]) -> Field {
perm::x5_16(state)[0]
}

#[no_predicates]
pub fn hash_16(input: [Field; 16]) -> Field {
let mut state = [0; 17];
for i in 0..input.len() {
Expand Down
1 change: 0 additions & 1 deletion noir_stdlib/src/hash/poseidon2.nr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ struct Poseidon2 {
}

impl Poseidon2 {
#[no_predicates]
pub fn hash<let N: u32>(input: [Field; N], message_size: u32) -> Field {
if message_size == N {
Poseidon2::hash_internal(input, N, false)
Expand Down
1 change: 0 additions & 1 deletion noir_stdlib/src/sha256.nr
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ fn hash_final_block(msg_block: [u8; 64], mut state: [u32; 8]) -> [u8; 32] {
}

// Variable size SHA-256 hash
#[no_predicates]
pub fn sha256_var<let N: u32>(msg: [u8; N], message_size: u64) -> [u8; 32] {
let mut msg_block: [u8; 64] = [0; 64];
let mut h: [u32; 8] = [1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225]; // Intermediate hash, starting with the canonical initial value
Expand Down
1 change: 0 additions & 1 deletion noir_stdlib/src/sha512.nr
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ fn msg_u8_to_u64(msg: [u8; 128]) -> [u64; 16] {
msg64
}
// SHA-512 hash function
#[no_predicates]
pub fn digest<let N: u32>(msg: [u8; N]) -> [u8; 64] {
let mut msg_block: [u8; 128] = [0; 128];
// noir-fmt:ignore
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
}

results
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] {
}

results
}
}
Loading

0 comments on commit 7b77bbf

Please sign in to comment.