From b313077dfaf63205fb2b535392b20b5371eb10c9 Mon Sep 17 00:00:00 2001 From: glihm Date: Fri, 3 Nov 2023 13:13:29 -0600 Subject: [PATCH] fix: remove unused dependencies and files --- Cargo.lock | 2 -- starknet-core/Cargo.toml | 2 -- starknet-core/src/utils.rs | 71 ++------------------------------------ 3 files changed, 2 insertions(+), 73 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 41436d96..895d3e16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1693,8 +1693,6 @@ dependencies = [ "criterion", "flate2", "hex", - "num-bigint", - "num-traits", "serde", "serde_json", "serde_json_pythonic", diff --git a/starknet-core/Cargo.toml b/starknet-core/Cargo.toml index d88f6e55..fa0a9073 100644 --- a/starknet-core/Cargo.toml +++ b/starknet-core/Cargo.toml @@ -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"] } diff --git a/starknet-core/src/utils.rs b/starknet-core/src/utils.rs index 8b97b77e..d5e9a377 100644 --- a/starknet-core/src/utils.rs +++ b/starknet-core/src/utils.rs @@ -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; @@ -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; @@ -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 {} @@ -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 { @@ -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, U256OutOfRange> { - // TODO: is it better to have the following code for u256->Vec 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)] @@ -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() - ); - } }