Skip to content

fix: removed implicit conversion felt => NodeIndex #103

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
Merged
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
22 changes: 10 additions & 12 deletions crates/committer/src/patricia_merkle_tree/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl NodeIndex {
path_to_bottom: &PathToBottom,
) -> NodeIndex {
let PathToBottom { path, length } = path_to_bottom;
(index << length.0) + NodeIndex::from(path.0)
(index << length.0) + Self::from_felt_value(&path.0)
}

pub(crate) fn bit_length(&self) -> u8 {
Expand All @@ -51,22 +51,26 @@ impl NodeIndex {
key: &StarknetStorageKey,
tree_height: &TreeHeight,
) -> Self {
Self::from_felt(&key.0, tree_height)
Self::from_leaf_felt(&key.0, tree_height)
}

pub(crate) fn from_contract_address(
address: &ContractAddress,
tree_height: &TreeHeight,
) -> Self {
Self::from_felt(&address.0, tree_height)
Self::from_leaf_felt(&address.0, tree_height)
}

pub(crate) fn from_class_hash(class_hash: &ClassHash, tree_height: &TreeHeight) -> Self {
Self::from_felt(&class_hash.0, tree_height)
Self::from_leaf_felt(&class_hash.0, tree_height)
}

fn from_felt(felt: &Felt, tree_height: &TreeHeight) -> Self {
Self(U256::from(1_u8) << tree_height.0) + Self::from(*felt)
fn from_leaf_felt(felt: &Felt, tree_height: &TreeHeight) -> Self {
Self(U256::from(1_u8) << tree_height.0) + Self::from_felt_value(felt)
}

fn from_felt_value(felt: &Felt) -> Self {
NodeIndex(U256::from_be_bytes(felt.to_bytes_be()))
}
}

Expand Down Expand Up @@ -94,12 +98,6 @@ impl From<u128> for NodeIndex {
}
}

impl From<Felt> for NodeIndex {
fn from(value: Felt) -> Self {
Self(U256::from_be_bytes(value.to_bytes_be()))
}
}

#[allow(dead_code)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, derive_more::Sub)]
pub struct TreeHeight(pub u8);
Loading