diff --git a/yarn-project/aztec-nr/address-note/Nargo.toml b/yarn-project/aztec-nr/address-note/Nargo.toml new file mode 100644 index 00000000000..1d50983678b --- /dev/null +++ b/yarn-project/aztec-nr/address-note/Nargo.toml @@ -0,0 +1,8 @@ +[package] +name = "address_note" +authors = ["aztec-labs"] +compiler_version = "0.7.1" +type = "lib" + +[dependencies] +aztec = { path = "../aztec" } \ No newline at end of file diff --git a/yarn-project/noir-contracts/src/contracts/escrow_contract/src/address_note.nr b/yarn-project/aztec-nr/address-note/src/address_note.nr similarity index 100% rename from yarn-project/noir-contracts/src/contracts/escrow_contract/src/address_note.nr rename to yarn-project/aztec-nr/address-note/src/address_note.nr diff --git a/yarn-project/aztec-nr/address-note/src/lib.nr b/yarn-project/aztec-nr/address-note/src/lib.nr new file mode 100644 index 00000000000..f016584e48c --- /dev/null +++ b/yarn-project/aztec-nr/address-note/src/lib.nr @@ -0,0 +1 @@ +mod address_note; \ No newline at end of file diff --git a/yarn-project/noir-contracts/src/contracts/escrow_contract/Nargo.toml b/yarn-project/noir-contracts/src/contracts/escrow_contract/Nargo.toml index 6278ae9ddfb..0273f8d5f8e 100644 --- a/yarn-project/noir-contracts/src/contracts/escrow_contract/Nargo.toml +++ b/yarn-project/noir-contracts/src/contracts/escrow_contract/Nargo.toml @@ -6,3 +6,4 @@ type = "contract" [dependencies] aztec = { path = "../../../../aztec-nr/aztec" } +address_note = { path = "../../../../aztec-nr/address-note"} diff --git a/yarn-project/noir-contracts/src/contracts/escrow_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/escrow_contract/src/main.nr index c12ddf56bb5..e489eb9812a 100644 --- a/yarn-project/noir-contracts/src/contracts/escrow_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/escrow_contract/src/main.nr @@ -1,5 +1,3 @@ -mod address_note; - // Sample escrow contract that stores a balance of a private token on behalf of an owner. contract Escrow { use dep::std::option::Option; @@ -17,7 +15,7 @@ contract Escrow { state_vars::set::Set, }; - use crate::address_note::{ + use dep::address_note::address_note::{ AddressNote, AddressNoteMethods, ADDRESS_NOTE_LEN, diff --git a/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/Nargo.toml b/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/Nargo.toml index 6b07ad277f4..5d8e70f060d 100644 --- a/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/Nargo.toml +++ b/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/Nargo.toml @@ -6,4 +6,5 @@ type = "contract" [dependencies] aztec = { path = "../../../../aztec-nr/aztec" } +address_note = { path = "../../../../aztec-nr/address-note"} value_note = { path = "../../../../aztec-nr/value-note"} \ No newline at end of file diff --git a/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/address_note.nr b/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/address_note.nr deleted file mode 100644 index 602f5e343d9..00000000000 --- a/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/address_note.nr +++ /dev/null @@ -1,78 +0,0 @@ -use dep::aztec::note::note_interface::NoteInterface; -use dep::aztec::note::note_header::NoteHeader; -use dep::aztec::note::utils::compute_unique_siloed_note_hash; -use dep::aztec::oracle::get_secret_key::get_secret_key; - -global ADDRESS_NOTE_LEN: Field = 1; - -struct AddressNote { - address: Field, - header: NoteHeader, -} - -impl AddressNote { - pub fn new(address: Field) -> Self { - AddressNote { - address, - header: NoteHeader::empty(), - } - } - - pub fn serialize(self) -> [Field; ADDRESS_NOTE_LEN] { - let mut res: [Field; ADDRESS_NOTE_LEN] = [0; ADDRESS_NOTE_LEN]; - res[0] = self.address; - res - } - - pub fn compute_nullifier(self) -> Field { - let unique_siloed_note_hash = compute_unique_siloed_note_hash(AddressNoteMethods, self); - let secret = get_secret_key(self.address); - // TODO(#1205) Should use a non-zero generator index. - dep::std::hash::pedersen([ - unique_siloed_note_hash, - secret.low, - secret.high, - ])[0] - } - - pub fn set_header(&mut self, header: NoteHeader) { - self.header = header; - } -} - -fn deserialize(preimage: [Field; ADDRESS_NOTE_LEN]) -> AddressNote { - AddressNote { - address: preimage[0], - header: NoteHeader::empty(), - } -} - -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] -} - -fn compute_nullifier(note: AddressNote) -> Field { - note.compute_nullifier() -} - -fn get_header(note: AddressNote) -> NoteHeader { - note.header -} - -fn set_header(note: &mut AddressNote, header: NoteHeader) { - note.set_header(header); -} - -global AddressNoteMethods = NoteInterface { - deserialize, - serialize, - compute_note_hash, - compute_nullifier, - get_header, - set_header, -}; diff --git a/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/main.nr index 1c3ef3fa5e8..7d9a7d77e0e 100644 --- a/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/pokeable_token_contract/src/main.nr @@ -1,5 +1,3 @@ -mod address_note; - contract PokeableToken { // Libs use dep::std::option::Option; @@ -19,7 +17,11 @@ contract PokeableToken { state_vars::{immutable_singleton::ImmutableSingleton, map::Map, set::Set}, types::point::Point, }; - use crate::address_note::{AddressNote, AddressNoteMethods, ADDRESS_NOTE_LEN}; + use dep::address_note::address_note::{ + AddressNote, + AddressNoteMethods, + ADDRESS_NOTE_LEN, + }; struct Storage { sender: ImmutableSingleton, @@ -50,8 +52,8 @@ contract PokeableToken { sender: Field, recipient: Field ) { - let mut sender_note = AddressNote::new(sender); - let mut recipient_note = AddressNote::new(recipient); + let mut sender_note = AddressNote::new(sender, sender); + let mut recipient_note = AddressNote::new(recipient, recipient); storage.sender.initialize(&mut sender_note, Option::none()); storage.recipient.initialize(&mut recipient_note, Option::none());