From b94bc0527009e9079fe35a3c8f09e6902e1b7a79 Mon Sep 17 00:00:00 2001 From: benesjan Date: Mon, 23 Oct 2023 09:01:39 +0000 Subject: [PATCH] WIP --- .../aztec-nr/address-note/src/address_note.nr | 31 +++++++++++++------ .../aztec-nr/value-note/src/value_note.nr | 6 +--- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/yarn-project/aztec-nr/address-note/src/address_note.nr b/yarn-project/aztec-nr/address-note/src/address_note.nr index 020f59fd8419..420af719a88a 100644 --- a/yarn-project/aztec-nr/address-note/src/address_note.nr +++ b/yarn-project/aztec-nr/address-note/src/address_note.nr @@ -8,6 +8,7 @@ use dep::aztec::{ utils::compute_siloed_note_hash, }, oracle::{ + rand::rand, get_secret_key::get_secret_key, get_public_key::get_public_key, }, @@ -15,26 +16,43 @@ use dep::aztec::{ context::PrivateContext, }; -global ADDRESS_NOTE_LEN: Field = 2; +global ADDRESS_NOTE_LEN: Field = 3; // Stores an address struct AddressNote { address: Field, owner: Field, + randomness: Field, header: NoteHeader, } impl AddressNote { pub fn new(address: Field, owner: Field) -> Self { + let randomness = rand(); AddressNote { address, owner, + randomness, header: NoteHeader::empty(), } } pub fn serialize(self) -> [Field; ADDRESS_NOTE_LEN]{ - [self.address, self.owner] + [self.address, self.owner, self.randomness] + } + + pub fn deserialize(preimage: [Field; ADDRESS_NOTE_LEN]) -> Self { + AddressNote { + address: preimage[0], + owner: preimage[1], + randomness: preimage[2], + header: NoteHeader::empty(), + } + } + + pub fn compute_note_hash(self) -> Field { + // TODO(#1205) Should use a non-zero generator index. + dep::std::hash::pedersen(self.serialize())[0] } pub fn compute_nullifier(self) -> Field { @@ -68,11 +86,7 @@ impl AddressNote { } fn deserialize(preimage: [Field; ADDRESS_NOTE_LEN]) -> AddressNote { - AddressNote { - address: preimage[0], - owner: preimage[1], - header: NoteHeader::empty(), - } + AddressNote::deserialize(preimage) } fn serialize(note: AddressNote) -> [Field; ADDRESS_NOTE_LEN]{ @@ -80,8 +94,7 @@ fn serialize(note: AddressNote) -> [Field; ADDRESS_NOTE_LEN]{ } fn compute_note_hash(note: AddressNote) -> Field { - // TODO(#1205) Should use a non-zero generator index. - pedersen_hash(note.serialize(),0) + note.compute_note_hash() } fn compute_nullifier(note: AddressNote) -> Field { diff --git a/yarn-project/aztec-nr/value-note/src/value_note.nr b/yarn-project/aztec-nr/value-note/src/value_note.nr index 31b9cc5f951b..c49e14281e0c 100644 --- a/yarn-project/aztec-nr/value-note/src/value_note.nr +++ b/yarn-project/aztec-nr/value-note/src/value_note.nr @@ -52,11 +52,7 @@ impl ValueNote { pub fn compute_note_hash(self) -> Field { // TODO(#1205) Should use a non-zero generator index. - pedersen_hash([ - self.value, - self.owner, - self.randomness, - ],0) + dep::std::hash::pedersen(self.serialize())[0] } // docs:start:nullifier