Skip to content

Commit

Permalink
feat: comptime deriving generators in macros (#9195)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored and AztecBot committed Oct 26, 2024
1 parent 2f76ffd commit 7531f88
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions aztec/src/macros/notes/mod.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::note::{note_getter_options::PropertySelector, note_header::NoteHeader};
use crate::{note::{note_getter_options::PropertySelector, note_header::NoteHeader}, prelude::Point};
use protocol_types::meta::{flatten_to_fields, pack_from_fields};
use std::{
collections::umap::UHashMap,
hash::{BuildHasherDefault, poseidon2::Poseidon2Hasher},
hash::{BuildHasherDefault, derive_generators, poseidon2::Poseidon2Hasher},
meta::{typ::fresh_type_variable, type_of, unquote},
};

Expand Down Expand Up @@ -310,16 +310,24 @@ comptime fn generate_multi_scalar_mul(
let mut scalars_list = &[];
let mut args_list = &[];
let mut aux_vars_list = &[];
// TODO(#8648): Generate generators at comptime instead of importing here.
for i in 0..indexed_fields.len() {
let (field_name, typ, index) = indexed_fields[i];
let start_generator_index = index + 1;
let (flattened_field, aux_vars) = flatten_to_fields(field_name, typ, &[]);
for j in 0..flattened_field.len() {
let flattened_as_field = flattened_field[j];
let generator_index = start_generator_index + j;
generators_list = generators_list.push_back(f"aztec::generators::Ga{generator_index}"
.quoted_contents());

let generators: [Point; 1] =
derive_generators("aztec_nr_generators".as_bytes(), generator_index);
let generator_x = generators[0].x;
let generator_y = generators[0].y;

generators_list = generators_list.push_back(
quote {
aztec::protocol_types::point::Point { x: $generator_x, y: $generator_y, is_infinite: false }
},
);
scalars_list =
scalars_list.push_back(quote { std::hash::from_field_unsafe($flattened_as_field) });
}
Expand Down

0 comments on commit 7531f88

Please sign in to comment.