Skip to content
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

Add missing methods to lambdaworks implementation #1290

Merged
merged 6 commits into from Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion felt/Cargo.toml
Expand Up @@ -19,7 +19,7 @@ lazy_static = { version = "1.4.0", default-features = false, features = [
"spin_no_std",
] }
serde = { version = "1.0", features = ["derive"], default-features = false }
lambdaworks-math = { version = "0.1.1", default-features = false, optional=true }
lambdaworks-math = { version = "0.1.1", default-features = false, optional = true }

[dev-dependencies]
proptest = "1.1.0"
Expand Down
6 changes: 6 additions & 0 deletions felt/src/lib_bigint_felt.rs
Expand Up @@ -142,11 +142,14 @@
pub fn new<T: Into<Felt252>>(value: T) -> Self {
value.into()
}

#[deprecated]
pub fn modpow(&self, exponent: &Felt252, modulus: &Felt252) -> Self {
Self {
value: self.value.modpow(&exponent.value, &modulus.value),
}
}

pub fn iter_u64_digits(&self) -> U64Digits {
self.value.iter_u64_digits()
}
Expand Down Expand Up @@ -184,10 +187,13 @@
}

#[cfg(any(feature = "std", feature = "alloc"))]
#[deprecated]
pub fn to_signed_bytes_le(&self) -> Vec<u8> {
// NOTE: this is unsigned

Check warning on line 192 in felt/src/lib_bigint_felt.rs

View check run for this annotation

Codecov / codecov/patch

felt/src/lib_bigint_felt.rs#L192

Added line #L192 was not covered by tests
self.value.to_signed_bytes_le()
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[deprecated]
pub fn to_bytes_be(&self) -> Vec<u8> {
self.value.to_bytes_be()
}
Expand Down
21 changes: 21 additions & 0 deletions felt/src/lib_lambdaworks.rs
Expand Up @@ -189,10 +189,31 @@ impl Felt252 {
value.into()
}

#[deprecated]
pub fn modpow(&self, exponent: &Felt252, modulus: &Felt252) -> Self {
Self::from(
self.to_biguint()
.modpow(&exponent.to_biguint(), &modulus.to_biguint()),
)
}

pub fn iter_u64_digits(&self) -> impl Iterator<Item = u64> {
self.value.representative().limbs.into_iter().rev()
}

#[cfg(any(feature = "std", feature = "alloc"))]
#[deprecated]
pub fn to_signed_bytes_le(&self) -> Vec<u8> {
// NOTE: this is unsigned
self.to_biguint().to_bytes_le()
}

#[cfg(any(feature = "std", feature = "alloc"))]
#[deprecated]
pub fn to_bytes_be(&self) -> Vec<u8> {
self.to_be_bytes().to_vec()
}

pub fn to_le_bytes(&self) -> [u8; 32] {
// TODO: upstream should return array
let mut bytes = [0; 32];
Expand Down