Skip to content
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
5 changes: 2 additions & 3 deletions crates/starknet-types-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description = "Core types representation for Starknet"
readme = "README.md"

[dependencies]
lambdaworks-math = { version = "0.7.0", default-features = false }
lambdaworks-math = { version = "0.10.0", default-features = false }
num-traits = { version = "0.2.18", default-features = false }
num-bigint = { version = "0.4.4", default-features = false }
num-integer = { version = "0.1.45", default-features = false }
Expand All @@ -21,7 +21,7 @@ arbitrary = { version = "1.3.2", optional = true }
serde = { version = "1.0.197", optional = true, default-features = false, features = [
"alloc",
] }
lambdaworks-crypto = { version = "0.7.0", default-features = false, optional = true }
lambdaworks-crypto = { version = "0.10.0", default-features = false, optional = true }
parity-scale-codec = { version = "3.6.9", default-features = false, optional = true }
lazy_static = { version = "1.4.0", default-features = false, optional = true }

Expand Down Expand Up @@ -57,4 +57,3 @@ lazy_static = { version = "1.4.0", default-features = false }
[[bench]]
name = "criterion_hashes"
harness = false

54 changes: 4 additions & 50 deletions crates/starknet-types-core/src/felt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(test)]
mod felt_arbitrary;
mod primitive_conversions;

use core::ops::{Add, Mul, Neg};
use core::str::FromStr;
Expand Down Expand Up @@ -38,13 +39,14 @@ use lambdaworks_math::{
#[cfg(feature = "arbitrary")]
use arbitrary::{self, Arbitrary, Unstructured};

#[repr(transparent)]
/// Definition of the Field Element type.
#[repr(transparent)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Felt(pub(crate) FieldElement<Stark252PrimeField>);

/// A non-zero [Felt].
#[derive(Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord)]
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NonZeroFelt(FieldElement<Stark252PrimeField>);

impl NonZeroFelt {
Expand Down Expand Up @@ -533,33 +535,6 @@ impl TryFrom<&Felt> for NonZeroFelt {
}
}

impl From<u128> for Felt {
fn from(value: u128) -> Felt {
Self(FieldElement::from(&UnsignedInteger::from(value)))
}
}

impl From<i128> for Felt {
fn from(value: i128) -> Felt {
let mut res = Self(FieldElement::from(&UnsignedInteger::from(
value.unsigned_abs(),
)));
if value.is_negative() {
res = -res;
}
res
}
}

impl From<bool> for Felt {
fn from(value: bool) -> Felt {
match value {
true => Felt::ONE,
false => Felt::ZERO,
}
}
}

impl From<&BigInt> for Felt {
fn from(bigint: &BigInt) -> Felt {
let (sign, bytes) = bigint.to_bytes_le();
Expand Down Expand Up @@ -595,27 +570,6 @@ impl From<BigUint> for Felt {
}
}

macro_rules! impl_from {
($from:ty, $with:ty) => {
impl From<$from> for Felt {
fn from(value: $from) -> Self {
(value as $with).into()
}
}
};
}

impl_from!(u8, u128);
impl_from!(u16, u128);
impl_from!(u32, u128);
impl_from!(u64, u128);
impl_from!(usize, u128);
impl_from!(i8, i128);
impl_from!(i16, i128);
impl_from!(i32, i128);
impl_from!(i64, i128);
impl_from!(isize, i128);

impl FromStr for Felt {
type Err = FromStrError;

Expand Down
Loading
Loading