Skip to content

Commit

Permalink
final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Aug 6, 2024
1 parent d69307d commit 67fb216
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/note/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn compute_note_hash_for_consumption<Note, let N: u32, let M: u32>(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
Expand Down
8 changes: 1 addition & 7 deletions noir-projects/aztec-nr/aztec/src/oracle/notes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ unconstrained pub fn notify_created_note<let N: u32>(
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)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl NoteInterface<TOKEN_NOTE_LEN, TOKEN_NOTE_BYTES_LEN> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl NoteInterface<TOKEN_NOTE_LEN, TOKEN_NOTE_BYTES_LEN> 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
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions noir-projects/noir-protocol-circuits/crates/types/src/hash.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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++;
Expand Down Expand Up @@ -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,
Expand All @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/database/incoming_note_dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/simulator/src/acvm/oracle/typed_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/simulator/src/client/execution_note_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/simulator/src/client/private_execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 67fb216

Please sign in to comment.