Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use dep::aztec::{
macros::notes::note,
oracle::random::random,
protocol_types::{address::AztecAddress, traits::Packable},
protocol_types::{address::AztecAddress, traits::{Deserialize, Packable, Serialize}},
};

// docs:start:address_note_def
#[derive(Eq, Packable)]
#[derive(Deserialize, Eq, Packable, Serialize)]
#[note]
pub struct AddressNote {
address: AztecAddress,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use protocol_types::constants::{ARCHIVE_HEIGHT, NOTE_HASH_TREE_HEIGHT};
use protocol_types::{
constants::{ARCHIVE_HEIGHT, NOTE_HASH_TREE_HEIGHT},
traits::{Deserialize, Serialize},
};

global NOTE_HASH_TREE_ID: Field = 1;
global ARCHIVE_TREE_ID: Field = 4;
Expand All @@ -10,6 +13,7 @@ global ARCHIVE_TREE_ID: Field = 4;
//
// Another way to do it would be to add "type_hint: [Field; T]" as argument to `get_membership_witness` but that's
// a bit too boilerplatey for my taste.
#[derive(Deserialize, Eq, Serialize)]
pub struct MembershipWitness<let N: u32, let M: u32> {
pub index: Field,
pub path: [Field; N],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
use crate::utils::array;
use dep::protocol_types::{
abis::nullifier_leaf_preimage::NullifierLeafPreimage, constants::NULLIFIER_TREE_HEIGHT,
use protocol_types::{
abis::nullifier_leaf_preimage::NullifierLeafPreimage,
constants::NULLIFIER_TREE_HEIGHT,
traits::{Deserialize, Serialize},
};

// INDEX_LENGTH + NULLIFIER_LEAF_PREIMAGE_LENGTH + NULLIFIER_TREE_HEIGHT
global NULLIFIER_MEMBERSHIP_WITNESS: u32 = 44;

#[derive(Deserialize, Eq, Serialize)]
pub struct NullifierMembershipWitness {
pub index: Field,
pub leaf_preimage: NullifierLeafPreimage,
pub path: [Field; NULLIFIER_TREE_HEIGHT],
}

impl NullifierMembershipWitness {
pub fn deserialize(fields: [Field; NULLIFIER_MEMBERSHIP_WITNESS]) -> Self {
let serialized_leaf_preimage = array::subarray(fields, 1);

Self {
index: fields[0],
leaf_preimage: NullifierLeafPreimage::deserialize(serialized_leaf_preimage),
path: array::subarray(fields, 1 + serialized_leaf_preimage.len()),
}
}
}

#[oracle(utilityGetLowNullifierMembershipWitness)]
unconstrained fn get_low_nullifier_membership_witness_oracle(
_block_number: u32,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use dep::protocol_types::{constants::PUBLIC_DATA_TREE_HEIGHT, data::PublicDataTreeLeafPreimage};
use protocol_types::{constants::PUBLIC_DATA_TREE_HEIGHT, data::PublicDataTreeLeafPreimage};
use protocol_types::traits::{Deserialize, Serialize};

#[derive(Deserialize, Eq, Serialize)]
pub struct PublicDataWitness {
pub index: Field,
pub leaf_preimage: PublicDataTreeLeafPreimage,
Expand Down
1 change: 0 additions & 1 deletion noir-projects/aztec-nr/aztec/src/utils/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ pub mod conversion;
pub mod point;
pub mod random;
pub mod to_bytes;
pub mod secrets;
pub mod with_hash;
pub mod remove_constraints;
14 changes: 0 additions & 14 deletions noir-projects/aztec-nr/aztec/src/utils/secrets.nr

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use dep::aztec::protocol_types::{traits::{Deserialize, Serialize}, utils::field:
/// into 31-byte chunks, with each chunk being put into a field.
/// Each field can store 31 characters, so N should be M/31 rounded up.
/// Can be used for longer strings that don't fit into a single field.
#[derive(Deserialize, Eq)]
#[derive(Deserialize, Eq, Serialize)]
pub struct CompressedString<let N: u32, let M: u32> {
value: [Field; N],
}
Expand Down Expand Up @@ -57,17 +57,6 @@ impl<let N: u32, let M: u32> CompressedString<N, M> {
}
}

// TODO: Replace this with the derived version. Not done yet as this uncovered a bug in the AVM. See the discussion
// below for more details:
// https://aztecprotocol.slack.com/archives/C02M7VC7TN0/p1754463522334449
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI passed so this is no longer an issue. What a nice surprise.

impl<let N: u32, let M: u32> Serialize for CompressedString<N, M> {
let N: u32 = N;

fn serialize(self) -> [Field; Self::N] {
self.value
}
}

#[test]
unconstrained fn test_short_string() {
let i = "Hello world";
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/value-note/src/value_note.nr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use aztec::{
macros::notes::note,
oracle::random::random,
protocol_types::{address::AztecAddress, traits::Packable},
protocol_types::{address::AztecAddress, traits::{Deserialize, Packable, Serialize}},
};

// docs:start:value-note-def
#[derive(Eq, Packable)]
#[derive(Deserialize, Eq, Packable, Serialize)]
#[note]
pub struct ValueNote {
value: Field,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
pub global NULLIFIER_LEAF_PREIMAGE_LENGTH: u32 = 3;

use crate::{
abis::{read_request::ScopedReadRequest, side_effect::Readable},
hash::compute_siloed_nullifier,
merkle_tree::{IndexedTreeLeafPreimage, LeafPreimage},
traits::{Empty, Hash},
traits::{Deserialize, Empty, Hash, Serialize},
};

#[derive(Deserialize, Eq, Serialize)]
pub struct NullifierLeafPreimage {
pub nullifier: Field,
pub next_nullifier: Field,
Expand Down Expand Up @@ -78,28 +77,4 @@ impl NullifierLeafPreimage {
pub fn is_empty(self) -> bool {
(self.nullifier == 0) & (self.next_nullifier == 0) & (self.next_index == 0)
}

pub fn serialize(self) -> [Field; NULLIFIER_LEAF_PREIMAGE_LENGTH] {
[self.nullifier, self.next_nullifier, self.next_index]
}

pub fn deserialize(fields: [Field; NULLIFIER_LEAF_PREIMAGE_LENGTH]) -> Self {
Self { nullifier: fields[0], next_nullifier: fields[1], next_index: fields[2] }
}
}

impl Eq for NullifierLeafPreimage {
fn eq(self, other: Self) -> bool {
(self.nullifier == other.nullifier)
& (self.next_nullifier == other.next_nullifier)
& (self.next_index == other.next_index)
}
}

#[test]
fn serialization_of_empty() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped this test as now, that serde is derived, it seems out of place.

let item = NullifierLeafPreimage::empty();
let serialized = item.serialize();
let deserialized = NullifierLeafPreimage::deserialize(serialized);
assert(item.eq(deserialized));
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::{
data::public_data_tree_leaf::PublicDataTreeLeaf,
merkle_tree::{IndexedTreeLeafPreimage, LeafPreimage},
traits::{Empty, Hash},
traits::{Deserialize, Empty, Hash, Serialize},
};

#[derive(Deserialize, Eq, Serialize)]
pub struct PublicDataTreeLeafPreimage {
pub slot: Field,
pub value: Field,
Expand All @@ -17,15 +18,6 @@ impl Empty for PublicDataTreeLeafPreimage {
}
}

impl Eq for PublicDataTreeLeafPreimage {
fn eq(self, other: Self) -> bool {
(self.slot == other.slot)
& (self.value == other.value)
& (self.next_slot == other.next_slot)
& (self.next_index == other.next_index)
}
}

impl Hash for PublicDataTreeLeafPreimage {
fn hash(self) -> Field {
if self.is_empty() {
Expand Down
Loading