Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 23, 2023
1 parent 69c1d66 commit 756cbea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
31 changes: 22 additions & 9 deletions yarn-project/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -67,20 +85,15 @@ 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]{
note.serialize()
}

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 {
Expand Down
6 changes: 1 addition & 5 deletions yarn-project/aztec-nr/value-note/src/value_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 756cbea

Please sign in to comment.