Skip to content

Commit

Permalink
fix: remove unused dependencies and files
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Nov 3, 2023
1 parent f174d1d commit b313077
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 73 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions starknet-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ starknet-ff = { version = "0.3.5", path = "../starknet-ff", default-features = f
base64 = { version = "0.21.0", default-features = false, features = ["alloc"] }
flate2 = { version = "1.0.25", optional = true }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
num-bigint = { version = "0.4.3", default-features = false }
num-traits = { version = "0.2.15", default-features = false }
serde = { version = "1.0.160", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.96", default-features = false, features = ["alloc", "raw_value"] }
serde_json_pythonic = { version = "0.1.2", default-features = false, features = ["alloc", "raw_value"] }
Expand Down
71 changes: 2 additions & 69 deletions starknet-core/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use alloc::{string::String, vec::Vec};
use alloc::string::String;

use crate::{crypto::compute_hash_on_elements, types::FieldElement};

use num_bigint::BigUint;
use num_traits::identities::One;
use sha3::{Digest, Keccak256};
use starknet_crypto::pedersen_hash;

Expand Down Expand Up @@ -42,9 +40,6 @@ pub struct UdcUniqueSettings {
mod errors {
use core::fmt::{Display, Formatter, Result};

#[derive(Debug)]
pub struct U256OutOfRange;

#[derive(Debug)]
pub struct NonAsciiNameError;

Expand All @@ -69,15 +64,6 @@ mod errors {
}
}

#[cfg(feature = "std")]
impl std::error::Error for U256OutOfRange {}

impl Display for U256OutOfRange {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "u256 out of range")
}
}

#[cfg(feature = "std")]
impl std::error::Error for CairoShortStringToFeltError {}

Expand Down Expand Up @@ -106,9 +92,7 @@ mod errors {
}
}
}
pub use errors::{
CairoShortStringToFeltError, NonAsciiNameError, ParseCairoShortStringError, U256OutOfRange,
};
pub use errors::{CairoShortStringToFeltError, NonAsciiNameError, ParseCairoShortStringError};

/// A variant of eth-keccak that computes a value that fits in a Starknet field element.
pub fn starknet_keccak(data: &[u8]) -> FieldElement {
Expand Down Expand Up @@ -239,33 +223,9 @@ pub fn normalize_address(address: FieldElement) -> FieldElement {
address % ADDR_BOUND
}

#[allow(clippy::vec_init_then_push)]
pub fn biguint_to_felts(v: BigUint) -> Result<Vec<FieldElement>, U256OutOfRange> {
// TODO: is it better to have the following code for u256->Vec<FieldElement> in utils.rs?
let u128_max_plus_1: BigUint = BigUint::one() << 128;

let high = &v / &u128_max_plus_1;

if high >= u128_max_plus_1 {
return Err(U256OutOfRange);
}

let low = &v % &u128_max_plus_1;

// Unwrapping is safe as these are never out of range
let high = FieldElement::from_byte_slice_be(&high.to_bytes_be()).unwrap();
let low = FieldElement::from_byte_slice_be(&low.to_bytes_be()).unwrap();

let mut u256 = Vec::new();
u256.push(low);
u256.push(high);
Ok(u256)
}

#[cfg(test)]
mod tests {
use super::*;
use num_traits::Num;

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
Expand Down Expand Up @@ -527,31 +487,4 @@ mod tests {
address
);
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_u256_to_felts() {
let v = BigUint::from_str_radix(
"7d56f59fe6cce2fd0620a4b1cce69c488acac84670c38053ffec3763a2eec09d",
16,
)
.unwrap();

let felts = biguint_to_felts(v).unwrap();

assert!(
felts[0]
== FieldElement::from_hex_be(
"0x000000000000000000000000000000008acac84670c38053ffec3763a2eec09d"
)
.unwrap()
);
assert!(
felts[1]
== FieldElement::from_hex_be(
"0x000000000000000000000000000000007d56f59fe6cce2fd0620a4b1cce69c48"
)
.unwrap()
);
}
}

0 comments on commit b313077

Please sign in to comment.