Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: let IndexedTreeLeafPreimage have LeafPreimage as a parent trait #10913

Merged
merged 6 commits into from
Jan 6, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ impl OrderedValue<Field> for LogHash {
fn value(self) -> Field {
self.value
}
fn counter(self) -> u32 {
self.counter
}
}

impl Eq for LogHash {
Expand Down Expand Up @@ -83,9 +80,6 @@ impl OrderedValue<Field> for ScopedLogHash {
fn value(self) -> Field {
self.log_hash.value
}
fn counter(self) -> u32 {
self.log_hash.counter
}
}

impl Eq for ScopedLogHash {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ impl OrderedValue<Field> for ScopedNoteHash {
fn value(self) -> Field {
self.note_hash.value
}
fn counter(self) -> u32 {
self.note_hash.counter
}
}

impl Eq for ScopedNoteHash {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ impl OrderedValue<Field> for Nullifier {
fn value(self) -> Field {
self.value
}
fn counter(self) -> u32 {
self.counter
}
}

impl Eq for Nullifier {
Expand Down Expand Up @@ -102,9 +99,6 @@ impl OrderedValue<Field> for ScopedNullifier {
fn value(self) -> Field {
self.nullifier.value
}
fn counter(self) -> u32 {
self.nullifier.counter
}
}

impl Eq for ScopedNullifier {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ impl LeafPreimage for NullifierLeafPreimage {
}

impl IndexedTreeLeafPreimage<Field> for NullifierLeafPreimage {
fn get_key(self) -> Field {
self.nullifier
}

fn get_next_key(self) -> Field {
self.next_nullifier
}
Expand All @@ -52,10 +48,6 @@ impl IndexedTreeLeafPreimage<Field> for NullifierLeafPreimage {
(self.next_nullifier == 0) & (self.next_index == 0)
}

fn as_leaf(self) -> Field {
self.hash()
}

fn update_pointers(self, next_key: Field, next_index: u32) -> Self {
Self { nullifier: self.nullifier, next_nullifier: next_key, next_index }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ pub trait RangeOrdered {
fn counter_end(self) -> u32;
}

pub trait OrderedValue<T>
pub trait OrderedValue<T>: Ordered
where
T: Eq,
{
fn value(self) -> T;
fn counter(self) -> u32;
}

pub trait Scoped<T>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
data::public_data_tree_leaf::PublicDataTreeLeaf,
merkle_tree::leaf_preimage::IndexedTreeLeafPreimage,
merkle_tree::leaf_preimage::{IndexedTreeLeafPreimage, LeafPreimage},
traits::{Empty, Hash},
};

Expand Down Expand Up @@ -41,11 +41,17 @@ impl Hash for PublicDataTreeLeafPreimage {
}
}

impl IndexedTreeLeafPreimage<PublicDataTreeLeaf> for PublicDataTreeLeafPreimage {
impl LeafPreimage for PublicDataTreeLeafPreimage {
fn get_key(self) -> Field {
self.slot
}

fn as_leaf(self) -> Field {
self.hash()
}
}

impl IndexedTreeLeafPreimage<PublicDataTreeLeaf> for PublicDataTreeLeafPreimage {
fn get_next_key(self) -> Field {
self.next_slot
}
Expand All @@ -54,10 +60,6 @@ impl IndexedTreeLeafPreimage<PublicDataTreeLeaf> for PublicDataTreeLeafPreimage
(self.next_slot == 0) & (self.next_index == 0)
}

fn as_leaf(self) -> Field {
self.hash()
}

fn update_pointers(self, next_slot: Field, next_index: u32) -> Self {
Self { slot: self.slot, value: self.value, next_slot, next_index }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod tests {
indexed_tree::check_valid_low_leaf::assert_check_valid_low_leaf,
leaf_preimage::IndexedTreeLeafPreimage,
};
use crate::merkle_tree::leaf_preimage::LeafPreimage;
use crate::traits::Empty;

struct TestLeafPreimage {
Expand All @@ -38,11 +39,18 @@ mod tests {
}
}

impl IndexedTreeLeafPreimage<Field> for TestLeafPreimage {
impl LeafPreimage for TestLeafPreimage {
fn get_key(self) -> Field {
self.value
}

fn as_leaf(self) -> Field {
self.value
}
}

impl IndexedTreeLeafPreimage<Field> for TestLeafPreimage {

fn get_next_key(self) -> Field {
self.next_value
}
Expand All @@ -51,10 +59,6 @@ mod tests {
(self.next_value == 0)
}

fn as_leaf(self) -> Field {
self.value
}

fn update_pointers(self, next_value: Field, _next_index: u32) -> Self {
Self { value: self.value, next_value }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ pub trait LeafPreimage {
fn as_leaf(self) -> Field;
}

pub trait IndexedTreeLeafPreimage<Value>: Eq + Empty {
fn get_key(self) -> Field;

pub trait IndexedTreeLeafPreimage<Value>: Eq + Empty + LeafPreimage {
fn get_next_key(self) -> Field;

fn as_leaf(self) -> Field;

fn points_to_infinity(self) -> bool;

fn update_pointers(self, next_key: Field, next_index: u32) -> Self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ mod tests {
}

impl IndexedTreeLeafPreimage<Field> for TestLeafPreimage {
fn get_key(self) -> Field {
self.value
}

fn get_next_key(self) -> Field {
self.next_value
}
Expand All @@ -136,10 +132,6 @@ mod tests {
(self.next_value == 0)
}

fn as_leaf(self) -> Field {
pedersen_hash([self.value])
}

fn update_pointers(self, next_value: Field, _next_index: u32) -> Self {
Self { value: self.value, next_value }
}
Expand Down
Loading