Skip to content

refactor: remove duplication of functions in imp felt #106

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
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
4 changes: 0 additions & 4 deletions crates/committer/src/felt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,4 @@ impl Felt {
pub(crate) fn from_hex(hex_string: &str) -> Result<Self, FromStrError> {
Ok(StarknetTypesFelt::from_hex(hex_string)?.into())
}

pub fn as_bytes(&self) -> [u8; 32] {
self.0.to_bytes_be()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type FilledNodeDeserializationResult = Result<FilledNode<LeafDataImpl>, Deserial

impl FilledNode<LeafDataImpl> {
pub(crate) fn suffix(&self) -> [u8; SERIALIZE_HASH_BYTES] {
self.hash.0.as_bytes()
self.hash.0.to_bytes_be()
}
}

Expand All @@ -48,8 +48,8 @@ impl Serializable for FilledNode<LeafDataImpl> {
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();
Expand All @@ -61,8 +61,8 @@ impl Serializable for FilledNode<LeafDataImpl> {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl LeafDataImpl {
/// describing the leaf and cast it into a byte vector.
pub(crate) fn serialize(&self) -> Result<StorageValue, SerializationError> {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions crates/committer_cli/src/tests/python_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub(crate) fn example_test(test_args: HashMap<String, String>) -> 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))
}
Expand Down Expand Up @@ -430,8 +430,8 @@ pub(crate) fn storage_serialize_test() -> Result<String, PythonTestError> {
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);
}

Expand Down
Loading