From 67fb2169426efb15123147e31ead1b57ab3f0e10 Mon Sep 17 00:00:00 2001 From: benesjan Date: Mon, 5 Aug 2024 13:25:13 +0000 Subject: [PATCH] final touches --- noir-projects/aztec-nr/aztec/src/note/utils.nr | 2 +- noir-projects/aztec-nr/aztec/src/oracle/notes.nr | 8 +------- .../contracts/token_contract/src/types/token_note.nr | 2 +- .../contracts/token_with_refunds_contract/src/main.nr | 7 ++++--- .../token_with_refunds_contract/src/types/token_note.nr | 4 ++-- .../noir-protocol-circuits/crates/types/src/hash.nr | 2 ++ .../src/hints/build_note_hash_read_request_hints.test.ts | 8 ++++---- yarn-project/pxe/src/database/incoming_note_dao.ts | 2 +- yarn-project/simulator/src/acvm/oracle/typed_oracle.ts | 2 +- .../simulator/src/client/client_execution_context.ts | 2 +- yarn-project/simulator/src/client/execution_note_cache.ts | 4 ++-- .../simulator/src/client/private_execution.test.ts | 4 ++-- 12 files changed, 22 insertions(+), 25 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/note/utils.nr b/noir-projects/aztec-nr/aztec/src/note/utils.nr index 7d9b200a49bc..8bce7674865c 100644 --- a/noir-projects/aztec-nr/aztec/src/note/utils.nr +++ b/noir-projects/aztec-nr/aztec/src/note/utils.nr @@ -49,7 +49,7 @@ pub fn compute_note_hash_for_consumption(note: Not if header.nonce == 0 { // Case 1. - // If a note is transient, we just read the note_hash (kernel will hash with nonce and silo by contract address). + // If a note is transient, we just read the note_hash (kernel will hash it with nonce and silo by contract address). note_hash } else { // Case 2: If a note is non-revertible, and is nullified by a revertible nullifier, we cannot squash them in the diff --git a/noir-projects/aztec-nr/aztec/src/oracle/notes.nr b/noir-projects/aztec-nr/aztec/src/oracle/notes.nr index ff832d692681..8732937b7aff 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/notes.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/notes.nr @@ -18,13 +18,7 @@ unconstrained pub fn notify_created_note( note_hash: Field, counter: u32 ) -> Field { - notify_created_note_oracle( - storage_slot, - note_type_id, - serialized_note, - note_hash, - counter - ) + notify_created_note_oracle(storage_slot, note_type_id, serialized_note, note_hash, counter) } #[oracle(notifyNullifiedNote)] diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr index dec44b798f3d..6a2d4e94fe25 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr @@ -62,7 +62,7 @@ impl NoteInterface for TokenNote { fn compute_note_hiding_point(self) -> Point { assert(self.header.storage_slot != 0, "Storage slot must be set before computing note hiding point"); - // TODO(benesjan): decompose amount with from_field_unsafe or constrain it fits into limb + // TODO(#7772): decompose amount with from_field_unsafe or constrain it fits into 1 limb let amount_scalar = Scalar { lo: self.amount.to_integer(), hi: 0 diff --git a/noir-projects/noir-contracts/contracts/token_with_refunds_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_with_refunds_contract/src/main.nr index 63a193a9574d..527024d7ea3f 100644 --- a/noir-projects/noir-contracts/contracts/token_with_refunds_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_with_refunds_contract/src/main.nr @@ -469,7 +469,8 @@ contract TokenWithRefunds { // to the user in the `complete_refund(...)` function. storage.balances.sub(user, U128::from_integer(funded_amount)).emit(encode_and_encrypt_note_with_keys(&mut context, user_ovpk, user_ivpk, user)); - // 4. Now we "manually" compute the slots (by setting the slots we insert the notes to the balances map under a correct key) + // 4. Now we "manually" compute the slots (by setting the slots we insert the notes to the balances map under + // the correct keys) let fee_payer_balances_slot = derive_storage_slot_in_map(TokenWithRefunds::storage().balances.slot, fee_payer); let user_balances_slot = derive_storage_slot_in_map(TokenWithRefunds::storage().balances.slot, user); @@ -518,14 +519,14 @@ contract TokenWithRefunds { #[aztec(public)] #[aztec(internal)] fn complete_refund( - // TODO: the following makes macros crash --> try getting it work once we migrate to metaprogramming + // TODO(#7771): the following makes macros crash --> try getting it work once we migrate to metaprogramming // mut fee_payer_point: TokenNoteHidingPoint, // mut user_point: TokenNoteHidingPoint, fee_payer_point_immutable: TokenNoteHidingPoint, user_point_immutable: TokenNoteHidingPoint, funded_amount: Field ) { - // TODO: nuke the following 2 lines once we have mutable args + // TODO(#7771): nuke the following 2 lines once we have mutable args let mut fee_payer_point = fee_payer_point_immutable; let mut user_point = user_point_immutable; diff --git a/noir-projects/noir-contracts/contracts/token_with_refunds_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_with_refunds_contract/src/types/token_note.nr index e7e9ad2f74c9..f7d4666c7065 100644 --- a/noir-projects/noir-contracts/contracts/token_with_refunds_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_with_refunds_contract/src/types/token_note.nr @@ -48,7 +48,7 @@ impl NoteInterface for TokenNote { fn compute_note_hiding_point(self) -> Point { assert(self.header.storage_slot != 0, "Storage slot must be set before computing note hiding point"); - // TODO(benesjan): decompose amount with from_field_unsafe or constrain it fits into limb + // TODO(#7772): decompose amount with from_field_unsafe or constrain it fits into 1 limb let amount_scalar = Scalar { lo: self.amount.to_integer(), hi: 0 @@ -86,7 +86,7 @@ impl TokenNoteHidingPoint { } fn add_amount(&mut self, amount: U128) { - // TODO(benesjan): decompose amount with from_field_unsafe or constrain it fits into limb + // TODO(#7772): decompose amount with from_field_unsafe or constrain it fits into 1 limb let amount_scalar = Scalar { lo: amount.to_integer(), hi: 0 }; self.inner = multi_scalar_mul([G_amt], [amount_scalar]) + self.inner; } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr index 0dfffa70e13a..c0045eb7d293 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr @@ -59,6 +59,8 @@ pub fn compute_siloed_note_hash(app: AztecAddress, unique_note_hash: Field) -> F ) } +/// Siloing in the context of Aztec refers to the process of hashing a note hash with a contract address (this way +/// the note hash is scoped to a specific contract). This is used to prevent intermingling of notes between contracts. pub fn silo_note_hash(note_hash: ScopedNoteHash, tx_hash: Field, note_index_in_tx: u32) -> Field { if note_hash.contract_address.is_zero() { 0 diff --git a/yarn-project/circuits.js/src/hints/build_note_hash_read_request_hints.test.ts b/yarn-project/circuits.js/src/hints/build_note_hash_read_request_hints.test.ts index 1fad5cfe586e..8117be97c140 100644 --- a/yarn-project/circuits.js/src/hints/build_note_hash_read_request_hints.test.ts +++ b/yarn-project/circuits.js/src/hints/build_note_hash_read_request_hints.test.ts @@ -39,7 +39,7 @@ describe('buildNoteHashReadRequestHints', () => { let numSettledReads = 0; let futureNoteHashes: ScopedNoteHash[]; - const noteHash = (index: number) => index + 9999; + const getNoteHashValue = (index: number) => index + 9999; const makeReadRequest = (value: number, counter = 2) => new ReadRequest(new Fr(value), counter).scope(contractAddress); @@ -49,7 +49,7 @@ describe('buildNoteHashReadRequestHints', () => { const readPendingNoteHash = (noteHashIndex: number) => { const readRequestIndex = numReadRequests; const hintIndex = numPendingReads; - noteHashReadRequests[readRequestIndex] = makeReadRequest(noteHash(noteHashIndex)); + noteHashReadRequests[readRequestIndex] = makeReadRequest(getNoteHashValue(noteHashIndex)); expectedHints.readRequestStatuses[readRequestIndex] = ReadRequestStatus.pending(hintIndex); expectedHints.pendingReadHints[hintIndex] = new PendingReadHint(readRequestIndex, noteHashIndex); numReadRequests++; @@ -89,7 +89,7 @@ describe('buildNoteHashReadRequestHints', () => { beforeEach(() => { noteHashReadRequests = makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_TX, ScopedReadRequest.empty); - noteHashes = makeTuple(MAX_NOTE_HASHES_PER_TX, i => makeNoteHash(noteHash(i))); + noteHashes = makeTuple(MAX_NOTE_HASHES_PER_TX, i => makeNoteHash(getNoteHashValue(i))); noteHashLeafIndexMap = new Map(); expectedHints = NoteHashReadRequestHintsBuilder.empty( MAX_NOTE_HASH_READ_REQUESTS_PER_TX, @@ -100,7 +100,7 @@ describe('buildNoteHashReadRequestHints', () => { numSettledReads = 0; futureNoteHashes = new Array(MAX_NOTE_HASHES_PER_TX) .fill(null) - .map((_, i) => makeNoteHash(noteHash(i + MAX_NOTE_HASHES_PER_TX))); + .map((_, i) => makeNoteHash(getNoteHashValue(i + MAX_NOTE_HASHES_PER_TX))); }); it('builds empty hints', async () => { diff --git a/yarn-project/pxe/src/database/incoming_note_dao.ts b/yarn-project/pxe/src/database/incoming_note_dao.ts index 7e4ee1eae0a9..cba1df864f6d 100644 --- a/yarn-project/pxe/src/database/incoming_note_dao.ts +++ b/yarn-project/pxe/src/database/incoming_note_dao.ts @@ -23,7 +23,7 @@ export class IncomingNoteDao implements NoteData { /** The nonce of the note. */ public nonce: Fr, /** - * Note hash of the note. This is customizable by the app circuit. + * A hash of the note. This is customizable by the app circuit. * We can use this value to compute siloedNoteHash and uniqueSiloedNoteHash. */ public noteHash: Fr, diff --git a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts index 84a8331a5cb4..1b9dae81e8aa 100644 --- a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts @@ -27,7 +27,7 @@ export interface NoteData { storageSlot: Fr; /** The nonce of the note. */ nonce: Fr; - /** The note hash of the note. */ + /** A hash of the note. */ noteHash: Fr; /** The corresponding nullifier of the note. Undefined for pending notes. */ siloedNullifier?: Fr; diff --git a/yarn-project/simulator/src/client/client_execution_context.ts b/yarn-project/simulator/src/client/client_execution_context.ts index 2eeb18484cc6..79b1f913ef4d 100644 --- a/yarn-project/simulator/src/client/client_execution_context.ts +++ b/yarn-project/simulator/src/client/client_execution_context.ts @@ -292,7 +292,7 @@ export class ClientExecutionContext extends ViewDataOracle { * @param storageSlot - The storage slot. * @param noteTypeId - The type ID of the note. * @param noteItems - The items to be included in a Note. - * @param noteHash - The hash of the new note. + * @param noteHash - A hash of the new note. * @returns */ public override notifyCreatedNote( diff --git a/yarn-project/simulator/src/client/execution_note_cache.ts b/yarn-project/simulator/src/client/execution_note_cache.ts index 4faf3e77adb2..f8e1ec0a670e 100644 --- a/yarn-project/simulator/src/client/execution_note_cache.ts +++ b/yarn-project/simulator/src/client/execution_note_cache.ts @@ -83,8 +83,8 @@ export class ExecutionNoteCache { * Add a nullifier to cache. It could be for a db note or a new note created during execution. * @param contractAddress - Contract address of the note. * @param innerNullifier - Inner nullifier of the note. - * @param noteHash - A note hash of the note. If this value equals 0, it means the - * note being nullified is from a previous transaction (and thus not a new note). + * @param noteHash - A hash of the note. If this value equals 0, it means the note being nullified is from a previous + * transaction (and thus not a new note). */ public nullifyNote(contractAddress: AztecAddress, innerNullifier: Fr, noteHash: Fr) { const siloedNullifier = siloNullifier(contractAddress, innerNullifier); diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 86de1471b383..d668a2130a3f 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -973,7 +973,7 @@ describe('Private Execution test suite', () => { expect(encryptedLog.noteHashCounter).toEqual(result.noteEncryptedLogs[0].noteHashCounter); expect(encryptedLog.value).toEqual(Fr.fromBuffer(result.noteEncryptedLogs[0].log.hash())); - // read request should match note hash for pending notes (there is no nonce, so can't compute "unique" hash) + // read request should match a note hash for pending notes (there is no nonce, so can't compute "unique" hash) const readRequest = getNonEmptyItems(result.callStackItem.publicInputs.noteHashReadRequests)[0]; expect(readRequest.value).toEqual(derivedNoteHash); @@ -1056,7 +1056,7 @@ describe('Private Execution test suite', () => { expect(encryptedLog.noteHashCounter).toEqual(execInsert.noteEncryptedLogs[0].noteHashCounter); expect(encryptedLog.value).toEqual(Fr.fromBuffer(execInsert.noteEncryptedLogs[0].log.hash())); - // read request should match note hash for pending notes (there is no nonce, so can't compute "unique" hash) + // read request should match a note hash for pending notes (there is no nonce, so can't compute "unique" hash) const readRequest = execGetThenNullify.callStackItem.publicInputs.noteHashReadRequests[0]; expect(readRequest.value).toEqual(derivedNoteHash);