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

refactor: use options.limit as upper limit for note-getter loop #7253

Merged
merged 1 commit into from
Jul 1, 2024
Merged
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
8 changes: 7 additions & 1 deletion noir-projects/aztec-nr/aztec/src/note/note_getter.nr
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn constrain_get_notes_internal<Note, N, M, FILTER_ARGS>(
let filtered_notes = filter_fn(opt_notes, filter_args);

let mut prev_fields = [0; N];
for i in 0..filtered_notes.len() {
for i in 0..options.limit {
let opt_note = filtered_notes[i];
if opt_note.is_some() {
let note = opt_note.unwrap_unchecked();
Expand All @@ -154,7 +154,13 @@ fn constrain_get_notes_internal<Note, N, M, FILTER_ARGS>(
};
}

// As long as we only loop till `options.limit` the array will be guaranteed to be at most of length `options.limit`.
assert(returned_notes.len() <= options.limit, "Got more notes than limit.");
// We will however check that nothing else was returned after the limit.
for i in options.limit..filtered_notes.len() {
assert(filtered_notes[i].is_none(), "Got more notes than limit.");
}

assert(returned_notes.len() != 0, "Cannot return zero notes");

returned_notes
Expand Down
Loading