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

chore: fix poor performance and long compile times in value_note.derement() #6523

Merged
merged 1 commit into from
May 17, 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
15 changes: 14 additions & 1 deletion noir-projects/aztec-nr/value-note/src/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,23 @@ pub fn decrement_by_at_most(
let options = create_note_getter_options_for_decreasing_balance(max_amount);
let opt_notes = balance.get_notes(options);

let owner_npk_m_hash = get_npk_m_hash(balance.context.private.unwrap(), owner);

let mut decremented = 0;
for i in 0..opt_notes.len() {
if opt_notes[i].is_some() {
decremented += destroy_note(balance, owner, opt_notes[i].unwrap_unchecked());
let note = opt_notes[i].unwrap_unchecked();

// This is similar to destroy_note, except we only compute the owner_npk_m_hash once instead of doing it in
// each loop iteration.

// Ensure the note is actually owned by the owner (to prevent user from generating a valid proof while
// spending someone else's notes).
// TODO (#6312): This will break with key rotation. Fix this. Will not be able to pass this after rotating keys.
assert(note.npk_m_hash.eq(owner_npk_m_hash));
decremented += note.value;

balance.remove(note);
}
}

Expand Down
Loading