Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 31, 2023
1 parent bebc37a commit 7f33d44
Show file tree
Hide file tree
Showing 33 changed files with 116 additions and 114 deletions.
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/token/src/artifacts/Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export class TokenContract extends ContractBase {
/** burn_public(from: struct, amount: field, nonce: field) */
burn_public: ((from: AztecAddressLike, amount: FieldLike, nonce: FieldLike) => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;

/** 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'>;

/** is_minter(minter: struct) */
is_minter: ((minter: AztecAddressLike) => ContractFunctionInteraction) & Pick<ContractMethod, 'selector'>;
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/boxes/token/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -427,18 +427,18 @@ contract Token {
// docs:end:balance_of_public

// Below this point is the stuff of nightmares.
// This should ideally not be required. What do we do if vastly different types of preimages?
// This should ideally not be required. What do we do if vastly different types of serialized_notes?

// docs:start:compute_note_hash_and_nullifier
// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; TOKEN_NOTE_LEN]) -> [Field; 4] {
unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, serialized_note: [Field; TOKEN_NOTE_LEN]) -> [Field; 4] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
if (storage_slot == 5) {
note_utils::compute_note_hash_and_nullifier(TransparentNoteMethods, note_header, preimage)
note_utils::compute_note_hash_and_nullifier(TransparentNoteMethods, note_header, serialized_note)
} else {
note_utils::compute_note_hash_and_nullifier(TokenNoteMethods, note_header, preimage)
note_utils::compute_note_hash_and_nullifier(TokenNoteMethods, note_header, serialized_note)
}
}
// docs:end:compute_note_hash_and_nullifier
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/boxes/token/src/contracts/src/types/token_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ impl TokenNote {
[self.amount.value as Field, self.owner.address, self.randomness]
}

pub fn deserialize(preimage: [Field; TOKEN_NOTE_LEN]) -> Self {
pub fn deserialize(serialized_note: [Field; TOKEN_NOTE_LEN]) -> Self {
Self {
amount: SafeU120::new(preimage[0]),
owner: AztecAddress::new(preimage[1]),
randomness: preimage[2],
amount: SafeU120::new(serialized_note[0]),
owner: AztecAddress::new(serialized_note[1]),
randomness: serialized_note[2],
header: NoteHeader::empty(),
}
}
Expand Down Expand Up @@ -101,8 +101,8 @@ impl TokenNote {
}
}

fn deserialize(preimage: [Field; TOKEN_NOTE_LEN]) -> TokenNote {
TokenNote::deserialize(preimage)
fn deserialize(serialized_note: [Field; TOKEN_NOTE_LEN]) -> TokenNote {
TokenNote::deserialize(serialized_note)
}

fn serialize(note: TokenNote) -> [Field; TOKEN_NOTE_LEN] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ impl TransparentNote {
[self.amount, self.secret_hash]
}

pub fn deserialize(preimage: [Field; TRANSPARENT_NOTE_LEN]) -> Self {
pub fn deserialize(serialized_note: [Field; TRANSPARENT_NOTE_LEN]) -> Self {
TransparentNote {
amount: preimage[0],
secret_hash: preimage[1],
amount: serialized_note[0],
secret_hash: serialized_note[1],
secret: 0,
header: NoteHeader::empty(),
}
Expand Down Expand Up @@ -90,8 +90,8 @@ impl TransparentNote {
}
}

fn deserialize(preimage: [Field; TRANSPARENT_NOTE_LEN]) -> TransparentNote {
TransparentNote::deserialize(preimage)
fn deserialize(serialized_note: [Field; TRANSPARENT_NOTE_LEN]) -> TransparentNote {
TransparentNote::deserialize(serialized_note)
}

fn serialize(note: TransparentNote) -> [Field; TRANSPARENT_NOTE_LEN] {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_token_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('e2e_token_contract', () => {
expect(receiptClaim.status).toBe(TxStatus.MINED);
tokenSim.redeemShield(accounts[0].address, amount);
// 1 note should be created containing `amount` of tokens
const notes = receiptClaim.notes!;
const notes = receiptClaim.visibleNotes!;
expect(notes.length).toBe(1);
expect(notes[0].note.items[0].toBigInt()).toBe(amount);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ contract Benchmarking {
emit_unencrypted_log(&mut context, storage.balances.at(owner).read());
}

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] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
note_utils::compute_note_hash_and_nullifier(ValueNoteMethods, note_header, preimage)
note_utils::compute_note_hash_and_nullifier(ValueNoteMethods, note_header, serialized_note)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ contract CardGame {
// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
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] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
note_utils::compute_note_hash_and_nullifier(ValueNoteMethods, note_header, preimage)
note_utils::compute_note_hash_and_nullifier(ValueNoteMethods, note_header, serialized_note)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ impl CardNote {
[self.points as Field, self.secret, self.owner]
}

pub fn deserialize(preimage: [Field; CARD_NOTE_LEN]) -> Self {
pub fn deserialize(serialized_note: [Field; CARD_NOTE_LEN]) -> Self {
CardNote {
points: preimage[0] as u8,
secret: preimage[1],
owner: preimage[2],
points: serialized_note[0] as u8,
secret: serialized_note[1],
owner: serialized_note[2],
header: NoteHeader::empty(),
}
}
Expand Down Expand Up @@ -82,8 +82,8 @@ impl CardNote {
}
}

fn deserialize(preimage: [Field; CARD_NOTE_LEN]) -> CardNote {
CardNote::deserialize(preimage)
fn deserialize(serialized_note: [Field; CARD_NOTE_LEN]) -> CardNote {
CardNote::deserialize(serialized_note)
}

fn serialize(note: CardNote) -> [Field; CARD_NOTE_LEN] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ impl ProfileNote {
[self.avatar, self.xp]
}

pub fn deserialize(preimage: [Field; PROFILE_NOTE_LEN]) -> Self {
pub fn deserialize(serialized_note: [Field; PROFILE_NOTE_LEN]) -> Self {
ProfileNote {
avatar: preimage[0],
xp: preimage[1],
avatar: serialized_note[0],
xp: serialized_note[1],
maybe_owner: Option::none(),
header: NoteHeader::empty(),
}
Expand Down Expand Up @@ -78,8 +78,8 @@ impl ProfileNote {
}
}

fn deserialize(preimage: [Field; PROFILE_NOTE_LEN]) -> ProfileNote {
ProfileNote::deserialize(preimage)
fn deserialize(serialized_note: [Field; PROFILE_NOTE_LEN]) -> ProfileNote {
ProfileNote::deserialize(serialized_note)
}

fn serialize(note: ProfileNote) -> [Field; PROFILE_NOTE_LEN] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ impl RulesNote {
[self.min_points as Field, self.max_points as Field]
}

pub fn deserialize(preimage: [Field; RULES_NOTE_LEN]) -> Self {
pub fn deserialize(serialized_note: [Field; RULES_NOTE_LEN]) -> Self {
RulesNote {
min_points: preimage[0] as u8,
max_points: preimage[1] as u8,
min_points: serialized_note[0] as u8,
max_points: serialized_note[1] as u8,
maybe_owner: Option::none(),
header: NoteHeader::empty(),
}
Expand Down Expand Up @@ -78,8 +78,8 @@ impl RulesNote {
}
}

fn deserialize(preimage: [Field; RULES_NOTE_LEN]) -> RulesNote {
RulesNote::deserialize(preimage)
fn deserialize(serialized_note: [Field; RULES_NOTE_LEN]) -> RulesNote {
RulesNote::deserialize(serialized_note)
}

fn serialize(note: RulesNote) -> [Field; RULES_NOTE_LEN] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ contract EasyPrivateToken {
// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
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] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
note_utils::compute_note_hash_and_nullifier(ValueNoteMethods, note_header, preimage)
note_utils::compute_note_hash_and_nullifier(ValueNoteMethods, note_header, serialized_note)
}
}
// docs:end:easy_private_token_contract
Loading

0 comments on commit 7f33d44

Please sign in to comment.