Skip to content

chore(skeleton): replace EdgeSibling with UnmodifiedBottom in original #145

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

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 @@ -139,24 +139,20 @@ impl OriginalSkeletonTreeImpl {
bottom_hash,
path_to_bottom,
}) => {
self.nodes.insert(
subtree.root_index,
OriginalSkeletonNode::Edge { path_to_bottom },
);
if subtree.is_sibling() {
// Sibling will remain an edge node. No need to open the bottom.
self.nodes.insert(
subtree.root_index,
OriginalSkeletonNode::EdgeSibling(EdgeData {
bottom_hash,
path_to_bottom,
}),
path_to_bottom.bottom_index(subtree.root_index),
OriginalSkeletonNode::UnmodifiedBottom(bottom_hash),
);
continue;
}
// Parse bottom.
let bottom_subtree =
subtree.get_bottom_subtree(&path_to_bottom, &self.tree_height, bottom_hash);
self.nodes.insert(
subtree.root_index,
OriginalSkeletonNode::Edge { path_to_bottom },
);
next_subtrees.push(bottom_subtree);
}
// Leaf node.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::felt::Felt;
use crate::hash::hash_trait::HashOutput;
use crate::patricia_merkle_tree::node_data::inner_node::{EdgeData, EdgePathLength, PathToBottom};
use crate::patricia_merkle_tree::node_data::inner_node::{EdgePathLength, PathToBottom};
use crate::patricia_merkle_tree::node_data::leaf::LeafModifications;
use crate::patricia_merkle_tree::original_skeleton_tree::create_tree::LeafDataImpl;
use crate::patricia_merkle_tree::original_skeleton_tree::node::OriginalSkeletonNode;
Expand Down Expand Up @@ -290,20 +290,12 @@ pub(crate) fn create_leaf_or_binary_sibling_skeleton_node(
)
}

pub(crate) fn create_edge_sibling_skeleton_node(
pub(crate) fn create_unmodified_bottom_skeleton_node(
idx: u128,
path: u128,
length: u8,
hash_output: u128,
) -> (NodeIndex, OriginalSkeletonNode) {
(
NodeIndex::from(idx),
OriginalSkeletonNode::EdgeSibling(EdgeData {
bottom_hash: HashOutput(Felt::from(hash_output)),
path_to_bottom: PathToBottom {
path: path.into(),
length: EdgePathLength(length),
},
}),
OriginalSkeletonNode::UnmodifiedBottom(HashOutput(Felt::from(hash_output))),
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::hash::hash_trait::HashOutput;
use crate::patricia_merkle_tree::node_data::inner_node::{EdgeData, PathToBottom};
use crate::patricia_merkle_tree::node_data::inner_node::PathToBottom;
use crate::patricia_merkle_tree::node_data::leaf::SkeletonLeaf;

#[allow(dead_code)]
Expand All @@ -10,7 +10,7 @@ pub(crate) enum OriginalSkeletonNode {
Edge { path_to_bottom: PathToBottom },
// Unmodified leaf / binary nodes on the merkle paths of modified leaves.
LeafOrBinarySibling(HashOutput),
// Unmodified edge nodes on the merkle paths of modified leaves.
EdgeSibling(EdgeData),
// Unmodified edge siblings bottom nodes on the merkle paths of modified leaves.
UnmodifiedBottom(HashOutput),
Leaf(SkeletonLeaf),
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::patricia_merkle_tree::filled_tree::node::{ClassHash, CompiledClassHas
use crate::patricia_merkle_tree::node_data::leaf::ContractState;
use crate::patricia_merkle_tree::original_skeleton_tree::create_tree::create_tree_test::{
create_32_bytes_entry, create_binary_entry, create_binary_skeleton_node, create_edge_entry,
create_edge_sibling_skeleton_node, create_edge_skeleton_node, create_expected_skeleton,
create_leaf_or_binary_sibling_skeleton_node,
create_edge_skeleton_node, create_expected_skeleton,
create_leaf_or_binary_sibling_skeleton_node, create_unmodified_bottom_skeleton_node,
};
use crate::patricia_merkle_tree::original_skeleton_tree::skeleton_forest::OriginalSkeletonForest;
use crate::patricia_merkle_tree::original_skeleton_tree::tree::OriginalSkeletonTreeImpl;
Expand Down Expand Up @@ -122,7 +122,8 @@ use super::OriginalSkeletonForestImpl;
create_edge_skeleton_node(1, 0, 1),
create_binary_skeleton_node(2),
create_binary_skeleton_node(4),
create_edge_sibling_skeleton_node(5, 1, 1, 76),
create_edge_skeleton_node(5, 1, 1),
create_unmodified_bottom_skeleton_node(11, 76),
create_leaf_or_binary_sibling_skeleton_node(9, 47)
],
3
Expand Down Expand Up @@ -219,6 +220,7 @@ fn test_create_original_skeleton_forest(
.unwrap();

assert_eq!(actual_forest.contracts_trie, expected_forest.contracts_trie);
// TODO(Nimrod, 1/6/2024): Add classes trie and storage_tries comparison.
}

fn create_contract_leaves(leaves: &[(u8, u8)]) -> HashMap<ContractAddress, ContractState> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::patricia_merkle_tree::node_data::inner_node::EdgeData;
use crate::patricia_merkle_tree::node_data::inner_node::PathToBottom;
use crate::patricia_merkle_tree::original_skeleton_tree::node::OriginalSkeletonNode;
use crate::patricia_merkle_tree::original_skeleton_tree::utils::split_leaves;
Expand Down Expand Up @@ -89,20 +88,9 @@ impl UpdatedSkeletonTreeImpl {
OriginalSkeletonNode::LeafOrBinarySibling(hash) => {
UpdatedSkeletonNode::Sibling(*hash)
}
OriginalSkeletonNode::EdgeSibling(EdgeData {
path_to_bottom,
bottom_hash,
}) => {
// Finalize bottom to allow the edge hash computation.
// TODO(Tzahi, 1/6/2024): Consider moving this to the create function, or
// even to the OriginalSkeleton creation.
self.skeleton_tree.insert(
path_to_bottom.bottom_index(index),
UpdatedSkeletonNode::Sibling(*bottom_hash),
);
UpdatedSkeletonNode::Edge {
path_to_bottom: *path_to_bottom,
}
OriginalSkeletonNode::UnmodifiedBottom(hash) => {
// TODO(Tzahi, 1/6/2024): create a new variant in UpdatedSkeletonNode.
UpdatedSkeletonNode::Sibling(*hash)
}
};
self.skeleton_tree.insert(index, updated);
Expand Down Expand Up @@ -147,12 +135,6 @@ impl UpdatedSkeletonTreeImpl {
OriginalSkeletonNode::Edge { path_to_bottom } => OriginalSkeletonNode::Edge {
path_to_bottom: path.concat_paths(*path_to_bottom),
},
OriginalSkeletonNode::EdgeSibling(edge_data) => {
OriginalSkeletonNode::EdgeSibling(EdgeData {
bottom_hash: edge_data.bottom_hash,
path_to_bottom: path.concat_paths(edge_data.path_to_bottom),
})
}
OriginalSkeletonNode::Binary => {
// Finalize bottom - a binary descendant cannot change form.
self.skeleton_tree
Expand All @@ -161,7 +143,8 @@ impl UpdatedSkeletonTreeImpl {
path_to_bottom: *path,
}
}
OriginalSkeletonNode::LeafOrBinarySibling(_) => OriginalSkeletonNode::Edge {
OriginalSkeletonNode::LeafOrBinarySibling(_)
| OriginalSkeletonNode::UnmodifiedBottom(_) => OriginalSkeletonNode::Edge {
path_to_bottom: *path,
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ethnum::U256;
use rstest::{fixture, rstest};

use crate::hash::hash_trait::HashOutput;
use crate::patricia_merkle_tree::node_data::inner_node::{EdgeData, EdgePathLength, PathToBottom};
use crate::patricia_merkle_tree::node_data::inner_node::{EdgePathLength, PathToBottom};
use crate::patricia_merkle_tree::node_data::leaf::SkeletonLeaf;
use crate::patricia_merkle_tree::original_skeleton_tree::node::OriginalSkeletonNode;
use crate::patricia_merkle_tree::types::{NodeIndex, TreeHeight};
Expand Down Expand Up @@ -217,16 +217,16 @@ fn test_node_from_binary_data(
),
&[],
)]
#[case::to_edge_sibling(
&PathToBottom::RIGHT_CHILD,
#[case::to_unmodified_bottom(
&PathToBottom::from("101"),
&NodeIndex::from(5),
&TempSkeletonNode::Original(OriginalSkeletonNode::EdgeSibling(
EdgeData {bottom_hash: HashOutput::ZERO, path_to_bottom: PathToBottom::from("01")}
&TempSkeletonNode::Original(OriginalSkeletonNode::UnmodifiedBottom(
HashOutput::ZERO
)),
&[],
TempSkeletonNode::Original(OriginalSkeletonNode::EdgeSibling(
EdgeData {bottom_hash: HashOutput::ZERO, path_to_bottom: (PathToBottom::from("101"))}
)),
TempSkeletonNode::Original(OriginalSkeletonNode::Edge{
path_to_bottom: PathToBottom::from("101")}
),
&[],
)]
#[case::to_binary(
Expand Down
Loading