diff --git a/noir-projects/aztec-nr/value-note/src/utils.nr b/noir-projects/aztec-nr/value-note/src/utils.nr index 80392c24b2f..4c4ba85021c 100644 --- a/noir-projects/aztec-nr/value-note/src/utils.nr +++ b/noir-projects/aztec-nr/value-note/src/utils.nr @@ -12,14 +12,10 @@ pub fn create_note_getter_options_for_decreasing_balance(amount: Field) -> NoteG // Creates a new note for the recipient. // Inserts it to the recipient's set of notes. -pub fn increment( - mut context: PrivateContext, - balance: PrivateSet, - amount: Field, - recipient: AztecAddress -) { - let recipient_npk_m_hash = get_npk_m_hash(&mut context, recipient); - let recipient_ivpk_m = get_ivpk_m(&mut context, recipient); +pub fn increment(balance: PrivateSet, amount: Field, recipient: AztecAddress) { + let context = balance.context.private.unwrap(); + let recipient_npk_m_hash = get_npk_m_hash(context, recipient); + let recipient_ivpk_m = get_ivpk_m(context, recipient); let mut note = ValueNote::new(amount, recipient_npk_m_hash); // Insert the new note to the owner's set of notes and emit the log if value is non-zero. @@ -30,13 +26,8 @@ pub fn increment( // Remove those notes. // If the value of the removed notes exceeds the requested `amount`, create a new note containing the excess value, so that exactly `amount` is removed. // Fail if the sum of the selected notes is less than the amount. -pub fn decrement( - mut context: PrivateContext, - balance: PrivateSet, - amount: Field, - owner: AztecAddress -) { - let sum = decrement_by_at_most(context, balance, amount, owner); +pub fn decrement(balance: PrivateSet, amount: Field, owner: AztecAddress) { + let sum = decrement_by_at_most(balance, amount, owner); assert(sum == amount, "Balance too low"); } @@ -49,7 +40,6 @@ pub fn decrement( // // It returns the decremented amount, which should be less than or equal to max_amount. pub fn decrement_by_at_most( - mut context: PrivateContext, balance: PrivateSet, max_amount: Field, owner: AztecAddress @@ -60,7 +50,7 @@ pub fn decrement_by_at_most( let mut decremented = 0; for i in 0..opt_notes.len() { if opt_notes[i].is_some() { - decremented += destroy_note(context, balance, owner, opt_notes[i].unwrap_unchecked()); + decremented += destroy_note(balance, owner, opt_notes[i].unwrap_unchecked()); } } @@ -70,22 +60,17 @@ pub fn decrement_by_at_most( change_value = decremented - max_amount; decremented -= change_value; } - increment(context, balance, change_value, owner); + increment(balance, change_value, owner); decremented } // Removes the note from the owner's set of notes. // Returns the value of the destroyed note. -pub fn destroy_note( - mut context: PrivateContext, - balance: PrivateSet, - owner: AztecAddress, - note: ValueNote -) -> Field { +pub fn destroy_note(balance: PrivateSet, owner: AztecAddress, note: ValueNote) -> Field { // Ensure the note is actually owned by the owner (to prevent user from generating a valid proof while // spending someone else's notes). - let owner_npk_m_hash = get_npk_m_hash(&mut context, owner); + let owner_npk_m_hash = get_npk_m_hash(balance.context.private.unwrap(), owner); // 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)); diff --git a/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr b/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr index 1a81cef4ff6..a8b9f34d36b 100644 --- a/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr @@ -18,7 +18,7 @@ contract Benchmarking { // Creates a new value note for the target owner. Use this method to seed an initial set of notes. #[aztec(private)] fn create_note(owner: AztecAddress, value: Field) { - increment(context, storage.notes.at(owner), value, owner); + increment(storage.notes.at(owner), value, owner); } // Deletes a note at a specific index in the set and creates a new one with the same value. @@ -33,7 +33,7 @@ contract Benchmarking { let notes = owner_notes.get_notes(getter_options.set_limit(1).set_offset(index)); let note = notes[0].unwrap_unchecked(); owner_notes.remove(note); - increment(context, owner_notes, note.value, owner); + increment(owner_notes, note.value, owner); } // Reads and writes to public storage and enqueues a call to another public function. diff --git a/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr index db8c9965eb2..2c3b7e682f6 100644 --- a/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/stateful_test_contract/src/main.nr @@ -37,7 +37,7 @@ contract StatefulTest { fn create_note(owner: AztecAddress, value: Field) { if (value != 0) { let loc = storage.notes.at(owner); - increment(context, loc, value, owner); + increment(loc, value, owner); } } @@ -47,7 +47,7 @@ contract StatefulTest { if (value != 0) { let loc = storage.notes.at(owner); // TODO (#6312): This will break with key rotation. Fix this. Will not be able to spend / increment any notes after rotating key. - increment(context, loc, value, owner); + increment(loc, value, owner); } } @@ -57,10 +57,10 @@ contract StatefulTest { let sender = context.msg_sender(); let sender_notes = storage.notes.at(sender); - decrement(context, sender_notes, amount, sender); + decrement(sender_notes, amount, sender); let recipient_notes = storage.notes.at(recipient); - increment(context, recipient_notes, amount, recipient); + increment(recipient_notes, amount, recipient); } #[aztec(private)] @@ -69,10 +69,10 @@ contract StatefulTest { let sender = context.msg_sender(); let sender_notes = storage.notes.at(sender); - decrement(context, sender_notes, amount, sender); + decrement(sender_notes, amount, sender); let recipient_notes = storage.notes.at(recipient); - increment(context, recipient_notes, amount, recipient); + increment(recipient_notes, amount, recipient); } #[aztec(public)]