Skip to content

Commit

Permalink
chore(noir-contracts): 1655 - rename functions to make hack clearer f…
Browse files Browse the repository at this point in the history
…or publicly created notes (#2230)

Resolves #1655

`assert_contains_and_remove` has a hack that makes it only work for
publicly created note hashes. This PR renames the function to make it
clear that it only works for publicly created note hashes. It also
renames `assert_contains_note_and_remove` to
`assert_contains_and_remove` with a TODO to tweak it to only
`ensure_note_hash_exists` instead of `ensure_note_exists` once
`get_commitment` supports privately created commitments.
  • Loading branch information
dbanks12 authored Sep 12, 2023
1 parent 9efdf56 commit 707bc09
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ contract NativeToken {
let public_note = TransparentNote::new_from_secret(amount, secret);

// Ensure that the note exists in the tree and remove it.
pending_shields.assert_contains_and_remove(public_note);
pending_shields.assert_contains_and_remove_publicly_created(public_note);

// Mint the tokens
let balance = storage.balances.at(owner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ contract NonNativeToken {
let public_note = TransparentNote::new_from_secret(amount, secret);

// Ensure that the note exists in the tree and remove it.
pending_shields.assert_contains_and_remove(public_note);
pending_shields.assert_contains_and_remove_publicly_created(public_note);

// Mint the tokens
let balance = storage.balances.at(owner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ contract PrivateTokenAirdrop {

// Remove the claim note if it exists in the set.
let note = ClaimNote::new(amount, secret);
storage.claims.assert_contains_note_and_remove(note);
storage.claims.assert_contains_and_remove(note);

// Send the value note.
let balance = storage.balances.at(owner);
Expand Down
14 changes: 7 additions & 7 deletions yarn-project/noir-libs/aztec-noir/src/state_vars/set.nr
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ impl<Note, N> Set<Note, N> {
);
}

// TODO(#1386)
// Should be replaced by `assert_contains_and_remove`.
fn assert_contains_note_and_remove(self, note: Note) {
fn assert_contains_and_remove(self, note: Note) {
let mut note_with_header = note;
// TODO(1386): replace with `ensure_note_hash_exists`
// once `get_commitment` works for privately created note hashes
ensure_note_exists(
self.context.private.unwrap(),
self.storage_slot,
Expand All @@ -67,10 +67,10 @@ impl<Note, N> Set<Note, N> {
);
}

// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386):
// replace function above ^ once public kernel injects
// nonces to note hashes.
fn assert_contains_and_remove(self, note: Note) {
// NOTE: this function should ONLY be used for PUBLICLY-CREATED note hashes!
// WARNING: function will be deprecated/removed eventually once `assert_contains_and_remove`
// works for publicly-created note hashes as well.
fn assert_contains_and_remove_publicly_created(self, note: Note) {
let mut note_with_header = note;
// Modifies note with the header which is necessary for the next step (remove).
ensure_note_hash_exists(
Expand Down

0 comments on commit 707bc09

Please sign in to comment.