From 707bc09a3c4b5a6460154931db55ee48842ee041 Mon Sep 17 00:00:00 2001 From: David Banks <47112877+dbanks12@users.noreply.github.com> Date: Tue, 12 Sep 2023 06:28:09 -0400 Subject: [PATCH] chore(noir-contracts): 1655 - rename functions to make hack clearer for 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. --- .../contracts/native_token_contract/src/main.nr | 2 +- .../non_native_token_contract/src/main.nr | 2 +- .../private_token_airdrop_contract/src/main.nr | 2 +- .../noir-libs/aztec-noir/src/state_vars/set.nr | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/yarn-project/noir-contracts/src/contracts/native_token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/native_token_contract/src/main.nr index 0f140b06731..ba2bc64737a 100644 --- a/yarn-project/noir-contracts/src/contracts/native_token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/native_token_contract/src/main.nr @@ -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); diff --git a/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/main.nr index c19f4ca5a3c..75aca44a9f7 100644 --- a/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/main.nr @@ -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); diff --git a/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/main.nr index da67fc0bb4f..2216e36ecba 100644 --- a/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/main.nr @@ -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); diff --git a/yarn-project/noir-libs/aztec-noir/src/state_vars/set.nr b/yarn-project/noir-libs/aztec-noir/src/state_vars/set.nr index 69685deeee4..c14eebb770d 100644 --- a/yarn-project/noir-libs/aztec-noir/src/state_vars/set.nr +++ b/yarn-project/noir-libs/aztec-noir/src/state_vars/set.nr @@ -49,10 +49,10 @@ impl Set { ); } - // 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, @@ -67,10 +67,10 @@ impl Set { ); } - // 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(