-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40cd251
commit 45e17c0
Showing
13 changed files
with
2,060 additions
and
23 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod types; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::types::Felt; | ||
|
||
#[allow(dead_code)] | ||
pub(crate) struct HashInputPair(pub Felt, pub Felt); | ||
|
||
#[allow(dead_code)] | ||
pub(crate) struct HashOutput(pub Felt); | ||
|
||
#[allow(dead_code)] | ||
impl HashOutput { | ||
pub(crate) const ZERO: HashOutput = HashOutput(Felt::ZERO); | ||
} | ||
|
||
pub(crate) trait HashFunction { | ||
/// Computes the hash of given input. | ||
async fn compute_hash(i: HashInputPair) -> HashOutput; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
// TODO(Dori, 3/3/2024): Delete this dummy code. | ||
pub fn dummy() -> u8 { | ||
7 | ||
} | ||
|
||
#[cfg(test)] | ||
pub mod test { | ||
use super::dummy; | ||
use pretty_assertions::assert_eq; | ||
|
||
#[test] | ||
fn test_dummy() { | ||
assert_eq!(dummy(), 7); | ||
} | ||
} | ||
pub mod hash; | ||
pub mod patricia_merkle_tree; | ||
pub mod types; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pub mod errors; | ||
pub mod filled_node; | ||
pub mod filled_tree; | ||
pub mod skeleton_node; | ||
pub mod skeleton_tree; | ||
pub mod types; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// TODO(Amos, 01/04/2024): Add error types. | ||
#[derive(Debug)] | ||
pub enum SkeletonTreeError {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use starknet_api::core::{ClassHash, Nonce}; | ||
|
||
use crate::patricia_merkle_tree::types::{Leaf, PathToBottom}; | ||
use crate::{hash::types::HashOutput, types::Felt}; | ||
|
||
#[allow(dead_code)] | ||
pub(crate) enum FilledNode<L: Leaf> { | ||
Binary { data: BinaryData, hash: HashOutput }, | ||
Edge { data: EdgeData<L>, hash: HashOutput }, | ||
Leaf(L), | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub(crate) struct BinaryData { | ||
left_hash: HashOutput, | ||
right_hash: HashOutput, | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub(crate) struct EdgeData<L: Leaf> { | ||
bottom_value: BottomData<L>, | ||
path_to_bottom: PathToBottom, | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub(crate) enum BottomData<L: Leaf> { | ||
BottomBinaryData(BinaryData), | ||
BottomLeafData(L), | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub(crate) enum LeafEnum { | ||
StorageValue(Felt), | ||
CompiledClassHash(Felt), | ||
StateTreeValue { | ||
class_hash: ClassHash, | ||
contract_state_root_hash: Felt, | ||
nonce: Nonce, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use std::iter::Map; | ||
|
||
use crate::patricia_merkle_tree::filled_node::FilledNode; | ||
use crate::patricia_merkle_tree::types::{Leaf, NodeIndex}; | ||
|
||
pub(crate) trait FilledTree<L: Leaf> { | ||
fn get_all_nodes(&self) -> Map<NodeIndex, &FilledNode<L>>; | ||
} |
10 changes: 10 additions & 0 deletions
10
crates/committer/src/patricia_merkle_tree/skeleton_node.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use crate::hash::types::HashOutput; | ||
use crate::patricia_merkle_tree::types::{Leaf, PathToBottom}; | ||
|
||
#[allow(dead_code)] | ||
pub(crate) enum SkeletonNode<L: Leaf> { | ||
Binary, | ||
Edge { path_to_bottom: PathToBottom }, | ||
Sibling(HashOutput), | ||
Leaf(L), | ||
} |
19 changes: 19 additions & 0 deletions
19
crates/committer/src/patricia_merkle_tree/skeleton_tree.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::iter::Map; | ||
|
||
use crate::patricia_merkle_tree::errors::SkeletonTreeError; | ||
use crate::patricia_merkle_tree::filled_tree::FilledTree; | ||
use crate::patricia_merkle_tree::skeleton_node::SkeletonNode; | ||
use crate::patricia_merkle_tree::types::{Leaf, NodeIndex, TreeHashFunction}; | ||
|
||
pub(crate) trait CurrentSkeletonTree<L: Leaf, H: TreeHashFunction<L>> { | ||
/// Computes and returns updated skeleton tree. | ||
fn compute_updated_skeleton_tree( | ||
&self, | ||
index_to_updated_leaf: Map<NodeIndex, &SkeletonNode<L>>, | ||
) -> Result<SkeletonTreeError, impl UpdatedSkeletonTree<L, H>>; | ||
} | ||
|
||
pub(crate) trait UpdatedSkeletonTree<L: Leaf, H: TreeHashFunction<L>> { | ||
/// Computes and returns the filled tree. | ||
fn compute_filled_tree(&self) -> Result<SkeletonTreeError, impl FilledTree<L>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::hash::types::HashOutput; | ||
use crate::patricia_merkle_tree::skeleton_node::SkeletonNode; | ||
use crate::types::Felt; | ||
|
||
pub(crate) trait TreeHashFunction<L: Leaf> { | ||
/// Computes the hash of given input. | ||
async fn compute_node_hash(skeleton_node: SkeletonNode<L>) -> HashOutput; | ||
} | ||
|
||
// TODO(Amos, 01/05/2024): Implement types for NodeIndex, EdgePath, EdgePathLength | ||
#[allow(dead_code)] | ||
pub(crate) struct NodeIndex(pub Felt); | ||
|
||
#[allow(dead_code)] | ||
pub(crate) struct EdgePath(pub Felt); | ||
|
||
#[allow(dead_code)] | ||
pub(crate) struct EdgePathLength(pub Felt); | ||
|
||
#[allow(dead_code)] | ||
pub(crate) struct PathToBottom { | ||
pub path: EdgePath, | ||
pub length: EdgePathLength, | ||
} | ||
|
||
pub(crate) trait Leaf { | ||
/// Returns data of leaf. | ||
fn get_data(&self) -> Self; | ||
/// Returns true if leaf is empty. | ||
fn is_empty(&self) -> bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
use starknet_types_core::felt::Felt as StarknetTypesFelt; | ||
|
||
pub(crate) type Felt = StarknetTypesFelt; |