diff --git a/crates/committer/src/patricia_merkle_tree/types.rs b/crates/committer/src/patricia_merkle_tree/types.rs index 28c40858..bc1d4242 100644 --- a/crates/committer/src/patricia_merkle_tree/types.rs +++ b/crates/committer/src/patricia_merkle_tree/types.rs @@ -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 { @@ -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())) } } @@ -94,12 +98,6 @@ impl From for NodeIndex { } } -impl From 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);