Skip to content

Commit

Permalink
refactor: continuation of note naming update (#3137)
Browse files Browse the repository at this point in the history
[PR 3051](#3051) was
getting too big so I decided to do the naming changes in noir contracts
in a separate PR. This is the PR.
  • Loading branch information
benesjan authored Oct 31, 2023
1 parent 59eb6af commit 582150f
Show file tree
Hide file tree
Showing 44 changed files with 143 additions and 141 deletions.
2 changes: 1 addition & 1 deletion docs/docs/dev_docs/tutorials/writing_token_contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ contract Token {

unconstrained fn balance_of_public(owner: AztecAddress) -> Field {}

unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; VALUE_NOTE_LEN]) -> [Field; 4] {}
unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, serialized_note: [Field; VALUE_NOTE_LEN]) -> [Field; 4] {}
}
```

Expand Down
12 changes: 6 additions & 6 deletions yarn-project/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ impl AddressNote {
[self.address, self.owner, self.randomness]
}

pub fn deserialize(preimage: [Field; ADDRESS_NOTE_LEN]) -> Self {
pub fn deserialize(serialized_note: [Field; ADDRESS_NOTE_LEN]) -> Self {
AddressNote {
address: preimage[0],
owner: preimage[1],
randomness: preimage[2],
address: serialized_note[0],
owner: serialized_note[1],
randomness: serialized_note[2],
header: NoteHeader::empty(),
}
}
Expand Down Expand Up @@ -85,8 +85,8 @@ impl AddressNote {
}
}

fn deserialize(preimage: [Field; ADDRESS_NOTE_LEN]) -> AddressNote {
AddressNote::deserialize(preimage)
fn deserialize(serialized_note: [Field; ADDRESS_NOTE_LEN]) -> AddressNote {
AddressNote::deserialize(serialized_note)
}

fn serialize(note: AddressNote) -> [Field; ADDRESS_NOTE_LEN]{
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-nr/aztec/src/note/lifecycle.nr
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pub fn create_note<Note, N>(
let inner_note_hash = compute_inner_note_hash(note_interface, *note);

let serialize = note_interface.serialize;
let preimage = serialize(*note);
assert(notify_created_note(storage_slot, preimage, inner_note_hash) == 0);
let serialized_note = serialize(*note);
assert(notify_created_note(storage_slot, serialized_note, inner_note_hash) == 0);

context.push_new_note_hash(inner_note_hash);

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-nr/aztec/src/note/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ pub fn compute_note_hash_for_read_or_nullify<Note, N>(
pub fn compute_note_hash_and_nullifier<Note, N, S>(
note_interface: NoteInterface<Note, N>,
note_header: NoteHeader,
preimage: [Field; S],
serialized_note: [Field; S],
) -> [Field; 4] {
let deserialize = note_interface.deserialize;
let set_header = note_interface.set_header;
let mut note = deserialize(arr_copy_slice(preimage, [0; N], 0));
let mut note = deserialize(arr_copy_slice(serialized_note, [0; N], 0));
set_header(&mut note, note_header);

let compute_note_hash = note_interface.compute_note_hash;
Expand Down
10 changes: 5 additions & 5 deletions yarn-project/aztec-nr/aztec/src/oracle/notes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ use crate::utils::arr_copy_slice;
#[oracle(notifyCreatedNote)]
fn notify_created_note_oracle<N>(
_storage_slot: Field,
_preimage: [Field; N],
_serialized_note: [Field; N],
_inner_note_hash: Field,
) -> Field {}

unconstrained pub fn notify_created_note<N>(
storage_slot: Field,
preimage: [Field; N],
serialized_note: [Field; N],
inner_note_hash: Field,
) -> Field {
notify_created_note_oracle(storage_slot, preimage, inner_note_hash)
notify_created_note_oracle(storage_slot, serialized_note, inner_note_hash)
}

#[oracle(notifyNullifiedNote)]
Expand Down Expand Up @@ -89,8 +89,8 @@ unconstrained pub fn get_notes<Note, N, M, S, NS>(
let nonce = fields[read_offset];
let is_transient = fields[read_offset + 1] as bool;
let header = NoteHeader { contract_address, nonce, storage_slot, is_transient };
let preimage = arr_copy_slice(fields, [0; N], read_offset + 2);
let mut note = deserialize(preimage);
let serialized_note = arr_copy_slice(fields, [0; N], read_offset + 2);
let mut note = deserialize(serialized_note);
set_header(&mut note, header);
placeholder_opt_notes[i] = Option::some(note);
};
Expand Down
10 changes: 5 additions & 5 deletions yarn-project/aztec-nr/field-note/src/field_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use dep::aztec::{
global FIELD_NOTE_LEN: Field = 1;

// A note which stores a field and is expected to be passed around using the `addNote` function.
// WARNING: This Note is not private as it does not contain randomness and hence it can be easy to perform preimage
// WARNING: This Note is not private as it does not contain randomness and hence it can be easy to perform serialized_note
// attack on it.
struct FieldNote {
value: Field,
Expand All @@ -29,9 +29,9 @@ impl FieldNote {
[self.value]
}

pub fn deserialize(preimage: [Field; FIELD_NOTE_LEN]) -> Self {
pub fn deserialize(serialized_note: [Field; FIELD_NOTE_LEN]) -> Self {
FieldNote {
value: preimage[0],
value: serialized_note[0],
header: NoteHeader::empty(),
}
}
Expand All @@ -51,8 +51,8 @@ impl FieldNote {
}
}

fn deserialize(preimage: [Field; FIELD_NOTE_LEN]) -> FieldNote {
FieldNote::deserialize(preimage)
fn deserialize(serialized_note: [Field; FIELD_NOTE_LEN]) -> FieldNote {
FieldNote::deserialize(serialized_note)
}

fn serialize(note: FieldNote) -> [Field; FIELD_NOTE_LEN]{
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/aztec-nr/value-note/src/value_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ impl ValueNote {
[self.value, self.owner, self.randomness]
}

pub fn deserialize(preimage: [Field; VALUE_NOTE_LEN]) -> Self {
pub fn deserialize(serialized_note: [Field; VALUE_NOTE_LEN]) -> Self {
ValueNote {
value: preimage[0],
owner: preimage[1],
randomness: preimage[2],
value: serialized_note[0],
owner: serialized_note[1],
randomness: serialized_note[2],
header: NoteHeader::empty(),
}
}
Expand Down Expand Up @@ -87,8 +87,8 @@ impl ValueNote {
}
}

fn deserialize(preimage: [Field; VALUE_NOTE_LEN]) -> ValueNote {
ValueNote::deserialize(preimage)
fn deserialize(serialized_note: [Field; VALUE_NOTE_LEN]) -> ValueNote {
ValueNote::deserialize(serialized_note)
}

fn serialize(note: ValueNote) -> [Field; VALUE_NOTE_LEN] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"visibility": "private"
},
{
"name": "preimage",
"name": "serialized_note",
"type": {
"kind": "array",
"length": 5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"visibility": "private"
},
{
"name": "preimage",
"name": "serialized_note",
"type": {
"kind": "array",
"length": 3,
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/aztec.js/src/contract/sent_tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class SentTx {
if (receipt.status !== TxStatus.MINED)
throw new Error(`Transaction ${await this.getTxHash()} was ${receipt.status}`);
if (opts?.getNotes) {
receipt.notes = await this.pxe.getNotes({ txHash: await this.getTxHash() });
receipt.visibleNotes = await this.pxe.getNotes({ txHash: await this.getTxHash() });
}
return receipt;
}
Expand All @@ -84,11 +84,11 @@ export class SentTx {
}

/**
* Gets notes created in this tx.
* Get notes of accounts registered in the provided PXE/Wallet created in this tx.
* @remarks This function will wait for the tx to be mined if it hasn't been already.
* @returns The requested notes.
*/
public async getNotes(): Promise<ExtendedNote[]> {
public async getVisibleNotes(): Promise<ExtendedNote[]> {
await this.wait();
return this.pxe.getNotes({ txHash: await this.getTxHash() });
}
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/boxes/blank/src/artifacts/Blank.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"visibility": "private"
},
{
"name": "preimage",
"name": "serialized_note",
"type": {
"kind": "array",
"length": 0,
Expand Down Expand Up @@ -87,7 +87,7 @@
],
"fileMap": {
"1": {
"source": "contract Blank {\n use dep::aztec::{\n abi,\n oracle::{\n get_public_key::get_public_key,\n },\n };\n\n #[aztec(private)]\n fn constructor() {}\n\n #[aztec(private)]\n fn getPublicKey(\n address: Field,\n ) -> [Field; 2]{\n let pub_key = get_public_key(address);\n \n [pub_key.x, pub_key.y]\n }\n\n // A function which needs to be implemented by every contract working with storage. Replace it's content with your\n // own logic once you start working with private storage.\n // TODO: Remove this placeholder once https://github.com/AztecProtocol/aztec-packages/issues/2918 is implemented.\n unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; 0]) -> [Field; 4] {\n [0, 0, 0, 0]\n }\n}\n",
"source": "contract Blank {\n use dep::aztec::{\n abi,\n oracle::{\n get_public_key::get_public_key,\n },\n };\n\n #[aztec(private)]\n fn constructor() {}\n\n #[aztec(private)]\n fn getPublicKey(\n address: Field,\n ) -> [Field; 2]{\n let pub_key = get_public_key(address);\n \n [pub_key.x, pub_key.y]\n }\n\n // A function which needs to be implemented by every contract working with storage. Replace it's content with your\n // own logic once you start working with private storage.\n // TODO: Remove this placeholder once https://github.com/AztecProtocol/aztec-packages/issues/2918 is implemented.\n unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, serialized_note: [Field; 0]) -> [Field; 4] {\n [0, 0, 0, 0]\n }\n}\n",
"path": "/mnt/user-data/jan/aztec-packages/yarn-project/boxes/blank/src/contracts/src/main.nr"
},
"35": {
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/boxes/blank/src/artifacts/Blank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export class BlankContract extends ContractBase {
/** Type-safe wrappers for the public methods exposed by the contract. */
public methods!: {

/** compute_note_hash_and_nullifier(contract_address: field, nonce: field, storage_slot: field, preimage: array) */
compute_note_hash_and_nullifier: ((contract_address: FieldLike, nonce: FieldLike, storage_slot: FieldLike, preimage: FieldLike[]) => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
/** compute_note_hash_and_nullifier(contract_address: field, nonce: field, storage_slot: field, serialized_note: array) */
compute_note_hash_and_nullifier: ((contract_address: FieldLike, nonce: FieldLike, storage_slot: FieldLike, serialized_note: FieldLike[]) => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;

/** getPublicKey(address: field) */
getPublicKey: ((address: FieldLike) => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/boxes/blank/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract Blank {
// A function which needs to be implemented by every contract working with storage. Replace it's content with your
// own logic once you start working with private storage.
// TODO: Remove this placeholder once https://github.com/AztecProtocol/aztec-packages/issues/2918 is implemented.
unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; 0]) -> [Field; 4] {
unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, serialized_note: [Field; 0]) -> [Field; 4] {
[0, 0, 0, 0]
}
}
Loading

0 comments on commit 582150f

Please sign in to comment.