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: rename types to hash_trait and add pedersen file #42

Merged
merged 1 commit into from
Apr 16, 2024
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
3 changes: 2 additions & 1 deletion crates/committer/src/hash.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod types;
pub mod hash_trait;
pub mod pedersen;
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use starknet_types_core::hash::{Pedersen, StarkHash};

use crate::types::Felt;

#[allow(dead_code)]
Expand All @@ -18,11 +16,3 @@ pub(crate) trait HashFunction {
/// Computes the hash of given input.
fn compute_hash(i: HashInputPair) -> HashOutput;
}

pub(crate) struct PedersenHashFunction;

impl HashFunction for PedersenHashFunction {
fn compute_hash(i: HashInputPair) -> HashOutput {
HashOutput(Pedersen::hash(&i.0.into(), &i.1.into()).into())
}
}
11 changes: 11 additions & 0 deletions crates/committer/src/hash/pedersen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use starknet_types_core::hash::{Pedersen, StarkHash};

use crate::hash::hash_trait::{HashFunction, HashInputPair, HashOutput};

pub(crate) struct PedersenHashFunction;

impl HashFunction for PedersenHashFunction {
fn compute_hash(i: HashInputPair) -> HashOutput {
HashOutput(Pedersen::hash(&i.0.into(), &i.1.into()).into())
}
}
2 changes: 1 addition & 1 deletion crates/committer/src/patricia_merkle_tree/filled_node.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::patricia_merkle_tree::types::{EdgeData, LeafDataTrait};
use crate::{hash::types::HashOutput, types::Felt};
use crate::{hash::hash_trait::HashOutput, types::Felt};
// TODO(Nimrod, 1/6/2024): Swap to starknet-types-core types once implemented.
#[allow(dead_code)]
pub(crate) struct ClassHash(pub Felt);
Expand Down
2 changes: 1 addition & 1 deletion crates/committer/src/patricia_merkle_tree/filled_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::collections::HashSet;
use std::sync::Mutex;

use crate::hash::types::HashOutput;
use crate::hash::hash_trait::HashOutput;
use crate::patricia_merkle_tree::errors::FilledTreeError;
use crate::patricia_merkle_tree::filled_node::FilledNode;
use crate::patricia_merkle_tree::types::{LeafDataTrait, NodeIndex};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::hash::types::HashOutput;
use crate::hash::hash_trait::HashOutput;
use crate::patricia_merkle_tree::types::{EdgeData, LeafDataTrait, PathToBottom};

#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use crate::hash::types::HashOutput;
use crate::hash::hash_trait::HashOutput;
use crate::patricia_merkle_tree::errors::OriginalSkeletonTreeError;
use crate::patricia_merkle_tree::types::{LeafDataTrait, NodeIndex, TreeHeight};
use crate::patricia_merkle_tree::updated_skeleton_tree::UpdatedSkeletonTree;
Expand Down
2 changes: 1 addition & 1 deletion crates/committer/src/patricia_merkle_tree/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::marker::PhantomData;

use crate::hash::types::{HashFunction, HashInputPair, HashOutput};
use crate::hash::hash_trait::{HashFunction, HashInputPair, HashOutput};
use crate::patricia_merkle_tree::filled_node::{BinaryData, LeafData, NodeData};
use crate::types::Felt;

Expand Down
3 changes: 2 additions & 1 deletion crates/committer/src/patricia_merkle_tree/types_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::hash::types::{HashFunction, HashInputPair, HashOutput, PedersenHashFunction};
use crate::hash::hash_trait::{HashFunction, HashInputPair, HashOutput};
use crate::hash::pedersen::PedersenHashFunction;
use crate::patricia_merkle_tree::filled_node::{BinaryData, NodeData};
use crate::patricia_merkle_tree::types::TreeHashFunction;
use crate::patricia_merkle_tree::types::{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::hash::types::HashOutput;
use crate::hash::hash_trait::HashOutput;
use crate::patricia_merkle_tree::types::{LeafDataTrait, PathToBottom};

#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use crate::hash::types::HashFunction;
use crate::hash::hash_trait::HashFunction;
use crate::patricia_merkle_tree::errors::UpdatedSkeletonTreeError;
use crate::patricia_merkle_tree::filled_tree::FilledTree;
use crate::patricia_merkle_tree::types::{LeafDataTrait, NodeIndex, TreeHashFunction};
Expand Down
Loading