From 756cbeab894b2abd45746d388cd86c00eab05549 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 d1de9c35f77e..6f13765ba134 100644 --- a/yarn-project/aztec-nr/address-note/src/address_note.nr +++ b/yarn-project/aztec-nr/address-note/src/address_note.nr @@ -8,32 +8,50 @@ use dep::aztec::{ utils::compute_siloed_note_hash, }, oracle::{ + rand::rand, get_secret_key::get_secret_key, get_public_key::get_public_key, }, 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 { @@ -67,11 +85,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]{ @@ -79,8 +93,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. - dep::std::hash::pedersen(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 dc568abd0c72..803cb82ce2a1 100644 --- a/yarn-project/aztec-nr/value-note/src/value_note.nr +++ b/yarn-project/aztec-nr/value-note/src/value_note.nr @@ -51,11 +51,7 @@ impl ValueNote { pub fn compute_note_hash(self) -> Field { // TODO(#1205) Should use a non-zero generator index. - dep::std::hash::pedersen([ - self.value, - self.owner, - self.randomness, - ])[0] + dep::std::hash::pedersen(self.serialize())[0] } // docs:start:nullifier