diff --git a/crates/committer/src/felt.rs b/crates/committer/src/felt.rs index 6d08274e..25665e06 100644 --- a/crates/committer/src/felt.rs +++ b/crates/committer/src/felt.rs @@ -80,8 +80,4 @@ impl Felt { pub(crate) fn from_hex(hex_string: &str) -> Result { Ok(StarknetTypesFelt::from_hex(hex_string)?.into()) } - - pub fn as_bytes(&self) -> [u8; 32] { - self.0.to_bytes_be() - } } diff --git a/crates/committer/src/patricia_merkle_tree/filled_tree/node_serde.rs b/crates/committer/src/patricia_merkle_tree/filled_tree/node_serde.rs index 308eb673..ddb09de8 100644 --- a/crates/committer/src/patricia_merkle_tree/filled_tree/node_serde.rs +++ b/crates/committer/src/patricia_merkle_tree/filled_tree/node_serde.rs @@ -32,7 +32,7 @@ type FilledNodeDeserializationResult = Result, Deserial impl FilledNode { pub(crate) fn suffix(&self) -> [u8; SERIALIZE_HASH_BYTES] { - self.hash.0.as_bytes() + self.hash.0.to_bytes_be() } } @@ -48,8 +48,8 @@ impl Serializable for FilledNode { right_hash, }) => { // Serialize left and right hashes to byte arrays. - let left: [u8; SERIALIZE_HASH_BYTES] = left_hash.0.as_bytes(); - let right: [u8; SERIALIZE_HASH_BYTES] = right_hash.0.as_bytes(); + let left: [u8; SERIALIZE_HASH_BYTES] = left_hash.0.to_bytes_be(); + let right: [u8; SERIALIZE_HASH_BYTES] = right_hash.0.to_bytes_be(); // Concatenate left and right hashes. let serialized = [left, right].concat(); @@ -61,8 +61,8 @@ impl Serializable for FilledNode { path_to_bottom, }) => { // Serialize bottom hash, path, and path length to byte arrays. - let bottom: [u8; SERIALIZE_HASH_BYTES] = bottom_hash.0.as_bytes(); - let path: [u8; SERIALIZE_HASH_BYTES] = path_to_bottom.path.0.as_bytes(); + let bottom: [u8; SERIALIZE_HASH_BYTES] = bottom_hash.0.to_bytes_be(); + let path: [u8; SERIALIZE_HASH_BYTES] = path_to_bottom.path.0.to_bytes_be(); let length: [u8; 1] = path_to_bottom.length.0.to_be_bytes(); // Concatenate bottom hash, path, and path length. diff --git a/crates/committer/src/patricia_merkle_tree/node_data/leaf_serde.rs b/crates/committer/src/patricia_merkle_tree/node_data/leaf_serde.rs index 6da50002..2d2cecba 100644 --- a/crates/committer/src/patricia_merkle_tree/node_data/leaf_serde.rs +++ b/crates/committer/src/patricia_merkle_tree/node_data/leaf_serde.rs @@ -20,7 +20,7 @@ impl LeafDataImpl { /// describing the leaf and cast it into a byte vector. pub(crate) fn serialize(&self) -> Result { match &self { - LeafDataImpl::StorageValue(value) => Ok(StorageValue(value.as_bytes().to_vec())), + LeafDataImpl::StorageValue(value) => Ok(StorageValue(value.to_bytes_be().to_vec())), LeafDataImpl::CompiledClassHash(class_hash) => { // Create a temporary object to serialize the leaf into a JSON. diff --git a/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree.rs b/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree.rs index a751d3f5..b931b20b 100644 --- a/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree.rs +++ b/crates/committer/src/patricia_merkle_tree/original_skeleton_tree/create_tree.rs @@ -197,7 +197,7 @@ impl OriginalSkeletonTreeImpl { }); continue; } - let key = create_db_key(StoragePrefix::InnerNode, &subtree.root_hash.0.as_bytes()); + let key = create_db_key(StoragePrefix::InnerNode, &subtree.root_hash.0.to_bytes_be()); let val = storage.get(&key).ok_or(StorageError::MissingKey(key))?; subtrees_roots.push(FilledNode::deserialize( &StorageKey::from(subtree.root_hash.0), diff --git a/crates/committer_cli/src/tests/python_tests.rs b/crates/committer_cli/src/tests/python_tests.rs index 2fc24f39..ac8b0893 100644 --- a/crates/committer_cli/src/tests/python_tests.rs +++ b/crates/committer_cli/src/tests/python_tests.rs @@ -112,7 +112,7 @@ pub(crate) fn example_test(test_args: HashMap) -> String { /// Serializes a Felt into a string. pub(crate) fn felt_serialize_test(felt: u128) -> String { - let bytes = Felt::from(felt).as_bytes().to_vec(); + let bytes = Felt::from(felt).to_bytes_be().to_vec(); serde_json::to_string(&bytes) .unwrap_or_else(|error| panic!("Failed to serialize felt: {}", error)) } @@ -430,8 +430,8 @@ pub(crate) fn storage_serialize_test() -> Result { storage: HashMap::new(), }; for i in 0..=99_u128 { - let key = StorageKey(Felt::from(i).as_bytes().to_vec()); - let value = StorageValue(Felt::from(i).as_bytes().to_vec()); + let key = StorageKey(Felt::from(i).to_bytes_be().to_vec()); + let value = StorageValue(Felt::from(i).to_bytes_be().to_vec()); storage.set(key, value); }